/** * Starts the remote listener. * @param reader Reader. * @param messaging Messaging. * @return Listen id. */ private UUID startRemoteListen(BinaryRawReaderEx reader, IgniteMessaging messaging) { Object nativeFilter = reader.readObjectDetached(); long ptr = reader.readLong(); // interop pointer Object topic = reader.readObjectDetached(); PlatformMessageFilter filter = platformCtx.createRemoteMessageFilter(nativeFilter, ptr); return messaging.remoteListen(topic, filter); }
@Override public Object call() throws Exception { boolean failed = false; try { client.message().remoteListen(null, new IgniteBiPredicate<UUID, Object>() { @Override public boolean apply(UUID uuid, Object o) { if (o.equals("Test message.")) recvLatch.countDown(); return true; } }); } catch (IgniteClientDisconnectedException e) { failed = true; checkAndWait(e); } assertTrue(failed); return client.message().remoteListen(null, new IgniteBiPredicate<UUID, Object>() { @Override public boolean apply(UUID uuid, Object o) { if (o.equals("Test message.")) recvLatch.countDown(); return true; } }); } },
/** * @param grp Cluster group. * @return Message listener uuid. * @throws Exception If failed. */ private UUID registerListener(ClusterGroup grp) throws Exception { Ignite ignite = grid(SERVER_NODE_IDX); IgniteBiPredicate<UUID,Object> lsnr = new MessageListener(); return ignite.message(grp).remoteListen(MESSAGE_TOPIC, lsnr); }
/** * @param prj Projection. * @param topic Topic. * @param ret Value returned from listener. * @throws Exception In case of error. */ private void listen(final ClusterGroup prj, @Nullable Object topic, final boolean ret) throws Exception { assert prj != null; message(prj).remoteListen(topic, new Listener(grid(0).localNode().id(), ret)); }
/** * @throws Exception If failed. */ @Test public void testNonNullTopicWithDeployment() throws Exception { ClassLoader ldr = getExternalClassLoader(); Class<?> topicCls = ldr.loadClass(TOPIC_CLS_NAME); Class<?> lsnrCls = ldr.loadClass(LSNR_CLS_NAME); Object topic = topicCls.newInstance(); grid(0).message().remoteListen(topic, (IgniteBiPredicate<UUID, Object>)lsnrCls.newInstance()); send(topic); boolean s = GridTestUtils.waitForCondition(new PA() { @Override public boolean apply() { return checkDeployedListeners(GRID_CNT); } }, 2000); assertTrue(s); }
ignite2.message().remoteListen(S_TOPIC_1, new P2<UUID, Object>() { @Override public boolean apply(UUID nodeId, Object msg) { try {
ignite2.message().remoteListen(null, new P2<UUID, Object>() { @Override public boolean apply(UUID nodeId, Object msg) { try {
/** * @throws Exception If failed. */ @Test public void testNullTopicWithDeployment() throws Exception { Class<?> cls = getExternalClassLoader().loadClass(LSNR_CLS_NAME); grid(0).message().remoteListen(null, (IgniteBiPredicate<UUID, Object>)cls.newInstance()); send(); boolean s = GridTestUtils.waitForCondition(new PA() { @Override public boolean apply() { return checkDeployedListeners(GRID_CNT); } }, 2000); assertTrue(s); }
rmtMsg.remoteListen("MyOrderedTopic", new MessageListener()); rmtMsg.remoteListen(topic, new MessageListener());
/** * @param ignite Ignite. * @param grp Cluster group. * @throws Exception If fail. */ private void registerListenerAndSendOrderedMessages(Ignite ignite, ClusterGroup grp) throws Exception { int messages = MSGS; LATCH = new CountDownLatch(grp.nodes().size() * messages); UUID opId = ignite.message(grp).remoteListen(MESSAGE_TOPIC, new OrderedMessageListener()); try { for (int i=0; i < messages; i++) ignite.message(grp).sendOrdered(MESSAGE_TOPIC, value(i), 2000); assertTrue(LATCH.await(10, TimeUnit.SECONDS)); } finally { ignite.message().stopRemoteListen(opId); } }
/** * @throws Exception If failed. */ @Test public void testListenActor() throws Exception { latch = new CountDownLatch(MSG_CNT * (GRID_CNT + 1)); grid(0).message().remoteListen(null, new Actor(grid(0).localNode().id())); try { Ignite g = startGrid("anotherGrid"); send(); assert latch.await(2, SECONDS); Thread.sleep(500); assertEquals(MSG_CNT * (GRID_CNT + 1), cnt.get()); List<UUID> allNodes0 = new ArrayList<>(allNodes); allNodes0.add(g.cluster().localNode().id()); Collections.sort(allNodes0); checkNodes(allNodes0); } finally { stopGrid("anotherGrid"); } }
ignite2.message().remoteListen(S_TOPIC_1, new P2<UUID, Object>() { @Override public boolean apply(UUID nodeId, Object msg) { try {
/** * * @throws Exception If fail. */ private void collectionMessage() throws Exception { Ignite ignite = grid(SERVER_NODE_IDX); ClusterGroup grp = gridCount() > 1 ? ignite.cluster().forRemotes() : ignite.cluster().forLocal(); assert !grp.nodes().isEmpty(); int messages = MSGS; LATCH = new CountDownLatch(grp.nodes().size() * messages); UUID opId = ignite.message(grp).remoteListen(MESSAGE_TOPIC, new MessageListener()); try { List<Object> msgs = new ArrayList<>(); for (int i = 0; i < messages; i++) msgs.add(value(i)); ignite.message(grp).send(MESSAGE_TOPIC, msgs); assertTrue(LATCH.await(10, TimeUnit.SECONDS)); } finally { ignite.message().stopRemoteListen(opId); } }
/** * @throws Exception If failed. */ @Test public void testCustomEventAckNotSend() throws Exception { try { TestCustomerEventAckSpi spi0 = new TestCustomerEventAckSpi(); nodeSpi.set(spi0); Ignite ignite0 = startGrid(0); nodeSpi.set(new TestCustomerEventAckSpi()); Ignite ignite1 = startGrid(1); spi0.stopBeforeSndAck = true; ignite1.message().remoteListen("test", new DummyPredicate()); waitNodeStop(ignite0.name()); startGrid(2); } finally { stopAllGrids(); } }
/** * @param expOldestIgnite Expected oldest ignite. * @throws InterruptedException If failed. */ private void remoteListenForOldest(Ignite expOldestIgnite) throws InterruptedException { ClusterGroup grp = ignite1.cluster().forOldest(); assertEquals(1, grp.nodes().size()); assertEquals(expOldestIgnite.cluster().localNode().id(), grp.node().id()); ignite1.message(grp).remoteListen(null, new P2<UUID, Object>() { @Override public boolean apply(UUID nodeId, Object msg) { System.out.println("Received new message [msg=" + msg + ", senderNodeId=" + nodeId + ']'); MSG_CNT.incrementAndGet(); return true; } }); ignite1.message().send(null, MSG_1); Thread.sleep(3000); assertEquals(1, MSG_CNT.get()); } }
ignite2.message().remoteListen(null, new P2<UUID, Object>() { @Override public boolean apply(UUID nodeId, Object msg) { try {
/** * @throws Exception If failed. */ @Test public void testClientReconnectOnNetworkProblem() throws Exception { clientsPerSrv = 1; startServerNodes(3); startClientNodes(3); checkNodes(3, 3); setClientRouter(2, 0); srvFailedLatch = new CountDownLatch(2); clientFailedLatch = new CountDownLatch(3); attachListeners(2, 3); ((TcpDiscoverySpi)G.ignite("client-2").configuration().getDiscoverySpi()).brakeConnection(); G.ignite("client-2").message().remoteListen(null, new MessageListener()); // Send some discovery message. checkNodes(3, 3); }
g.message().remoteListen(null, new MessagingListenActor<String>() { @Override protected void receive(UUID nodeId, String rcvMsg) throws Throwable { if (hello.equals(rcvMsg)) {
/** * @param masterName Node name * @throws Exception If failed. */ private void testDataExchange(String masterName) throws Exception { startServerNodes(2); startClientNodes(2); checkNodes(2, 2); IgniteMessaging msg = grid(masterName).message(); UUID id = msg.remoteListen(null, new MessageListener()); try { msgLatch = new CountDownLatch(2); msg.send(null, "Message 1"); await(msgLatch); startServerNodes(1); startClientNodes(1); checkNodes(3, 3); msgLatch = new CountDownLatch(3); msg.send(null, "Message 2"); await(msgLatch); } finally { msg.stopRemoteListen(id); } }
/** * @throws Exception If failed. */ @Test public void testDataExchangeFromServer2() throws Exception { startServerNodes(2); IgniteMessaging msg = grid("server-1").message(); UUID id = msg.remoteListen(null, new MessageListener()); try { startClientNodes(1); assertEquals(G.ignite("server-0").cluster().localNode().id(), ((TcpDiscoveryNode) G.ignite("client-0").cluster().localNode()).clientRouterNodeId()); checkNodes(2, 1); msgLatch = new CountDownLatch(3); msg.send(null, "Message"); await(msgLatch); } finally { msg.stopRemoteListen(id); } }