Search in sources :

Example 6 with ClientConnection

use of com.hazelcast.client.connection.nio.ClientConnection in project hazelcast by hazelcast.

the class NearCachedClientMapProxy method getConnectedServerVersion.

private int getConnectedServerVersion() {
    ClientContext clientContext = getClientContext();
    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 7 with ClientConnection

use of com.hazelcast.client.connection.nio.ClientConnection in project hazelcast by hazelcast.

the class ClientCacheHelper method deserializeCacheConfig.

private static <K, V> CacheConfig<K, V> deserializeCacheConfig(HazelcastClientInstanceImpl client, ClientMessage responseMessage, SerializationService serializationService, ClientInvocation clientInvocation) {
    Data responseData = CacheGetConfigCodec.decodeResponse(responseMessage).response;
    ClientConnection sendConnection = clientInvocation.getSendConnection();
    if (null != sendConnection && BuildInfo.UNKNOWN_HAZELCAST_VERSION == sendConnection.getConnectedServerVersion()) {
        boolean compatibilityEnabled = client.getProperties().getBoolean(ClientProperty.COMPATIBILITY_3_6_SERVER_ENABLED);
        if (compatibilityEnabled) {
            LegacyCacheConfig<K, V> legacyConfig = serializationService.toObject(responseData, LegacyCacheConfig.class);
            if (null == legacyConfig) {
                return null;
            }
            return legacyConfig.getConfigAndReset();
        }
    }
    return serializationService.toObject(responseData);
}
Also used : Data(com.hazelcast.nio.serialization.Data) ClientConnection(com.hazelcast.client.connection.nio.ClientConnection)

Example 8 with ClientConnection

use of com.hazelcast.client.connection.nio.ClientConnection 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 9 with ClientConnection

use of com.hazelcast.client.connection.nio.ClientConnection 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 10 with ClientConnection

use of com.hazelcast.client.connection.nio.ClientConnection 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)

Aggregations

ClientConnection (com.hazelcast.client.connection.nio.ClientConnection)13 Address (com.hazelcast.nio.Address)10 Connection (com.hazelcast.nio.Connection)6 ClientConnectionManager (com.hazelcast.client.connection.ClientConnectionManager)4 HazelcastClientInstanceImpl (com.hazelcast.client.impl.HazelcastClientInstanceImpl)4 ClientClusterService (com.hazelcast.client.spi.ClientClusterService)4 IOException (java.io.IOException)4 ClientContext (com.hazelcast.client.spi.ClientContext)2 ClientInvocation (com.hazelcast.client.spi.impl.ClientInvocation)2 InetSocketAddress (java.net.InetSocketAddress)2 ClientImpl (com.hazelcast.client.impl.ClientImpl)1 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1 ClientInvocationFuture (com.hazelcast.client.spi.impl.ClientInvocationFuture)1 EntryAdapter (com.hazelcast.core.EntryAdapter)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 IMap (com.hazelcast.core.IMap)1 Data (com.hazelcast.nio.serialization.Data)1 TargetNotMemberException (com.hazelcast.spi.exception.TargetNotMemberException)1 AssertTask (com.hazelcast.test.AssertTask)1 NightlyTest (com.hazelcast.test.annotation.NightlyTest)1