Ignite事件侦听器注册错误

时间:2017-11-08 09:14:53

标签: events listener ignite

我正在尝试在Apache上实现一个远程侦听器,但由于某种原因,注册似乎失败了,请使用以下代码。

IgniteMessaging message = ignite.message(ignite.cluster());
message.remoteListen("topic1", new IgniteBiPredicate<UUID, String>() {

    @Override
    public boolean apply(UUID e1, String e2) {
        System.out.println("message received" + e2);
        return true;
    }
    });

但是我在注册时遇到以下错误。

&#13;
&#13;
Exception in thread "main" class org.apache.ignite.spi.IgniteSpiException: Failed to marshal custom event: StartRoutineDiscoveryMessage [startReqData=StartRequestData [prjPred=AlwaysTruePredicate [], clsName=null, depInfo=null, hnd=GridMessageListenHandler [pred=independent.messaging.Receiver$1@e24ddd0, clsName=null, depInfo=null, depEnabled=false], bufSize=1, interval=0, autoUnsubscribe=false], keepBinary=false, routineId=13f09f06-4ebe-4cc8-9671-54162472df15]
	at org.apache.ignite.spi.discovery.tcp.ServerImpl.sendCustomEvent(ServerImpl.java:773)
	at org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi.sendCustomEvent(TcpDiscoverySpi.java:453)
	at org.apache.ignite.internal.managers.discovery.GridDiscoveryManager.sendCustomEvent(GridDiscoveryManager.java:2090)
	at org.apache.ignite.internal.processors.continuous.GridContinuousProcessor.startRoutine(GridContinuousProcessor.java:748)
	at org.apache.ignite.internal.IgniteMessagingImpl.remoteListen(IgniteMessagingImpl.java:212)
	at independent.messaging.Receiver.listenForMessages(Receiver.java:71)
	at independent.messaging.Receiver.main(Receiver.java:55)
Caused by: class org.apache.ignite.IgniteCheckedException: Failed to serialize object: StartRoutineDiscoveryMessage [startReqData=StartRequestData [prjPred=AlwaysTruePredicate [], clsName=null, depInfo=null, hnd=GridMessageListenHandler [pred=independent.messaging.Receiver$1@e24ddd0, clsName=null, depInfo=null, depEnabled=false], bufSize=1, interval=0, autoUnsubscribe=false], keepBinary=false, routineId=13f09f06-4ebe-4cc8-9671-54162472df15]
	at org.apache.ignite.marshaller.jdk.JdkMarshaller.marshal0(JdkMarshaller.java:85)
	at org.apache.ignite.marshaller.AbstractNodeNameAwareMarshaller.marshal(AbstractNodeNameAwareMarshaller.java:70)
	at org.apache.ignite.marshaller.jdk.JdkMarshaller.marshal0(JdkMarshaller.java:99)
	at org.apache.ignite.marshaller.AbstractNodeNameAwareMarshaller.marshal(AbstractNodeNameAwareMarshaller.java:58)
	at org.apache.ignite.internal.util.IgniteUtils.marshal(IgniteUtils.java:9815)
	at org.apache.ignite.spi.discovery.tcp.ServerImpl.sendCustomEvent(ServerImpl.java:769)
	... 6 more
Caused by: java.io.NotSerializableException: independent.messaging.Receiver
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)
	at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
	at org.apache.ignite.internal.GridMessageListenHandler.writeExternal(GridMessageListenHandler.java:244)
	at java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1459)
	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1430)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
	at org.apache.ignite.internal.processors.continuous.StartRequestData.writeExternal(StartRequestData.java:241)
	at java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1459)
	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1430)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
	at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
	at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
	at org.apache.ignite.marshaller.jdk.JdkMarshaller.marshal0(JdkMarshaller.java:80)
	... 11 more
&#13;
&#13;
&#13;

出现此错误的可能原因是什么?

1 个答案:

答案 0 :(得分:2)

您的IgniteBiPredicate将被序列化并发送到其他节点,因此,在您的情况下,由于此类是匿名的,外部类也将被序列化。

我建议使用此实现为谓词创建私有静态类,并创建它的实例作为remoteListen方法的参数