Search in sources :

Example 1 with CacheWriter

use of org.infinispan.persistence.spi.CacheWriter in project infinispan by infinispan.

the class NonBlockingStoreAdapter method determineCharacteristics.

private static Set<Characteristic> determineCharacteristics(Object storeImpl) {
    EnumSet<Characteristic> characteristics;
    if (storeImpl instanceof SegmentedAdvancedLoadWriteStore) {
        characteristics = EnumSet.of(Characteristic.SEGMENTABLE, Characteristic.EXPIRATION, Characteristic.BULK_READ);
    } else {
        characteristics = EnumSet.noneOf(Characteristic.class);
        if (storeImpl instanceof AdvancedCacheLoader) {
            characteristics.add(Characteristic.BULK_READ);
        } else if (!(storeImpl instanceof CacheLoader)) {
            characteristics.add(Characteristic.WRITE_ONLY);
        }
        if (storeImpl instanceof AdvancedCacheWriter) {
            characteristics.add(Characteristic.EXPIRATION);
        } else if (!(storeImpl instanceof CacheWriter)) {
            characteristics.add(Characteristic.READ_ONLY);
        }
    }
    Store storeAnnotation = storeImpl.getClass().getAnnotation(Store.class);
    if (storeAnnotation != null && storeAnnotation.shared()) {
        characteristics.add(Characteristic.SHAREABLE);
    }
    // Transactional is a special interface that could be true on a segment or not segmented store both
    if (storeImpl instanceof TransactionalCacheWriter) {
        characteristics.add(Characteristic.TRANSACTIONAL);
    }
    return characteristics;
}
Also used : AdvancedCacheLoader(org.infinispan.persistence.spi.AdvancedCacheLoader) AdvancedCacheWriter(org.infinispan.persistence.spi.AdvancedCacheWriter) TransactionalCacheWriter(org.infinispan.persistence.spi.TransactionalCacheWriter) CacheWriter(org.infinispan.persistence.spi.CacheWriter) AdvancedCacheWriter(org.infinispan.persistence.spi.AdvancedCacheWriter) SegmentedAdvancedLoadWriteStore(org.infinispan.persistence.spi.SegmentedAdvancedLoadWriteStore) SegmentedAdvancedLoadWriteStore(org.infinispan.persistence.spi.SegmentedAdvancedLoadWriteStore) FlagAffectedStore(org.infinispan.persistence.spi.FlagAffectedStore) ExternalStore(org.infinispan.persistence.spi.ExternalStore) NonBlockingStore(org.infinispan.persistence.spi.NonBlockingStore) Store(org.infinispan.commons.persistence.Store) AdvancedCacheLoader(org.infinispan.persistence.spi.AdvancedCacheLoader) CacheLoader(org.infinispan.persistence.spi.CacheLoader) TransactionalCacheWriter(org.infinispan.persistence.spi.TransactionalCacheWriter)

Example 2 with CacheWriter

use of org.infinispan.persistence.spi.CacheWriter in project infinispan by infinispan.

the class TestingUtil method getFirstTxWriter.

