Package org.jgroups.blocks
Class PartitionedHashMap<K,V>
java.lang.Object
org.jgroups.blocks.PartitionedHashMap<K,V>
- All Implemented Interfaces:
MembershipListener
Hashmap which distributes its keys and values across the cluster. A PUT/GET/REMOVE computes the cluster node to which
or from which to get/set the key/value from a hash of the key and then forwards the request to the remote cluster node.
We also maintain a local cache (L1 cache) which is a bounded cache that caches retrieved keys/values.
Todos:
Todos:
- Use MarshalledValue to keep track of byte[] buffers, and be able to compute the exact size of the cache. This is good for maintaining a bounded cache (rather than using the number of entries)
- Provide a better consistent hashing algorithm than ConsistentHashFunction as default
- GUI (showing at least the topology and L1 and L2 caches)
- Notifications (puts, removes, gets etc)
- Invalidation of L1 caches (if used) on removal/put of item
- Benchmarks, comparison to memcached
- Documentation, comparison to memcached
- Author:
- Bela Ban
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classUses arrays to store hash values of addresses, plus addresses.static classstatic interface -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidblock()Called (usually by the FLUSH protocol), as an indication that the member should stop sending messages.dump()longlonggetProps()getView()booleanbooleanvoidvoidAdds a key/value to the cache, replacing a previous item if there was onevoidvoidvoidsetCachingTime(long caching_time) voidsetCallTimeout(long call_timeout) voidsetClusterName(String cluster_name) voidsetHashFunction(PartitionedHashMap.HashFunction<K> hash_function) voidsetL1Cache(Cache<K, V> cache) voidsetL2Cache(Cache<K, V> cache) voidsetMigrateData(boolean migrate_data) voidvoidstart()voidstop()voidCalled whenever a member is suspected of having crashed, but has not yet been excluded.toString()voidviewAccepted(View new_view) Called when a change in membership has occurred.
-
Field Details
-
methods
-
-
Constructor Details
-
PartitionedHashMap
-
-
Method Details
-
getProps
-
setProps
-
getLocalAddress
-
getLocalAddressAsString
-
getView
-
isL1CacheEnabled
public boolean isL1CacheEnabled() -
getClusterName
-
setClusterName
-
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) -
getHashFunction
-
setHashFunction
-
addMembershipListener
-
removeMembershipListener
-
getL1Cache
-
setL1Cache
-
getL2Cache
-
setL2Cache
-
start
- Throws:
Exception
-
stop
public void stop() -
put
-
put
Adds a key/value to the cache, replacing a previous item if there was one- Parameters:
key- The keyval- The valuecaching_time- Time to live. -1 means never cache, 0 means cache forever. All other (positive) values are the number of milliseconds to cache the item
-
get
-
remove
-
_put
-
_get
-
_remove
-
viewAccepted
Description copied from interface:MembershipListenerCalled when a change in membership has occurred. No long running actions or sending of messages 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 whenChannel.connect(String)returns.- Specified by:
viewAcceptedin interfaceMembershipListener
-
suspect
Description copied from interface:MembershipListenerCalled whenever a member is suspected of having crashed, but has not yet been excluded.- Specified by:
suspectin interfaceMembershipListener
-
block
public void block()Description copied from interface:MembershipListenerCalled (usually by the FLUSH protocol), as an indication that the member should stop sending messages. Any messages sent after returning from this callback might get blocked by the FLUSH protocol. When the FLUSH protocol is done, and messages can be sent again, the FLUSH protocol will simply unblock all pending messages. If a callback for unblocking is desired, implementExtendedMembershipListener.unblock(). Note that block() is the equivalent of reception of a BlockEvent in the pull mode.- Specified by:
blockin interfaceMembershipListener
-
toString
-
dump
-