private Optional<ConsistentHash> updateMembershipForServiceInstance(ServiceInstance serviceInstance, AtomicReference<ConsistentHash> atomicConsistentHash) { if (logger.isDebugEnabled()) { logger.debug("Updating membership for service instance: [{}]", serviceInstance); } Member member = buildMember(serviceInstance); Optional<MessageRoutingInformation> optionalMessageRoutingInfo = getMessageRoutingInformation(serviceInstance); if (optionalMessageRoutingInfo.isPresent()) { MessageRoutingInformation messageRoutingInfo = optionalMessageRoutingInfo.get(); return Optional.of(atomicConsistentHash.updateAndGet( consistentHash -> consistentHash.with(member, messageRoutingInfo.getLoadFactor(), messageRoutingInfo.getCommandFilter(serializer)) )); } else { logger.info( "Black listed ServiceInstance [{}] under host [{}] and port [{}] since we could not retrieve the " + "required Message Routing Information from it.", serviceInstance.getServiceId(), serviceInstance.getHost(), serviceInstance.getPort() ); blackListedServiceInstances.add(serviceInstance); } return Optional.empty(); }
/** * Connects this Node to the cluster and shares membership details about this node with the other nodes in the * cluster. * <p> * The Join messages have been sent, but may not have been processed yet when the method returns. Before sending * messages via this connector, await for the joining process to be completed (see {@link #awaitJoined() and * {@link #awaitJoined(long, TimeUnit)}}. * * @throws Exception when an error occurs connecting or communicating with the cluster */ public void connect() throws Exception { if (channel.getClusterName() != null && !clusterName.equals(channel.getClusterName())) { throw new ConnectionFailedException("Already joined cluster: " + channel.getClusterName()); } channel.setReceiver(this); channel.connect(clusterName); Address localAddress = channel.getAddress(); String localName = localAddress.toString(); SimpleMember<Address> localMember = new SimpleMember<>(localName, localAddress, LOCAL_MEMBER, null); members.put(localAddress, new VersionedMember(localMember, membershipVersion.getAndIncrement())); updateConsistentHash(ch -> ch.with(localMember, loadFactor, commandFilter)); if (!executorProvided) { executorService = Executors.newCachedThreadPool(new AxonThreadFactory("JGroupsConnector - " + localName)); } }
/** * Connects this Node to the cluster and shares membership details about this node with the other nodes in the * cluster. * <p> * The Join messages have been sent, but may not have been processed yet when the method returns. Before sending * messages via this connector, await for the joining process to be completed (see {@link #awaitJoined() and * {@link #awaitJoined(long, TimeUnit)}}. * * @throws Exception when an error occurs connecting or communicating with the cluster */ public void connect() throws Exception { if (channel.getClusterName() != null && !clusterName.equals(channel.getClusterName())) { throw new ConnectionFailedException("Already joined cluster: " + channel.getClusterName()); } channel.setReceiver(this); channel.connect(clusterName); Address localAddress = channel.getAddress(); String localName = localAddress.toString(); SimpleMember<Address> localMember = new SimpleMember<>(localName, localAddress, LOCAL_MEMBER, null); members.put(localAddress, new VersionedMember(localMember, membershipVersion.getAndIncrement())); updateConsistentHash(ch -> ch.with(localMember, loadFactor, commandFilter)); if (!executorProvided) { executorService = Executors.newCachedThreadPool(new AxonThreadFactory("JGroupsConnector - " + localName)); } }
return; updateConsistentHash(ch -> ch.with(member, loadFactor, commandFilter));
return; updateConsistentHash(ch -> ch.with(member, loadFactor, commandFilter));