@SuppressWarnings("unchecked")
public static <T extends CacheWriter<K, V>, K, V> T getFirstTxWriter(Cache<K, V> cache) {
    PersistenceManagerImpl persistenceManager = getActualPersistenceManager(cache);
    NonBlockingStore<K, V> nonBlockingStore = persistenceManager.<K, V>getAllStores(characteristics -> characteristics.contains(NonBlockingStore.Characteristic.TRANSACTIONAL)).get(0);
    // TODO: Once stores convert to non blocking implementations this will change
    return (T) ((NonBlockingStoreAdapter<K, V>) nonBlockingStore).transactionalStore();
}
Also used : Arrays(java.util.Arrays) Enumeration(java.util.Enumeration) LogFactory(org.infinispan.util.logging.LogFactory) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) KnownComponentNames(org.infinispan.factories.KnownComponentNames) DISCARD(org.jgroups.protocols.DISCARD) StreamAwareMarshaller(org.infinispan.commons.marshall.StreamAwareMarshaller) Cache(org.infinispan.Cache) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) Future(java.util.concurrent.Future) AdvancedCache(org.infinispan.AdvancedCache) ModuleLifecycle(org.infinispan.lifecycle.ModuleLifecycle) CacheWriter(org.infinispan.persistence.spi.CacheWriter) Map(java.util.Map) ConsistentHash(org.infinispan.distribution.ch.ConsistentHash) JGroupsTransport(org.infinispan.remoting.transport.jgroups.JGroupsTransport) EmbeddedMetadata(org.infinispan.metadata.EmbeddedMetadata) DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) MergeView(org.jgroups.MergeView) MBeanOperationInfo(javax.management.MBeanOperationInfo) Set(java.util.Set) CacheTopology(org.infinispan.topology.CacheTopology) GMS(org.jgroups.protocols.pbcast.GMS) Serializable(java.io.Serializable) LockSupport(java.util.concurrent.locks.LockSupport) MalformedObjectNameException(javax.management.MalformedObjectNameException) ConsistentHashFactory(org.infinispan.distribution.ch.ConsistentHashFactory) ComponentStatus(org.infinispan.lifecycle.ComponentStatus) IntSet(org.infinispan.commons.util.IntSet) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) AdvancedLoadWriteStore(org.infinispan.persistence.spi.AdvancedLoadWriteStore) Flag(org.infinispan.context.Flag) JMException(javax.management.JMException) DelegatingNonBlockingStore(org.infinispan.persistence.support.DelegatingNonBlockingStore) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) JChannel(org.jgroups.JChannel) InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) Proxy(java.lang.reflect.Proxy) PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) ProtobufUtil(org.infinispan.protostream.ProtobufUtil) JGroupsAddress(org.infinispan.remoting.transport.jgroups.JGroupsAddress) NonBlockingStoreAdapter(org.infinispan.persistence.support.NonBlockingStoreAdapter) Callable(java.util.concurrent.Callable) ComponentRegistry(org.infinispan.factories.ComponentRegistry) Supplier(java.util.function.Supplier) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) PersistenceMarshallerImpl(org.infinispan.marshall.persistence.impl.PersistenceMarshallerImpl) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) SerializationContextInitializer(org.infinispan.protostream.SerializationContextInitializer) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BiConsumer(java.util.function.BiConsumer) MarshallableEntry(org.infinispan.persistence.spi.MarshallableEntry) LinkedHashSet(java.util.LinkedHashSet) Address(org.infinispan.remoting.transport.Address) ProtocolStack(org.jgroups.stack.ProtocolStack) AsyncInterceptor(org.infinispan.interceptors.AsyncInterceptor) Properties(java.util.Properties) CacheEntry(org.infinispan.container.entries.CacheEntry) Executor(java.util.concurrent.Executor) Publisher(org.reactivestreams.Publisher) FileOutputStream(java.io.FileOutputStream) AssertJUnit.assertFalse(org.testng.AssertJUnit.assertFalse) IOException(java.io.IOException) Field(java.lang.reflect.Field) AssertJUnit.fail(org.testng.AssertJUnit.fail) MBeanInfo(javax.management.MBeanInfo) ProtoStreamMarshaller(org.infinispan.commons.marshall.ProtoStreamMarshaller) SerializationContext(org.infinispan.protostream.SerializationContext) DistributionManager(org.infinispan.distribution.DistributionManager) InternalCacheRegistry(org.infinispan.registry.InternalCacheRegistry) ScheduledFuture(java.util.concurrent.ScheduledFuture) IntSets(org.infinispan.commons.util.IntSets) MarshalledEntryUtil(org.infinispan.marshall.persistence.impl.MarshalledEntryUtil) CacheLoader(org.infinispan.persistence.spi.CacheLoader) Random(java.util.Random) StateTransferManagerImpl(org.infinispan.statetransfer.StateTransferManagerImpl) BOTH(org.infinispan.persistence.manager.PersistenceManager.AccessMode.BOTH) StreamingMarshaller(org.infinispan.commons.marshall.StreamingMarshaller) WaitDelegatingNonBlockingStore(org.infinispan.persistence.support.WaitDelegatingNonBlockingStore) LockManager(org.infinispan.util.concurrent.locks.LockManager) SecureCacheImpl(org.infinispan.security.impl.SecureCacheImpl) ComponentRef(org.infinispan.factories.impl.ComponentRef) SingleSegmentPublisher(org.infinispan.persistence.support.SingleSegmentPublisher) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) CacheContainer(org.infinispan.manager.CacheContainer) Lifecycle(org.infinispan.commons.api.Lifecycle) AbstractDelegatingCache(org.infinispan.cache.impl.AbstractDelegatingCache) DependencyGraph(org.infinispan.util.DependencyGraph) Method(java.lang.reflect.Method) CommandsFactory(org.infinispan.commands.CommandsFactory) Predicate(java.util.function.Predicate) PersistenceManagerImpl(org.infinispan.persistence.manager.PersistenceManagerImpl) Collection(java.util.Collection) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ObjectName(javax.management.ObjectName) Collectors(java.util.stream.Collectors) ViewId(org.jgroups.ViewId) List(java.util.List) Principal(java.security.Principal) PerCacheInboundInvocationHandler(org.infinispan.remoting.inboundhandler.PerCacheInboundInvocationHandler) Exceptions(org.infinispan.commons.test.Exceptions) SegmentPublisherWrapper(org.infinispan.persistence.support.SegmentPublisherWrapper) Pattern(java.util.regex.Pattern) CacheJmxRegistration(org.infinispan.jmx.CacheJmxRegistration) TimeoutException(org.infinispan.util.concurrent.TimeoutException) AssertJUnit(org.testng.AssertJUnit) MBeanParameterInfo(javax.management.MBeanParameterInfo) DELAY(org.jgroups.protocols.DELAY) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Metadata(org.infinispan.metadata.Metadata) CompletionStages(org.infinispan.util.concurrent.CompletionStages) TestComponentAccessors(org.infinispan.factories.impl.TestComponentAccessors) GlobalMarshaller(org.infinispan.marshall.core.GlobalMarshaller) Function(java.util.function.Function) AbstractDelegatingTransport(org.infinispan.remoting.transport.AbstractDelegatingTransport) HashSet(java.util.HashSet) Version(org.infinispan.commons.util.Version) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) MBeanServer(javax.management.MBeanServer) Log(org.infinispan.util.logging.Log) LinkedList(java.util.LinkedList) TP(org.jgroups.protocols.TP) OutputStream(java.io.OutputStream) CacheException(org.infinispan.commons.CacheException) DataContainer(org.infinispan.container.DataContainer) CacheManagerJmxRegistration(org.infinispan.jmx.CacheManagerJmxRegistration) Transport(org.infinispan.remoting.transport.Transport) Flowable(io.reactivex.rxjava3.core.Flowable) Iterator(java.util.Iterator) InternalDataContainer(org.infinispan.container.impl.InternalDataContainer) NonBlockingStore(org.infinispan.persistence.spi.NonBlockingStore) MutableDigest(org.jgroups.util.MutableDigest) DelegatingPersistenceManager(org.infinispan.persistence.support.DelegatingPersistenceManager) Subject(javax.security.auth.Subject) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) AbstractMap(java.util.AbstractMap) Status(javax.transaction.Status) CacheMode(org.infinispan.configuration.cache.CacheMode) LocalizedCacheTopology(org.infinispan.distribution.LocalizedCacheTopology) Configuration(org.infinispan.configuration.cache.Configuration) TransactionManager(javax.transaction.TransactionManager) Collections(java.util.Collections) TransactionTable(org.infinispan.transaction.impl.TransactionTable) InputStream(java.io.InputStream) View(org.jgroups.View) PersistenceManagerImpl(org.infinispan.persistence.manager.PersistenceManagerImpl)

