Class CoherenceRegion

  • All Implemented Interfaces:
    org.hibernate.cache.spi.ExtendedStatisticsSupport, org.hibernate.cache.spi.Region

    public class CoherenceRegion
    extends Object
    implements org.hibernate.cache.spi.Region, org.hibernate.cache.spi.ExtendedStatisticsSupport
    CoherenceRegion is an abstract superclass for classes representing different kinds of "region" in the Hibernate second-level cache. It abstracts behavior (and state) common to all types of Hibernate second-level cache region. Note that there is a concept (and therefore terminology) mapping between the Hibernate world and the Coherence world. Hibernate uses "cache" to mean the whole, and "region" to mean a part of the whole. Coherence uses "data grid" to mean the whole, and "NamedCache" to mean a part of the whole. So a "region" to Hibernate is a NamedCache to Coherence. Therefore, CoherenceRegion is basically an Adapter, adapting the Region SPI to the NamedCache API by encapsulating and delegating to a NamedCache.
    Author:
    Randy Stafford, Gunnar Hillert
    • Field Detail

      • LOCK_LEASE_DURATION_PROPERTY_NAME

        public static final String LOCK_LEASE_DURATION_PROPERTY_NAME
        The name of the property specifying the lock lease duration.
        See Also:
        Constant Field Values
      • DEFAULT_LOCK_LEASE_DURATION

        public static final int DEFAULT_LOCK_LEASE_DURATION
        The default lock lease duration in milliseconds.
        See Also:
        Constant Field Values
    • Constructor Detail

      • CoherenceRegion

        public CoherenceRegion​(org.hibernate.cache.spi.RegionFactory regionFactory,
                               com.tangosol.net.NamedCache namedCache,
                               Map<String,​Object> properties)
        Complete constructor.
        Parameters:
        regionFactory - the region factory
        namedCache - the Coherence NamedCache
        properties - the properties
    • Method Detail

      • getNamedCache

        protected com.tangosol.net.NamedCache getNamedCache()
        Returns the NamedCache implementing this CoherenceRegion.
        Returns:
        the NamedCache implementing this CoherenceRegion
      • getRegionFactory

        public org.hibernate.cache.spi.RegionFactory getRegionFactory()
        Specified by:
        getRegionFactory in interface org.hibernate.cache.spi.Region
      • newSoftLockExpirationTime

        public long newSoftLockExpirationTime()
        Computes and returns the expiration time for a new soft lock.
        Returns:
        a long representing the expiration time for a new soft lock
      • getValue

        public Object getValue​(Object key)
        Returns the object at the argument key in this CoherenceRegion.
        Parameters:
        key - the key of the sought object
        Returns:
        the CoherenceRegionValue at the argument key in this CoherenceRegion
      • putValue

        public void putValue​(Object key,
                             Object value)
        Put the argument value into this CoherenceRegion at the argument key.
        Parameters:
        key - the key at which to put the value
        value - the value to put
      • evict

        public void evict​(Object key)
        Evicts from this CoherenceRegion the entry at the argument key.
        Parameters:
        key - the key of the entry to remove
      • evictAll

        public void evictAll()
        Evicts all entries from this CoherenceRegion.
      • lockCache

        public void lockCache()
        Locks the entire cache.
      • unlockCache

        public void unlockCache()
        Unlocks the entire cache.
      • invoke

        public Object invoke​(Object key,
                             com.tangosol.util.InvocableMap.EntryProcessor entryProcessor)
        Invoke the argument EntryProcessor on the argument key and return the result of the invocation.
        Parameters:
        key - the key on which to invoke the EntryProcessor
        entryProcessor - the EntryProcessor to invoke.
        Returns:
        the Object resulting from the EntryProcessor invocation
      • getName

        public String getName()
        Specified by:
        getName in interface org.hibernate.cache.spi.Region
      • destroy

        public void destroy()
                     throws org.hibernate.cache.CacheException
        Specified by:
        destroy in interface org.hibernate.cache.spi.Region
        Throws:
        org.hibernate.cache.CacheException
      • contains

        public boolean contains​(Object key)
      • getSizeInMemory

        public long getSizeInMemory()
        Specified by:
        getSizeInMemory in interface org.hibernate.cache.spi.ExtendedStatisticsSupport
      • getElementCountInMemory

        public long getElementCountInMemory()
        Specified by:
        getElementCountInMemory in interface org.hibernate.cache.spi.ExtendedStatisticsSupport
      • getElementCountOnDisk

        public long getElementCountOnDisk()
        Specified by:
        getElementCountOnDisk in interface org.hibernate.cache.spi.ExtendedStatisticsSupport
      • nextTimestamp

        public long nextTimestamp()
        This method is undocumented in Hibernate javadoc, but seems intended to return the "current" time.
        Returns:
        a millisecond clock value
      • getTimeout

        public int getTimeout()
        This method is undocumented in Hibernate javadoc. Comments in the Coherence-based implementation of the Hibernate 2.1 second-level cache SPI suggest the returned value is used as a lock lease duration.
        Returns:
        an int lock lease duration
      • getDurationProperty

        protected long getDurationProperty​(Map<String,​Object> properties,
                                           String propertyName,
                                           long defaultValue,
                                           long maxValue)
        Get a duration value in milliseconds from the argument properties or defaults, capped at a maximum value.
        Parameters:
        properties - the property set containing the property
        propertyName - the name of the property
        defaultValue - the default value (in milliseconds)
        maxValue - the maximum value (saturating, in milliseconds)
        Returns:
        a long duration value in milliseconds
      • clear

        public void clear()
        Specified by:
        clear in interface org.hibernate.cache.spi.Region