util.rmi
Class AbstractRmiListener

java.lang.Object
  extended by util.PropertyContainer
      extended by util.rmi.RmiPropertyContainer
          extended by util.rmi.AbstractRmiListener
All Implemented Interfaces:
Cloneable, Remote, EventListener, ExitCleaning, Initializable, PropertyBearing, RmiEventListener, RmiListener, RmiPropertyBearing
Direct Known Subclasses:
AbstractErrorHandler, AbstractRmiCasterAndListener, ApplicationJoiner, DailyDump, DailyDumpRepository, DatabaseNow, ErrorRelay, FieldSerializer, FileDump, FitsRelay, FitsUpdateListener, JImageURLButton.ImageListener, JLaunchBox, MasterListener, MessageListener, MyRmiListener, PointingGrabber, ReadoutRepository, StatusSerializer, TransferListener

public abstract class AbstractRmiListener
extends RmiPropertyContainer
implements RmiEventListener, ExitCleaning

The common base class for all implementations of rmi-based listeners. It provides base implementation for the RmiEventListener methods. The isConnected() method returns true. The connection to the casters is checked with the innner AbstractRmiListener.CheckCaster class. The functionality of this class is served with a TimerTask at a fixed delay. Please note that subclasses should always use the getCaster(java.lang.String) method to derive a remote reference to the caster this listener wants to subscribe to together with the registerAtCaster(util.rmi.RmiCaster, java.lang.Class) method.

The #rebind method is also served, allowing first for a deregistration at the appropriate caster, see deregisterAtCaster(util.rmi.RmiCaster, java.lang.Class), a timed wait and a new cycle of registering. Note that during the rebinding phase, the #isValid timer task is blocked.

For convenience this abstract base class provides the two methods defined in the ListenerControlling interface. They default to the #initBinding and releaseBinding(java.lang.String) methods. Daugther classes that do not require special treatment of the listener control capabilities can therefore simply implement the ListenerControlling interface without further caring about an implementation.


Nested Class Summary
private  class AbstractRmiListener.BindingThread
          A thread that initiates a binding to a special service.
private  class AbstractRmiListener.CheckCaster
          Checks if all casters are still valid references.
private static class AbstractRmiListener.ServiceReference
          Combines a service name, which should be a valid registry reference and a service class to a single Map key.
 
Nested classes/interfaces inherited from class util.PropertyContainer
PropertyContainer.URLResource
 
Field Summary
private  boolean cancel
          Cancel the get caster loop.
private  TimerTask check
          The timer task to run.
private static long DEFALIVE
          The default connection check intervall, ms (1min).
private static int DEFEXPORTPORT
          The port at which unicast should export.
private static long DEFINIT
          The default connection check initial delay, ms (1min).
private static int DEFRETRY
          The default maximum nuber of binding retries.
private static long DEFRETRYSLEEP
          The default sleep intervall between binding retries, in ms.
private static long DEFSHUTDOWNDELAY
          The default shutdown delay time, 5 sec.
static String KEY_ALIVE
          The key to the connection check intervall.
static String KEY_EXPORTPORT
          For unicast exports, the port at which we should export.
static String KEY_INIT
          The key to the connection check initial delay.
static String KEY_LISTENERNAME
          The key to the name of this listener.
static String KEY_RETRY
          The key in the properties for the maximum nuber of binding retries.
static String KEY_RETRYSLEEP
          The key for the sleep intervall between binding retries.
static String KEY_SHUTDOWNDELAY
          The time delay from receiving quit-command until orderly shutdown.
private  Map<AbstractRmiListener.ServiceReference,RmiCaster> namingToRemote
          The map of full URL names to RMICaster references.
private  List<AbstractRmiListener.BindingThread> running
          A list of currently active binding thread.
private static Timer validate
          The timer to schedule the #isValid timer task.
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR, KEY_NOINITONCREATE, KEY_RESOURCEBUNDLES
 
Fields inherited from interface util.PropertyBearing
CONFIG, KEY_CLASS, KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Constructor Summary
protected AbstractRmiListener(Map<String,String> prop)
          Constructs a new rmi-listener base class.
 
