/** * @param topic Listener's topic. * @param lsnr Listener to add. */ public void addMessageListener(GridTopic topic, GridMessageListener lsnr) { addMessageListener((Object)topic, lsnr); }
/** * Send IO message. * * @param nodeId Node ID. * @param msg Message. */ private void sendMessage(UUID nodeId, Message msg) throws IgniteCheckedException { ctx.io().sendToGridTopic(nodeId, TOPIC_CACHE_COORDINATOR, msg, SYSTEM_POOL); }
/** * @param topic Message topic. * @return Whether or not listener was indeed removed. */ public boolean removeMessageListener(Object topic) { return removeMessageListener(topic, null); }
/** * */ private void replaceWithStoppingMappingRequestListener(GridIoManager ioMgr, final int nodeIdToStop) { ioMgr.removeMessageListener(GridTopic.TOPIC_METADATA_REQ); ioMgr.addMessageListener(GridTopic.TOPIC_METADATA_REQ, new GridMessageListener() { @Override public void onMessage(UUID nodeId, Object msg, byte plc) { new Thread(new Runnable() { @Override public void run() { metadataReqsCounter.incrementAndGet(); stopGrid(nodeIdToStop, true); } }).start(); } }); }
/** * @param nodes Nodes. * @param payload Payload. * @param procFromNioThread If {@code true} message is processed from NIO thread. * @return Response future. */ public IgniteInternalFuture sendIoTest(List<ClusterNode> nodes, byte[] payload, boolean procFromNioThread) { long id = ioTestId.getAndIncrement(); IoTestFuture fut = new IoTestFuture(id, nodes.size()); IgniteIoTestMessage msg = new IgniteIoTestMessage(id, true, payload); msg.processFromNioThread(procFromNioThread); ioTestMap().put(id, fut); for (int i = 0; i < nodes.size(); i++) { ClusterNode node = nodes.get(i); try { sendToGridTopic(node, GridTopic.TOPIC_IO_TEST, msg, GridIoPolicy.SYSTEM_POOL); } catch (IgniteCheckedException e) { ioTestMap().remove(msg.id()); return new GridFinishedFuture(e); } } return fut; }
/** {@inheritDoc} */ @Override public void start(HadoopContext ctx) throws IgniteCheckedException { super.start(ctx); ctx.kernalContext().io().addMessageListener(GridTopic.TOPIC_HADOOP_MSG, new GridMessageListener() { @Override public void onMessage(UUID nodeId, Object msg, byte plc) { onMessageReceived(nodeId, (HadoopMessage)msg); } }); ctx.kernalContext().io().addUserMessageListener(GridTopic.TOPIC_HADOOP, new IgniteBiPredicate<UUID, Object>() { @Override public boolean apply(UUID nodeId, Object msg) { return onMessageReceived(nodeId, (HadoopMessage)msg); } }); }
/** * @param nodeId Node ID to send message to. * @param msg Message to send. * @throws IgniteCheckedException If send failed. */ private void send0(UUID nodeId, Object msg) throws IgniteCheckedException { ClusterNode node = ctx.kernalContext().discovery().node(nodeId); if (msg instanceof Message) ctx.kernalContext().io().sendToGridTopic(node, GridTopic.TOPIC_HADOOP_MSG, (Message)msg, GridIoPolicy.PUBLIC_POOL); else ctx.kernalContext().io().sendUserMessage(F.asList(node), msg, GridTopic.TOPIC_HADOOP, false, 0, false); }
sendOrderedMessageToGridTopic(nodes, TOPIC_COMM_USER, ioMsg, PUBLIC_POOL, timeout, true); else if (loc) { send(F.first(nodes), TOPIC_COMM_USER, TOPIC_COMM_USER.ordinal(), sendToGridTopic(rmtNodes, TOPIC_COMM_USER, ioMsg, PUBLIC_POOL); send(locNode, TOPIC_COMM_USER, TOPIC_COMM_USER.ordinal(),
startSpi(); getSpi().setListener(commLsnr = new CommunicationListener<Serializable>() { @Override public void onMessage(UUID nodeId, Serializable msg, IgniteRunnable msgC) { try { log.debug(startInfo()); addMessageListener(GridTopic.TOPIC_IO_TEST, new GridMessageListener() { @Override public void onMessage(UUID nodeId, Object msg, byte plc) { ClusterNode node = ctx.discovery().node(nodeId);
/** * Resets metrics for this manager. */ public void resetMetrics() { getSpi().resetMetrics(); }
@Override public Object call() throws Exception { new GridIoManager(ctx).sendToGridTopic(F.asList(locNode, rmtNode), GridTopic.TOPIC_CACHE, new TestMessage(), GridIoPolicy.P2P_POOL); return null; } }, AssertionError.class, "Internal Ignite code should never call the method with local node in a node list.");
/** * Implementation of send. * @param topic Topic. * @param msg Message. * @param async Async flag. * @throws IgniteException On error. */ private void send0(@Nullable Object topic, Object msg, boolean async) throws IgniteException { A.notNull(msg, "msg"); guard(); try { Collection<ClusterNode> snapshot = prj.nodes(); if (snapshot.isEmpty()) throw U.emptyTopologyException(); ctx.io().sendUserMessage(snapshot, msg, topic, false, 0, async); } catch (IgniteCheckedException e) { throw U.convertException(e); } finally { unguard(); } }
@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); }
processOrderedMessage(locNodeId, ioMsg, plc, null); else if (async) processRegularMessage(locNodeId, ioMsg, plc, NOOP); else processRegularMessage0(ioMsg, locNodeId); if ((CommunicationSpi)getSpi() instanceof TcpCommunicationSpi) ((TcpCommunicationSpi)(CommunicationSpi)getSpi()).sendMessage(node, ioMsg, ackC); else getSpi().sendMessage(node, ioMsg);
/** * @throws Exception If failed. */ @Test public void testSendUserMessageOrderedThickVersionIfOneOfNodesIsLocal() throws Exception { Object msg = new Object(); GridIoManager ioMgr = spy(new TestGridIoManager(ctx)); try { ioMgr.sendUserMessage(F.asList(locNode, rmtNode), msg, GridTopic.TOPIC_IGFS, true, 123L, false); } catch (Exception ignored) { // No-op. We are using mocks so real sending is impossible. } verify(ioMgr).sendOrderedMessageToGridTopic( argThat(new IsEqualCollection(F.asList(locNode, rmtNode))), eq(GridTopic.TOPIC_COMM_USER), any(GridIoUserMessage.class), eq(GridIoPolicy.PUBLIC_POOL), eq(123L), false); }
/** * @param nodes Nodes. * @param payload Message payload. * @param procFromNioThread If {@code true} message is processed from NIO thread. * @return Response future. */ public IgniteInternalFuture sendIoTest(List<ClusterNode> nodes, byte[] payload, boolean procFromNioThread) { return ctx.io().sendIoTest(nodes, payload, procFromNioThread); }
/** {@inheritDoc} */ @Override public RegisterStatus register(UUID nodeId, UUID routineId, final GridKernalContext ctx) throws IgniteCheckedException { ctx.io().addUserMessageListener(topic, pred); return RegisterStatus.REGISTERED; }
/** * @throws Exception If failed. */ @Test public void testStopCommunicationManager() throws Exception { CommunicationSpi spi = new TcpCommunicationSpi(); injectLogger(spi); ctx.config().setCommunicationSpi(spi); ctx.config().setMarshaller(new BinaryMarshaller()); GridIoManager mgr = new GridIoManager(ctx); mgr.onKernalStop(true); mgr.stop(false); }
/** * Get IO policy. * * @return IO policy. */ private static byte threadIoPolicy() { Byte plc = GridIoManager.currentPolicy(); if (plc == null) plc = DATA_STREAMER_POOL; return plc; }