Class TerracottaTransactionalCopyingCacheStore

  • All Implemented Interfaces:
    Store, TerracottaStore

    public final class TerracottaTransactionalCopyingCacheStore
    extends java.lang.Object
    implements TerracottaStore
    A copying cache store designed for transactional terracotta clustered stores
    Author:
    ljacomet
    • Constructor Detail

      • TerracottaTransactionalCopyingCacheStore

        public TerracottaTransactionalCopyingCacheStore​(TerracottaStore store,
                                                        ReadWriteCopyStrategy<Element> copyStrategyInstance,
                                                        java.lang.ClassLoader loader)
        Creates a terracotta copying instance of store, that wraps the actual storage
        Parameters:
        store - the real store
        copyStrategyInstance - the copy strategy to use on every copy operation
        loader - classloader of the containing cache
    • Method Detail

      • unsafeGet

        public Element unsafeGet​(java.lang.Object key)
        Description copied from interface: TerracottaStore
        Returns the local value associated with the key. Local value means that the object mapped to the key is present in the VM locally. In case its not, will return null. Note that even when returning null, the value may be present in the Terracotta server array.

        This operation does not acquire any locks when doing the operation and may return stale values. This Operation does not update last usage statistics

        Specified by:
        unsafeGet in interface TerracottaStore
        Parameters:
        key - the key
        Returns:
        the element associated with key or null
      • quickSize

        public int quickSize()
        Description copied from interface: TerracottaStore
        Get an approximate count of elements in the store.
        Specified by:
        quickSize in interface TerracottaStore
        Returns:
        an approximate count of elements in the store.
      • getLocalKeys

        public java.util.Set getLocalKeys()
        Description copied from interface: TerracottaStore
        Returns set of keys from the cache which are present in the node locally.
        Specified by:
        getLocalKeys in interface TerracottaStore
        Returns:
        set of keys present locally in the node
      • notifyCacheEventListenersChanged

        public void notifyCacheEventListenersChanged()
        Description copied from interface: TerracottaStore
        Notify the underlying store that some change has occured in the set of registered cache listeners.
        Specified by:
        notifyCacheEventListenersChanged in interface TerracottaStore
      • addStoreListener

        public void addStoreListener​(StoreListener listener)
        Description copied from interface: Store
        Add a listener to the store.
        Specified by:
        addStoreListener in interface Store
      • put

        public boolean put​(Element e)
                    throws CacheException
        Description copied from interface: Store
        Puts an item into the store.
        Specified by:
        put in interface Store
        Returns:
        true if this is a new put for the key or element is null. Returns false if it was an update.
        Throws:
        CacheException
      • putAll

        public void putAll​(java.util.Collection<Element> elements)
                    throws CacheException
        Description copied from interface: Store
        Puts a collection of elements into the store.
        Specified by:
        putAll in interface Store
        Parameters:
        elements - Collection of elements to be put in the store
        Throws:
        CacheException
      • putWithWriter

        public boolean putWithWriter​(Element element,
                                     CacheWriterManager writerManager)
                              throws CacheException
        Description copied from interface: Store
        Puts an item into the store and the cache writer manager in an atomic operation
        Specified by:
        putWithWriter in interface Store
        Returns:
        true if this is a new put for the key or element is null. Returns false if it was an update.
        Throws:
        CacheException
      • get

        public Element get​(java.lang.Object key)
        Description copied from interface: Store
        Gets an item from the cache.
        Specified by:
        get in interface Store
      • getQuiet

        public Element getQuiet​(java.lang.Object key)
        Description copied from interface: Store
        Gets an Element from the Store, without updating statistics
        Specified by:
        getQuiet in interface Store
        Returns:
        The element
      • getKeys

        public java.util.List getKeys()
        Description copied from interface: Store
        Gets an Array of the keys for all elements in the disk store.
        Specified by:
        getKeys in interface Store
        Returns:
        An List of Serializable keys
      • remove

        public Element remove​(java.lang.Object key)
        Description copied from interface: Store
        Removes an item from the cache.
        Specified by:
        remove in interface Store
      • removeAll

        public void removeAll​(java.util.Collection<?> keys)
        Description copied from interface: Store
        Removes a collection of elements from the cache.
        Specified by:
        removeAll in interface Store
      • removeAll

        public void removeAll()
                       throws CacheException
        Description copied from interface: Store
        Remove all of the elements from the store.

        If there are registered CacheEventListeners they are notified of the expiry or removal of the Element as each is removed.

        Specified by:
        removeAll in interface Store
        Throws:
        CacheException
      • putIfAbsent

        public Element putIfAbsent​(Element element)
                            throws java.lang.NullPointerException
        Description copied from interface: Store
        Put an element in the store if no element is currently mapped to the elements key.
        Specified by:
        putIfAbsent in interface Store
        Parameters:
        element - element to be added
        Returns:
        the element previously cached for this key, or null if none.
        Throws:
        java.lang.NullPointerException - if the element is null, or has a null key
      • removeElement

        public Element removeElement​(Element element,
                                     ElementValueComparator comparator)
                              throws java.lang.NullPointerException
        Description copied from interface: Store
        Remove the Element mapped to the key for the supplied element if the value of the supplied Element is equal to the value of the cached Element. This is a CAS operation. It is consistent even against a distributed cache that is not coherent. If the old value is stale when this operation is attempted the remove does not take place.
        Specified by:
        removeElement in interface Store
        Parameters:
        element - Element to be removed
        comparator - ElementValueComparator to use to compare elements
        Returns:
        the Element removed or null if no Element was removed
        Throws:
        java.lang.NullPointerException - if the element is null, or has a null key
      • replace

        public boolean replace​(Element old,
                               Element element,
                               ElementValueComparator comparator)
                        throws java.lang.NullPointerException,
                               java.lang.IllegalArgumentException
        Description copied from interface: Store
        Replace the cached element only if the value of the current Element is equal to the value of the supplied old Element.
        Specified by:
        replace in interface Store
        Parameters:
        old - Element to be test against
        element - Element to be cached
        comparator - ElementValueComparator to use to compare elements
        Returns:
        true is the Element was replaced
        Throws:
        java.lang.NullPointerException - if the either Element is null or has a null key
        java.lang.IllegalArgumentException - if the two Element keys are non-null but not equal
      • replace

        public Element replace​(Element element)
                        throws java.lang.NullPointerException
        Description copied from interface: Store
        Replace the cached element only if an Element is currently cached for this key
        Specified by:
        replace in interface Store
        Parameters:
        element - Element to be cached
        Returns:
        the Element previously cached for this key, or null if no Element was cached
        Throws:
        java.lang.NullPointerException - if the Element is null or has a null key
      • dispose

        public void dispose()
        Description copied from interface: Store
        Prepares for shutdown.
        Specified by:
        dispose in interface Store
      • getSize

        public int getSize()
        Description copied from interface: Store
        Returns the current local store size
        Specified by:
        getSize in interface Store
        Returns:
        the count of the Elements in the Store on the local machine
      • getInMemorySize

        public int getInMemorySize()
        Description copied from interface: Store
        Returns the current local in-memory store size
        Specified by:
        getInMemorySize in interface Store
        Returns:
        the count of the Elements in the Store and in-memory on the local machine
      • getOffHeapSize

        public int getOffHeapSize()
        Description copied from interface: Store
        Returns the current local off-heap store size
        Specified by:
        getOffHeapSize in interface Store
        Returns:
        the count of the Elements in the Store and off-heap on the local machine
      • getOnDiskSize

        public int getOnDiskSize()
        Description copied from interface: Store
        Returns the current local on-disk store size
        Specified by:
        getOnDiskSize in interface Store
        Returns:
        the count of the Elements in the Store and on-disk on the local machine
      • getTerracottaClusteredSize

        public int getTerracottaClusteredSize()
        Description copied from interface: Store
        Returns the current Terracotta clustered store size
        Specified by:
        getTerracottaClusteredSize in interface Store
        Returns:
        the count of the Elements in the Store across the cluster
      • getInMemorySizeInBytes

        public long getInMemorySizeInBytes()
        Description copied from interface: Store
        Gets the size of the in-memory portion of the store, in bytes.

        This method may be expensive to run, depending on implementation. Implementers may choose to return an approximate size.

        Specified by:
        getInMemorySizeInBytes in interface Store
        Returns:
        the approximate in-memory size of the store in bytes
      • getOffHeapSizeInBytes

        public long getOffHeapSizeInBytes()
        Description copied from interface: Store
        Gets the size of the off-heap portion of the store, in bytes.
        Specified by:
        getOffHeapSizeInBytes in interface Store
        Returns:
        the approximate off-heap size of the store in bytes
      • getOnDiskSizeInBytes

        public long getOnDiskSizeInBytes()
        Description copied from interface: Store
        Gets the size of the on-disk portion of the store, in bytes.
        Specified by:
        getOnDiskSizeInBytes in interface Store
        Returns:
        the on-disk size of the store in bytes
      • hasAbortedSizeOf

        public boolean hasAbortedSizeOf()
        Description copied from interface: Store
        Checks if the cache may contain elements for which the SizeOf engine gave up and only partially calculated the size.
        Specified by:
        hasAbortedSizeOf in interface Store
        Returns:
        true if at least one partially sized element may be in the cache
      • getStatus

        public Status getStatus()
        Description copied from interface: Store
        Returns the cache status.
        Specified by:
        getStatus in interface Store
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Description copied from interface: Store
        A check to see if a key is in the Store.
        Specified by:
        containsKey in interface Store
        Parameters:
        key - The Element key
        Returns:
        true if found. No check is made to see if the Element is expired. 1.2
      • containsKeyOnDisk

        public boolean containsKeyOnDisk​(java.lang.Object key)
        Description copied from interface: Store
        A check to see if a key is in the Store and is currently held on disk.
        Specified by:
        containsKeyOnDisk in interface Store
        Parameters:
        key - The Element key
        Returns:
        true if found. No check is made to see if the Element is expired.
      • containsKeyOffHeap

        public boolean containsKeyOffHeap​(java.lang.Object key)
        Description copied from interface: Store
        A check to see if a key is in the Store and is currently held off-heap.
        Specified by:
        containsKeyOffHeap in interface Store
        Parameters:
        key - The Element key
        Returns:
        true if found. No check is made to see if the Element is expired.
      • containsKeyInMemory

        public boolean containsKeyInMemory​(java.lang.Object key)
        Description copied from interface: Store
        A check to see if a key is in the Store and is currently held in memory.
        Specified by:
        containsKeyInMemory in interface Store
        Parameters:
        key - The Element key
        Returns:
        true if found. No check is made to see if the Element is expired.
      • expireElements

        public void expireElements()
        Description copied from interface: Store
        Expire all elements.
        Specified by:
        expireElements in interface Store
      • flush

        public void flush()
                   throws java.io.IOException
        Description copied from interface: Store
        Flush elements to persistent store.
        Specified by:
        flush in interface Store
        Throws:
        java.io.IOException - if any IO error occurs
      • bufferFull

        public boolean bufferFull()
        Description copied from interface: Store
        Some store types, such as the disk stores can fill their write buffers if puts come in too fast. The thread will wait for a short time before checking again.
        Specified by:
        bufferFull in interface Store
        Returns:
        true if the store write buffer is backed up.
      • setInMemoryEvictionPolicy

        public void setInMemoryEvictionPolicy​(Policy policy)
        Description copied from interface: Store
        Sets the eviction policy strategy. The Store will use a policy at startup. The store may allow changing the eviction policy strategy dynamically. Otherwise implementations will throw an exception if this method is called.
        Specified by:
        setInMemoryEvictionPolicy in interface Store
        Parameters:
        policy - the new policy
      • getInternalContext

        public java.lang.Object getInternalContext()
        Description copied from interface: Store
        This should not be used, and will generally return null
        Specified by:
        getInternalContext in interface Store
        Returns:
        some internal context (probably null)
      • isCacheCoherent

        public boolean isCacheCoherent()
        Description copied from interface: Store
        Indicates whether this store provides a coherent view of all the elements in a cache. Note that this is same as calling Store.isClusterCoherent() (introduced since 2.0) Use Store.isNodeCoherent() to find out if the cache is coherent in the current node in the cluster
        Specified by:
        isCacheCoherent in interface Store
        Returns:
        true if the store is coherent; or false if the store potentially splits the cache storage with another store or isn't internally coherent
      • isClusterCoherent

        public boolean isClusterCoherent()
                                  throws TerracottaNotRunningException
        Description copied from interface: Store
        Returns true if the cache is in coherent mode cluster-wide. Returns false otherwise.

        It applies to coherent clustering mechanisms only e.g. Terracotta

        Specified by:
        isClusterCoherent in interface Store
        Returns:
        true if the cache is in coherent mode cluster-wide, false otherwise
        Throws:
        TerracottaNotRunningException
      • isNodeCoherent

        public boolean isNodeCoherent()
                               throws TerracottaNotRunningException
        Description copied from interface: Store
        Returns true if the cache is in coherent mode for the current node. Returns false otherwise.

        It applies to coherent clustering mechanisms only e.g. Terracotta

        Specified by:
        isNodeCoherent in interface Store
        Returns:
        true if the cache is in coherent mode cluster-wide, false otherwise
        Throws:
        TerracottaNotRunningException
      • setNodeCoherent

        public void setNodeCoherent​(boolean coherent)
                             throws java.lang.UnsupportedOperationException,
                                    TerracottaNotRunningException
        Description copied from interface: Store
        Sets the cache in coherent or incoherent mode for the current node depending on the parameter. Calling setNodeCoherent(true) when the cache is already in coherent mode or calling setNodeCoherent(false) when already in incoherent mode will be a no-op.

        It applies to coherent clustering mechanisms only e.g. Terracotta

        Specified by:
        setNodeCoherent in interface Store
        Parameters:
        coherent - true transitions to coherent mode, false to incoherent mode
        Throws:
        java.lang.UnsupportedOperationException - if this store does not support cache coherence, like RMI replication
        TerracottaNotRunningException
      • waitUntilClusterCoherent

        public void waitUntilClusterCoherent()
                                      throws java.lang.UnsupportedOperationException,
                                             TerracottaNotRunningException,
                                             java.lang.InterruptedException
        Description copied from interface: Store
        This method waits until the cache is in coherent mode in all the connected nodes. If the cache is already in coherent mode it returns immediately

        It applies to coherent clustering mechanisms only e.g. Terracotta

        Specified by:
        waitUntilClusterCoherent in interface Store
        Throws:
        java.lang.UnsupportedOperationException - if this store does not support cache coherence, like RMI replication
        java.lang.InterruptedException
        TerracottaNotRunningException
      • getMBean

        public java.lang.Object getMBean()
        Description copied from interface: Store
        Optional implementation specific MBean exposed by the store.
        Specified by:
        getMBean in interface Store
        Returns:
        implementation specific management bean
      • setAttributeExtractors

        public void setAttributeExtractors​(java.util.Map<java.lang.String,​AttributeExtractor> extractors)
        Description copied from interface: Store
        Inform this store of the configured attribute extractors. Stores that will not invoke extractors are free to ignore this call
        Specified by:
        setAttributeExtractors in interface Store
      • getSearchAttribute

        public <S> Attribute<S> getSearchAttribute​(java.lang.String attributeName)
        Description copied from interface: Store
        Retrieve the given named search attribute
        Specified by:
        getSearchAttribute in interface Store
        Type Parameters:
        S - type of the attribute
        Parameters:
        attributeName - the name of the attribute to retrieve
        Returns:
        the search attribute or null if non-existent
      • getSearchAttributes

        public java.util.Set<Attribute> getSearchAttributes()
        Specified by:
        getSearchAttributes in interface Store
        Returns:
        all search attributes known to this store at the time of invoking the method
      • getAllQuiet

        public java.util.Map<java.lang.Object,​Element> getAllQuiet​(java.util.Collection<?> keys)
        Description copied from interface: Store
        Retries the elements associated with a set of keys without updating the statistics Keys which are not present in the cache will have null values associated with them in the returned map
        Specified by:
        getAllQuiet in interface Store
        Parameters:
        keys - a collection of keys to look for
        Returns:
        a map of keys and their corresponding values
      • getAll

        public java.util.Map<java.lang.Object,​Element> getAll​(java.util.Collection<?> keys)
        Description copied from interface: Store
        Retries the elements associated with a set of keys and update the statistics Keys which are not present in the cache will have null values associated with them in the returned map
        Specified by:
        getAll in interface Store
        Parameters:
        keys - a collection of keys to look for
        Returns:
        a map of keys and their corresponding values
      • recalculateSize

        public void recalculateSize​(java.lang.Object key)
        Description copied from interface: Store
        Recalculate size of the element mapped to the key
        Specified by:
        recalculateSize in interface Store
        Parameters:
        key - the key
      • getUnderlyingStore

        public T getUnderlyingStore()
        Accessor to the underlying store
        Returns:
        the underlying store