final Endpoint endpoint = this.endpointValue.getOptionalValue();
if(ejbRemoteConnectorService == null || endpoint == null) {
return;
}
final List<EJBRemoteConnectorService.EjbListenerAddress> listeningAddresses = ejbRemoteConnectorService.getListeningAddresses();
final ClusterContext clusterContext = ejbClientContext.getOrCreateClusterContext(clusterName);
// add the nodes to the cluster context
for (Map.Entry<String, List<ClientMapping>> entry : addedNodes.entrySet()) {
final String addedNodeName = entry.getKey();
// if the current node is being added, then let the local receiver handle it
if (LocalEjbReceiver.this.getNodeName().equals(addedNodeName)) {
clusterContext.addClusterNodes(new LocalClusterNodeManager());
continue;
}
// if the EJB client context is the default server level EJB client context
// which can only handle local receiver and no remote receivers (due to lack of configurations
// to connect to them), then skip that context
if (this.isLocalOnlyEJBClientContext(ejbClientContext)) {
logger.debugf("Skipping cluster node additions to EJB client context %s since it can only handle local node", ejbClientContext);
continue;
}
// find a matching client mapping for our bind address
final List<ClientMapping> clientMappings = entry.getValue();
ClientMapping resolvedClientMapping = null;
for (final ClientMapping clientMapping : clientMappings) {
final InetAddress sourceNetworkAddress = clientMapping.getSourceNetworkAddress();
final int netMask = clientMapping.getSourceNetworkMaskBits();
for(EJBRemoteConnectorService.EjbListenerAddress binding : listeningAddresses) {
final boolean match = NetworkUtil.belongsToNetwork(binding.getAddress().getAddress(), sourceNetworkAddress, (byte) (netMask & 0xff));
if (match) {
resolvedClientMapping = clientMapping;
logger.debugf("Client mapping %s matches client address %s", clientMapping, binding.getAddress().getAddress());
break;
}
}
if(resolvedClientMapping != null) {
break;
}
}
if (resolvedClientMapping == null) {
EjbLogger.ROOT_LOGGER.cannotAddClusterNodeDueToUnresolvableClientMapping(addedNodeName, clusterName, listeningAddresses);
continue;
}
final ClusterNodeManager remotingClusterNodeManager = new RemotingConnectionClusterNodeManager(clusterContext, endpoint, addedNodeName, resolvedClientMapping.getDestinationAddress(), resolvedClientMapping.getDestinationPort(), ejbRemoteConnectorService.getProtocol());
clusterContext.addClusterNodes(remotingClusterNodeManager);
}
}