com.hazelcast.client.proxy
Class ClientMultiMapProxy<K,V>

java.lang.Object
  extended by com.hazelcast.client.spi.ClientProxy
      extended by com.hazelcast.client.proxy.ClientMultiMapProxy<K,V>
All Implemented Interfaces:
BaseMultiMap<K,V>, DistributedObject, MultiMap<K,V>

public class ClientMultiMapProxy<K,V>
extends ClientProxy
implements MultiMap<K,V>

Author:
ali 5/19/13

Field Summary
protected static String NULL_KEY_IS_NOT_ALLOWED
           
protected static String NULL_VALUE_IS_NOT_ALLOWED
           
 
Constructor Summary
ClientMultiMapProxy(String serviceName, String name)
           
 
Method Summary
 String addEntryListener(EntryListener<K,V> listener, boolean includeValue)
          Adds an entry listener for this multimap.
 String addEntryListener(EntryListener<K,V> listener, K key, boolean includeValue)
          Adds the specified entry listener for the specified key.
 String addLocalEntryListener(EntryListener<K,V> listener)
          Adds a local entry listener for this multimap.
<SuppliedValue,Result>
Result
aggregate(Supplier<K,V,SuppliedValue> supplier, Aggregation<K,SuppliedValue,Result> aggregation)
          Executes a predefined aggregation on the multimaps data set.
<SuppliedValue,Result>
Result
aggregate(Supplier<K,V,SuppliedValue> supplier, Aggregation<K,SuppliedValue,Result> aggregation, JobTracker jobTracker)
          Executes a predefined aggregation on the multimaps data set.
 void clear()
          Clears the multimap.
 boolean containsEntry(K key, V value)
          Returns whether the multimap contains the given key-value pair.
 boolean containsKey(K key)
          Returns whether the multimap contains an entry with the key.
 boolean containsValue(Object value)
          Returns whether the multimap contains an entry with the value.
 Set<Map.Entry<K,V>> entrySet()
          Returns the set of key-value pairs in the multimap.
 void forceUnlock(K key)
          Releases the lock for the specified key regardless of the lock owner.
 Collection<V> get(K key)
          Returns the collection of values associated with the key.
 LocalMultiMapStats getLocalMultiMapStats()
          Returns LocalMultiMapStats for this map.
protected  long getTimeInMillis(long time, TimeUnit timeunit)
           
 boolean isLocked(K key)
          Checks the lock for the specified key.
 Set<K> keySet()
          Returns the set of keys in the multimap.
 Set<K> localKeySet()
          Returns the locally owned set of keys.
 void lock(K key)
          Acquires a lock for the specified key.
 void lock(K key, long leaseTime, TimeUnit timeUnit)
          Acquires the lock for the specified key for the specified lease time.
protected  void onDestroy()
          Called before proxy is destroyed.
 boolean put(K key, V value)
          Stores a key-value pair in the multimap.
 Collection<V> remove(Object key)
          Removes all the entries with the given key.
 boolean remove(Object key, Object value)
          Removes the given key value pair from the multimap.
 boolean removeEntryListener(String registrationId)
          Removes the specified entry listener.
 int size()
          Returns the number of key-value pairs in the multimap.
 String toString()
           
 boolean tryLock(K key)
          Tries to acquire the lock for the specified key.
 boolean tryLock(K key, long time, TimeUnit timeunit)
          Tries to acquire the lock for the specified key.
 void unlock(K key)
          Releases the lock for the specified key.
 int valueCount(K key)
          Returns the number of values that match the given key in the multimap.
 Collection<V> values()
          Returns the collection of values in the multimap.
 
Methods inherited from class com.hazelcast.client.spi.ClientProxy
destroy, equals, getContext, getId, getName, getPartitionKey, getServiceName, hashCode, invoke, invoke, invoke, invokeInterruptibly, listen, listen, onInitialize, onShutdown, setContext, stopListening, throwExceptionIfNull, toData, toObject
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.hazelcast.core.MultiMap
getName
 
Methods inherited from interface com.hazelcast.core.DistributedObject
destroy, getId, getPartitionKey, getServiceName
 

Field Detail

NULL_KEY_IS_NOT_ALLOWED

protected static final String NULL_KEY_IS_NOT_ALLOWED
See Also:
Constant Field Values

NULL_VALUE_IS_NOT_ALLOWED

protected static final String NULL_VALUE_IS_NOT_ALLOWED
See Also:
Constant Field Values
Constructor Detail

