Search in sources :

Example 36 with Address

use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.

the class TcpIpJoiner method tryJoinAddresses.

private void tryJoinAddresses(Collection<Address> addresses) throws InterruptedException {
    long connectionTimeoutMillis = TimeUnit.SECONDS.toMillis(getConnTimeoutSeconds());
    long start = Clock.currentTimeMillis();
    while (!clusterService.isJoined() && Clock.currentTimeMillis() - start < connectionTimeoutMillis) {
        Address masterAddress = clusterService.getMasterAddress();
        if (isAllBlacklisted(addresses) && masterAddress == null) {
            return;
        }
        if (masterAddress != null) {
            if (logger.isFineEnabled()) {
                logger.fine("Sending join request to " + masterAddress);
            }
            clusterJoinManager.sendJoinRequest(masterAddress);
        } else {
            sendMasterQuestion(addresses);
        }
        if (!clusterService.isJoined()) {
            clusterService.blockOnJoin(JOIN_RETRY_WAIT_TIME);
        }
        addresses.removeIf(address -> {
            try {
                return isLocalAddress(address);
            } catch (UnknownHostException e) {
                if (logger.isFineEnabled()) {
                    logger.fine("Error during resolving possible target address!", e);
                }
                ignore(e);
                return false;
            }
        });
    }
}
Also used : Address(com.hazelcast.cluster.Address) InetAddress(java.net.InetAddress) UnknownHostException(java.net.UnknownHostException)

Example 37 with Address

use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.

the class TcpIpJoiner method getRequiredMemberAddress.

private Address getRequiredMemberAddress() {
    TcpIpConfig tcpIpConfig = joinConfig.getTcpIpConfig();
    String host = tcpIpConfig.getRequiredMember();
    try {
        AddressHolder addressHolder = AddressUtil.getAddressHolder(host, getActiveMemberNetworkConfig(config).getPort());
        if (AddressUtil.isIpAddress(addressHolder.getAddress())) {
            return new Address(addressHolder.getAddress(), addressHolder.getPort());
        }
        InterfacesConfig interfaces = getActiveMemberNetworkConfig(config).getInterfaces();
        if (interfaces.isEnabled()) {
            InetAddress[] inetAddresses = InetAddress.getAllByName(addressHolder.getAddress());
            if (inetAddresses.length > 1) {
                for (InetAddress inetAddress : inetAddresses) {
                    if (AddressUtil.matchAnyInterface(inetAddress.getHostAddress(), interfaces.getInterfaces())) {
                        return new Address(inetAddress, addressHolder.getPort());
                    }
                }
            } else if (AddressUtil.matchAnyInterface(inetAddresses[0].getHostAddress(), interfaces.getInterfaces())) {
                return new Address(addressHolder.getAddress(), addressHolder.getPort());
            }
        } else {
            return new Address(addressHolder.getAddress(), addressHolder.getPort());
        }
    } catch (final Exception e) {
        logger.warning(e);
    }
    return null;
}
Also used : AddressHolder(com.hazelcast.internal.util.AddressUtil.AddressHolder) InterfacesConfig(com.hazelcast.config.InterfacesConfig) Address(com.hazelcast.cluster.Address) InetAddress(java.net.InetAddress) TcpIpConfig(com.hazelcast.config.TcpIpConfig) InetAddress(java.net.InetAddress) InvalidAddressException(com.hazelcast.internal.util.AddressUtil.InvalidAddressException) UnknownHostException(java.net.UnknownHostException)

Example 38 with Address

use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.

the class ClusterHeartbeatManager method onInvalidHeartbeat.

private void onInvalidHeartbeat(MembersViewMetadata senderMembersViewMetadata) {
    Address senderAddress = senderMembersViewMetadata.getMemberAddress();
    if (clusterService.isMaster()) {
        if (!clusterService.getClusterJoinManager().isMastershipClaimInProgress()) {
            logger.fine("Sending explicit suspicion to " + senderAddress + " for heartbeat " + senderMembersViewMetadata + ", because it is not a member of this cluster" + " or its heartbeat cannot be validated!");
            clusterService.sendExplicitSuspicion(senderMembersViewMetadata);
        }
    } else {
        MemberImpl master = clusterService.getMember(clusterService.getMasterAddress());
        if (clusterService.getMembershipManager().isMemberSuspected(master)) {
            logger.fine("Not sending heartbeat complaint for " + senderMembersViewMetadata + " to suspected master: " + master.getAddress());
            return;
        }
        logger.fine("Sending heartbeat complaint to master " + master.getAddress() + " for heartbeat " + senderMembersViewMetadata + ", because it is not a member of this cluster" + " or its heartbeat cannot be validated!");
        sendHeartbeatComplaintToMaster(senderMembersViewMetadata);
    }
}
Also used : Address(com.hazelcast.cluster.Address) MemberImpl(com.hazelcast.cluster.impl.MemberImpl)

Example 39 with Address

use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.

the class ClusterStateManager method lockClusterStateOnAllMembers.

private void lockClusterStateOnAllMembers(ClusterStateChange stateChange, NodeEngineImpl nodeEngine, long leaseTime, UUID txnId, Collection<MemberImpl> members, int memberListVersion, long partitionStateStamp) {
    Collection<Future> futures = new ArrayList<>(members.size());
    final Address thisAddress = node.getThisAddress();
    for (Member member : members) {
        Operation op = new LockClusterStateOp(stateChange, thisAddress, txnId, leaseTime, memberListVersion, partitionStateStamp);
        Future future = nodeEngine.getOperationService().invokeOnTarget(SERVICE_NAME, op, member.getAddress());
        futures.add(future);
    }
    StateManagerExceptionHandler exceptionHandler = new StateManagerExceptionHandler(logger);
    waitWithDeadline(futures, leaseTime, TimeUnit.MILLISECONDS, exceptionHandler);
    exceptionHandler.rethrowIfFailed();
}
Also used : Address(com.hazelcast.cluster.Address) LockClusterStateOp(com.hazelcast.internal.cluster.impl.operations.LockClusterStateOp) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Operation(com.hazelcast.spi.impl.operationservice.Operation) Member(com.hazelcast.cluster.Member)

Example 40 with Address

use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.

the class MemberMap method createNew.

/**
 * Creates a new {@code MemberMap} including given members.
 *
 * @param version version
 * @param members members
 * @return a new {@code MemberMap}
 */
static MemberMap createNew(int version, MemberImpl... members) {
    Map<Address, MemberImpl> addressMap = createLinkedHashMap(members.length);
    Map<UUID, MemberImpl> uuidMap = createLinkedHashMap(members.length);
    for (MemberImpl member : members) {
        putMember(addressMap, uuidMap, member);
    }
    return new MemberMap(version, addressMap, uuidMap);
}
Also used : Address(com.hazelcast.cluster.Address) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) UUID(java.util.UUID)

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