Example 3 with CacheWriter

use of org.infinispan.persistence.spi.CacheWriter in project infinispan by infinispan.

the class TestingUtil method getWriter.

public static <T extends CacheWriter<K, V>, K, V> T getWriter(Cache<K, V> cache, int position) {
    PersistenceManagerImpl persistenceManager = getActualPersistenceManager(cache);
    NonBlockingStore<K, V> nonBlockingStore = persistenceManager.<K, V>getAllStores(characteristics -> !characteristics.contains(NonBlockingStore.Characteristic.READ_ONLY)).get(position);
    // TODO: Once stores convert to non blocking implementations this will change
    return (T) ((NonBlockingStoreAdapter<K, V>) nonBlockingStore).writer();
}
Also used : Arrays(java.util.Arrays) Enumeration(java.util.Enumeration) LogFactory(org.infinispan.util.logging.LogFactory) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) KnownComponentNames(org.infinispan.factories.KnownComponentNames) DISCARD(org.jgroups.protocols.DISCARD) StreamAwareMarshaller(org.infinispan.commons.marshall.StreamAwareMarshaller) Cache(org.infinispan.Cache) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) Future(java.util.concurrent.Future) AdvancedCache(org.infinispan.AdvancedCache) ModuleLifecycle(org.infinispan.lifecycle.ModuleLifecycle) CacheWriter(org.infinispan.persistence.spi.CacheWriter) Map(java.util.Map) ConsistentHash(org.infinispan.distribution.ch.ConsistentHash) JGroupsTransport(org.infinispan.remoting.transport.jgroups.JGroupsTransport) EmbeddedMetadata(org.infinispan.metadata.EmbeddedMetadata) DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) MergeView(org.jgroups.MergeView) MBeanOperationInfo(javax.management.MBeanOperationInfo) Set(java.util.Set) CacheTopology(org.infinispan.topology.CacheTopology) GMS(org.jgroups.protocols.pbcast.GMS) Serializable(java.io.Serializable) LockSupport(java.util.concurrent.locks.LockSupport) MalformedObjectNameException(javax.management.MalformedObjectNameException) ConsistentHashFactory(org.infinispan.distribution.ch.ConsistentHashFactory) ComponentStatus(org.infinispan.lifecycle.ComponentStatus) IntSet(org.infinispan.commons.util.IntSet) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) AdvancedLoadWriteStore(org.infinispan.persistence.spi.AdvancedLoadWriteStore) Flag(org.infinispan.context.Flag) JMException(javax.management.JMException) DelegatingNonBlockingStore(org.infinispan.persistence.support.DelegatingNonBlockingStore) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) JChannel(org.jgroups.JChannel) InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) Proxy(java.lang.reflect.Proxy) PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) ProtobufUtil(org.infinispan.protostream.ProtobufUtil) JGroupsAddress(org.infinispan.remoting.transport.jgroups.JGroupsAddress) NonBlockingStoreAdapter(org.infinispan.persistence.support.NonBlockingStoreAdapter) Callable(java.util.concurrent.Callable) ComponentRegistry(org.infinispan.factories.ComponentRegistry) Supplier(java.util.function.Supplier) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) PersistenceMarshallerImpl(org.infinispan.marshall.persistence.impl.PersistenceMarshallerImpl) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) SerializationContextInitializer(org.infinispan.protostream.SerializationContextInitializer) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BiConsumer(java.util.function.BiConsumer) MarshallableEntry(org.infinispan.persistence.spi.MarshallableEntry) LinkedHashSet(java.util.LinkedHashSet) Address(org.infinispan.remoting.transport.Address) ProtocolStack(org.jgroups.stack.ProtocolStack) AsyncInterceptor(org.infinispan.interceptors.AsyncInterceptor) Properties(java.util.Properties) CacheEntry(org.infinispan.container.entries.CacheEntry) Executor(java.util.concurrent.Executor) Publisher(org.reactivestreams.Publisher) FileOutputStream(java.io.FileOutputStream) AssertJUnit.assertFalse(org.testng.AssertJUnit.assertFalse) IOException(java.io.IOException) Field(java.lang.reflect.Field) AssertJUnit.fail(org.testng.AssertJUnit.fail) MBeanInfo(javax.management.MBeanInfo) ProtoStreamMarshaller(org.infinispan.commons.marshall.ProtoStreamMarshaller) SerializationContext(org.infinispan.protostream.SerializationContext) DistributionManager(org.infinispan.distribution.DistributionManager) InternalCacheRegistry(org.infinispan.registry.InternalCacheRegistry) ScheduledFuture(java.util.concurrent.ScheduledFuture) IntSets(org.infinispan.commons.util.IntSets) MarshalledEntryUtil(org.infinispan.marshall.persistence.impl.MarshalledEntryUtil) CacheLoader(org.infinispan.persistence.spi.CacheLoader) Random(java.util.Random) StateTransferManagerImpl(org.infinispan.statetransfer.StateTransferManagerImpl) BOTH(org.infinispan.persistence.manager.PersistenceManager.AccessMode.BOTH) StreamingMarshaller(org.infinispan.commons.marshall.StreamingMarshaller) WaitDelegatingNonBlockingStore(org.infinispan.persistence.support.WaitDelegatingNonBlockingStore) LockManager(org.infinispan.util.concurrent.locks.LockManager) SecureCacheImpl(org.infinispan.security.impl.SecureCacheImpl) ComponentRef(org.infinispan.factories.impl.ComponentRef) SingleSegmentPublisher(org.infinispan.persistence.support.SingleSegmentPublisher) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) CacheContainer(org.infinispan.manager.CacheContainer) Lifecycle(org.infinispan.commons.api.Lifecycle) AbstractDelegatingCache(org.infinispan.cache.impl.AbstractDelegatingCache) DependencyGraph(org.infinispan.util.DependencyGraph) Method(java.lang.reflect.Method) CommandsFactory(org.infinispan.commands.CommandsFactory) Predicate(java.util.function.Predicate) PersistenceManagerImpl(org.infinispan.persistence.manager.PersistenceManagerImpl) Collection(java.util.Collection) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ObjectName(javax.management.ObjectName) Collectors(java.util.stream.Collectors) ViewId(org.jgroups.ViewId) List(java.util.List) Principal(java.security.Principal) PerCacheInboundInvocationHandler(org.infinispan.remoting.inboundhandler.PerCacheInboundInvocationHandler) Exceptions(org.infinispan.commons.test.Exceptions) SegmentPublisherWrapper(org.infinispan.persistence.support.SegmentPublisherWrapper) Pattern(java.util.regex.Pattern) CacheJmxRegistration(org.infinispan.jmx.CacheJmxRegistration) TimeoutException(org.infinispan.util.concurrent.TimeoutException) AssertJUnit(org.testng.AssertJUnit) MBeanParameterInfo(javax.management.MBeanParameterInfo) DELAY(org.jgroups.protocols.DELAY) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Metadata(org.infinispan.metadata.Metadata) CompletionStages(org.infinispan.util.concurrent.CompletionStages) TestComponentAccessors(org.infinispan.factories.impl.TestComponentAccessors) GlobalMarshaller(org.infinispan.marshall.core.GlobalMarshaller) Function(java.util.function.Function) AbstractDelegatingTransport(org.infinispan.remoting.transport.AbstractDelegatingTransport) HashSet(java.util.HashSet) Version(org.infinispan.commons.util.Version) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) MBeanServer(javax.management.MBeanServer) Log(org.infinispan.util.logging.Log) LinkedList(java.util.LinkedList) TP(org.jgroups.protocols.TP) OutputStream(java.io.OutputStream) CacheException(org.infinispan.commons.CacheException) DataContainer(org.infinispan.container.DataContainer) CacheManagerJmxRegistration(org.infinispan.jmx.CacheManagerJmxRegistration) Transport(org.infinispan.remoting.transport.Transport) Flowable(io.reactivex.rxjava3.core.Flowable) Iterator(java.util.Iterator) InternalDataContainer(org.infinispan.container.impl.InternalDataContainer) NonBlockingStore(org.infinispan.persistence.spi.NonBlockingStore) MutableDigest(org.jgroups.util.MutableDigest) DelegatingPersistenceManager(org.infinispan.persistence.support.DelegatingPersistenceManager) Subject(javax.security.auth.Subject) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) AbstractMap(java.util.AbstractMap) Status(javax.transaction.Status) CacheMode(org.infinispan.configuration.cache.CacheMode) LocalizedCacheTopology(org.infinispan.distribution.LocalizedCacheTopology) Configuration(org.infinispan.configuration.cache.Configuration) TransactionManager(javax.transaction.TransactionManager) Collections(java.util.Collections) TransactionTable(org.infinispan.transaction.impl.TransactionTable) InputStream(java.io.InputStream) View(org.jgroups.View) PersistenceManagerImpl(org.infinispan.persistence.manager.PersistenceManagerImpl)

Aggregations

Flowable (io.reactivex.rxjava3.core.Flowable)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 Serializable (java.io.Serializable)2 Field (java.lang.reflect.Field)2 Method (java.lang.reflect.Method)2 Proxy (java.lang.reflect.Proxy)2 Principal (java.security.Principal)2 AbstractMap (java.util.AbstractMap)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Enumeration (java.util.Enumeration)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 LinkedHashSet (java.util.LinkedHashSet)2