/** * Connect to a remote node if appropriate * * @param bootstrap the client bootstrap object * @param n the node to connect to */ protected void doNodeConnect(ClusterNode n) { if (!shutDown && n.getNodeId() < syncManager.getLocalNodeId()) { Short nodeId = n.getNodeId(); synchronized (connections) { NodeConnection c = connections.get(n.getNodeId()); if (c == null) { connections.put(nodeId, c = new NodeConnection()); } if (logger.isTraceEnabled()) { logger.trace( "[{}->{}] Connection state: {}", new Object[] {syncManager.getLocalNodeId(), nodeId, c.state}); } if (c.state.equals(NodeConnectionState.NONE)) { if (logger.isDebugEnabled()) { logger.debug( "[{}->{}] Attempting connection {} {}", new Object[] {syncManager.getLocalNodeId(), nodeId, n.getHostname(), n.getPort()}); } SocketAddress sa = new InetSocketAddress(n.getHostname(), n.getPort()); c.pendingFuture = clientBootstrap.connect(sa); c.pendingFuture.addListener(new ConnectCFListener(n)); c.state = NodeConnectionState.PENDING; } } } }
/** * Add the node connection to the node connection map * * @param nodeId the node ID for the channel * @param channel the new channel */ protected void nodeConnected(short nodeId, Channel channel) { logger.debug("[{}->{}] Connection established", syncManager.getLocalNodeId(), nodeId); synchronized (connections) { NodeConnection c = connections.get(nodeId); if (c == null) { connections.put(nodeId, c = new NodeConnection()); } c.nodeChannel = channel; c.state = NodeConnectionState.CONNECTED; } clusterManager.connectionStateChange(); }