Search in sources :

Example 1 with NodeUnreachableException

use of org.apache.ignite.spi.communication.tcp.internal.NodeUnreachableException in project ignite by apache.

the class TcpCommunicationSpi method sendMessage0.

/**
 * @param node Destination node.
 * @param msg Message to send.
 * @param ackC Ack closure.
 * @throws org.apache.ignite.spi.IgniteSpiException Thrown in case of any error during sending the message. Note
 * that this is not guaranteed that failed communication will result in thrown exception as this is dependant on SPI
 * implementation.
 */
private void sendMessage0(ClusterNode node, Message msg, IgniteInClosure<IgniteException> ackC) throws IgniteSpiException {
    assert node != null;
    assert msg != null;
    IgniteLogger log = this.log;
    if (log != null && log.isTraceEnabled())
        log.trace("Sending message with ack to node [node=" + node + ", msg=" + msg + ']');
    if (stateProvider.isLocalNodeDisconnected()) {
        throw new IgniteSpiException("Failed to send a message to remote node because local node has " + "been disconnected [rmtNodeId=" + node.id() + ']');
    }
    ClusterNode locNode = getLocalNode();
    if (locNode == null)
        throw new IgniteSpiException("Local node has not been started or fully initialized " + "[isStopping=" + getSpiContext().isStopping() + ']');
    if (node.id().equals(locNode.id()))
        notifyListener(node.id(), msg, NOOP);
    else {
        GridCommunicationClient client = null;
        int connIdx;
        Message connIdxMsg = msg instanceof GridIoMessage ? ((GridIoMessage) msg).message() : msg;
        if (connIdxMsg instanceof TcpConnectionIndexAwareMessage) {
            int msgConnIdx = ((TcpConnectionIndexAwareMessage) connIdxMsg).connectionIndex();
            connIdx = msgConnIdx == UNDEFINED_CONNECTION_INDEX ? connPlc.connectionIndex() : msgConnIdx;
        } else
            connIdx = connPlc.connectionIndex();
        try {
            boolean retry;
            do {
                client = clientPool.reserveClient(node, connIdx);
                UUID nodeId = null;
                if (!client.async())
                    nodeId = node.id();
                retry = client.sendMessage(nodeId, msg, ackC);
                client.release();
                if (retry) {
                    clientPool.removeNodeClient(node.id(), client);
                    ClusterNode node0 = getSpiContext().node(node.id());
                    if (node0 == null)
                        throw new IgniteCheckedException("Failed to send message to remote node " + "(node has left the grid): " + node.id());
                }
                client = null;
            } while (retry);
        } catch (Throwable t) {
            if (stopping)
                throw new IgniteSpiException("Node is stopping.", t);
            // connection attempt fails as well.
            if (!(t instanceof NodeUnreachableException))
                log.error("Failed to send message to remote node [node=" + node + ", msg=" + msg + ']', t);
            if (t instanceof Error)
                throw (Error) t;
            if (t instanceof RuntimeException)
                throw (RuntimeException) t;
            throw new IgniteSpiException("Failed to send message to remote node: " + node, t);
        } finally {
            if (client != null && clientPool.removeNodeClient(node.id(), client))
                client.forceClose();
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) TcpConnectionIndexAwareMessage(org.apache.ignite.spi.communication.tcp.internal.TcpConnectionIndexAwareMessage) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) TcpConnectionIndexAwareMessage(org.apache.ignite.spi.communication.tcp.internal.TcpConnectionIndexAwareMessage) NodeUnreachableException(org.apache.ignite.spi.communication.tcp.internal.NodeUnreachableException) GridCommunicationClient(org.apache.ignite.internal.util.nio.GridCommunicationClient) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteLogger(org.apache.ignite.IgniteLogger) UUID(java.util.UUID)

Aggregations

UUID (java.util.UUID)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteLogger (org.apache.ignite.IgniteLogger)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 GridIoMessage (org.apache.ignite.internal.managers.communication.GridIoMessage)1 GridCommunicationClient (org.apache.ignite.internal.util.nio.GridCommunicationClient)1 Message (org.apache.ignite.plugin.extensions.communication.Message)1 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)1 NodeUnreachableException (org.apache.ignite.spi.communication.tcp.internal.NodeUnreachableException)1 TcpConnectionIndexAwareMessage (org.apache.ignite.spi.communication.tcp.internal.TcpConnectionIndexAwareMessage)1