com.sun.jini.norm
Class ClientLeaseMapWrapper

java.lang.Object
  extended by java.util.AbstractMap
      extended by com.sun.jini.norm.ClientLeaseMapWrapper
All Implemented Interfaces:
Map, LeaseMap

 class ClientLeaseMapWrapper
extends AbstractMap
implements LeaseMap

Class that wraps LeaseMap created by client Leases. Provides hooks for synchronization and data associated with each client lease while allowing us to use LeaseRenewalManager. Objects of this class are returned by createLeaseMap calls made on ClientLeaseWrapper objects that are not deformed.

This class only allows as keys ClientLeaseWrappers that are non-deformed. Internally the mapping from ClientLeaseWrappers to longs is held in two Maps. The first is a LeaseMap that is created by the client lease associated with the first ClientLeaseWrapper added to the set. The second is a Map from client leases to the ClientLeaseWrappers that wrap them.

Author:
Sun Microsystems, Inc.
See Also:
ClientLeaseWrapper

Nested Class Summary
private  class ClientLeaseMapWrapper.Entry
          Our implementation of Map.Entry
private  class ClientLeaseMapWrapper.EntryIterator
          An implementation of Iterator backed by the ClientMapWrapper's mappings, which are from wrapperMap's values to clientLeaseMap
private  class ClientLeaseMapWrapper.EntrySet
          An implementation of Set backed by the ClientLeaseMapWrapper's mappings, which are from wrapperMap's values to clientLeaseMap
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Field Summary
private  LeaseMap clientLeaseMap
          LeaseMap created by client lease, mapping client leases to Long expiration times.
private  ClientLeaseWrapper example
          Retain initial wrapper so canContainKey can use it to determine if a specified lease may be added.
private static Method[] leaseToLeaseMapMethods
          Methods for converting lease constraints to lease map constraints.
private static long serialVersionUID
           
private  Map wrapperMap
          Map from client leases to ClientLeaseWrapper instances.
 
Constructor Summary
ClientLeaseMapWrapper(ClientLeaseWrapper wrapper, long duration)
          Create a ClientLeaseMapWrapper object that will hold the specified client Lease.
 
Method Summary
private  void applyException(Throwable t)
          For each lease in the map, call failedRenewal
 void cancelAll()
          Cancels all leases in the LeaseMap.
 boolean canContainKey(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.
private  Lease checkKey(Object key)
          Check that the key is valid for this map, if it is return the client lease, if not throw IllegalArgumentException.
private static void checkValue(Object value)
          Check that the value is a Long.
 void clear()
           
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
 Set entrySet()
           
 boolean equals(Object o)
           
 Object get(Object key)
           
 int hashCode()
           
 Object put(Object key, Object value)
           
 void putAll(Map m)
           
 Object remove(Object key)
           
 void renewAll()
          Renews all leases in the LeaseMap, using their current values as the renewal durations.
 
Methods inherited from class java.util.AbstractMap
clone, isEmpty, keySet, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
isEmpty, keySet, size, values
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

leaseToLeaseMapMethods

private static final Method[] leaseToLeaseMapMethods
Methods for converting lease constraints to lease map constraints.


clientLeaseMap

private final LeaseMap clientLeaseMap
LeaseMap created by client lease, mapping client leases to Long expiration times.


wrapperMap

private final Map wrapperMap
Map from client leases to ClientLeaseWrapper instances.


example

private final ClientLeaseWrapper example
Retain initial wrapper so canContainKey can use it to determine if a specified lease may be added.

Constructor Detail

ClientLeaseMapWrapper

ClientLeaseMapWrapper(ClientLeaseWrapper wrapper,
                      long duration)
Create a ClientLeaseMapWrapper object that will hold the specified client Lease.

Parameters:
wrapper - a wrapper for the lease that wants to be renewed
duration - the duration to associate with wrapper
Throws:
IllegalArgumentException - if wrapper is deformed
Method Detail

cancelAll

public void cancelAll()
Description copied from interface: LeaseMap
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 LeaseMap

applyException

private void applyException(Throwable t)
For each lease in the map, call failedRenewal


renewAll

public void renewAll()
              throws LeaseMapException,
                     RemoteException
Description copied from interface: LeaseMap
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 LeaseMap
Throws:
LeaseMapException
RemoteException

canContainKey

public boolean canContainKey(Object key)
Description copied from interface: LeaseMap
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 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)

checkKey

private Lease checkKey(Object key)
Check that the key is valid for this map, if it is return the client lease, if not throw IllegalArgumentException.


checkValue

private static void checkValue(Object value)
Check that the value is a Long.


containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map
Overrides:
containsKey in class AbstractMap

containsValue

public boolean containsValue(Object value)
Specified by:
containsValue in interface Map
Overrides:
containsValue in class AbstractMap

get

public Object get(Object key)
Specified by:
get in interface Map
Overrides:
get in class AbstractMap

put

public Object put(Object key,
                  Object value)
Specified by:
put in interface Map
Overrides:
put in class AbstractMap

remove

public Object remove(Object key)
Specified by:
remove in interface Map
Overrides:
remove in class AbstractMap

putAll

public void putAll(Map m)
Specified by:
putAll in interface Map
Overrides:
putAll in class AbstractMap

clear

public void clear()
Specified by:
clear in interface Map
Overrides:
clear in class AbstractMap

equals

public boolean equals(Object o)
Specified by:
equals in interface Map
Overrides:
equals in class AbstractMap

hashCode

public int hashCode()
Specified by:
hashCode in interface Map
Overrides:
hashCode in class AbstractMap

entrySet

public Set entrySet()
Specified by:
entrySet in interface Map
Specified by:
entrySet in class AbstractMap


Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.