use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class MembershipManager method createMember.
private MemberImpl createMember(MemberInfo memberInfo, Map<String, String> attributes) {
Address address = memberInfo.getAddress();
Address thisAddress = node.getThisAddress();
String ipV6ScopeId = thisAddress.getScopeId();
address.setScopeId(ipV6ScopeId);
boolean localMember = thisAddress.equals(address);
MemberImpl.Builder builder;
if (memberInfo.getAddressMap() != null && memberInfo.getAddressMap().containsKey(MEMBER)) {
builder = new MemberImpl.Builder(memberInfo.getAddressMap());
} else {
builder = new MemberImpl.Builder(memberInfo.getAddress());
}
return builder.version(memberInfo.getVersion()).localMember(localMember).uuid(memberInfo.getUuid()).attributes(attributes).liteMember(memberInfo.isLiteMember()).memberListJoinVersion(memberInfo.getMemberListJoinVersion()).instance(node.hazelcastInstance).build();
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class MembershipManager method addSuspectedMember.
private boolean addSuspectedMember(MemberImpl suspectedMember, String reason, boolean shouldCloseConn) {
Address address = suspectedMember.getAddress();
if (getMember(address, suspectedMember.getUuid()) == null) {
if (logger.isFineEnabled()) {
logger.fine("Cannot suspect " + suspectedMember + ", since it's not a member.");
}
return false;
}
if (suspectedMembers.add(suspectedMember)) {
if (reason != null) {
logger.warning(suspectedMember + " is suspected to be dead for reason: " + reason);
} else {
logger.warning(suspectedMember + " is suspected to be dead");
}
node.getNodeExtension().getAuditlogService().eventBuilder(AuditlogTypeIds.CLUSTER_MEMBER_SUSPECTED).message("Member is suspected").addParameter("address", address).addParameter("reason", reason).log();
clusterService.getClusterJoinManager().addLeftMember(suspectedMember);
}
if (shouldCloseConn) {
closeConnections(address, reason);
}
return true;
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class PNCounterProxy method getReplicaAddresses.
/**
* Returns the addresses of the CRDT replicas from the current state of the
* local membership list. Addresses contained in the {@code excludedAddresses}
* collection are excluded.
*
* @param excludedAddresses the addresses to exclude
* @return list of possible CRDT replica addresses
*/
private List<Address> getReplicaAddresses(Collection<Address> excludedAddresses) {
final Collection<Member> dataMembers = getNodeEngine().getClusterService().getMembers(MemberSelectors.DATA_MEMBER_SELECTOR);
final int maxConfiguredReplicaCount = getNodeEngine().getConfig().findPNCounterConfig(name).getReplicaCount();
final int currentReplicaCount = Math.min(maxConfiguredReplicaCount, dataMembers.size());
final ArrayList<Address> replicaAddresses = new ArrayList<Address>(currentReplicaCount);
final Iterator<Member> dataMemberIterator = dataMembers.iterator();
for (int i = 0; i < currentReplicaCount; i++) {
final Address dataMemberAddress = dataMemberIterator.next().getAddress();
if (!excludedAddresses.contains(dataMemberAddress)) {
replicaAddresses.add(dataMemberAddress);
}
}
return replicaAddresses;
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class PNCounterProxy method invokeInternal.
/**
* Invokes the {@code operation} recursively on viable replica addresses
* until successful or the list of viable replicas is exhausted.
* Replicas with addresses contained in the {@code excludedAddresses} are
* skipped. If there are no viable replicas, this method will throw the
* {@code lastException} if not {@code null} or a
* {@link NoDataMemberInClusterException} if the {@code lastException} is
* {@code null}.
*
* @param operation the operation to invoke on a CRDT replica
* @param excludedAddresses the addresses to exclude when choosing a replica
* address, must not be {@code null}
* @param lastException the exception thrown from the last invocation of
* the {@code operation} on a replica, may be {@code null}
* @return the result of the operation invocation on a replica
* @throws NoDataMemberInClusterException if there are no replicas and the
* {@code lastException} is {@code null}
*/
private long invokeInternal(Operation operation, List<Address> excludedAddresses, HazelcastException lastException) {
final Address target = getCRDTOperationTarget(excludedAddresses);
if (target == null) {
throw lastException != null ? lastException : new NoDataMemberInClusterException("Cannot invoke operations on a CRDT because the cluster does not contain any data members");
}
try {
final InvocationBuilder builder = getNodeEngine().getOperationService().createInvocationBuilder(SERVICE_NAME, operation, target);
if (operationTryCount > 0) {
builder.setTryCount(operationTryCount);
}
final InvocationFuture<CRDTTimestampedLong> future = builder.invoke();
final CRDTTimestampedLong result = future.joinInternal();
updateObservedReplicaTimestamps(result.getVectorClock());
return result.getValue();
} catch (HazelcastException e) {
logger.fine("Exception occurred while invoking operation on target " + target + ", choosing different target", e);
if (excludedAddresses == EMPTY_ADDRESS_LIST) {
excludedAddresses = new ArrayList<Address>();
}
excludedAddresses.add(target);
return invokeInternal(operation, excludedAddresses, e);
}
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class AbstractPNCounterOperation method isCRDTReplica.
/**
* Returns {@code true} if this member is a CRDT replica.
*
* @param configuredReplicaCount the configured max replica count
*/
private boolean isCRDTReplica(int configuredReplicaCount) {
final Collection<Member> dataMembers = getNodeEngine().getClusterService().getMembers(MemberSelectors.DATA_MEMBER_SELECTOR);
final Iterator<Member> dataMemberIterator = dataMembers.iterator();
final Address thisAddress = getNodeEngine().getThisAddress();
for (int i = 0; i < Math.min(configuredReplicaCount, dataMembers.size()); i++) {
final Address dataMemberAddress = dataMemberIterator.next().getAddress();
if (thisAddress.equals(dataMemberAddress)) {
return true;
}
}
return false;
}
Aggregations