/** * Starts TensorFlow cluster. */ private void startCluster() { TensorFlowCluster cluster = clusterMgr.createCluster( clusterId, jobArchive, str -> ignite.message().sendOrdered("us_out_" + clusterId, str, 60 * 1000), str -> ignite.message().sendOrdered("us_err_" + clusterId, str, 60 * 1000) ); ignite.message().send(topicName, Optional.of(cluster)); }
/** * Stops TensorFlow cluster. * * @param terminate Terminate TensorFlow cluster and notify all listeners that cluster won't be started again. */ private void stopCluster(boolean terminate) { clusterMgr.stopClusterIfExists(clusterId); if (terminate) ignite.message().send(topicName, Optional.empty()); }
/** {@inheritDoc} */ @Override public boolean apply(Event evt) { try { int[] res = new int[] { System.identityHashCode(getClass().getClassLoader()) }; ignite.message(ignite.cluster().forRemotes()).send(null, res); } catch (IgniteException e) { throw new RuntimeException(e); } return true; } }
/** {@inheritDoc} */ @Override public boolean apply(Event evt) { try { int[] res = new int[] { System.identityHashCode(getClass().getClassLoader()) }; ignite.message(ignite.cluster().forRemotes()).send(null, res); } catch (IgniteException e) { throw new RuntimeException(e); } return true; } }
@Override public Object call() throws Exception { ignite1.message().send(null, Collections.emptyList()); return null; } }, IllegalArgumentException.class, "Ouch! Argument is invalid: msgs cannot be null or empty");
@Override public Object call() throws Exception { ignite1.message().send(null, null); return null; } }, IllegalArgumentException.class, "Ouch! Argument is invalid: msgs cannot be null or empty");
@Override public Object call() throws Exception { ignite1.message().send(null, (Object)null); return null; } }, NullPointerException.class, "Ouch! Argument cannot be null: msg");
@Override public Object call() throws Exception { ignite1.message().send(null, Arrays.asList(null, new Object())); return null; } }, NullPointerException.class, "Ouch! Argument cannot be null: msg");
@Override public Boolean apply(Object o) { assertNotNull(o); IgniteMessaging msg = client.message(); msg.send(null, "Test message."); try { assertTrue(recvLatch.await(2, SECONDS)); } catch (InterruptedException ignored) { fail("Message wasn't received."); } return true; } }
/** * @param nodeSnd Sender Ignite node. * @param grp Cluster group. * @param msg Message. * @param async Async message send flag. */ private void sendMessage(Ignite nodeSnd, ClusterGroup grp, Object msg, boolean async) { if (async) nodeSnd.message(grp).withAsync().send(MESSAGE_TOPIC, msg); else nodeSnd.message(grp).send(MESSAGE_TOPIC, msg); }
/** * Sends optional message. If message is {@code null} - it's no-op. * * @param nodeId ID of the node to send message to. * @param respMsg Message to send. * @throws IgniteException Thrown in case of any errors. */ private void send(UUID nodeId, @Nullable Object respMsg) throws IgniteException { assert nodeId != null; if (respMsg != null) { ClusterNode node = ignite.cluster().node(nodeId); if (node != null) ignite.message(ignite.cluster().forNode(node)).send(null, respMsg); // Can still fail. else throw new IgniteException("Failed to send message since destination node has " + "left topology (ignoring) [nodeId=" +nodeId + ", respMsg=" + respMsg + ']'); } }
/** {@inheritDoc} */ @Override public boolean apply(UUID nodeId, String msg) { ignite.message(ignite.cluster().forNodeId(nodeId)).send(TOPIC.ORDERED, msg); return true; } }
/** * * @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); } }
/** * @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); } }
/** * @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()); } }
/** * 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); } }
/** * @param nodes Nodes to send message to. * @param cntr Counter. */ private void sendMessage(Collection<ClusterNode> nodes, int cntr) { try { message(ignite.cluster().forNodes(nodes)).send(null, new GridTestCommunicationMessage(cntr, ignite.cluster().localNode().id())); } catch (IgniteException e) { error("Failed to send message.", e); } }
/** * @throws Exception If failed. */ @Test public void testMessaging() throws Exception { IgniteConfiguration cfg = optimize(getConfiguration("g1")); try (Ignite g1 = G.start(cfg)) { IgniteMessaging messaging = message(grid().cluster().forNode(g1.cluster().localNode())); messaging.send(null, "test"); GridMarshallerTestBean inBean = newTestBean(messaging); byte[] buf = marshal(inBean); GridMarshallerTestBean outBean = unmarshal(buf); assert inBean.getObjectField() != null; assert outBean.getObjectField() != null; assert inBean.getObjectField().getClass().equals(IgniteMessagingImpl.class); assert outBean.getObjectField().getClass().equals(IgniteMessagingImpl.class); assert inBean != outBean; assert inBean.equals(outBean); ClusterGroup inPrj = messaging.clusterGroup(); ClusterGroup outPrj = ((IgniteMessaging)outBean.getObjectField()).clusterGroup(); assert inPrj.getClass().equals(outPrj.getClass()); assert F.eqNotOrdered(inPrj.nodes(), outPrj.nodes()); outBean.checkNullResources(); } }
/** * @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); } }