use of com.hazelcast.client.impl.protocol.ClientMessage 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);
}
}
}
use of com.hazelcast.client.impl.protocol.ClientMessage in project hazelcast by hazelcast.
the class ClientCacheProxy method loadAll.
@Override
public void loadAll(Set<? extends K> keys, boolean replaceExistingValues, CompletionListener completionListener) {
ensureOpen();
validateNotNull(keys);
for (K key : keys) {
CacheProxyUtil.validateConfiguredTypes(cacheConfig, key);
}
HashSet<Data> keysData = new HashSet<Data>();
for (K key : keys) {
keysData.add(toData(key));
}
ClientMessage request = CacheLoadAllCodec.encodeRequest(nameWithPrefix, keysData, replaceExistingValues);
try {
submitLoadAllTask(request, completionListener, keysData);
} catch (Exception e) {
if (completionListener != null) {
completionListener.onException(e);
}
throw new CacheException(e);
}
}
use of com.hazelcast.client.impl.protocol.ClientMessage in project hazelcast by hazelcast.
the class ClientCacheProxy method containsKey.
@Override
public boolean containsKey(K key) {
ensureOpen();
validateNotNull(key);
final Data keyData = toData(key);
Object cached = getCachedValue(keyData, false);
if (cached != NOT_CACHED) {
return true;
}
ClientMessage request = CacheContainsKeyCodec.encodeRequest(nameWithPrefix, keyData);
ClientMessage result = invoke(request, keyData);
return CacheContainsKeyCodec.decodeResponse(result).response;
}
use of com.hazelcast.client.impl.protocol.ClientMessage in project hazelcast by hazelcast.
the class ClientCacheProxy method invoke.
@Override
public <T> T invoke(K key, EntryProcessor<K, V, T> entryProcessor, Object... arguments) throws EntryProcessorException {
ensureOpen();
validateNotNull(key);
if (entryProcessor == null) {
throw new NullPointerException("Entry Processor is null");
}
final Data keyData = toData(key);
Data epData = toData(entryProcessor);
List<Data> argumentsData = null;
if (arguments != null) {
argumentsData = new ArrayList<Data>(arguments.length);
for (int i = 0; i < arguments.length; i++) {
argumentsData.add(toData(arguments[i]));
}
}
final int completionId = nextCompletionId();
ClientMessage request = CacheEntryProcessorCodec.encodeRequest(nameWithPrefix, keyData, epData, argumentsData, completionId);
try {
final ICompletableFuture<ClientMessage> f = invoke(request, keyData, completionId);
final ClientMessage response = getSafely(f);
final Data data = CacheEntryProcessorCodec.decodeResponse(response).response;
// At client side, we don't know what entry processor does so we ignore it from statistics perspective
return toObject(data);
} catch (CacheException ce) {
throw ce;
} catch (Exception e) {
throw new EntryProcessorException(e);
}
}
use of com.hazelcast.client.impl.protocol.ClientMessage 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);
}
}
}
Aggregations