Search in sources :

Example 81 with Address

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

the class TcpIpJoiner method getRequiredMemberAddress.

private Address getRequiredMemberAddress() {
    TcpIpConfig tcpIpConfig = config.getNetworkConfig().getJoin().getTcpIpConfig();
    String host = tcpIpConfig.getRequiredMember();
    try {
        AddressHolder addressHolder = AddressUtil.getAddressHolder(host, config.getNetworkConfig().getPort());
        if (AddressUtil.isIpAddress(addressHolder.getAddress())) {
            return new Address(addressHolder.getAddress(), addressHolder.getPort());
        }
        InterfacesConfig interfaces = config.getNetworkConfig().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.util.AddressUtil.AddressHolder) InterfacesConfig(com.hazelcast.config.InterfacesConfig) Address(com.hazelcast.nio.Address) InetAddress(java.net.InetAddress) TcpIpConfig(com.hazelcast.config.TcpIpConfig) InetAddress(java.net.InetAddress) InvalidAddressException(com.hazelcast.util.AddressUtil.InvalidAddressException) UnknownHostException(java.net.UnknownHostException)

Example 82 with Address

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

the class TcpIpJoiner method claimMastership.

@SuppressWarnings("checkstyle:npathcomplexity")
private boolean claimMastership(Collection<Address> possibleAddresses) {
    if (logger.isFineEnabled()) {
        Set<Address> votingEndpoints = new HashSet<Address>(possibleAddresses);
        votingEndpoints.removeAll(blacklistedAddresses.keySet());
        logger.fine("Claiming myself as master node! Asking to endpoints: " + votingEndpoints);
    }
    claimingMaster = true;
    Collection<Future<Boolean>> responses = new LinkedList<Future<Boolean>>();
    for (Address address : possibleAddresses) {
        if (isBlacklisted(address)) {
            continue;
        }
        if (node.getConnectionManager().getConnection(address) != null) {
            Future<Boolean> future = node.nodeEngine.getOperationService().createInvocationBuilder(ClusterServiceImpl.SERVICE_NAME, new MasterClaimOperation(), address).setTryCount(1).invoke();
            responses.add(future);
        }
    }
    final long maxWait = TimeUnit.SECONDS.toMillis(10);
    long waitTime = 0L;
    boolean consensus = true;
    for (Future<Boolean> response : responses) {
        long t = Clock.currentTimeMillis();
        try {
            consensus = response.get(1, TimeUnit.SECONDS);
        } catch (Exception e) {
            logger.finest(e);
            consensus = false;
        } finally {
            waitTime += (Clock.currentTimeMillis() - t);
        }
        if (!consensus) {
            break;
        }
        if (waitTime > maxWait) {
            consensus = false;
            break;
        }
    }
    return consensus;
}
Also used : Address(com.hazelcast.nio.Address) InetAddress(java.net.InetAddress) Future(java.util.concurrent.Future) MasterClaimOperation(com.hazelcast.internal.cluster.impl.operations.MasterClaimOperation) LinkedList(java.util.LinkedList) InvalidAddressException(com.hazelcast.util.AddressUtil.InvalidAddressException) UnknownHostException(java.net.UnknownHostException) HashSet(java.util.HashSet)

Example 83 with Address

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

the class ClientCacheProxy method updateCacheListenerConfigOnOtherNodes.

protected void updateCacheListenerConfigOnOtherNodes(CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration, boolean isRegister) {
    final Collection<Member> members = clientContext.getClusterService().getMemberList();
    final HazelcastClientInstanceImpl client = (HazelcastClientInstanceImpl) clientContext.getHazelcastInstance();
    for (Member member : members) {
        try {
            final Address address = member.getAddress();
            Data configData = toData(cacheEntryListenerConfiguration);
            final ClientMessage request = CacheListenerRegistrationCodec.encodeRequest(nameWithPrefix, configData, isRegister, address);
            final ClientInvocation invocation = new ClientInvocation(client, request, address);
            invocation.invoke();
        } catch (Exception e) {
            ExceptionUtil.sneakyThrow(e);
        }
    }
}
Also used : Address(com.hazelcast.nio.Address) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) Data(com.hazelcast.nio.serialization.Data) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) Member(com.hazelcast.core.Member) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException)

Example 84 with Address

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

the class AbstractClientInternalCacheProxy method getConnectedServerVersion.

private int getConnectedServerVersion() {
    ClientContext clientContext = getContext();
    ClientClusterService clusterService = clientContext.getClusterService();
    Address ownerConnectionAddress = clusterService.getOwnerConnectionAddress();
    HazelcastClientInstanceImpl client = getClient();
    ClientConnectionManager connectionManager = client.getConnectionManager();
    Connection connection = connectionManager.getConnection(ownerConnectionAddress);
    if (connection == null) {
        logger.warning(format("No owner connection is available, " + "near cached cache %s will be started in legacy mode", name));
        return UNKNOWN_HAZELCAST_VERSION;
    }
    return ((ClientConnection) connection).getConnectedServerVersion();
}
Also used : Address(com.hazelcast.nio.Address) ClientContext(com.hazelcast.client.spi.ClientContext) ClientConnection(com.hazelcast.client.connection.nio.ClientConnection) Connection(com.hazelcast.nio.Connection) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) ClientConnection(com.hazelcast.client.connection.nio.ClientConnection) ClientConnectionManager(com.hazelcast.client.connection.ClientConnectionManager) ClientClusterService(com.hazelcast.client.spi.ClientClusterService)

Example 85 with Address

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

the class ClientMapReduceProxy method invoke.

private ClientMessage invoke(ClientMessage request, String jobId) throws Exception {
    ClientTrackableJob trackableJob = trackableJobs.get(jobId);
    if (trackableJob != null) {
        ClientConnection sendConnection = trackableJob.clientInvocation.getSendConnectionOrWait();
        Address runningMember = sendConnection.getEndPoint();
        final ClientInvocation clientInvocation = new ClientInvocation(getClient(), request, runningMember);
        ClientInvocationFuture future = clientInvocation.invoke();
        return future.get();
    }
    return null;
}
Also used : Address(com.hazelcast.nio.Address) ClientConnection(com.hazelcast.client.connection.nio.ClientConnection) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Aggregations

Address (com.hazelcast.nio.Address)274 Test (org.junit.Test)44 QuickTest (com.hazelcast.test.annotation.QuickTest)36 HashMap (java.util.HashMap)33 ParallelTest (com.hazelcast.test.annotation.ParallelTest)29 Member (com.hazelcast.core.Member)27 ArrayList (java.util.ArrayList)27 Map (java.util.Map)26 ILogger (com.hazelcast.logging.ILogger)25 InetAddress (java.net.InetAddress)25 MemberImpl (com.hazelcast.instance.MemberImpl)21 List (java.util.List)20 HashSet (java.util.HashSet)18 Connection (com.hazelcast.nio.Connection)17 NodeEngine (com.hazelcast.spi.NodeEngine)16 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)16 IOException (java.io.IOException)16 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)14 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 IPartitionService (com.hazelcast.spi.partition.IPartitionService)13