Search in sources :

Example 1 with RemoteCacheConfiguration

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);
}
Also used : Pattern(java.util.regex.Pattern) RemoteCacheConfiguration(org.infinispan.client.hotrod.configuration.RemoteCacheConfiguration) TransactionalRemoteCacheImpl(org.infinispan.client.hotrod.impl.transaction.TransactionalRemoteCacheImpl) RemoteCacheImpl(org.infinispan.client.hotrod.impl.RemoteCacheImpl) NearCacheConfiguration(org.infinispan.client.hotrod.configuration.NearCacheConfiguration)

Example 2 with RemoteCacheConfiguration

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;
    }
}
Also used : StringConfiguration(org.infinispan.commons.configuration.StringConfiguration) HashMap(java.util.HashMap) PingResponse(org.infinispan.client.hotrod.impl.operations.PingResponse) OperationsFactory(org.infinispan.client.hotrod.impl.operations.OperationsFactory) RemoteCacheConfiguration(org.infinispan.client.hotrod.configuration.RemoteCacheConfiguration) TransactionMode(org.infinispan.client.hotrod.configuration.TransactionMode) TransactionManager(javax.transaction.TransactionManager)

Example 3 with RemoteCacheConfiguration

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);
            }
        }
    }
}
Also used : IdentityMarshaller(org.infinispan.commons.marshall.IdentityMarshaller) Marshaller(org.infinispan.commons.marshall.Marshaller) RemoteCacheConfiguration(org.infinispan.client.hotrod.configuration.RemoteCacheConfiguration)

Aggregations

RemoteCacheConfiguration (org.infinispan.client.hotrod.configuration.RemoteCacheConfiguration)3 HashMap (java.util.HashMap)1 Pattern (java.util.regex.Pattern)1 TransactionManager (javax.transaction.TransactionManager)1 NearCacheConfiguration (org.infinispan.client.hotrod.configuration.NearCacheConfiguration)1 TransactionMode (org.infinispan.client.hotrod.configuration.TransactionMode)1 RemoteCacheImpl (org.infinispan.client.hotrod.impl.RemoteCacheImpl)1 OperationsFactory (org.infinispan.client.hotrod.impl.operations.OperationsFactory)1 PingResponse (org.infinispan.client.hotrod.impl.operations.PingResponse)1 TransactionalRemoteCacheImpl (org.infinispan.client.hotrod.impl.transaction.TransactionalRemoteCacheImpl)1 StringConfiguration (org.infinispan.commons.configuration.StringConfiguration)1 IdentityMarshaller (org.infinispan.commons.marshall.IdentityMarshaller)1 Marshaller (org.infinispan.commons.marshall.Marshaller)1