Search in sources :

Example 1 with HazelcastClientInstanceImpl

use of com.hazelcast.client.impl.HazelcastClientInstanceImpl in project hazelcast by hazelcast.

the class HazelcastClientManager method shutdown.

public static void shutdown(String instanceName) {
    HazelcastClientProxy proxy = INSTANCE.clients.remove(instanceName);
    if (proxy == null) {
        return;
    }
    HazelcastClientInstanceImpl client = proxy.client;
    if (client == null) {
        return;
    }
    proxy.client = null;
    try {
        client.shutdown();
    } catch (Throwable ignored) {
        EmptyStatement.ignore(ignored);
    } finally {
        OutOfMemoryErrorDispatcher.deregisterClient(client);
    }
}
Also used : HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy)

Example 2 with HazelcastClientInstanceImpl

use of com.hazelcast.client.impl.HazelcastClientInstanceImpl in project hazelcast by hazelcast.

the class AbstractClientCacheProxy method getInternal.

protected Object getInternal(final K key, ExpiryPolicy expiryPolicy, boolean async) {
    final long start = System.nanoTime();
    ensureOpen();
    validateNotNull(key);
    final Data keyData = toData(key);
    Object cached = getCachedValue(keyData, !async);
    if (cached != NOT_CACHED) {
        return asCompletedFutureOrValue(cached, async);
    }
    final long reservationId = tryReserveForUpdate(keyData);
    final Data expiryPolicyData = toData(expiryPolicy);
    ClientMessage request = CacheGetCodec.encodeRequest(nameWithPrefix, keyData, expiryPolicyData);
    ClientInvocationFuture future;
    try {
        final int partitionId = clientContext.getPartitionService().getPartitionId(keyData);
        final HazelcastClientInstanceImpl client = (HazelcastClientInstanceImpl) clientContext.getHazelcastInstance();
        final ClientInvocation clientInvocation = new ClientInvocation(client, request, partitionId);
        future = clientInvocation.invoke();
    } catch (Throwable t) {
        invalidateNearCache(keyData);
        throw rethrow(t);
    }
    SerializationService serializationService = clientContext.getSerializationService();
    ClientDelegatingFuture<V> delegatingFuture = new ClientDelegatingFuture<V>(future, serializationService, cacheGetResponseDecoder);
    if (async) {
        if (nearCache != null) {
            delegatingFuture.andThenInternal(new ExecutionCallback<Data>() {

                public void onResponse(Data valueData) {
                    storeInNearCache(keyData, valueData, null, reservationId, false);
                    if (statisticsEnabled) {
                        handleStatisticsOnGet(start, valueData);
                    }
                }

                public void onFailure(Throwable t) {
                    invalidateNearCache(keyData);
                }
            }, false);
        }
        return delegatingFuture;
    } else {
        try {
            V value = toObject(delegatingFuture.get());
            if (nearCache != null) {
                storeInNearCache(keyData, (Data) delegatingFuture.getResponse(), value, reservationId, false);
            }
            if (statisticsEnabled) {
                handleStatisticsOnGet(start, value);
            }
            return value;
        } catch (Throwable e) {
            invalidateNearCache(keyData);
            throw rethrowAllowedTypeFirst(e, CacheException.class);
        }
    }
}
Also used : ClientDelegatingFuture(com.hazelcast.client.util.ClientDelegatingFuture) CacheException(javax.cache.CacheException) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl)

Example 3 with HazelcastClientInstanceImpl

use of com.hazelcast.client.impl.HazelcastClientInstanceImpl in project hazelcast by hazelcast.

the class AbstractClientCacheProxyBase method submitLoadAllTask.

protected void submitLoadAllTask(ClientMessage request, CompletionListener completionListener, final Set<Data> keys) {
    final CompletionListener compListener = completionListener != null ? completionListener : NULL_COMPLETION_LISTENER;
    ClientDelegatingFuture<V> delegatingFuture = null;
    try {
        injectDependencies(completionListener);
        final long start = System.nanoTime();
        ClientInvocationFuture future = new ClientInvocation((HazelcastClientInstanceImpl) clientContext.getHazelcastInstance(), request).invoke();
        SerializationService serializationService = clientContext.getSerializationService();
        delegatingFuture = new ClientDelegatingFuture<V>(future, serializationService, LOAD_ALL_DECODER);
        final Future delFuture = delegatingFuture;
        loadAllCalls.put(delegatingFuture, compListener);
        delegatingFuture.andThen(new ExecutionCallback<V>() {

            @Override
            public void onResponse(V response) {
                loadAllCalls.remove(delFuture);
                onLoadAll(keys, response, start, System.nanoTime());
                compListener.onCompletion();
            }

            @Override
            public void onFailure(Throwable t) {
                loadAllCalls.remove(delFuture);
                handleFailureOnCompletionListener(compListener, t);
            }
        });
    } catch (Throwable t) {
        if (delegatingFuture != null) {
            loadAllCalls.remove(delegatingFuture);
        }
        handleFailureOnCompletionListener(compListener, t);
    }
}
Also used : CompletionListener(javax.cache.integration.CompletionListener) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) SerializationService(com.hazelcast.spi.serialization.SerializationService) ClientDelegatingFuture(com.hazelcast.client.util.ClientDelegatingFuture) Future(java.util.concurrent.Future) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Example 4 with HazelcastClientInstanceImpl

