Hazelcast request in custom objects

I use Hazelcast as a shared card in my application. My card is as follows:

Map<String, MyObject> 

and MyObject :

 class MyObject implements Serializeble { // Map FieldName -> FieldValue Map<String, Object> myMap; } 

Therefore, I would like to use Hazelcast support for the request in my object. I verified that Hazelcast uses the get method to retrieve the value of the object, but in my case I do not have get, instead I would like to implement my own getField as:

 Object getField(String fieldName) { return myMap[fieldName]; } 

And get Hazelcast to call this method. As a workaround, I cracked the Hazelcast code to use CustomGetter in the class

 /hazelcast/src/main/java/com/hazelcast/query/impl/ReflectionHelper.java 

line 144:

 if (localGetter == null) { localGetter = new CustomFieldGetter(name, obj); } 

and here is My CustomFieldGetter class:

 static class CustomFieldGetter extends Getter { final Object value; final Class type; final String fieldName; CustomFieldGetter(String fieldName, Object obj) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { super(null); this.fieldName = fieldName; this.value = obj.getClass().getMethod("getField", String.class).invoke(obj, fieldName); this.type = value.getClass(); } @Override Object getValue(Object obj) throws Exception { return value; } @Override Class getReturnType() { return type; } @Override boolean isCacheable() { return false; } @Override public String toString() { return "FieldGetter [parent=" + parent + ", field=" + fieldName + "]"; } } 

Well, after recompiling Hazelcast, and using this new jar, I could get queries using simple sql. But for pagingQueries, I got some errors.

So my last question is: I would like to avoid hacking the Hazelcast code (for future updates). Does Hazelcast have some support on this issue? Is there any other solution for this problem?

PS: I am using the Hazelcast version β†’ hazelcast-3.3-RC3

Thanks in advance.

+6
source share
1 answer

one option is to implement a Portable interface. Then you can write each entry as a separate field. This assumes that the value of the record also implements the Portable interface.

Take a look at the sample code on how to use Portable.

+3
source

Source: https://habr.com/ru/post/974553/


All Articles