use of com.hazelcast.client.impl.protocol.codec.holder.CacheConfigHolder in project hazelcast by hazelcast.
the class ClientCacheHelper method getCacheConfig.
/**
* Gets the cache configuration from the server.
*
* @param client the client instance which will send the operation to server
* @param cacheName full cache name with prefixes
* @param simpleCacheName pure cache name without any prefix
* @param <K> type of the key of the cache
* @param <V> type of the value of the cache
* @return the cache configuration if it can be found
*/
static <K, V> CacheConfig<K, V> getCacheConfig(HazelcastClientInstanceImpl client, String cacheName, String simpleCacheName) {
ClientMessage request = CacheGetConfigCodec.encodeRequest(cacheName, simpleCacheName);
try {
int partitionId = client.getClientPartitionService().getPartitionId(cacheName);
ClientInvocation clientInvocation = new ClientInvocation(client, request, cacheName, partitionId);
Future<ClientMessage> future = clientInvocation.invoke();
ClientMessage responseMessage = future.get();
SerializationService serializationService = client.getSerializationService();
CacheConfigHolder cacheConfigHolder = CacheGetConfigCodec.decodeResponse(responseMessage);
if (cacheConfigHolder == null) {
return null;
}
return cacheConfigHolder.asCacheConfig(serializationService);
} catch (Exception e) {
throw rethrow(e);
}
}
use of com.hazelcast.client.impl.protocol.codec.holder.CacheConfigHolder in project hazelcast by hazelcast.
the class ClientCacheHelper method createCacheConfig.
/**
* Creates a new cache configuration on Hazelcast members.
*
* @param client the client instance which will send the operation to server
* @param newCacheConfig the cache configuration to be sent to server
* @param <K> type of the key of the cache
* @param <V> type of the value of the cache
* @param urgent whether creating the config is urgent or not(urgent messages can be send in DISCONNECTED state )
* @return the created cache configuration
* @see com.hazelcast.cache.impl.operation.AddCacheConfigOperation
*/
static <K, V> CacheConfig<K, V> createCacheConfig(HazelcastClientInstanceImpl client, CacheConfig<K, V> newCacheConfig, boolean urgent) {
try {
String nameWithPrefix = newCacheConfig.getNameWithPrefix();
int partitionId = client.getClientPartitionService().getPartitionId(nameWithPrefix);
InternalSerializationService serializationService = client.getSerializationService();
ClientMessage request = CacheCreateConfigCodec.encodeRequest(CacheConfigHolder.of(newCacheConfig, serializationService), true);
ClientInvocation clientInvocation = new ClientInvocation(client, request, nameWithPrefix, partitionId);
Future<ClientMessage> future = urgent ? clientInvocation.invokeUrgent() : clientInvocation.invoke();
final ClientMessage response = future.get();
final CacheConfigHolder cacheConfigHolder = CacheCreateConfigCodec.decodeResponse(response);
if (cacheConfigHolder == null) {
return null;
}
return cacheConfigHolder.asCacheConfig(serializationService);
} catch (Exception e) {
throw rethrow(e);
}
}
Aggregations