org.infinispan.spring.remote.provider.SpringRemoteCacheManager Maven / Gradle / Ivy
package org.infinispan.spring.remote.provider;
import java.util.Collection;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.client.hotrod.impl.MarshallerRegistry;
import org.infinispan.commons.configuration.ClassAllowList;
import org.infinispan.commons.dataconversion.MediaType;
import org.infinispan.commons.logging.Log;
import org.infinispan.commons.marshall.JavaSerializationMarshaller;
import org.infinispan.commons.marshall.ProtoStreamMarshaller;
import org.infinispan.commons.util.NullValue;
import org.infinispan.protostream.BaseMarshaller;
import org.infinispan.protostream.SerializationContext;
import org.infinispan.protostream.SerializationContextInitializer;
import org.infinispan.spring.common.provider.SpringCache;
import org.infinispan.spring.common.session.MapSessionProtoAdapter;
import org.springframework.session.MapSession;
import org.springframework.util.Assert;
/**
*
* A {@link org.springframework.cache.CacheManager CacheManager
} implementation that is
* backed by an {@link RemoteCacheManager
* Infinispan RemoteCacheManager
} instance.
*
*
* @author Olaf Bergner
* @author Marius Bogoevici
*
*/
public class SpringRemoteCacheManager implements org.springframework.cache.CacheManager {
private final RemoteCacheManager nativeCacheManager;
private final ConcurrentMap springCaches = new ConcurrentHashMap<>();
private volatile long readTimeout;
private volatile long writeTimeout;
private volatile boolean reactive;
/**
* @param nativeCacheManager the underlying cache manager
*/
public SpringRemoteCacheManager(final RemoteCacheManager nativeCacheManager, boolean reactive, long readTimeout, long writeTimeout) {
Assert.notNull(nativeCacheManager,
"A non-null instance of EmbeddedCacheManager needs to be supplied");
this.nativeCacheManager = nativeCacheManager;
this.readTimeout = readTimeout;
this.writeTimeout = writeTimeout;
this.reactive = reactive;
configureMarshallers(nativeCacheManager);
}
public SpringRemoteCacheManager(final RemoteCacheManager nativeCacheManager, long readTimeout, long writeTimeout) {
this(nativeCacheManager, false,readTimeout, writeTimeout);
}
public SpringRemoteCacheManager(final RemoteCacheManager nativeCacheManager) {
this(nativeCacheManager, false,0, 0);
}
public SpringRemoteCacheManager(final RemoteCacheManager nativeCacheManager, boolean reactive) {
this(nativeCacheManager, reactive,0, 0);
}
/**
* @see org.springframework.cache.CacheManager#getCache(String)
*/
@Override
public SpringCache getCache(final String name) {
final RemoteCache