ClientMultiMapProxy

public ClientMultiMapProxy(String serviceName,
                           String name)
Method Detail

put

public boolean put(K key,
                   V value)
Description copied from interface: MultiMap
Stores a key-value pair in the multimap.

Warning:

This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

Specified by:
put in interface BaseMultiMap<K,V>
Specified by:
put in interface MultiMap<K,V>
Parameters:
key - the key to be stored
value - the value to be stored
Returns:
true if size of the multimap is increased, false if the multimap already contains the key-value pair.

get

public Collection<V> get(K key)
Description copied from interface: MultiMap
Returns the collection of values associated with the key.

Warning:

This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

Warning-2:

The collection is NOT backed by the map, so changes to the map are NOT reflected in the collection, and vice-versa.

Specified by:
get in interface BaseMultiMap<K,V>
Specified by:
get in interface MultiMap<K,V>
Parameters:
key - the key whose associated values are to be returned
Returns:
the collection of the values associated with the key.

remove

public boolean remove(Object key,
                      Object value)
Description copied from interface: MultiMap
Removes the given key value pair from the multimap.

Warning:

This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

Specified by:
remove in interface BaseMultiMap<K,V>
Specified by:
remove in interface MultiMap<K,V>
Parameters:
key - the key of the entry to remove
value - the value of the entry to remove
Returns:
true if the size of the multimap changed after the remove operation, false otherwise.

remove

public Collection<V> remove(Object key)
Description copied from interface: MultiMap
Removes all the entries with the given key.

Warning:

This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

Warning-2:

The collection is NOT backed by the map, so changes to the map are NOT reflected in the collection, and vice-versa.

Specified by:
remove in interface BaseMultiMap<K,V>
Specified by:
remove in interface MultiMap<K,V>
Parameters:
key - the key of the entries to remove
Returns:
the collection of removed values associated with the given key. The returned collection might be modifiable but it has no effect on the multimap.

localKeySet

public Set<K> localKeySet()
Description copied from interface: MultiMap
Returns the locally owned set of keys.

Each key in this map is owned and managed by a specific member in the cluster.

Note that ownership of these keys might change over time so that key ownerships can be almost evenly distributed in the cluster.

Warning:

The set is NOT backed by the map, so changes to the map are NOT reflected in the set, and vice-versa.

Specified by:
localKeySet in interface MultiMap<K,V>
Returns:
the locally owned keys

keySet

public Set<K> keySet()
Description copied from interface: MultiMap
Returns the set of keys in the multimap.

Warning:

The set is NOT backed by the map, so changes to the map are NOT reflected in the set, and vice-versa.

Specified by:
keySet in interface MultiMap<K,V>
Returns:
the set of keys in the multimap. The returned set might be modifiable but it has no effect on the multimap.

values

public Collection<V> values()
Description copied from interface: MultiMap
Returns the collection of values in the multimap.

Warning:

The collection is NOT backed by the map, so changes to the map are NOT reflected in the collection, and vice-versa.

Specified by:
values in interface MultiMap<K,V>
Returns:
the collection of values in the multimap. the returned collection might be modifiable but it has no effect on the multimap.

entrySet

public Set<Map.Entry<K,V>> entrySet()
Description copied from interface: MultiMap
Returns the set of key-value pairs in the multimap.

Warning:

The set is NOT backed by the map, so changes to the map are NOT reflected in the set, and vice-versa.

Specified by:
entrySet in interface MultiMap<K,V>
Returns:
the set of key-value pairs in the multimap. The returned set might be modifiable but it has no effect on the multimap.

containsKey

public boolean containsKey(K key)
Description copied from interface: MultiMap
Returns whether the multimap contains an entry with the key.

Warning:

This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

Specified by:
containsKey in interface MultiMap<K,V>
Parameters:
key - the key whose existence is checked.
Returns:
true if the multimap contains an entry with the key, false otherwise.

containsValue

public boolean containsValue(Object value)
Description copied from interface: MultiMap
Returns whether the multimap contains an entry with the value.

Specified by:
containsValue in interface MultiMap<K,V>
Parameters:
value - the value whose existence is checked.
Returns:
true if the multimap contains an entry with the value, false otherwise.

containsEntry

public boolean containsEntry(K key,
                             V value)
Description copied from interface: MultiMap
Returns whether the multimap contains the given key-value pair.

This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in key's class.

