我正在创建一个自定义谓词。它需要一个整数并将其与map的值进行比较。
public class LocationPredicate implements Predicate<Key, Portable> {
private int rssi;
public LocationPredicate() {
}
public LocationPredicate(int rssi) {
this.rssi = rssi;
}
@Override
public boolean apply(Entry<Key, Aortable> arg0) {
return false;
//int val = arg0.getValue().getData().getLocation().getRssiVal();
//return (rssi == val ) ;
}
}
当我运行程序时,我收到以下错误:
Exception in thread "main" com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.ClassNotFoundException: com.snmpapp.main.LocationPredicate
at com.hazelcast.internal.serialization.impl.JavaDefaultSerializers$JavaSerializer.read(JavaDefaultSerializers.java:224)
at com.hazelcast.internal.serialization.impl.StreamSerializerAdapter.read(StreamSerializerAdapter.java:48)
at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toObject(AbstractSerializationService.java:184)
at com.hazelcast.client.impl.protocol.task.map.MapAggregateWithPredicateMessageTask.getPredicate(MapAggregateWithPredicateMessageTask.java:45)
at com.hazelcast.client.impl.protocol.task.map.AbstractMapQueryMessageTask.call(AbstractMapQueryMessageTask.java:87)
at com.hazelcast.client.impl.protocol.task.AbstractCallableMessageTask.processMessage(AbstractCallableMessageTask.java:35)
at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.initializeAndProcessMessage(AbstractMessageTask.java:123)
at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.run(AbstractMessageTask.java:103)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at com.hazelcast.util.executor.HazelcastManagedThread.executeRun(HazelcastManagedThread.java:64)
at com.hazelcast.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:80)
at ------ submitted from ------.(Unknown Source)
at com.hazelcast.client.spi.impl.ClientInvocationFuture.resolveAndThrowIfException(ClientInvocationFuture.java:95)
at com.hazelcast.client.spi.impl.ClientInvocationFuture.resolveAndThrowIfException(ClientInvocationFuture.java:32)
at com.hazelcast.spi.impl.AbstractInvocationFuture.get(AbstractInvocationFuture.java:155)
at com.hazelcast.client.spi.ClientProxy.invoke(ClientProxy.java:172)
at com.hazelcast.client.proxy.ClientMapProxy.aggregate(ClientMapProxy.java:1356)
at com.snmpapp.main.Main.main(Main.java:370)
Caused by: java.lang.ClassNotFoundException: com.aruba.acp.snmpapp.main.LocationPredicate
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.hazelcast.nio.ClassLoaderUtil.tryLoadClass(ClassLoaderUtil.java:149)
at com.hazelcast.nio.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:123)
at com.hazelcast.nio.IOUtil$ClassLoaderAwareObjectInputStream.resolveClass(IOUtil.java:522)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1613)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1518)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1774)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
at com.hazelcast.internal.serialization.impl.JavaDefaultSerializers$JavaSerializer.read(JavaDefaultSerializers.java:219)
at com.hazelcast.internal.serialization.impl.StreamSerializerAdapter.read(StreamSerializerAdapter.java:48)
at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toObject(AbstractSerializationService.java:184)
at com.hazelcast.client.impl.protocol.task.map.MapAggregateWithPredicateMessageTask.getPredicate(MapAggregateWithPredicateMessageTask.java:45)
at com.hazelcast.client.impl.protocol.task.map.AbstractMapQueryMessageTask.call(AbstractMapQueryMessageTask.java:87)
at com.hazelcast.client.impl.protocol.task.AbstractCallableMessageTask.processMessage(AbstractCallableMessageTask.java:35)
at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.initializeAndProcessMessage(AbstractMessageTask.java:123)
at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.run(AbstractMessageTask.java:103)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at com.hazelcast.util.executor.HazelcastManagedThread.executeRun(HazelcastManagedThread.java:64)
at com.hazelcast.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:80)
我有点困惑。我是否需要在服务器上创建谓词?我作为Hcast客户端运行,客户端正在创建谓词。
据我所知,在创建谓词时,它会作为序列化对象发送到hazelcast服务器。
另外,我尝试将Predicate实现为Serializable,但它没有帮助。 感谢
答案 0 :(得分:1)
我对Hazelcast没有经验,但据我所知,在序列化和反序列化期间,您可以传输状态(在这种情况下是成员变量)但不是行为(您实际应用apply方法)。不知何故(我对这项技术没有经验)你应该为Hazelcast的类加载器提供你的类(也许复制到类路径)。祝你好运!
答案 1 :(得分:0)
该类需要位于所有节点的类路径上。