Search in sources :

Example 41 with Connection

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

the class ClientSmartInvocationServiceImpl method invokeOnRandomTarget.

@Override
public void invokeOnRandomTarget(ClientInvocation invocation) throws IOException {
    final Address randomAddress = getRandomAddress();
    if (randomAddress == null) {
        throw new IOException("Not address found to invoke ");
    }
    final Connection connection = getOrTriggerConnect(randomAddress);
    send(invocation, (ClientConnection) connection);
}
Also used : Address(com.hazelcast.nio.Address) ClientConnection(com.hazelcast.client.connection.nio.ClientConnection) Connection(com.hazelcast.nio.Connection) IOException(java.io.IOException)

Example 42 with Connection

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

the class ClientSmartInvocationServiceImpl method getOrTriggerConnect.

private Connection getOrTriggerConnect(Address target) throws IOException {
    ensureOwnerConnectionAvailable();
    Connection connection = connectionManager.getOrTriggerConnect(target, false);
    if (connection == null) {
        throw new IOException("No available connection to address " + target);
    }
    return connection;
}
Also used : ClientConnection(com.hazelcast.client.connection.nio.ClientConnection) Connection(com.hazelcast.nio.Connection) IOException(java.io.IOException)

Example 43 with Connection

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

the class ClientSmartInvocationServiceImpl method invokeOnTarget.

@Override
public void invokeOnTarget(ClientInvocation invocation, Address target) throws IOException {
    if (target == null) {
        throw new NullPointerException("Target can not be null");
    }
    if (!isMember(target)) {
        throw new TargetNotMemberException("Target :  " + target + " is not member. ");
    }
    final Connection connection = getOrTriggerConnect(target);
    invokeOnConnection(invocation, (ClientConnection) connection);
}
Also used : TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) ClientConnection(com.hazelcast.client.connection.nio.ClientConnection) Connection(com.hazelcast.nio.Connection)

Example 44 with Connection

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

the class ClientSmartInvocationServiceImpl method invokeOnPartitionOwner.

@Override
public void invokeOnPartitionOwner(ClientInvocation invocation, int partitionId) throws IOException {
    final Address owner = partitionService.getPartitionOwner(partitionId);
    if (owner == null) {
        throw new IOException("Partition does not have owner. partitionId : " + partitionId);
    }
    invocation.getClientMessage().setPartitionId(partitionId);
    Connection connection = getOrTriggerConnect(owner);
    send(invocation, (ClientConnection) connection);
}
Also used : Address(com.hazelcast.nio.Address) ClientConnection(com.hazelcast.client.connection.nio.ClientConnection) Connection(com.hazelcast.nio.Connection) IOException(java.io.IOException)

Example 45 with Connection

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

the class TcpIpConnectionManager method getOrConnect.

@Override
public Connection getOrConnect(final Address address, final boolean silent) {
    Connection connection = connectionsMap.get(address);
    if (connection == null && live) {
        if (connectionsInProgress.add(address)) {
            ioService.shouldConnectTo(address);
            ioService.executeAsync(new InitConnectionTask(this, address, silent));
        }
    }
    return connection;
}
Also used : Connection(com.hazelcast.nio.Connection)

Aggregations

Connection (com.hazelcast.nio.Connection)59 Address (com.hazelcast.nio.Address)15 ClientConnection (com.hazelcast.client.connection.nio.ClientConnection)10 Test (org.junit.Test)9 QuickTest (com.hazelcast.test.annotation.QuickTest)7 IOException (java.io.IOException)7 ClientConnectionManager (com.hazelcast.client.connection.ClientConnectionManager)6 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)6 AssertTask (com.hazelcast.test.AssertTask)6 HazelcastClientInstanceImpl (com.hazelcast.client.impl.HazelcastClientInstanceImpl)5 Packet (com.hazelcast.nio.Packet)5 ClientClusterService (com.hazelcast.client.spi.ClientClusterService)4 ClientInvocation (com.hazelcast.client.spi.impl.ClientInvocation)4 Member (com.hazelcast.core.Member)4 Node (com.hazelcast.instance.Node)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 ParallelTest (com.hazelcast.test.annotation.ParallelTest)3 EventHandler (com.hazelcast.client.spi.EventHandler)2 ClientInvocationFuture (com.hazelcast.client.spi.impl.ClientInvocationFuture)2