Search in sources :

Example 41 with Address

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();
}
Also used : Address(com.hazelcast.cluster.Address) MemberImpl(com.hazelcast.cluster.impl.MemberImpl)

Example 42 with Address

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;
}
Also used : Address(com.hazelcast.cluster.Address)

Example 43 with Address

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;
}
Also used : Address(com.hazelcast.cluster.Address) ArrayList(java.util.ArrayList) Member(com.hazelcast.cluster.Member)

Example 44 with Address

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);
    }
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) Address(com.hazelcast.cluster.Address) ArrayList(java.util.ArrayList) InvocationBuilder(com.hazelcast.spi.impl.operationservice.InvocationBuilder) NoDataMemberInClusterException(com.hazelcast.partition.NoDataMemberInClusterException) CRDTTimestampedLong(com.hazelcast.internal.crdt.pncounter.operations.CRDTTimestampedLong)

Example 45 with Address

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;
}
Also used : Address(com.hazelcast.cluster.Address) Member(com.hazelcast.cluster.Member)

Aggregations

Address (com.hazelcast.cluster.Address)540 Test (org.junit.Test)211 QuickTest (com.hazelcast.test.annotation.QuickTest)191 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)178 HazelcastInstance (com.hazelcast.core.HazelcastInstance)92 InetAddress (java.net.InetAddress)75 ArrayList (java.util.ArrayList)66 Member (com.hazelcast.cluster.Member)63 Accessors.getAddress (com.hazelcast.test.Accessors.getAddress)54 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)48 Config (com.hazelcast.config.Config)43 PartitionReplica (com.hazelcast.internal.partition.PartitionReplica)43 UUID (java.util.UUID)43 ILogger (com.hazelcast.logging.ILogger)37 HashMap (java.util.HashMap)36 Operation (com.hazelcast.spi.impl.operationservice.Operation)35 List (java.util.List)35 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)34 Map (java.util.Map)33 InetSocketAddress (java.net.InetSocketAddress)32