我在我的应用程序中使用Hazelcast作为共享地图.我的地图是这样的:
Map<String, MyObject>
Run Code Online (Sandbox Code Playgroud)
并且MyObject:
class MyObject implements Serializeble {
// Map FieldName -> FieldValue
Map<String, Object> myMap;
}
Run Code Online (Sandbox Code Playgroud)
所以我想使用Hazelcast分布式查询支持在我的对象中查询.我已经检查过Hazelcast使用get的方法来检索对象值,但在我的情况下我没有得到,而不是我想实现我自己的getField:
Object getField(String fieldName) {
return myMap[fieldName];
}
Run Code Online (Sandbox Code Playgroud)
并强制Hazelcast称这种方法.作为一种解决方法,我已经破解了Hazelcast代码,以便在课堂上使用CustomGetter
/hazelcast/src/main/java/com/hazelcast/query/impl/ReflectionHelper.java
Run Code Online (Sandbox Code Playgroud)
第144行:
if (localGetter == null) {
localGetter = new CustomFieldGetter(name, obj);
}
Run Code Online (Sandbox Code Playgroud)
在这里我的CustomFieldGetter班级:
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", …Run Code Online (Sandbox Code Playgroud)