Search in sources :

Example 46 with Connection

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

the class ClientNonSmartInvocationServiceImpl method sendToOwner.

private void sendToOwner(ClientInvocation invocation) throws IOException {
    ClientClusterService clusterService = client.getClientClusterService();
    Address ownerConnectionAddress = clusterService.getOwnerConnectionAddress();
    if (ownerConnectionAddress == null) {
        throw new IOException("Packet is not send to owner address");
    }
    Connection conn = connectionManager.getConnection(ownerConnectionAddress);
    if (conn == null) {
        throw new IOException("Packet is not sent to owner address: " + ownerConnectionAddress);
    }
    send(invocation, (ClientConnection) conn);
}
Also used : Address(com.hazelcast.nio.Address) ClientConnection(com.hazelcast.client.connection.nio.ClientConnection) Connection(com.hazelcast.nio.Connection) IOException(java.io.IOException) ClientClusterService(com.hazelcast.client.spi.ClientClusterService)

Example 47 with Connection

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

the class ClientSmartInvocationServiceImpl method getOrConnect.

private Connection getOrConnect(Address target) throws IOException {
    ensureOwnerConnectionAvailable();
    Connection connection = connectionManager.getOrConnect(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 48 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 49 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 50 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)

Aggregations

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