casa.JION.lease
Class LeaseMap

java.lang.Object
  extended by casa.JION.lease.LeaseMap
All Implemented Interfaces:
java.util.Map, net.jini.core.lease.LeaseMap

public class LeaseMap
extends java.lang.Object
implements net.jini.core.lease.LeaseMap

An unsynchronized Map from Lease to Long (the duration to use when renewing the lease). For all methods of LeaseMap except canContainKey, an IllegalArgumentException is thrown if a key is not a Lease or a value is not a Long. Null keys and values are not supported.

Since:
1.0
Author:
Sun Microsystems, Inc.

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
LeaseMap(Lease lease, long duration)
          Instantiates a new lease map.
LeaseMap(java.util.Map<Lease,java.lang.Long> map, Lease lease, long duration)
          Instantiates a new lease map.
 
Method Summary
 void cancelAll()
          Cancels all leases in the LeaseMap.
 boolean canContainKey(java.lang.Object key)
          Returns true if the given object is a Lease which can be renewed and cancelled in a batch with other leases in the map.
 void clear()
          Removes all of the mappings from this map.
 boolean containsKey(java.lang.Object key)
          Returns true if this map contains a mapping for the specified key.
 boolean containsValue(java.lang.Object value)
          Returns true if this map maps one or more keys to the specified value.
 java.util.Set entrySet()
          Returns a Set view of the mappings contained in this map.
 java.lang.Object get(java.lang.Object key)
          Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
 boolean isEmpty()
          Returns true if this map contains no key-value mappings.
 java.util.Set keySet()
          Returns a Set view of the keys contained in this map.
static void main(java.lang.String[] args)
          The main method.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Associates the specified value with the specified key in this map.
 void putAll(java.util.Map m)
          Copies all of the mappings from the specified map to this map.
 java.lang.Object remove(java.lang.Object key)
          Removes the mapping for the specified key from this map if present.
 void renewAll()
          Renews all leases in the LeaseMap, using their current values as the renewal durations.
 int size()
          Returns the number of key-value mappings in this map.
 java.lang.String toString()
          
 java.util.Collection values()
          Returns a Collection view of the values contained in this map.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

LeaseMap

public LeaseMap(Lease lease,
                long duration)
Instantiates a new lease map.

Parameters:
lease - the lease
duration - the duration

LeaseMap

public LeaseMap(java.util.Map<Lease,java.lang.Long> map,
                Lease lease,
                long duration)
Instantiates a new lease map.

Parameters:
map - the map
lease - the lease
duration - the duration
Method Detail

size

public int size()
Returns the number of key-value mappings in this map.

Specified by:
size in interface java.util.Map
Returns:
the number of key-value mappings in this map

isEmpty

public boolean isEmpty()
Returns true if this map contains no key-value mappings.

Specified by:
isEmpty in interface java.util.Map
Returns:
true if this map contains no key-value mappings

containsKey

public boolean containsKey(java.lang.Object key)
Returns true if this map contains a mapping for the specified key.

Specified by:
containsKey in interface java.util.Map
Parameters:
key - The key whose presence in this map is to be tested
Returns:
true if this map contains a mapping for the specified key.

containsValue

public boolean containsValue(java.lang.Object value)
Returns true if this map maps one or more keys to the specified value.

Specified by:
containsValue in interface java.util.Map
Parameters:
value - value whose presence in this map is to be tested
Returns:
true if this map maps one or more keys to the specified value

get

public java.lang.Object get(java.lang.Object key)
Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

More formally, if this map contains a mapping from a key k to a value v such that (key==null ? k==null : key.equals(k)), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

A return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

Specified by:
get in interface java.util.Map
See Also:
put(Object, Object)

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced.

Specified by:
put in interface java.util.Map
Parameters:
key - key with which the specified value is to be associated
value - value to be associated with the specified key
Returns:
the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key.)

remove

public java.lang.Object remove(java.lang.Object key)
Removes the mapping for the specified key from this map if present.

Specified by:
remove in interface java.util.Map
Parameters:
key - key whose mapping is to be removed from the map
Returns:
the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key.)

putAll

public void putAll(java.util.Map m)
Copies all of the mappings from the specified map to this map. These mappings will replace any mappings that this map had for any of the keys currently in the specified map.

Specified by:
putAll in interface java.util.Map
Parameters:
m - mappings to be stored in this map
Throws:
java.lang.NullPointerException - if the specified map is null

clear

public void clear()
Removes all of the mappings from this map. The map will be empty after this call returns.

Specified by:
clear in interface java.util.Map

keySet

public java.util.Set keySet()
Returns a Set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

Specified by:
keySet in interface java.util.Map

values

public java.util.Collection values()
Returns a Collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Specified by:
values in interface java.util.Map

entrySet

public java.util.Set entrySet()
Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Specified by:
entrySet in interface java.util.Map
Returns:
a set view of the mappings contained in this map

canContainKey

public boolean canContainKey(java.lang.Object key)
Returns true if the given object is a Lease which can be renewed and cancelled in a batch with other leases in the map. Whether or not two Lease objects can be batched is an implementation detail determined by the objects.

Specified by:
canContainKey in interface net.jini.core.lease.LeaseMap
Parameters:
key - an object that should be a lease
Returns:
true if the lease can be renewed and cancelled in a a batch with other leases
See Also:
Lease.canBatch(net.jini.core.lease.Lease)

renewAll

public void renewAll()
              throws net.jini.core.lease.LeaseMapException,
                     java.rmi.RemoteException
Renews all leases in the LeaseMap, using their current values as the renewal durations. If all renewals are successful, returns normally. Otherwise, removes all leases that failed to renew from the LeaseMap, and throws LeaseMapException.

Specified by:
renewAll in interface net.jini.core.lease.LeaseMap
Throws:
net.jini.core.lease.LeaseMapException
java.rmi.RemoteException

cancelAll

public void cancelAll()
               throws net.jini.core.lease.LeaseMapException,
                      java.rmi.RemoteException
Cancels all leases in the LeaseMap. If all cancels are successful, returns normally (leaving all leases in the map). Otherwise, removes all leases that failed to cancel from the LeaseMap, and throws LeaseMapException.

Specified by:
cancelAll in interface net.jini.core.lease.LeaseMap
Throws:
net.jini.core.lease.LeaseMapException
java.rmi.RemoteException

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object

main

public static void main(java.lang.String[] args)
The main method.

Parameters:
args - the arguments