use of com.hazelcast.client.impl.HazelcastClientInstanceImpl in project hazelcast by hazelcast.

the class ClientCacheProxy method updateCacheListenerConfigOnOtherNodes.

protected void updateCacheListenerConfigOnOtherNodes(CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration, boolean isRegister) {
    final Collection<Member> members = clientContext.getClusterService().getMemberList();
    final HazelcastClientInstanceImpl client = (HazelcastClientInstanceImpl) clientContext.getHazelcastInstance();
    for (Member member : members) {
        try {
            final Address address = member.getAddress();
            Data configData = toData(cacheEntryListenerConfiguration);
            final ClientMessage request = CacheListenerRegistrationCodec.encodeRequest(nameWithPrefix, configData, isRegister, address);
            final ClientInvocation invocation = new ClientInvocation(client, request, address);
            invocation.invoke();
        } catch (Exception e) {
            ExceptionUtil.sneakyThrow(e);
        }
    }
}
Also used : Address(com.hazelcast.nio.Address) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) Data(com.hazelcast.nio.serialization.Data) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) Member(com.hazelcast.core.Member) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException)

Example 5 with HazelcastClientInstanceImpl

use of com.hazelcast.client.impl.HazelcastClientInstanceImpl in project hazelcast by hazelcast.

the class ClientClusterWideIterator method fetch.

protected List fetch() {
    HazelcastClientInstanceImpl client = (HazelcastClientInstanceImpl) context.getHazelcastInstance();
    if (prefetchValues) {
        ClientMessage request = CacheIterateEntriesCodec.encodeRequest(cacheProxy.getPrefixedName(), partitionIndex, lastTableIndex, fetchSize);
        try {
            ClientInvocation clientInvocation = new ClientInvocation(client, request, partitionIndex);
            ClientInvocationFuture f = clientInvocation.invoke();
            CacheIterateEntriesCodec.ResponseParameters responseParameters = CacheIterateEntriesCodec.decodeResponse(f.get());
            setLastTableIndex(responseParameters.entries, responseParameters.tableIndex);
            return responseParameters.entries;
        } catch (Exception e) {
            throw ExceptionUtil.rethrow(e);
        }
    } else {
        ClientMessage request = CacheIterateCodec.encodeRequest(cacheProxy.getPrefixedName(), partitionIndex, lastTableIndex, fetchSize);
        try {
            ClientInvocation clientInvocation = new ClientInvocation(client, request, partitionIndex);
            ClientInvocationFuture f = clientInvocation.invoke();
            CacheIterateCodec.ResponseParameters responseParameters = CacheIterateCodec.decodeResponse(f.get());
            setLastTableIndex(responseParameters.keys, responseParameters.tableIndex);
            return responseParameters.keys;
        } catch (Exception e) {
            throw ExceptionUtil.rethrow(e);
        }
    }
}
Also used : CacheIterateCodec(com.hazelcast.client.impl.protocol.codec.CacheIterateCodec) CacheIterateEntriesCodec(com.hazelcast.client.impl.protocol.codec.CacheIterateEntriesCodec) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Aggregations

HazelcastClientInstanceImpl (com.hazelcast.client.impl.HazelcastClientInstanceImpl)32 HazelcastInstance (com.hazelcast.core.HazelcastInstance)12 ClientInvocation (com.hazelcast.client.spi.impl.ClientInvocation)9 Test (org.junit.Test)9 Address (com.hazelcast.nio.Address)8 ParallelTest (com.hazelcast.test.annotation.ParallelTest)8 QuickTest (com.hazelcast.test.annotation.QuickTest)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)7 ClientInvocationFuture (com.hazelcast.client.spi.impl.ClientInvocationFuture)7 ClientConnectionManager (com.hazelcast.client.connection.ClientConnectionManager)6 HazelcastClientProxy (com.hazelcast.client.impl.HazelcastClientProxy)5 LifecycleEvent (com.hazelcast.core.LifecycleEvent)5 LifecycleListener (com.hazelcast.core.LifecycleListener)5 Connection (com.hazelcast.nio.Connection)5 AssertTask (com.hazelcast.test.AssertTask)5 ClientConnection (com.hazelcast.client.connection.nio.ClientConnection)4 CacheException (javax.cache.CacheException)4 ClientTestUtil.getHazelcastClientInstanceImpl (com.hazelcast.client.impl.ClientTestUtil.getHazelcastClientInstanceImpl)3 ProxyManager (com.hazelcast.client.spi.ProxyManager)3