/** * 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 rsrcName Resource to undeploy. * @param rmtNodes Nodes to send request to. * @throws IgniteCheckedException If request could not be sent. */ void sendUndeployRequest(String rsrcName, Collection<ClusterNode> rmtNodes) throws IgniteCheckedException { assert !rmtNodes.contains(ctx.discovery().localNode()); Message req = new GridDeploymentRequest(null, null, rsrcName, true); if (!rmtNodes.isEmpty()) { ctx.io().sendToGridTopic( rmtNodes, TOPIC_CLASSLOAD, req, GridIoPolicy.P2P_POOL); } }
/** * @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; }
/** */ private void sendProbe(UUID destNodeId, GridCacheVersion initiatorVer, Collection<ProbedTx> waitChain, ProbedTx blocker, boolean near) { DeadlockProbe probe = new DeadlockProbe(initiatorVer, waitChain, blocker, near); if (log.isDebugEnabled()) log.debug("Sending probe [probe=" + probe + ", destNode=" + destNodeId + ']'); try { cctx.gridIO().sendToGridTopic(destNodeId, TOPIC_DEADLOCK_DETECTION, probe, SYSTEM_POOL); } catch (ClusterTopologyCheckedException ignored) { } catch (IgniteCheckedException e) { log.warning("Failed to send a deadlock probe [nodeId=" + destNodeId + ']', e); } }
@Override public void apply(IgniteInternalFuture<Void> future) { try { if (node.isLocal()) h2.reduceQueryExecutor().onMessage(ctx.localNodeId(), msg); else ctx.io().sendToGridTopic(node, GridTopic.TOPIC_QUERY, msg, QUERY_POOL); } catch (Exception e) { U.error(log, e); } } });
/** * Sends message accounting for local and remote nodes. * * @param nodes Nodes to receive event. * @param topic Topic to send the message to. * @param msg Event to be sent. * @param plc Type of processing. * @throws IgniteCheckedException If sending failed. */ private void sendMessage(Collection<? extends ClusterNode> nodes, GridTopic topic, GridEventStorageMessage msg, byte plc) throws IgniteCheckedException { ClusterNode locNode = F.find(nodes, null, F.localNode(ctx.localNodeId())); Collection<? extends ClusterNode> rmtNodes = F.view(nodes, F.remoteNodes(ctx.localNodeId())); if (locNode != null) ctx.io().sendToGridTopic(locNode, topic, msg, plc); if (!rmtNodes.isEmpty()) { msg.responseTopicBytes(U.marshal(marsh, msg.responseTopic())); ctx.io().sendToGridTopic(rmtNodes, topic, msg, plc); } }
/** * @param msg Finish message. */ private void sendFinish(UserManagementOperationFinishedMessage msg) { try { ctx.io().sendToGridTopic(coordinator(), GridTopic.TOPIC_AUTH, msg, GridIoPolicy.SYSTEM_POOL); } catch (Exception e) { U.error(log, "Failed to send UserManagementOperationFinishedMessage [op=" + msg.operationId() + ", node=" + coordinator() + ", err=" + msg.errorMessage() + ']', e); } }
/** * @throws Exception If failed. */ @Test public void testSendUserMessageUnorderedThickVersionIfOneOfNodesIsLocal() throws Exception { Object msg = new Object(); GridIoManager ioMgr = spy(new TestGridIoManager(ctx)); try { ioMgr.sendUserMessage(F.asList(locNode, rmtNode), msg, GridTopic.TOPIC_IGFS, false, 123L, false); } catch (IgniteCheckedException ignored) { // No-op. We are using mocks so real sending is impossible. } verify(ioMgr).sendToGridTopic(eq(locNode), eq(GridTopic.TOPIC_COMM_USER), any(GridIoUserMessage.class), eq(GridIoPolicy.PUBLIC_POOL)); Collection<? extends ClusterNode> rmtNodes = F.view(F.asList(rmtNode), F.remoteNodes(locNode.id())); verify(ioMgr).sendToGridTopic(argThat(new IsEqualCollection(rmtNodes)), eq(GridTopic.TOPIC_COMM_USER), any(GridIoUserMessage.class), eq(GridIoPolicy.PUBLIC_POOL)); }
/** * @throws Exception If failed. */ @Test public void testSendUserMessageThinVersionIfOneOfNodesIsLocal() throws Exception { Object msg = new Object(); GridIoManager ioMgr = spy(new TestGridIoManager(ctx)); try { ioMgr.sendUserMessage(F.asList(locNode, rmtNode), msg, null, false, 0, false); } catch (IgniteCheckedException ignored) { // No-op. We are using mocks so real sending is impossible. } verify(ioMgr).sendToGridTopic(eq(locNode), eq(GridTopic.TOPIC_COMM_USER), any(GridIoUserMessage.class), eq(GridIoPolicy.PUBLIC_POOL)); Collection<? extends ClusterNode> rmtNodes = F.view(F.asList(rmtNode), F.remoteNodes(locNode.id())); verify(ioMgr).sendToGridTopic(argThat(new IsEqualCollection(rmtNodes)), eq(GridTopic.TOPIC_COMM_USER), any(GridIoUserMessage.class), eq(GridIoPolicy.PUBLIC_POOL)); }
/** * @param node Node. * @param reqId Request ID. * @param segmentId Index segment ID. */ private void sendRetry(ClusterNode node, long reqId, int segmentId, String retryCause) { try { boolean loc = node.isLocal(); GridQueryNextPageResponse msg = new GridQueryNextPageResponse(reqId, segmentId, /*qry*/0, /*page*/0, /*allRows*/0, /*cols*/1, loc ? null : Collections.<Message>emptyList(), loc ? Collections.<Value[]>emptyList() : null, false); msg.retry(h2.readyTopologyVersion()); msg.retryCause(retryCause); if (loc) h2.reduceQueryExecutor().onMessage(ctx.localNodeId(), msg); else ctx.io().sendToGridTopic(node, GridTopic.TOPIC_QUERY, msg, QUERY_POOL); } catch (Exception e) { U.warn(log, "Failed to send retry message: " + e.getMessage()); } }
@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.");
/** * @param nodeId Target node ID. * @param c Message closure. * @return Message future. */ private IgniteInternalFuture<IgniteDiagnosticInfo> sendDiagnosticMessage(UUID nodeId, IgniteClosure<GridKernalContext, IgniteDiagnosticInfo> c) { try { IgniteDiagnosticMessage msg = IgniteDiagnosticMessage.createRequest(marsh, c, diagFutId.getAndIncrement()); InternalDiagnosticFuture fut = new InternalDiagnosticFuture(nodeId, msg.futureId()); diagnosticFuturesMap().put(msg.futureId(), fut); ctx.io().sendToGridTopic(nodeId, TOPIC_INTERNAL_DIAGNOSTIC, msg, GridIoPolicy.SYSTEM_POOL); return fut; } catch (Exception e) { U.error(diagnosticLog, "Failed to send diagnostic message: " + e); return new GridFinishedFuture<>(new IgniteDiagnosticInfo("Failed to send diagnostic message: " + e)); } }
/** * @param node Node. * @param qryReqId Query request ID. * @param err Error. */ private void sendError(ClusterNode node, long qryReqId, Throwable err) { try { GridQueryFailResponse msg = new GridQueryFailResponse(qryReqId, err); if (node.isLocal()) { U.error(log, "Failed to run map query on local node.", err); h2.reduceQueryExecutor().onMessage(ctx.localNodeId(), msg); } else ctx.io().sendToGridTopic(node, GridTopic.TOPIC_QUERY, msg, QUERY_POOL); } catch (Exception e) { e.addSuppressed(err); U.error(log, "Failed to send error message.", e); } }
/** * @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); }
/** * @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); }
/** * Constructor. * * @param latchUid Latch uid. * @param participants Participant nodes. */ ServerLatch(CompletableLatchUid latchUid, Collection<ClusterNode> participants) { super(latchUid, participants); this.permits = new AtomicInteger(participants.size()); // Send final acks when latch is completed. this.complete.listen(f -> { for (ClusterNode node : participants) { try { if (discovery.alive(node)) { io.sendToGridTopic(node, GridTopic.TOPIC_EXCHANGE, new LatchAckMessage(id, topVer, true), GridIoPolicy.SYSTEM_POOL); if (log.isDebugEnabled()) log.debug("Final ack has sent [latch=" + latchId() + ", to=" + node.id() + "]"); } } catch (IgniteCheckedException e) { if (log.isDebugEnabled()) log.debug("Failed to send final ack [latch=" + latchId() + ", to=" + node.id() + "]: " + e.getMessage()); } } }); }
/** {@inheritDoc} */ @Override public void onMessage(UUID nodeId, Object msg, byte plc) { assert msg instanceof MissingMappingRequestMessage : msg; MissingMappingRequestMessage msg0 = (MissingMappingRequestMessage) msg; byte platformId = msg0.platformId(); int typeId = msg0.typeId(); String resolvedClsName = marshallerCtx.resolveMissedMapping(platformId, typeId); try { ioMgr.sendToGridTopic( nodeId, TOPIC_MAPPING_MARSH, new MissingMappingResponseMessage(platformId, typeId, resolvedClsName), SYSTEM_POOL); } catch (ClusterTopologyCheckedException e) { if (log.isDebugEnabled()) log.debug("Failed to send missing mapping response, node failed: " + nodeId); } catch (IgniteCheckedException e) { U.error(log, "Failed to send missing mapping response.", e); } } }
/** */ private void sendGenerateEncryptionKeyRequest(GenerateEncryptionKeyFuture fut) throws IgniteCheckedException { ClusterNode rndNode = U.randomServerNode(ctx); if (rndNode == null) throw new IgniteCheckedException("There is no node to send GenerateEncryptionKeyRequest to"); GenerateEncryptionKeyRequest req = new GenerateEncryptionKeyRequest(fut.keyCount()); fut.id(req.id()); fut.nodeId(rndNode.id()); ctx.io().sendToGridTopic(rndNode.id(), TOPIC_GEN_ENC_KEY, req, SYSTEM_POOL); }
/** * Sends ack to coordinator node. * There is ack deduplication on coordinator. So it's fine to send same ack twice. */ private void sendAck() { try { ackSent = true; io.sendToGridTopic(coordinator, GridTopic.TOPIC_EXCHANGE, new LatchAckMessage(id, topVer, false), GridIoPolicy.SYSTEM_POOL); if (log.isDebugEnabled()) log.debug("Ack has sent [latch=" + latchId() + ", to=" + coordinator.id() + "]"); } catch (IgniteCheckedException e) { // Coordinator is unreachable. On coodinator node left discovery event ack will be resent. if (log.isDebugEnabled()) log.debug("Failed to send ack [latch=" + latchId() + ", to=" + coordinator.id() + "]: " + e.getMessage()); } }
/** * @param nodeId Node ID. * @param msg Message. */ private void onAuthenticateRequestMessage(UUID nodeId, UserAuthenticateRequestMessage msg) { UserAuthenticateResponseMessage respMsg; try { User u = authenticateOnServer(msg.name(), msg.password()); respMsg = new UserAuthenticateResponseMessage(msg.id(), null); } catch (IgniteCheckedException e) { respMsg = new UserAuthenticateResponseMessage(msg.id(), e.toString()); e.printStackTrace(); } try { ctx.io().sendToGridTopic(nodeId, GridTopic.TOPIC_AUTH, respMsg, GridIoPolicy.SYSTEM_POOL); } catch (IgniteCheckedException e) { U.error(log, "Unexpected exception on send UserAuthenticateResponseMessage.", e); } }