Method Summary
private  void addCasterForCheck(String name, Class<?> only, RmiCaster server)
          Adds a server defined by its binding reference and its service class to our look-up table that checks routinely for validity of the server.
 boolean allBound()
          Returns true, if all bindings are valid in the sense that there is no active binding thread.
 boolean blockBinding(String name)
          Initializes a binding without type constraints.
 boolean blockBinding(String name, Class<?> only)
          Initializes a binding.
protected abstract  boolean deregisterAtCaster(RmiCaster caster, Class<?> reference)
          Deregisters this listener at a certain csater.
 void disconnect(RmiCaster from)
          Called by the caster to signal that the listener should remove itself.
 void exit()
          Prior to performing a shutdown, we de-register from all valid casters.
private  RmiCaster getCaster(String name)
          Returns a remote reference to the rmi-caster resolvable by the given name.
 InetAddress getIP()
          Returns the IP-address of the machine this listener runs on.
 String getListenerName()
          Returns the property name KEY_LISTENERNAME.
 boolean isConnected()
          Returns true.
protected  String listenerName()
          Returns the property name KEY_LISTENERNAME.
protected abstract  boolean registerAtCaster(RmiCaster caster, Class<?> reference)
          Registers this listener at a certain caster.
 boolean releaseBinding(String name)
          Releases a binding without type constraints.
 boolean releaseBinding(String name, Class<?> only)
          Releases a binding.
protected  double rescanned(String key, String old, String newval)
          Reloads all relevant parameters for this listener to allow subclasses to become reloadable.
 Thread startBinding(String name)
          Initializes a binding without type constraints.
 Thread startBinding(String name, Class<?> only)
          Initializes a binding.
 
Methods inherited from class util.rmi.RmiPropertyContainer
containsRemoteProperty, getRemoteProperties, getRemoteProperty, setRemoteProperty
 
Methods inherited from class util.PropertyContainer
augment, augment, augment, clone, createFrom, createFrom, createFrom, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getLocalClassLoader, getLocalized, getLocalized, getLocalizedString, getLocalizedString, getProperties, getPropertiesToKey, getPropertiesToKey, getProperty, getResource, getResourceAsStream, getResourceFromKey, getResources, has, init, isNew, keyCreate, keyCreate, parseObject, reload, reload, removeProperty, setObject, setProperties, setProperty, stringProperties, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

KEY_LISTENERNAME

public static final String KEY_LISTENERNAME
The key to the name of this listener.

See Also:
Constant Field Values

KEY_RETRY

public static final String KEY_RETRY
The key in the properties for the maximum nuber of binding retries.

See Also:
Constant Field Values

KEY_RETRYSLEEP

public static final String KEY_RETRYSLEEP
The key for the sleep intervall between binding retries.

See Also:
Constant Field Values

KEY_ALIVE

public static final String KEY_ALIVE
The key to the connection check intervall.

See Also:
Constant Field Values

KEY_INIT

public static final String KEY_INIT
The key to the connection check initial delay.

See Also:
Constant Field Values

KEY_SHUTDOWNDELAY

public static final String KEY_SHUTDOWNDELAY
The time delay from receiving quit-command until orderly shutdown.

See Also:
Constant Field Values

KEY_EXPORTPORT

public static final String KEY_EXPORTPORT
For unicast exports, the port at which we should export.

See Also:
Constant Field Values

DEFEXPORTPORT

private static final int DEFEXPORTPORT
The port at which unicast should export. Zero means anonymous port.

See Also:
Constant Field Values

DEFRETRY

private static final int DEFRETRY
The default maximum nuber of binding retries.

See Also:
Constant Field Values

DEFRETRYSLEEP

private static final long DEFRETRYSLEEP
The default sleep intervall between binding retries, in ms.

See Also:
Constant Field Values

DEFALIVE

private static final long DEFALIVE
The default connection check intervall, ms (1min).

See Also:
Constant Field Values

DEFINIT

private static final long DEFINIT
The default connection check initial delay, ms (1min).

See Also:
Constant Field Values

DEFSHUTDOWNDELAY

private static final long DEFSHUTDOWNDELAY
The default shutdown delay time, 5 sec.

See Also:
Constant Field Values

validate