Specified by:
containsEntry in interface MultiMap<K,V>
Parameters:
key - the key whose existence is checked.
value - the value whose existence is checked.
Returns:
true if the multimap contains the key-value pair, false otherwise.

size

public int size()
Description copied from interface: MultiMap
Returns the number of key-value pairs in the multimap.

Specified by:
size in interface BaseMultiMap<K,V>
Specified by:
size in interface MultiMap<K,V>
Returns:
the number of key-value pairs in the multimap.

clear

public void clear()
Description copied from interface: MultiMap
Clears the multimap. Removes all key-value pairs.

Specified by:
clear in interface MultiMap<K,V>

valueCount

public int valueCount(K key)
Description copied from interface: MultiMap
Returns the number of values that match the given key in the multimap.

Warning:

This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

Specified by:
valueCount in interface BaseMultiMap<K,V>
Specified by:
valueCount in interface MultiMap<K,V>
Parameters:
key - the key whose values count is to be returned
Returns:
the number of values that match the given key in the multimap

addLocalEntryListener

public String addLocalEntryListener(EntryListener<K,V> listener)
Description copied from interface: MultiMap
Adds a local entry listener for this multimap. The added listener will be only listening for the events (add/remove/update) of the locally owned entries.

Note that entries in distributed multimap are partitioned across the cluster members; each member owns and manages some portion of the entries. Owned entries are called local entries. This listener will be listening for the events of local entries. Let's say your cluster has member1 and member2. On member2 you added a local listener, and from member1, you call multimap.put(key2, value2). If the key2 is owned by member2, then the local listener will be notified for the add/update event. Also note that entries can migrate to other nodes for load balancing and/or membership change.

Specified by:
addLocalEntryListener in interface MultiMap<K,V>
Parameters:
listener - entry listener for this multimap
Returns:
returns registration id for the entry listener
See Also:
MultiMap.localKeySet()

addEntryListener

public String addEntryListener(EntryListener<K,V> listener,
                               boolean includeValue)
Description copied from interface: MultiMap
Adds an entry listener for this multimap. The listener will be notified for all multimap add/remove/update/evict events.

Specified by:
addEntryListener in interface MultiMap<K,V>
Parameters:
listener - entry listener for this multimap
includeValue - true if EntryEvent should contain the value, false otherwise
Returns:
returns registration id for the entry listener

removeEntryListener

public boolean removeEntryListener(String registrationId)
Description copied from interface: MultiMap
Removes the specified entry listener. Returns silently if no such listener was added before.

Specified by:
removeEntryListener in interface MultiMap<K,V>
Parameters:
registrationId - registration id of listener
Returns:
true if registration is removed, false otherwise

addEntryListener

public String addEntryListener(EntryListener<K,V> listener,
                               K key,
                               boolean includeValue)
Description copied from interface: MultiMap
Adds the specified entry listener for the specified key. The listener will be notified for all add/remove/update/evict events for the specified key only.

Warning:

This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

Specified by:
addEntryListener in interface MultiMap<K,V>
Parameters:
listener - the entry listener
key - the key to listen to
includeValue - true if EntryEvent should contain the value, false otherwise
Returns:
returns registration id.

lock

public void lock(K key)
Description copied from interface: MultiMap
Acquires a lock for the specified key.

If the lock is not available, then the current thread becomes disabled for thread scheduling purposes and lies dormant until the lock has been acquired.

The scope of the lock is for this multimap only. The acquired lock is only for the key in this multimap.

Locks are re-entrant, so if the key is locked N times, then it should be unlocked N times before another thread can acquire it.

Warning:

This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

Specified by:
lock in interface MultiMap<K,V>
Parameters:
key - the key to lock.

lock

public void lock(K key,
                 long leaseTime,
                 TimeUnit timeUnit)
Description copied from interface: MultiMap
Acquires the lock for the specified key for the specified lease time.

After the lease time, the lock will be released.

If the lock is not available, then the current thread becomes disabled for thread scheduling purposes and lies dormant until the lock has been acquired.

Scope of the lock is for this map only. The acquired lock is only for the key in this map.

Locks are re-entrant, so if the key is locked N times, then it should be unlocked N times before another thread can acquire it.

Warning:

This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

Specified by:
lock in interface MultiMap<K,V>
Parameters:
key - the key to lock.
leaseTime - time to wait before releasing the lock.
timeUnit - unit of time for the lease time.

isLocked

