Ignite client and server message interaction analysis

Extracted two classes, one is requested, the result is a

  1. GridJobExecuteRequest
  2. GridJobExecuteResponse

First, a request from the
class org.apache.ignite.internal.processors.task.GridTaskWorker, there is a method sendRequest
see the following code

                 //如果是本地,则直接执行
                  if (loc)
                        //这个虽然是本地调用, 猜测在远程服务器也是这个方法,后面开始寻找消息的流转
                        ctx.job().processJobExecuteRequest(ctx.discovery().localNode(), req);
                    else {
                        byte plc;

                        if (internal)
                            plc = MANAGEMENT_POOL;
                        else {
                            Byte ctxPlc = getThreadContext(TC_IO_POLICY);

                            if (ctxPlc != null)
                                plc = ctxPlc;
                            else
                                plc = PUBLIC_POOL;
                        }

                        // Send job execution request.
                        //如果是远程,发关到GridTopic, 这个topic名字叫  TOPIC_JOB
                        ctx.io().sendToGridTopic(node, TOPIC_JOB, req, plc);

                        if (log.isDebugEnabled())
                            log.debug("Sent job request [req=" + req + ", node=" + node + ']');
                    }

This method sendToGridTopic class org.apache.ignite.internal.managers.communication.GridIoManager located in
the Annotated this class, mainly communication processing Grid

send method

   /**
     * @param node Destination node.
     * @param topic Topic to send the message to.
     * @param topicOrd GridTopic enumeration ordinal.
     * @param msg Message to send.
     * @param plc Type of processing.
     * @param ordered Ordered flag.
     * @param timeout Timeout.
     * @param skipOnTimeout Whether message can be skipped on timeout.
     * @param ackC Ack closure.
     * @param async If {@code true} message for local node will be processed in pool, otherwise in current thread.
     * @throws IgniteCheckedException Thrown in case of any errors.
     */
    private void send(
        ClusterNode node,
        Object topic,
        int topicOrd,
        Message msg,
        byte plc,
        boolean ordered,
        long timeout,
        boolean skipOnTimeout,
        IgniteInClosure<IgniteException> ackC,
        boolean async
    ) throws IgniteCheckedException {
        assert node != null;
        assert topic != null;
        assert msg != null;
        assert !async || msg instanceof GridIoUserMessage : msg; // Async execution was added only for IgniteMessaging.
        assert topicOrd >= 0 || !(topic instanceof GridTopic) : msg;

         //封装成 GridIoMessage
        GridIoMessage ioMsg = new GridIoMessage(plc, topic, topicOrd, msg, ordered, timeout, skipOnTimeout);

//如果是本地节点,直接处理
        if (locNodeId.equals(node.id())) {
            assert plc != P2P_POOL;

            CommunicationListener commLsnr = this.commLsnr;

            if (commLsnr == null)
                throw new IgniteCheckedException("Trying to send message when grid is not fully started.");

            if (ordered)
                processOrderedMessage(locNodeId, ioMsg, plc, null);
            else if (async)
                processRegularMessage(locNodeId, ioMsg, plc, NOOP);
            else
                processRegularMessage0(ioMsg, locNodeId);

            if (ackC != null)
                ackC.apply(null);
        }
        else {
            if (topicOrd < 0)
                ioMsg.topicBytes(U.marshal(marsh, topic));

            try {
            //通过spi发送消息
                if ((CommunicationSpi)getSpi() instanceof TcpCommunicationSpi)
                    ((TcpCommunicationSpi)(CommunicationSpi)getSpi()).sendMessage(node, ioMsg, ackC);
                else
                    getSpi().sendMessage(node, ioMsg);
            }
            catch (IgniteSpiException e) {
                if (e.getCause() instanceof ClusterTopologyCheckedException)
                    throw (ClusterTopologyCheckedException)e.getCause();

                if (!ctx.discovery().alive(node))
                    throw new ClusterTopologyCheckedException("Failed to send message, node left: " + node.id(), e);

                throw new IgniteCheckedException("Failed to send message (node may have left the grid or " +
                    "TCP connection cannot be established due to firewall issues) " +
                    "[node=" + node + ", topic=" + topic +
                    ", msg=" + msg + ", policy=" + plc + ']', e);
            }
        }
    }

GridTcpNioCommunicationClient in sendMessage final call to
call ses.sendNoFuture (msg, c) after;

ses an instance of the implementation class GridNioSessionImpl of GridNioSession

chain().onSessionWrite(this, msg, false, ackC);

tail.onSessionWrite(ses, msg, fut, ackC);

Here is a variety of the Write filter
GridNioServer.onSessionWrite
GridNioCodecFilter.onSessionWrite

GridConnectionBytesVerifyFilter

GridNioServer.send0

The final message is to put

DirectNioClientWorker.offer

Continued unfinished

Guess you like

Origin blog.csdn.net/gs80140/article/details/89400194