private static Timer validate
The timer to schedule the #isValid timer task.


namingToRemote

private Map<AbstractRmiListener.ServiceReference,RmiCaster> namingToRemote
The map of full URL names to RMICaster references.


running

private List<AbstractRmiListener.BindingThread> running
A list of currently active binding thread.


check

private TimerTask check
The timer task to run.


cancel

private boolean cancel
Cancel the get caster loop.

Constructor Detail

AbstractRmiListener

protected AbstractRmiListener(Map<String,String> prop)
Constructs a new rmi-listener base class. The timer associated with the rmi listener is constructed, but not timer task is scheduled. This should occur on the first call to the #initBinding call.
Note that this class does not export itself as a unicast remote object.

Method Detail

exit

public void exit()
Prior to performing a shutdown, we de-register from all valid casters. We iterate through our the values of our look-up table and directly call deregisterAtCaster(util.rmi.RmiCaster, java.lang.Class).

Specified by:
exit in interface ExitCleaning

rescanned

protected double rescanned(String key,
                           String old,
                           String newval)
Reloads all relevant parameters for this listener to allow subclasses to become reloadable.

Overrides:
rescanned in class PropertyContainer

blockBinding

public boolean blockBinding(String name)
Initializes a binding without type constraints. This is a blocking method.

Returns:
True on success

blockBinding

public boolean blockBinding(String name,
                            Class<?> only)
Initializes a binding. This means This method blocks until registering was successful.

Returns:
True on success

startBinding

public Thread startBinding(String name)
Initializes a binding without type constraints. This is a blocking method.


startBinding

public Thread startBinding(String name,
                           Class<?> only)
Initializes a binding. This means This method does not block until registering was successful.


releaseBinding

public boolean releaseBinding(String name)
Releases a binding without type constraints.


releaseBinding

public boolean releaseBinding(String name,
                              Class<?> only)
Releases a binding. This means


allBound

public boolean allBound()
Returns true, if all bindings are valid in the sense that there is no active binding thread.


getIP

public InetAddress getIP()
                  throws RemoteException
Returns the IP-address of the machine this listener runs on. Uses the getLocalHost of the InetAddress class. If the local host does not have an ip address, null is returned.

Throws:
RemoteException

isConnected

public boolean isConnected()
                    throws RemoteException
Returns true. Called by casters to check if the reference is still valid. Note that the RemoteException this method throws in case of faulty references is the real thing to detect.

Specified by:
isConnected in interface RmiListener
Throws:
RemoteException

disconnect

public void disconnect(RmiCaster from)
                throws RemoteException
Called by the caster to signal that the listener should remove itself. Called normally on caster exit.

Specified by:
disconnect in interface RmiListener
Throws:
RemoteException

addCasterForCheck

private void addCasterForCheck(String name,
                               Class<?> only,
                               RmiCaster server)
Adds a server defined by its binding reference and its service class to our look-up table that checks routinely for validity of the server.


getListenerName

public String getListenerName()
                       throws RemoteException
Returns the property name KEY_LISTENERNAME.

Specified by:
getListenerName in interface RmiEventListener
Throws:
RemoteException

listenerName

protected String listenerName()
Returns the property name KEY_LISTENERNAME.


registerAtCaster

protected abstract boolean registerAtCaster(RmiCaster caster,
                                            Class<?> reference)
Registers this listener at a certain caster. This method is abstract because it is not a-priori known to which type of caster this listener should subscribe, nor which listener type this instance is. If the registering process was successful this method should return true.

Returns:
True, if this listener can register at the specified caster

deregisterAtCaster

protected abstract boolean deregisterAtCaster(RmiCaster caster,
                                              Class<?> reference)
Deregisters this listener at a certain csater. This method is abstract because it is not a-priori known to which type of caster this listener should subscribe, nor which listener type this instance is. If the deregistering process was successful this method should return true.

Returns:
True, if this listener can deregister at the specified caster

getCaster

private RmiCaster getCaster(String name)
Returns a remote reference to the rmi-caster resolvable by the given name. If registry-lookup is successful, a mapping of the name to the remote caster instance is stored in the namingToRemote hash-map. This method is called only in a synchronized on namingToRemote state.