public boolean isLocked(K key)
Description copied from interface: MultiMap
Checks the lock for the specified key.

If the lock is acquired, this method returns true, else it returns false.

Warning:

This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

Specified by:
isLocked in interface MultiMap<K,V>
Parameters:
key - key to lock to be checked.
Returns:
true if the lock is acquired, false otherwise.

tryLock

public boolean tryLock(K key)
Description copied from interface: MultiMap
Tries to acquire the lock for the specified key.

If the lock is not available, then the current thread does not wait and the method returns false immediately.

Warning:

This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

Specified by:
tryLock in interface MultiMap<K,V>
Parameters:
key - the key to lock.
Returns:
true if lock is acquired, false otherwise.

tryLock

public boolean tryLock(K key,
                       long time,
                       TimeUnit timeunit)
                throws InterruptedException
Description copied from interface: MultiMap
Tries to acquire the lock for the specified key.

If the lock is not available, then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happens:

Warning:

This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

Specified by:
tryLock in interface MultiMap<K,V>
time - the maximum time to wait for the lock
timeunit - the time unit of the time argument
Returns:
true if the lock was acquired, false if the waiting time elapsed before the lock was acquired.
Throws:
InterruptedException

unlock

public void unlock(K key)
Description copied from interface: MultiMap
Releases the lock for the specified key. It never blocks and returns immediately.

Warning:

This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

Specified by:
unlock in interface MultiMap<K,V>
Parameters:
key - the key to lock.

forceUnlock

public void forceUnlock(K key)
Description copied from interface: MultiMap
Releases the lock for the specified key regardless of the lock owner. It always successfully unlocks the key, never blocks and returns immediately.

Warning:

This method uses hashCode and equals of binary form of the key, not the actual implementations of hashCode and equals defined in key's class.

Specified by:
forceUnlock in interface MultiMap<K,V>
Parameters:
key - key to lock.

getLocalMultiMapStats

public LocalMultiMapStats getLocalMultiMapStats()
Description copied from interface: MultiMap
Returns LocalMultiMapStats for this map. LocalMultiMapStats is the statistics for the local portion of this distributed multi map and contains information such as ownedEntryCount backupEntryCount, lastUpdateTime, and lockedEntryCount.

Since this stats are only for the local portion of this multi map, if you need the cluster-wide MultiMapStats, then you need to get the LocalMapStats from all members of the cluster and combine them.

Specified by:
getLocalMultiMapStats in interface MultiMap<K,V>
Returns:
this multimap's local statistics.

aggregate

public <SuppliedValue,Result> Result aggregate(Supplier<K,V,SuppliedValue> supplier,
                                               Aggregation<K,SuppliedValue,Result> aggregation)
Description copied from interface: MultiMap
Executes a predefined aggregation on the multimaps data set. The Supplier is used to either select or to select and extract a (sub-)value. A predefined set of aggregations can be found in Aggregations.

Specified by:
aggregate in interface MultiMap<K,V>
Type Parameters:
SuppliedValue - the final type emitted from the supplier
Result - the resulting aggregation value type
Parameters:
supplier - the supplier to select and / or extract a (sub-)value from the multimap
aggregation - the aggregation that is being executed against the multimap
Returns:
Returns the aggregated value for the multimaps data set

aggregate

public <SuppliedValue,Result> Result aggregate(Supplier<K,V,SuppliedValue> supplier,
                                               Aggregation<K,SuppliedValue,Result> aggregation,
                                               JobTracker jobTracker)
Description copied from interface: MultiMap
Executes a predefined aggregation on the multimaps data set. The Supplier is used to either select, or to select and extract, a (sub-)value. A predefined set of aggregations can be found in Aggregations.

Specified by:
aggregate in interface MultiMap<K,V>
Type Parameters:
SuppliedValue - the final type emitted from the supplier
Result - the resulting aggregation value type
Parameters:
supplier - the supplier to select and / or extract a (sub-)value from the multimap
aggregation - the aggregation that is being executed against the multimap
jobTracker - the JobTracker instance to execute the aggregation
Returns:
Returns the aggregated value

onDestroy

protected void onDestroy()
Description copied from class: ClientProxy
Called before proxy is destroyed. Overriding implementations should clean/release resources created during initialization.

Overrides:
onDestroy in class ClientProxy

getTimeInMillis

protected long getTimeInMillis(long time,
                               TimeUnit timeunit)

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2015 Hazelcast, Inc.. All Rights Reserved.