Class Caches
- java.lang.Object
-
- org.infinispan.hibernate.cache.commons.util.Caches
-
public class Caches extends Object
Helper for dealing with Infinispan cache instances.- Since:
- 4.1
- Author:
- Galder ZamarreƱo
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceCaches.CollectableCloseableIterable<T>This interface is provided for convenient fluent use of CloseableIterablestatic interfaceCaches.MapCollectableCloseableIterable<K,V>
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.infinispan.AdvancedCacheasyncWriteCache(org.infinispan.AdvancedCache cache, org.infinispan.context.Flag extraFlag)Transform a given cache into a cache that writes cache entries without waiting for them to complete, adding an extra flag.static voidbroadcastEvictAll(org.infinispan.AdvancedCache cache)Broadcast an evict-all command with the given cache instance.static <K,V>
Caches.MapCollectableCloseableIterable<K,V>entrySet(org.infinispan.AdvancedCache<K,V> cache)static <K,V>
Caches.MapCollectableCloseableIterable<K,V>entrySet(org.infinispan.AdvancedCache<K,V> cache, org.infinispan.filter.KeyValueFilter<K,V> filter)static <K,V,T>
Caches.MapCollectableCloseableIterable<K,T>entrySet(org.infinispan.AdvancedCache<K,V> cache, org.infinispan.filter.KeyValueFilter<K,V> filter, org.infinispan.filter.Converter<K,V,T> converter)static org.infinispan.AdvancedCachefailSilentReadCache(org.infinispan.AdvancedCache cache)Transform a given cache into a cache that fails silently if cache reads fail.static org.infinispan.AdvancedCachefailSilentWriteCache(org.infinispan.AdvancedCache cache)Transform a given cache into a cache that fails silently if cache writes fail.static org.infinispan.AdvancedCachefailSilentWriteCache(org.infinispan.AdvancedCache cache, org.infinispan.context.Flag extraFlag)Transform a given cache into a cache that fails silently if cache writes fail, adding an extra flag.static org.infinispan.AdvancedCacheignoreReturnValuesCache(org.infinispan.AdvancedCache cache)Transform a given cache into a cache that ignores return values for operations returning previous values, i.e.static org.infinispan.AdvancedCacheignoreReturnValuesCache(org.infinispan.AdvancedCache cache, org.infinispan.context.Flag extraFlag)Transform a given cache into a cache that ignores return values for operations returning previous values, i.e.static booleanisClustered(org.infinispan.AdvancedCache cache)Indicates whether the given cache is configured to cluster its contents.static booleanisInvalidationCache(org.infinispan.AdvancedCache cache)Indicates whether the given cache is configured withCacheMode.INVALIDATION_ASYNCorCacheMode.INVALIDATION_SYNC.static booleanisSynchronousCache(org.infinispan.AdvancedCache cache)Indicates whether the given cache is configured withCacheMode.REPL_SYNC,CacheMode.INVALIDATION_SYNC, orCacheMode.DIST_SYNC.static booleanisTransactionalCache(org.infinispan.AdvancedCache cache)static org.infinispan.AdvancedCachelocalCache(org.infinispan.AdvancedCache cache)Transform a given cache into a local cachestatic voidremoveAll(org.infinispan.AdvancedCache cache)static voidwithinTx(TransactionManager tm, Runnable runnable)static <T> TwithinTx(TransactionManager tm, Callable<T> c)Call an operation within a transaction.static <T> TwithinTx(org.infinispan.AdvancedCache cache, Callable<T> c)Call an operation within a transaction.
-
-
-
Method Detail
-
withinTx
public static <T> T withinTx(org.infinispan.AdvancedCache cache, Callable<T> c) throws ExceptionCall an operation within a transaction. This method guarantees that the right pattern is used to make sure that the transaction is always either committed or rollback.- Type Parameters:
T- type of callable return- Parameters:
cache- instance whose transaction manager to usec- callable instance to run within a transaction- Returns:
- returns whatever the callable returns
- Throws:
Exception- if any operation within the transaction fails
-
withinTx
public static <T> T withinTx(TransactionManager tm, Callable<T> c) throws Exception
Call an operation within a transaction. This method guarantees that the right pattern is used to make sure that the transaction is always either committed or rollbacked.- Type Parameters:
T- type of callable return- Parameters:
tm- transaction managerc- callable instance to run within a transaction- Returns:
- returns whatever the callable returns
- Throws:
Exception- if any operation within the transaction fails
-
withinTx
public static void withinTx(TransactionManager tm, Runnable runnable) throws Exception
- Throws:
Exception
-
localCache
public static org.infinispan.AdvancedCache localCache(org.infinispan.AdvancedCache cache)
Transform a given cache into a local cache- Parameters:
cache- to be transformed- Returns:
- a cache that operates only in local-mode
-
ignoreReturnValuesCache
public static org.infinispan.AdvancedCache ignoreReturnValuesCache(org.infinispan.AdvancedCache cache)
Transform a given cache into a cache that ignores return values for operations returning previous values, i.e.BasicCache.put(Object, Object)- Parameters:
cache- to be transformed- Returns:
- a cache that ignores return values
-
ignoreReturnValuesCache
public static org.infinispan.AdvancedCache ignoreReturnValuesCache(org.infinispan.AdvancedCache cache, org.infinispan.context.Flag extraFlag)Transform a given cache into a cache that ignores return values for operations returning previous values, i.e.BasicCache.put(Object, Object), adding an extra flag.- Parameters:
cache- to be transformedextraFlag- to add to the returned cache- Returns:
- a cache that ignores return values
-
asyncWriteCache
public static org.infinispan.AdvancedCache asyncWriteCache(org.infinispan.AdvancedCache cache, org.infinispan.context.Flag extraFlag)Transform a given cache into a cache that writes cache entries without waiting for them to complete, adding an extra flag.- Parameters:
cache- to be transformedextraFlag- to add to the returned cache- Returns:
- a cache that writes asynchronously
-
failSilentWriteCache
public static org.infinispan.AdvancedCache failSilentWriteCache(org.infinispan.AdvancedCache cache)
Transform a given cache into a cache that fails silently if cache writes fail.- Parameters:
cache- to be transformed- Returns:
- a cache that fails silently if cache writes fail
-
failSilentWriteCache
public static org.infinispan.AdvancedCache failSilentWriteCache(org.infinispan.AdvancedCache cache, org.infinispan.context.Flag extraFlag)Transform a given cache into a cache that fails silently if cache writes fail, adding an extra flag.- Parameters:
cache- to be transformedextraFlag- to be added to returned cache- Returns:
- a cache that fails silently if cache writes fail
-
failSilentReadCache
public static org.infinispan.AdvancedCache failSilentReadCache(org.infinispan.AdvancedCache cache)
Transform a given cache into a cache that fails silently if cache reads fail.- Parameters:
cache- to be transformed- Returns:
- a cache that fails silently if cache reads fail
-
broadcastEvictAll
public static void broadcastEvictAll(org.infinispan.AdvancedCache cache)
Broadcast an evict-all command with the given cache instance.- Parameters:
cache- instance used to broadcast command
-
isInvalidationCache
public static boolean isInvalidationCache(org.infinispan.AdvancedCache cache)
Indicates whether the given cache is configured withCacheMode.INVALIDATION_ASYNCorCacheMode.INVALIDATION_SYNC.- Parameters:
cache- to check for invalidation configuration- Returns:
- true if the cache is configured with invalidation, false otherwise
-
isSynchronousCache
public static boolean isSynchronousCache(org.infinispan.AdvancedCache cache)
Indicates whether the given cache is configured withCacheMode.REPL_SYNC,CacheMode.INVALIDATION_SYNC, orCacheMode.DIST_SYNC.- Parameters:
cache- to check for synchronous configuration- Returns:
- true if the cache is configured with synchronous mode, false otherwise
-
isClustered
public static boolean isClustered(org.infinispan.AdvancedCache cache)
Indicates whether the given cache is configured to cluster its contents. A cache is considered to clustered if it's configured with any cache mode exceptCacheMode.LOCAL- Parameters:
cache- to check whether it clusters its contents- Returns:
- true if the cache is configured with clustering, false otherwise
-
isTransactionalCache
public static boolean isTransactionalCache(org.infinispan.AdvancedCache cache)
-
removeAll
public static void removeAll(org.infinispan.AdvancedCache cache)
-
entrySet
public static <K,V> Caches.MapCollectableCloseableIterable<K,V> entrySet(org.infinispan.AdvancedCache<K,V> cache)
-
entrySet
public static <K,V> Caches.MapCollectableCloseableIterable<K,V> entrySet(org.infinispan.AdvancedCache<K,V> cache, org.infinispan.filter.KeyValueFilter<K,V> filter)
-
entrySet
public static <K,V,T> Caches.MapCollectableCloseableIterable<K,T> entrySet(org.infinispan.AdvancedCache<K,V> cache, org.infinispan.filter.KeyValueFilter<K,V> filter, org.infinispan.filter.Converter<K,V,T> converter)
-
-