Search in sources :

Example 11 with ClientConnectionManager

use of com.hazelcast.client.connection.ClientConnectionManager in project hazelcast by hazelcast.

the class ClientClusterServiceImpl method getLocalClient.

@Override
public Client getLocalClient() {
    Address address = getOwnerConnectionAddress();
    final ClientConnectionManager cm = client.getConnectionManager();
    final ClientConnection connection = (ClientConnection) cm.getConnection(address);
    InetSocketAddress inetSocketAddress = connection != null ? connection.getLocalSocketAddress() : null;
    final String uuid = getPrincipal().getUuid();
    return new ClientImpl(uuid, inetSocketAddress);
}
Also used : Address(com.hazelcast.nio.Address) InetSocketAddress(java.net.InetSocketAddress) InetSocketAddress(java.net.InetSocketAddress) ClientImpl(com.hazelcast.client.impl.ClientImpl) ClientConnection(com.hazelcast.client.connection.nio.ClientConnection) ClientConnectionManager(com.hazelcast.client.connection.ClientConnectionManager)

Example 12 with ClientConnectionManager

use of com.hazelcast.client.connection.ClientConnectionManager in project hazelcast by hazelcast.

the class ClientServiceTest method testPendingEventPacketsWithEvents.

@Test(timeout = 120000)
public void testPendingEventPacketsWithEvents() throws InterruptedException, UnknownHostException {
    HazelcastInstance hazelcastInstance = hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    IMap map = client.getMap(randomName());
    map.addEntryListener(new EntryAdapter(), false);
    for (int i = 0; i < 10; i++) {
        map.put(randomString(), randomString());
    }
    HazelcastClientInstanceImpl clientInstanceImpl = ClientTestUtil.getHazelcastClientInstanceImpl(client);
    InetSocketAddress socketAddress = hazelcastInstance.getCluster().getLocalMember().getSocketAddress();
    Address address = new Address(socketAddress.getAddress().getHostAddress(), socketAddress.getPort());
    ClientConnectionManager connectionManager = clientInstanceImpl.getConnectionManager();
    final ClientConnection connection = (ClientConnection) connectionManager.getConnection(address);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(0, connection.getPendingPacketCount());
        }
    });
}
Also used : IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) InetSocketAddress(java.net.InetSocketAddress) InetSocketAddress(java.net.InetSocketAddress) EntryAdapter(com.hazelcast.core.EntryAdapter) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) AssertTask(com.hazelcast.test.AssertTask) ClientConnection(com.hazelcast.client.connection.nio.ClientConnection) ClientConnectionManager(com.hazelcast.client.connection.ClientConnectionManager) UnknownHostException(java.net.UnknownHostException) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 13 with ClientConnectionManager

use of com.hazelcast.client.connection.ClientConnectionManager in project hazelcast by hazelcast.

the class ClientTestSupport method blockMessagesToInstance.

/**
     * Blocks outgoing messages from client to given instance
     */
protected void blockMessagesToInstance(HazelcastInstance instance, HazelcastInstance client) {
    HazelcastClientInstanceImpl clientImpl = getHazelcastClientInstanceImpl(client);
    ClientConnectionManager connectionManager = clientImpl.getConnectionManager();
    Address address = instance.getCluster().getLocalMember().getAddress();
    ((TestClientRegistry.MockClientConnectionManager) connectionManager).blockTo(address);
}
Also used : Address(com.hazelcast.nio.Address) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) ClientConnectionManager(com.hazelcast.client.connection.ClientConnectionManager)

Aggregations

ClientConnectionManager (com.hazelcast.client.connection.ClientConnectionManager)13 HazelcastClientInstanceImpl (com.hazelcast.client.impl.HazelcastClientInstanceImpl)10 Address (com.hazelcast.nio.Address)10 Connection (com.hazelcast.nio.Connection)6 ClientConnection (com.hazelcast.client.connection.nio.ClientConnection)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 AssertTask (com.hazelcast.test.AssertTask)3 InetSocketAddress (java.net.InetSocketAddress)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ClientClusterService (com.hazelcast.client.spi.ClientClusterService)2 ClientContext (com.hazelcast.client.spi.ClientContext)2 ConnectionHeartbeatListener (com.hazelcast.client.spi.impl.ConnectionHeartbeatListener)2 ExecutionException (java.util.concurrent.ExecutionException)2 ClientImpl (com.hazelcast.client.impl.ClientImpl)1 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1 ClientMessageReadHandler (com.hazelcast.client.impl.protocol.util.ClientMessageReadHandler)1 EntryAdapter (com.hazelcast.core.EntryAdapter)1