Search in sources :

Example 91 with Address

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

the class ClusterListenerSupport method connect.

private boolean connect(Set<InetSocketAddress> triedAddresses) throws Exception {
    final Collection<InetSocketAddress> socketAddresses = getSocketAddresses();
    for (InetSocketAddress inetSocketAddress : socketAddresses) {
        if (!client.getLifecycleService().isRunning()) {
            if (logger.isFinestEnabled()) {
                logger.finest("Giving up on retrying to connect to cluster since client is shutdown");
            }
            break;
        }
        Connection connection = null;
        try {
            triedAddresses.add(inetSocketAddress);
            Address address = new Address(inetSocketAddress);
            logger.info("Trying to connect to " + address + " as owner member");
            connection = connectionManager.getOrConnect(address, true);
            clientMembershipListener.listenMembershipEvents(ownerConnectionAddress);
            fireConnectionEvent(LifecycleEvent.LifecycleState.CLIENT_CONNECTED);
            return true;
        } catch (Exception e) {
            Level level = e instanceof AuthenticationException ? Level.WARNING : Level.FINEST;
            logger.log(level, "Exception during initial connection to " + inetSocketAddress, e);
            if (null != connection) {
                connection.close("Could not connect to " + inetSocketAddress + " as owner", e);
            }
        }
    }
    return false;
}
Also used : Address(com.hazelcast.nio.Address) InetSocketAddress(java.net.InetSocketAddress) AuthenticationException(com.hazelcast.client.AuthenticationException) InetSocketAddress(java.net.InetSocketAddress) Connection(com.hazelcast.nio.Connection) Level(java.util.logging.Level) AuthenticationException(com.hazelcast.client.AuthenticationException) TargetDisconnectedException(com.hazelcast.spi.exception.TargetDisconnectedException)

Example 92 with Address

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

the class DiscoveryAddressProvider method loadAddresses.

@Override
public Collection<InetSocketAddress> loadAddresses() {
    Iterable<DiscoveryNode> discoveredNodes = checkNotNull(discoveryService.discoverNodes(), "Discovered nodes cannot be null!");
    Collection<InetSocketAddress> possibleMembers = new ArrayList<InetSocketAddress>();
    for (DiscoveryNode discoveryNode : discoveredNodes) {
        Address discoveredAddress = discoveryNode.getPrivateAddress();
        try {
            possibleMembers.add(discoveredAddress.getInetSocketAddress());
        } catch (UnknownHostException e) {
            logger.warning("Unresolvable host exception", e);
        }
    }
    return possibleMembers;
}
Also used : DiscoveryNode(com.hazelcast.spi.discovery.DiscoveryNode) Address(com.hazelcast.nio.Address) InetSocketAddress(java.net.InetSocketAddress) UnknownHostException(java.net.UnknownHostException) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList)

Example 93 with Address

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

the class ClientNonSmartInvocationServiceImpl method getConnection.

@Override
public ClientConnection getConnection(int partitionId) throws IOException {
    ClientClusterService clusterService = client.getClientClusterService();
    Address ownerConnectionAddress = clusterService.getOwnerConnectionAddress();
    if (ownerConnectionAddress == null) {
        throw new IOException("ClientNonSmartInvocationServiceImpl: Owner connection is not available.");
    }
    return (ClientConnection) connectionManager.getConnection(ownerConnectionAddress);
}
Also used : Address(com.hazelcast.nio.Address) ClientConnection(com.hazelcast.client.connection.nio.ClientConnection) IOException(java.io.IOException) ClientClusterService(com.hazelcast.client.spi.ClientClusterService)

Example 94 with Address

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

the class ClientPartitionServiceImpl method getOwnerConnection.

private Connection getOwnerConnection() {
    ClientClusterService clusterService = client.getClientClusterService();
    Address ownerAddress = clusterService.getOwnerConnectionAddress();
    if (ownerAddress == null) {
        return null;
    }
    Connection connection = client.getConnectionManager().getConnection(ownerAddress);
    if (connection == null) {
        return null;
    }
    return connection;
}
Also used : Address(com.hazelcast.nio.Address) Connection(com.hazelcast.nio.Connection) ClientClusterService(com.hazelcast.client.spi.ClientClusterService)

Example 95 with Address

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

the class ClientTransactionManagerServiceImpl method connect.

public ClientConnection connect() throws Exception {
    Exception lastError = null;
    int count = 0;
    while (count < RETRY_COUNT) {
        try {
            final Address randomAddress = getRandomAddress();
            return (ClientConnection) client.getConnectionManager().getOrConnect(randomAddress, false);
        } catch (Exception e) {
            lastError = e;
        }
        count++;
    }
    throw lastError;
}
Also used : Address(com.hazelcast.nio.Address) ClientConnection(com.hazelcast.client.connection.nio.ClientConnection) TransactionException(com.hazelcast.transaction.TransactionException)

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