TensorFlowClusterGateway gateway = getCluster(clusterId); ignite.message().localListen("us_out_" + clusterId, (node, msg) -> { out.accept(msg.toString()); return true; }); ignite.message().localListen("us_err_" + clusterId, (node, msg) -> { err.accept(msg.toString()); return true;
/** {@inheritDoc} */ @Override public Collection<? extends ComputeJob> split(int gridSize, Object arg) { ignite.message().localListen(null, new P2<UUID, Object>() { @Override public boolean apply(UUID uuid, Object o) { return stop.get(); } }); return Arrays.asList(new ComputeJobAdapter() { @Override public Object execute() { return null; } }); }
@Override public void apply() { message(grid(1).cluster().forNode(loc)).localListen(null, new IgniteBiPredicate<UUID, String>() { @Override public boolean apply(UUID uuid, String s) { log.info("Received test message [nodeId: " + uuid + ", s=" + s + ']'); ignite.countDownLatch("messagesPending", 1, false, true).countDown(); execCntr.incrementAndGet(); return false; } }); } });
/** * @param igniteMsg Ignite message. * @param msgs messages for send. * @param cls Callback for compare result. * @throws Exception If failed. */ private<T> void sendOrdered( final IgniteMessaging igniteMsg, final List<T> msgs, final IgniteBiInClosure<List<T>,List<Thread>> cls ) throws Exception { final CountDownLatch latch = new CountDownLatch(msgs.size()); final List<T> received = Lists.newArrayList(); final List<Thread> threads = Lists.newArrayList(); for (T msg : msgs) igniteMsg.sendOrdered(TOPIC, msg, 1000); igniteMsg.localListen(TOPIC, new IgniteBiPredicate<UUID, T>() { @Override public boolean apply(UUID uuid, T s) { received.add(s); threads.add(Thread.currentThread()); latch.countDown(); return true; } }); latch.await(); cls.apply(received, threads); }
/** * @param ignite2 Second node. * @param igniteMsg Ignite message. * @param msgStr Message string. * @param cls Callback for compare result. * @param async Use sendAsync flag. * @throws Exception If failed. */ private void sendWith2Nodes( final Ignite ignite2, final IgniteMessaging igniteMsg, final String msgStr, final IgniteBiInClosure<String, Thread> cls, final boolean async ) throws Exception { final CountDownLatch latch = new CountDownLatch(1); ignite2.message().localListen(TOPIC, new IgniteBiPredicate<UUID, String>() { @Override public boolean apply(UUID uuid, String msg) { Assert.assertEquals(msgStr, msg); latch.countDown(); return true; } }); send(igniteMsg, msgStr, cls, async); latch.await(); }
/** * @param ignite2 Second node. * @param igniteMsg Ignite message. * @param msgs messages for send. * @param cls Callback for compare result. * @throws Exception If failed. */ private void sendOrderedWith2Node( final Ignite ignite2, final IgniteMessaging igniteMsg, final List<String> msgs, final IgniteBiInClosure<List<String>, List<Thread>> cls ) throws Exception { final CountDownLatch latch = new CountDownLatch(msgs.size()); final List<String> received = Lists.newArrayList(); ignite2.message().localListen(TOPIC, new IgniteBiPredicate<UUID, String>() { @Override public boolean apply(UUID uuid, String msg) { received.add(msg); latch.countDown(); return true; } }); sendOrdered(igniteMsg, msgs, cls); latch.await(); assertTrue(msgs.equals(received)); }
ignite2.message().localListen(TOPIC, new IgniteBiPredicate<UUID, Message>() { @Override public boolean apply(UUID uuid, Message msg) { actlMsgNode2.putIfAbsent(msg.threadName, Lists.<String>newArrayList());
/** * Creates TensorFlow cluster gateway. * * @param topicName Topic name. * @return TensorFlow cluster gateway. */ private TensorFlowClusterGateway createTensorFlowClusterGateway(String topicName) { TensorFlowClusterGateway gateway = new TensorFlowClusterGateway(subscriber -> { ignite.message().stopLocalListen(topicName, subscriber); log.info("Stop listen to cluster gateway [topicName=" + topicName + "]"); }); ignite.message().localListen(topicName, gateway); log.info("Start listen to cluster gateway [topicName=" + topicName + "]"); return gateway; } }
final AtomicReference<String> val = new AtomicReference<>(); igniteMsg.localListen(TOPIC, new IgniteBiPredicate<UUID, String>() { @Override public boolean apply(UUID uuid, String msgStr) { thread.set(Thread.currentThread());
grid().message().localListen(null, new MessagingListenActor<String>() { @Override protected void receive(UUID nodeId, String rcvMsg) { System.out.println(Thread.currentThread().getName() + "# Received message: '" + rcvMsg + "'");
/** * @throws Exception If failed. */ @Test public void testPingPong() throws Exception { final AtomicInteger pingCnt = new AtomicInteger(); final AtomicInteger pongCnt = new AtomicInteger(); final CountDownLatch latch = new CountDownLatch(PING_PONG_STEPS); grid().message().localListen(null, new MessagingListenActor<String>() { @Override protected void receive(UUID nodeId, String rcvMsg) { System.out.println("Received message: '" + rcvMsg + "'"); if ("PING".equals(rcvMsg)) { pingCnt.incrementAndGet(); respond("PONG"); } else if ("PONG".equals(rcvMsg)) { pongCnt.incrementAndGet(); latch.countDown(); if (latch.getCount() > 0) respond("PING"); else stop(); } } }); grid().message().send(null, "PING"); latch.await(); assert pingCnt.intValue() == PING_PONG_STEPS; assert pongCnt.intValue() == PING_PONG_STEPS; }
/** * This is the workaround- as long as we keep a message listener in * the stack, our FIFO bug isn't exposed. Comment above out to see. */ @Test public void testOneListener() { Ignite ignite = G.ignite(getTestIgniteInstanceName()); final AtomicBoolean stop = new AtomicBoolean(); P2<UUID, Object> l = new P2<UUID, Object>() { @Override public boolean apply(UUID uuid, Object o) { return stop.get(); } }; try { ignite.message().localListen(null, l); checkLoop(2000); } finally { stop.set(true); } }
/** * * @throws Exception Thrown if failed. */ @Test public void testBasicFlow() throws Exception { final AtomicInteger cnt = new AtomicInteger(0); grid().message().localListen(null, new MessagingListenActor<String>() { @Override public void receive(UUID uuid, String rcvMsg) { if ("TEST".equals(rcvMsg)) { cnt.incrementAndGet(); // "Exit" after 1st message. // Should never receive any more messages. stop(); } else { assert false : "Unknown message: " + rcvMsg; stop(); } } }); grid().message().send(null, "TEST"); // This message we should receive. // Flood it. for (int i = 0; i < 100; i++) grid().message().send(null, "TEST"); // This message should be lost... Thread.sleep(2000); assert cnt.get() == 1 : "Count is " + cnt.get(); }
ignite1.message().localListen(null, new P2<UUID, Object>() { @Override public boolean apply(UUID nodeId, Object msg) { try {
/** * Works fine. */ @Test public void testDifferentListeners() { Ignite ignite = G.ignite(getTestIgniteInstanceName()); for (int i = 0; i < 2000; i++) { P2<UUID, Object> l = new P2<UUID, Object>() { @Override public boolean apply(UUID uuid, Object o) { return false; } }; ignite.message().localListen(null, l); } info(getName() + ": worked without exceptions."); }
ignite1.message().localListen(null, new MessagingListenActor<Object>() { @Override protected void receive(UUID nodeId, Object rcvMsg) throws Throwable { respond(rcvMsg); ignite2.message().localListen(null, new MessagingListenActor<Object>() { @Override protected void receive(UUID nodeId, Object rcvMsg) throws Throwable { evtLatch.countDown();
/** * Single server test with local listener. * @throws Exception If failed. */ private void localListenerInternal() throws Exception { int messages = MSGS; Ignite ignite = grid(SERVER_NODE_IDX); LATCH = new CountDownLatch(messages); ClusterGroup grp = grid(SERVER_NODE_IDX).cluster().forLocal(); MessageListener c = new MessageListener(); try { ignite.message(grp).localListen("localListenerTopic", c); for (int i = 0; i < messages; i++) ignite.message(grp).send("localListenerTopic", value(i)); assertTrue(LATCH.await(10, TimeUnit.SECONDS)); } finally { ignite.message().stopLocalListen("localListenerTopic", c); } }
final ClusterNode rmt = grid(1).localNode(); grid().message().localListen(null, new MessagingListenActor<String>() { @Override protected void receive(UUID nodeId, String rcvMsg) throws IgniteException { System.out.println("Local node received message: '" + rcvMsg + "'"); grid(1).message().localListen(null, new MessagingListenActor<String>() { @Override public void receive(UUID nodeId, String rcvMsg) { if ("RESPONSE".equals(rcvMsg)) {
g.message().localListen(null, new P2<UUID, String>() { @Override public boolean apply(UUID nodeId, String msg) { if (msg.equals(bye))
messaging.localListen(topic, filter);