use of org.apache.ignite.spi.communication.tcp.internal.TcpConnectionIndexAwareMessage 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();
}
}
}
Aggregations