Class TransformingCacheProxy<K,​V,​K0,​V0>

  • All Implemented Interfaces:
    Closeable, AutoCloseable, Iterable<javax.cache.Cache.Entry<K,​V>>, javax.cache.Cache<K,​V>
    Direct Known Subclasses:
    CopyCacheProxy

    public abstract class TransformingCacheProxy<K,​V,​K0,​V0>
    extends Object
    implements javax.cache.Cache<K,​V>
    This is a proxy that filters all keys and values that go in and out. The basic use case is to mimic store by value semantics on a heap based cache. This is done by cloning or otherwise copying all instances that go in and out from a cache.

    This generic approach also may convert the types. Right now we just need the identical types, so this might be a little over engineered.

    Complete except listeners and configuration.

    Author:
    Jens Wilke
    • Constructor Detail

      • TransformingCacheProxy

        public TransformingCacheProxy​(javax.cache.Cache<K0,​V0> cache,
                                      ObjectTransformer<K,​K0> keyTransformer,
                                      ObjectTransformer<V,​V0> valueTransformer,
                                      ObjectTransformer<K,​K0> passingKeyTransformer,
                                      ObjectTransformer<V,​V0> passingValueTransformer)
        Parameters:
        cache - the wrapped cache
        keyTransformer - Keys that go in and out will be sent through
        valueTransformer - Values that go in and out will be sent through
        passingKeyTransformer - Special transformer for keys that go in and are not stored by the cache (e.g. for #conatainsKey)
        passingValueTransformer - Special transformer for keys that go in and are not stored by the cache (e.g. for the oldValue in replace)
    • Method Detail

      • get

        public V get​(K key)
        Specified by:
        get in interface javax.cache.Cache<K,​V>
      • getAll

        public Map<K,​V> getAll​(Set<? extends K> keys)
        Specified by:
        getAll in interface javax.cache.Cache<K,​V>
      • containsKey

        public boolean containsKey​(K key)
        Specified by:
        containsKey in interface javax.cache.Cache<K,​V>
      • loadAll

        public void loadAll​(Set<? extends K> keys,
                            boolean replaceExistingValues,
                            javax.cache.integration.CompletionListener completionListener)
        Specified by:
        loadAll in interface javax.cache.Cache<K,​V>
      • put

        public void put​(K key,
                        V value)
        Specified by:
        put in interface javax.cache.Cache<K,​V>
      • getAndPut

        public V getAndPut​(K key,
                           V value)
        Specified by:
        getAndPut in interface javax.cache.Cache<K,​V>
      • putAll

        public void putAll​(Map<? extends K,​? extends V> map)
        Specified by:
        putAll in interface javax.cache.Cache<K,​V>
      • putIfAbsent

        public boolean putIfAbsent​(K key,
                                   V value)
        Specified by:
        putIfAbsent in interface javax.cache.Cache<K,​V>
      • remove

        public boolean remove​(K key)
        Specified by:
        remove in interface javax.cache.Cache<K,​V>
      • remove

        public boolean remove​(K key,
                              V oldValue)
        Specified by:
        remove in interface javax.cache.Cache<K,​V>
      • getAndRemove

        public V getAndRemove​(K key)
        Specified by:
        getAndRemove in interface javax.cache.Cache<K,​V>
      • replace

        public boolean replace​(K key,
                               V oldValue,
                               V newValue)
        Specified by:
        replace in interface javax.cache.Cache<K,​V>
      • replace

        public boolean replace​(K key,
                               V value)
        Specified by:
        replace in interface javax.cache.Cache<K,​V>
      • getAndReplace

        public V getAndReplace​(K key,
                               V value)
        Specified by:
        getAndReplace in interface javax.cache.Cache<K,​V>
      • removeAll

        public void removeAll​(Set<? extends K> keys)
        Specified by:
        removeAll in interface javax.cache.Cache<K,​V>
      • removeAll

        public void removeAll()
        Specified by:
        removeAll in interface javax.cache.Cache<K,​V>
      • clear

        public void clear()
        Specified by:
        clear in interface javax.cache.Cache<K,​V>
      • invoke

        public <T> T invoke​(K key,
                            javax.cache.processor.EntryProcessor<K,​V,​T> entryProcessor,
                            Object... arguments)
                     throws javax.cache.processor.EntryProcessorException
        Specified by:
        invoke in interface javax.cache.Cache<K,​V>
        Throws:
        javax.cache.processor.EntryProcessorException
      • invokeAll

        public <T> Map<K,​javax.cache.processor.EntryProcessorResult<T>> invokeAll​(Set<? extends K> keys,
                                                                                        javax.cache.processor.EntryProcessor<K,​V,​T> entryProcessor,
                                                                                        Object... arguments)
        Specified by:
        invokeAll in interface javax.cache.Cache<K,​V>
      • getName

        public String getName()
        Specified by:
        getName in interface javax.cache.Cache<K,​V>
      • getCacheManager

        public javax.cache.CacheManager getCacheManager()
        Specified by:
        getCacheManager in interface javax.cache.Cache<K,​V>
      • close

        public void close()
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface javax.cache.Cache<K,​V>
        Specified by:
        close in interface Closeable
      • isClosed

        public boolean isClosed()
        Specified by:
        isClosed in interface javax.cache.Cache<K,​V>
      • unwrap

        public <T> T unwrap​(Class<T> clazz)
        Specified by:
        unwrap in interface javax.cache.Cache<K,​V>
      • iterator

        public Iterator<javax.cache.Cache.Entry<K,​V>> iterator()
        Specified by:
        iterator in interface javax.cache.Cache<K,​V>
        Specified by:
        iterator in interface Iterable<K>
      • getWrappedCache

        public javax.cache.Cache<K0,​V0> getWrappedCache()