Class ReplCache<K,V>

java.lang.Object
org.jgroups.blocks.ReplCache<K,V>
Type Parameters:
K - K
V - V
All Implemented Interfaces:
Cache.ChangeListener, Receiver

public class ReplCache<K,V> extends Object implements Receiver, Cache.ChangeListener
Cache which allows for replication factors per data items; the factor determines how many replicas of a key/value we create across the cluster.
See doc/design/ReplCache.txt for details.
Author:
Bela Ban
  • Field Details

  • Constructor Details

    • ReplCache

      public ReplCache(String props, String cluster_name)
  • Method Details

    • getProps

      public String getProps()
    • setProps

      public void setProps(String props)
    • getLocalAddress

      public Address getLocalAddress()
    • getLocalAddressAsString

      public String getLocalAddressAsString()
    • getView

      public String getView()
    • getClusterSize

      public int getClusterSize()
    • isL1CacheEnabled

      public boolean isL1CacheEnabled()
    • getClusterName

      public String getClusterName()
    • setClusterName

      public void setClusterName(String cluster_name)
    • getCallTimeout

      public long getCallTimeout()
    • setCallTimeout

      public void setCallTimeout(long call_timeout)
    • getCachingTime

      public long getCachingTime()
    • setCachingTime

      public void setCachingTime(long caching_time)
    • isMigrateData

      public boolean isMigrateData()
    • setMigrateData

      public void setMigrateData(boolean migrate_data)
    • getDefaultReplicationCount

      public short getDefaultReplicationCount()
    • setDefaultReplicationCount

      public void setDefaultReplicationCount(short default_replication_count)
    • getHashFunction

      public ReplCache.HashFunction getHashFunction()
    • setHashFunction

      public void setHashFunction(ReplCache.HashFunction<K> hash_function)
    • getHashFunctionFactory

      public ReplCache.HashFunctionFactory getHashFunctionFactory()
    • setHashFunctionFactory

      public void setHashFunctionFactory(ReplCache.HashFunctionFactory<K> hash_function_factory)
    • addReceiver

      public void addReceiver(Receiver r)
    • removeMembershipListener

      public void removeMembershipListener(Receiver r)
    • addChangeListener

      public void addChangeListener(ReplCache.ChangeListener l)
    • removeChangeListener

      public void removeChangeListener(ReplCache.ChangeListener l)
    • getL1Cache

      public Cache<K,V> getL1Cache()
    • setL1Cache

      public void setL1Cache(Cache<K,V> cache)
    • getL2Cache

      public Cache<K, ReplCache.Value<V>> getL2Cache()
    • setL2Cache

      public void setL2Cache(Cache<K, ReplCache.Value<V>> cache)
    • start

      public void start() throws Exception
      Throws:
      Exception
    • stop

      public void stop()
    • put

      public void put(K key, V val, short repl_count, long timeout, boolean synchronous)
      Places a key/value pair into one or several nodes in the cluster.
      Parameters:
      key - The key, needs to be serializable
      val - The value, needs to be serializable
      repl_count - Number of replicas. The total number of times a data item should be present in a cluster. Needs to be > 0
      • -1: create key/val in all the nodes in the cluster
      • 1: create key/val only in one node in the cluster, picked by computing the consistent hash of KEY
      • K > 1: create key/val in those nodes in the cluster which match the consistent hashes created for KEY
      timeout - Expiration time for key/value.
      • -1: don't cache at all in the L1 cache
      • 0: cache forever, until removed or evicted because we need space for newer elements
      • > 0: number of milliseconds to keep an idle element in the cache. An element is idle when not accessed.
      synchronous - Whether or not to block until all cluster nodes have applied the change
    • put

      public void put(K key, V val, short repl_count, long timeout)
      Places a key/value pair into one or several nodes in the cluster.
      Parameters:
      key - The key, needs to be serializable
      val - The value, needs to be serializable
      repl_count - Number of replicas. The total number of times a data item should be present in a cluster. Needs to be > 0
      • -1: create key/val in all the nodes in the cluster
      • 1: create key/val only in one node in the cluster, picked by computing the consistent hash of KEY
      • K > 1: create key/val in those nodes in the cluster which match the consistent hashes created for KEY
      timeout - Expiration time for key/value.
      • -1: don't cache at all in the L1 cache
      • 0: cache forever, until removed or evicted because we need space for newer elements
      • > 0: number of milliseconds to keep an idle element in the cache. An element is idle when not accessed.
    • put

      public void put(K key, V val)
    • get

      public V get(K key)
      Returns the value associated with key
      Parameters:
      key - The key, has to be serializable
      Returns:
      The value associated with key, or null
    • remove

      public void remove(K key)
      Removes key in all nodes in the cluster, both from their local hashmaps and L1 caches
      Parameters:
      key - The key, needs to be serializable
    • remove

      public void remove(K key, boolean synchronous)
      Removes key in all nodes in the cluster, both from their local hashmaps and L1 caches
      Parameters:
      key - The key, needs to be serializable
    • clear

      public void clear()
      Removes all keys and values in the L2 and L1 caches
    • _put

      public V _put(K key, V val, short repl_count, long timeout)
    • _put

      public V _put(K key, V val, short repl_count, long timeout, boolean force)
      Parameters:
      key -
      val -
      repl_count -
      timeout -
      force - Skips acceptance checking and simply adds the key/value
      Returns:
    • _get

      public Cache.Value<ReplCache.Value<V>> _get(K key)
    • _remove

      public V _remove(K key)
    • _removeMany

      public void _removeMany(Set<K> keys)
    • viewAccepted

      public void viewAccepted(View new_view)
      Description copied from interface: Receiver
      Called when a change in membership has occurred. No long running actions, sending of messages or anything that could block should be done in this callback. If some long running action needs to be performed, it should be done in a separate thread.
      Note that on reception of the first view (a new member just joined), the channel will not yet be in the connected state. This only happens when JChannel.connect(String) returns.
      Specified by:
      viewAccepted in interface Receiver
    • changed

      public void changed()
      Specified by:
      changed in interface Cache.ChangeListener
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • dump

      public String dump()
    • mcastEntries

      public void mcastEntries()