org.ws4d.java.structures
Class LockedMap

java.lang.Object
  extended by org.ws4d.java.structures.HashMap
      extended by org.ws4d.java.structures.LockedMap
All Implemented Interfaces:
Lockable

public class LockedMap
extends HashMap
implements Lockable

Class synchronizes access to a map.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.ws4d.java.structures.HashMap
HashMap.Entry
 
Constructor Summary
LockedMap()
          Constuctor.
LockedMap(HashMap map)
          Constuctor.
 
Method Summary
 void clear()
           
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 Set entrySet()
           
 boolean equals(java.lang.Object o)
           
 void exclusiveLock()
          Acquires an exclusive lock.
 java.lang.Object get(java.lang.Object key)
          Get associated value to given key.
 int hashCode()
           
 boolean isEmpty()
           
 Set keySet()
           
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
           
 void putAll(HashMap t)
           
 boolean releaseExclusiveLock()
          Releases an exclusive lock of the current thread.
 void releaseSharedLock()
          Releases a shared lock of the current thread.
 java.lang.Object remove(java.lang.Object key)
           
 void sharedLock()
          Acquires a shared lock.
 int size()
           
 java.lang.String toString()
           
 boolean tryExclusiveLock()
          Try to get an exclusive lock immediately.
 boolean trySharedLock()
          Tries to get a shared lock immediately.
 DataStructure values()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LockedMap

public LockedMap()
Constuctor. Uses new HashMap.


LockedMap

public LockedMap(HashMap map)
Constuctor.

Parameters:
map - Map, which should be synchronized
Method Detail

sharedLock

public void sharedLock()
Description copied from interface: Lockable
Acquires a shared lock. If the lock cannot be allocated immediately, the thread is blocked until allocation is possible.

Specified by:
sharedLock in interface Lockable

exclusiveLock

public void exclusiveLock()
Description copied from interface: Lockable
Acquires an exclusive lock. If the lock cannot be allocated immediately, the thread is blocked until allocation is possible.

Specified by:
exclusiveLock in interface Lockable

releaseSharedLock

public void releaseSharedLock()
Description copied from interface: Lockable
Releases a shared lock of the current thread.

Specified by:
releaseSharedLock in interface Lockable

releaseExclusiveLock

public boolean releaseExclusiveLock()
Description copied from interface: Lockable
Releases an exclusive lock of the current thread.

Specified by:
releaseExclusiveLock in interface Lockable
Returns:
true = if last exclusive lock of this thread is released.

tryExclusiveLock

public boolean tryExclusiveLock()
Description copied from interface: Lockable
Try to get an exclusive lock immediately.

Specified by:
tryExclusiveLock in interface Lockable
Returns:
true if the lock has been allocated, false otherwise

trySharedLock

public boolean trySharedLock()
Description copied from interface: Lockable
Tries to get a shared lock immediately.

Specified by:
trySharedLock in interface Lockable
Returns:
true if the lock has been allocated, false otherwise

clear

public void clear()
Overrides:
clear in class HashMap

containsKey

public boolean containsKey(java.lang.Object key)
Overrides:
containsKey in class HashMap

containsValue

public boolean containsValue(java.lang.Object value)
Overrides:
containsValue in class HashMap

entrySet

public Set entrySet()
Overrides:
entrySet in class HashMap

get

public java.lang.Object get(java.lang.Object key)
Description copied from class: HashMap
Get associated value to given key. A key == null will always return null;

Overrides:
get in class HashMap
Parameters:
key - the key to lookup
Returns:
the value for the given key or null

isEmpty

public boolean isEmpty()
Overrides:
isEmpty in class HashMap

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Overrides:
put in class HashMap

putAll

public void putAll(HashMap t)
Overrides:
putAll in class HashMap

remove

public java.lang.Object remove(java.lang.Object key)
Overrides:
remove in class HashMap

size

public int size()
Overrides:
size in class HashMap

values

public DataStructure values()
Overrides:
values in class HashMap

keySet

public Set keySet()
Overrides:
keySet in class HashMap

hashCode

public int hashCode()
Overrides:
hashCode in class HashMap

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class HashMap

toString

public java.lang.String toString()
Overrides:
toString in class HashMap