use of org.infinispan.client.hotrod.configuration.RemoteCacheConfiguration in project infinispan by infinispan.
the class RemoteCacheManager method createRemoteCache.
private <K, V> InternalRemoteCache<K, V> createRemoteCache(String cacheName) {
RemoteCacheConfiguration remoteCacheConfiguration = configuration.remoteCaches().get(cacheName);
NearCacheConfiguration nearCache;
if (remoteCacheConfiguration != null) {
nearCache = new NearCacheConfiguration(remoteCacheConfiguration.nearCacheMode(), remoteCacheConfiguration.nearCacheMaxEntries(), remoteCacheConfiguration.nearCacheBloomFilter(), null, remoteCacheConfiguration.nearCacheFactory());
} else {
Pattern pattern = configuration.nearCache().cacheNamePattern();
if (pattern == null || pattern.matcher(cacheName).matches()) {
nearCache = configuration.nearCache();
} else {
nearCache = new NearCacheConfiguration(NearCacheMode.DISABLED, -1, false);
}
}
if (nearCache.mode() == NearCacheMode.INVALIDATED) {
Pattern pattern = nearCache.cacheNamePattern();
if (pattern == null || pattern.matcher(cacheName).matches()) {
if (log.isTraceEnabled()) {
log.tracef("Enabling near-caching for cache '%s'", cacheName);
}
NearCacheService<K, V> nearCacheService = createNearCacheService(cacheName, nearCache);
return InvalidatedNearRemoteCache.delegatingNearCache(new RemoteCacheImpl<>(this, cacheName, timeService, nearCacheService), nearCacheService);
}
}
return new RemoteCacheImpl<>(this, cacheName, timeService);
}
use of org.infinispan.client.hotrod.configuration.RemoteCacheConfiguration in project infinispan by infinispan.
the class RemoteCacheManager method createRemoteCache.
private <K, V> RemoteCache<K, V> createRemoteCache(String cacheName, boolean forceReturnValueOverride, TransactionMode transactionModeOverride, TransactionManager transactionManagerOverride) {
RemoteCacheConfiguration cacheConfiguration = findConfiguration(cacheName);
boolean forceReturnValue = forceReturnValueOverride || (cacheConfiguration != null ? cacheConfiguration.forceReturnValues() : configuration.forceReturnValues());
RemoteCacheKey key = new RemoteCacheKey(cacheName, forceReturnValue);
if (cacheName2RemoteCache.containsKey(key)) {
return cacheName2RemoteCache.get(key).remoteCache();
}
OperationsFactory operationsFactory = createOperationFactory(cacheName, forceReturnValue, codec, null);
PingResponse pingResponse;
if (started) {
// Verify if the cache exists on the server first
pingResponse = await(operationsFactory.newFaultTolerantPingOperation().execute());
// If ping not successful assume that the cache does not exist
if (pingResponse.isCacheNotFound()) {
// We may be able to create it. Don't use RemoteCacheAdmin for this, since it would end up calling this method again
Map<String, byte[]> params = new HashMap<>(2);
params.put(RemoteCacheManagerAdminImpl.CACHE_NAME, cacheName.getBytes(HotRodConstants.HOTROD_STRING_CHARSET));
if (cacheConfiguration != null && cacheConfiguration.templateName() != null) {
params.put(RemoteCacheManagerAdminImpl.CACHE_TEMPLATE, cacheConfiguration.templateName().getBytes(HotRodConstants.HOTROD_STRING_CHARSET));
} else if (cacheConfiguration != null && cacheConfiguration.configuration() != null) {
params.put(RemoteCacheManagerAdminImpl.CACHE_CONFIGURATION, new StringConfiguration(cacheConfiguration.configuration()).toStringConfiguration(cacheName).getBytes(HotRodConstants.HOTROD_STRING_CHARSET));
} else {
// We cannot create the cache
return null;
}
// Create and re-ping
OperationsFactory adminOperationsFactory = new OperationsFactory(channelFactory, codec, listenerNotifier, configuration);
pingResponse = await(adminOperationsFactory.newAdminOperation("@@cache@getorcreate", params).execute().thenCompose(s -> operationsFactory.newFaultTolerantPingOperation().execute()));
}
} else {
pingResponse = PingResponse.EMPTY;
}
TransactionMode transactionMode = getTransactionMode(transactionModeOverride, cacheConfiguration);
InternalRemoteCache<K, V> remoteCache;
if (transactionMode == TransactionMode.NONE) {
remoteCache = createRemoteCache(cacheName);
} else {
if (!await(checkTransactionSupport(cacheName, operationsFactory).toCompletableFuture())) {
throw HOTROD.cacheDoesNotSupportTransactions(cacheName);
} else {
TransactionManager transactionManager = getTransactionManager(transactionManagerOverride, cacheConfiguration);
remoteCache = createRemoteTransactionalCache(cacheName, forceReturnValueOverride, transactionMode == TransactionMode.FULL_XA, transactionMode, transactionManager);
}
}
synchronized (cacheName2RemoteCache) {
startRemoteCache(remoteCache, operationsFactory.getCodec(), forceReturnValue);
RemoteCacheHolder holder = new RemoteCacheHolder(remoteCache, forceReturnValueOverride);
remoteCache.resolveStorage(pingResponse.isObjectStorage());
cacheName2RemoteCache.putIfAbsent(key, holder);
return remoteCache;
}
}
use of org.infinispan.client.hotrod.configuration.RemoteCacheConfiguration in project infinispan by infinispan.
the class DataFormat method initialize.
public void initialize(RemoteCacheManager remoteCacheManager, String cacheName, boolean serverObjectStorage) {
this.marshallerRegistry = remoteCacheManager.getMarshallerRegistry();
this.isObjectStorage = serverObjectStorage;
this.defaultMarshaller = remoteCacheManager.getMarshaller();
RemoteCacheConfiguration remoteCacheConfiguration = remoteCacheManager.getConfiguration().remoteCaches().get(cacheName);
if (remoteCacheConfiguration != null) {
Marshaller cacheMarshaller = remoteCacheConfiguration.marshaller();
if (cacheMarshaller != null) {
defaultMarshaller = cacheMarshaller;
} else {
Class<? extends Marshaller> marshallerClass = remoteCacheConfiguration.marshallerClass();
if (marshallerClass != null) {
Marshaller registryMarshaller = marshallerRegistry.getMarshaller(marshallerClass);
defaultMarshaller = registryMarshaller != null ? registryMarshaller : Util.getInstance(marshallerClass);
}
}
}
}
Aggregations