/** * @param nodeId Id of destination node. * @param topic Topic to send the message to. * @param msg Message to send. * @param plc Type of processing. * @throws IgniteCheckedException Thrown in case of any errors. */ public void sendToCustomTopic(UUID nodeId, Object topic, Message msg, byte plc) throws IgniteCheckedException { ClusterNode node = ctx.discovery().node(nodeId); if (node == null) throw new ClusterTopologyCheckedException("Failed to send message to node (has node left grid?): " + nodeId); sendToCustomTopic(node, topic, msg, plc); }
@Override public void send(ClusterNode node, Serializable msg, String topic) throws IgniteSpiException { A.notNull(node, "node"); A.notNull(msg, "msg"); A.notNull(topic, "topic"); try { if (msg instanceof Message) ctx.io().sendToCustomTopic(node, topic, (Message)msg, SYSTEM_POOL); else ctx.io().sendUserMessage(Collections.singletonList(node), msg, topic, false, 0, false); } catch (IgniteCheckedException e) { throw unwrapException(e); } }
/** {@inheritDoc} */ @Override public void run() { try { ClusterNode dst = awaitOther(g.context().discovery()); GridIoManager io = g.context().io(); Random rnd = ThreadLocalRandom.current(); IgniteUuid msgId = IgniteUuid.randomUuid(); while (!Thread.interrupted()) { CountDownLatch latch = null; if (testLatency) latches.put(msgId, latch = new CountDownLatch(1)); else sem.acquire(); io.sendToCustomTopic( dst, TEST_TOPIC, new GridTestMessage(msgId, testHeavyMsgs ? arrs[rnd.nextInt(arrs.length)] : null), PUBLIC_POOL); if (testLatency && !latch.await(1000, MILLISECONDS)) throw new RuntimeException("Failed to await latch."); } } catch (IgniteCheckedException e) { e.printStackTrace(); } catch (InterruptedException ignored) { // No-op. } }
/** * @param nodeId Node ID. * @param topic Topic. * @param msg Message. * @param plc Policy. * @throws IgniteCheckedException In case of error. */ public void send(UUID nodeId, Object topic, IgfsCommunicationMessage msg, byte plc) throws IgniteCheckedException { if (!kernalContext().localNodeId().equals(nodeId)) msg.prepareMarshal(kernalContext().config().getMarshaller()); if (topic instanceof GridTopic) kernalContext().io().sendToGridTopic(nodeId, (GridTopic)topic, msg, plc); else kernalContext().io().sendToCustomTopic(nodeId, topic, msg, plc); }
/** * @param nodeId Node ID. * @param resTopic Response topic. * @param reqId Request ID. * @param err Error. * @param forceLocDep Force local deployment. */ private void sendResponse(UUID nodeId, Object resTopic, long reqId, @Nullable Throwable err, boolean forceLocDep) { byte[] errBytes; try { errBytes = err != null ? U.marshal(marsh, err) : null; } catch (Exception e) { U.error(log, "Failed to marshal error [err=" + err + ", marshErr=" + e + ']', e); errBytes = marshErrBytes; } DataStreamerResponse res = new DataStreamerResponse(reqId, errBytes, forceLocDep); try { ctx.io().sendToCustomTopic(nodeId, resTopic, res, threadIoPolicy()); } catch (IgniteCheckedException e) { if (ctx.discovery().alive(nodeId)) U.error(log, "Failed to respond to node [nodeId=" + nodeId + ", res=" + res + ']', e); else if (log.isDebugEnabled()) log.debug("Node has left the grid: " + nodeId); } }
@Override public void onMessage(UUID nodeId, Object msg, byte plc) { if (node == null) node = g.context().discovery().node(nodeId); GridTestMessage testMsg = ((GridTestMessage)msg); testMsg.bytes(null); try { io.sendToCustomTopic(node, TEST_TOPIC, testMsg, PUBLIC_POOL); } catch (IgniteCheckedException e) { e.printStackTrace(); } } };
/** * @param msg Message to send. * @param msgCls Message class to check the received message. * * @throws Exception If failed. */ private void doSend(Message msg, final Class<?> msgCls) throws Exception { GridIoManager mgr0 = grid(0).context().io(); GridIoManager mgr1 = grid(1).context().io(); String topic = "test-topic"; final CountDownLatch latch = new CountDownLatch(SAMPLE_CNT); mgr1.addMessageListener(topic, new GridMessageListener() { @Override public void onMessage(UUID nodeId, Object msg, byte plc) { if (msgCls.isInstance(msg)) latch.countDown(); } }); long time = System.nanoTime(); for (int i = 1; i <= SAMPLE_CNT; i++) { mgr0.sendToCustomTopic(grid(1).localNode(), topic, msg, GridIoPolicy.PUBLIC_POOL); if (i % 500 == 0) info("Sent messages count: " + i); } assert latch.await(3, SECONDS); time = System.nanoTime() - time; info(">>>"); info(">>> send() time (ms): " + MILLISECONDS.convert(time, NANOSECONDS)); info(">>>"); }
ctx.io().sendToCustomTopic(nodeId, topic, res, SYSTEM_POOL);
ctx.io().sendToCustomTopic(nodeId, topic, new GridJobSiblingsResponse( loc ? siblings : null,
/** * @param nodeId Destination node ID. * @param topic Response topic. * @param res Response. */ private void sendResponse(UUID nodeId, Object topic, Message res) { ClusterNode node = ctx.discovery().node(nodeId); if (node != null) { try { ctx.io().sendToCustomTopic(node, topic, res, GridIoPolicy.P2P_POOL); if (log.isDebugEnabled()) log.debug("Sent peer class loading response [node=" + node.id() + ", res=" + res + ']'); } catch (ClusterTopologyCheckedException e) { if (log.isDebugEnabled()) log.debug("Failed to send peer class loading response to node " + "(node does not exist): " + nodeId); } catch (IgniteCheckedException e) { if (ctx.discovery().pingNodeNoError(nodeId)) U.error(log, "Failed to send peer class loading response to node: " + nodeId, e); else if (log.isDebugEnabled()) log.debug("Failed to send peer class loading response to node " + "(node does not exist): " + nodeId); } } else if (log.isDebugEnabled()) log.debug("Failed to send peer class loading response to node " + "(node does not exist): " + nodeId); }
((IgniteKernal)ignite).context().cache().context().gridIO().sendToCustomTopic( ((IgniteKernal)client).localNode(), TOPIC, msg, GridIoPolicy.PUBLIC_POOL);
/** * @throws Exception If failed. */ @Test public void testBrokenMessage() throws Exception { startGrids(GRID_CNT); try { IgniteKernal kernal = (IgniteKernal)ignite(0); UUID nodeId = ignite(1).cluster().localNode().id(); // This should trigger a failure in a NIO thread. kernal.context().io().sendToCustomTopic(nodeId, GridTopic.TOPIC_CACHE.topic("cache"), new BrokenMessage(), (byte)0); for (int i = 0; i < 100; i++) ignite(0).cache("cache").put(i, i); } finally { stopAllGrids(); } }
ctx.io().sendToCustomTopic(node, req.responseTopic(), res, PUBLIC_POOL);
mgr0.sendToCustomTopic(grid(1).localNode(), topic, msg, GridIoPolicy.PUBLIC_POOL);
/** * @param nodeId Id of destination node. * @param topic Topic to send the message to. * @param msg Message to send. * @param plc Type of processing. * @throws IgniteCheckedException Thrown in case of any errors. */ public void sendToCustomTopic(UUID nodeId, Object topic, Message msg, byte plc) throws IgniteCheckedException { ClusterNode node = ctx.discovery().node(nodeId); if (node == null) throw new ClusterTopologyCheckedException("Failed to send message to node (has node left grid?): " + nodeId); sendToCustomTopic(node, topic, msg, plc); }
@Override public void send(ClusterNode node, Serializable msg, String topic) throws IgniteSpiException { A.notNull(node, "node"); A.notNull(msg, "msg"); A.notNull(topic, "topic"); try { if (msg instanceof Message) ctx.io().sendToCustomTopic(node, topic, (Message)msg, SYSTEM_POOL); else ctx.io().sendUserMessage(Collections.singletonList(node), msg, topic, false, 0, false); } catch (IgniteCheckedException e) { throw unwrapException(e); } }
/** * @param nodeId Node ID. * @param topic Topic. * @param msg Message. * @param plc Policy. * @throws IgniteCheckedException In case of error. */ public void send(UUID nodeId, Object topic, IgfsCommunicationMessage msg, byte plc) throws IgniteCheckedException { if (!kernalContext().localNodeId().equals(nodeId)) msg.prepareMarshal(kernalContext().config().getMarshaller()); if (topic instanceof GridTopic) kernalContext().io().sendToGridTopic(nodeId, (GridTopic)topic, msg, plc); else kernalContext().io().sendToCustomTopic(nodeId, topic, msg, plc); }
/** * @param nodeId Node ID. * @param resTopic Response topic. * @param reqId Request ID. * @param err Error. * @param forceLocDep Force local deployment. */ private void sendResponse(UUID nodeId, Object resTopic, long reqId, @Nullable Throwable err, boolean forceLocDep) { byte[] errBytes; try { errBytes = err != null ? U.marshal(marsh, err) : null; } catch (Exception e) { U.error(log, "Failed to marshal error [err=" + err + ", marshErr=" + e + ']', e); errBytes = marshErrBytes; } DataStreamerResponse res = new DataStreamerResponse(reqId, errBytes, forceLocDep); try { ctx.io().sendToCustomTopic(nodeId, resTopic, res, threadIoPolicy()); } catch (IgniteCheckedException e) { if (ctx.discovery().alive(nodeId)) U.error(log, "Failed to respond to node [nodeId=" + nodeId + ", res=" + res + ']', e); else if (log.isDebugEnabled()) log.debug("Node has left the grid: " + nodeId); } }
ctx.io().sendToCustomTopic(nodeId, topic, res, SYSTEM_POOL);
/** * @param nodeId Destination node ID. * @param topic Response topic. * @param res Response. */ private void sendResponse(UUID nodeId, Object topic, Message res) { ClusterNode node = ctx.discovery().node(nodeId); if (node != null) { try { ctx.io().sendToCustomTopic(node, topic, res, GridIoPolicy.P2P_POOL); if (log.isDebugEnabled()) log.debug("Sent peer class loading response [node=" + node.id() + ", res=" + res + ']'); } catch (ClusterTopologyCheckedException e) { if (log.isDebugEnabled()) log.debug("Failed to send peer class loading response to node " + "(node does not exist): " + nodeId); } catch (IgniteCheckedException e) { if (ctx.discovery().pingNodeNoError(nodeId)) U.error(log, "Failed to send peer class loading response to node: " + nodeId, e); else if (log.isDebugEnabled()) log.debug("Failed to send peer class loading response to node " + "(node does not exist): " + nodeId); } } else if (log.isDebugEnabled()) log.debug("Failed to send peer class loading response to node " + "(node does not exist): " + nodeId); }