jap.forward
Class JAPRoutingUseableMixCascades

java.lang.Object
  extended by java.util.Observable
      extended by jap.forward.JAPRoutingUseableMixCascades
All Implemented Interfaces:
java.lang.Runnable, java.util.Observer

public final class JAPRoutingUseableMixCascades
extends java.util.Observable
implements java.util.Observer, java.lang.Runnable

This class manages the useable mixcascades for the clients of the local forwarding server. So they get always an up-to-date list of running and allowed mixcascades.


Field Summary
(package private)  boolean m_allowAllAvailableCascades
          This stores, whether the access to all available mixcascades shall be allowed for the clients of the local forwarding server (true) or it shall be restricted to some cascades (false).
(package private)  java.util.Hashtable m_allowedMixCascades
          This stores the list of allowed mixcascades.
(package private)  java.util.Hashtable m_currentlyRunningMixCascades
          This stores the list of currently running mixcascades.
(package private)  java.lang.Thread m_updateMixCascadesListThread
          This stores the instance of the update thread for the mixcascades.
private static long MIXCASCADELIST_UPDATE_INTERVAL
          This is the update interval of the mixcascade list.
 
Constructor Summary
JAPRoutingUseableMixCascades()
          This creates a new instance of JAPRoutingUseableMixCascades.
 
Method Summary
 void addToAllowedMixCascades(MixCascade a_mixCascade)
          This adds a MixCascade to the list of allowed mixcascades for the clients of the local forwarding server.
 boolean getAllowAllAvailableMixCascades()
          Returns the restriction mode.
 java.util.Vector getAllowedMixCascades()
          Returns a clone of the list of allowed mixcascades for the forwarding server.
 org.w3c.dom.Element getSettingsAsXml(org.w3c.dom.Document a_doc)
          Returns the current settings for the allowed forwarding mixcascades (allowed cascades, whether all running mixcascades are allowed) for storage within an XML document.
 boolean loadSettingsFromXml(org.w3c.dom.Element a_allowedMixCascadesSettingsNode)
          This method loads all settings for the allowed mixcascades for the forwarding server from a prior created XML structure.
 void removeFromAllowedMixCascades(java.lang.String a_mixCascadeId)
          This removes a MixCascade from the list of allowed mixcascades for the clients of the local forwarding server.
 void run()
          This is the implementation of the mixcascades management thread for the local forwarding server.
 void setAllowAllAvailableMixCascades(boolean a_allowAllAvailableCascades)
          This changes the restriction mode for the clients between no restriction (access to all running mixcascades is allowed) or restriction to the list of allowed mixcascades, which needs to be also running.
 void setAllowedMixCascades(java.util.Vector a_mixCascades)
          This changes the list of allowed mixcascades for the clients of the local forwarding server.
private  void startMixCascadesListUpdateThread()
          This starts the management thread for the useable mixcascades of the local forwarding server, if it is not already running.
private  void stopMixCascadesListUpdateThread()
          This stops the management thread for the useable mixcascades of the local forwarding server, if it is running.
 void update(java.util.Observable a_notifier, java.lang.Object a_message)
          This is the observer implementation to observe the instance of JAPRoutingSettings.
private  void updateUseableCascadesDatabase()
          Updates the ForwardServerDatabase, which contains the currently useable mixcascades for the clients of the local forwarding server.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIXCASCADELIST_UPDATE_INTERVAL

private static final long MIXCASCADELIST_UPDATE_INTERVAL
This is the update interval of the mixcascade list. The list update is done by fetching the mixcascade list from the infoservices (via InfoServiceHolder.getMixCascades()). Then the internal stored list (in ForwardCascadeDatabase) is updated by adding the new (allowed) cascades and removing that ones, which are not in the list of currently running cascades. So the client always gets an up-to-date list of available (and allowed) cascades. The default update interval is 10 minutes.

See Also:
Constant Field Values

m_allowedMixCascades

java.util.Hashtable m_allowedMixCascades
This stores the list of allowed mixcascades. This list is used, if the access to the mixcascades shall be restricted for the clients of the local forwarding server. So if access to all available mixcascades is enabled, this list is not used. The usage of the hashtable has only comfort reasons. So accessing the cascades by the ID is much easier.


m_allowAllAvailableCascades

boolean m_allowAllAvailableCascades
This stores, whether the access to all available mixcascades shall be allowed for the clients of the local forwarding server (true) or it shall be restricted to some cascades (false).


m_currentlyRunningMixCascades

java.util.Hashtable m_currentlyRunningMixCascades
This stores the list of currently running mixcascades. This list is updated once within an update interval. The usage of the hashtable has only comfort reasons. So accessing the cascades by the ID is much easier.


m_updateMixCascadesListThread

java.lang.Thread m_updateMixCascadesListThread
This stores the instance of the update thread for the mixcascades. It updates the list of currently running mixcascades and also the database of useable mixcascades for the clients of the local forwarding server is updated. This thread is executed while we are in server routing mode. If the thread is not running, this value is null. There can be only one running instance of that thread at one time.

Constructor Detail

JAPRoutingUseableMixCascades

public JAPRoutingUseableMixCascades()
This creates a new instance of JAPRoutingUseableMixCascades. Some initialization is done here. The new instance is configured for allowing access to all available mixcascades.

Method Detail

update

public void update(java.util.Observable a_notifier,
                   java.lang.Object a_message)
This is the observer implementation to observe the instance of JAPRoutingSettings. We handle the messages about changes of the routing mode here. If the forwarding server is started, also we start also the mixcascades management thread. If it is stopped, we stop also that thread.

Specified by:
update in interface java.util.Observer
Parameters:
a_notifier - The observed Object. This should always be JAPRoutingSettings at the moment.
a_message - The reason of the notification. This should always be a JAPRoutingMessage at the moment.

setAllowedMixCascades

public void setAllowedMixCascades(java.util.Vector a_mixCascades)
This changes the list of allowed mixcascades for the clients of the local forwarding server. If we are in the restricted mode (accessing all available mixcascades is not enabled), clients can only connect to the mixcascades specified here, which are also running at the moment of the client connection. If JAPRoutingSettings is in server routing mode (mixcascade management thread is running) and we are in the restricted mode, also the database of useable mixcascades for the client is updated immediately. Attention: Calling this method does not automatically activate the restricted mode. So you have to do this by the call of the setAllowAllMixCascades() method explicitly.

Parameters:
a_mixCascades - A Vector of mixcascades, which shall be allowed for the clients of the local forwarding server in the restricted mode.

addToAllowedMixCascades

public void addToAllowedMixCascades(MixCascade a_mixCascade)
This adds a MixCascade to the list of allowed mixcascades for the clients of the local forwarding server. If we are in the restricted mode (accessing all available mixcascades is not enabled), clients can only connect to the mixcascades specified in that list, which are also running at the moment of the client connection. If JAPRoutingSettings is in server routing mode (mixcascade management thread is running) and we are in the restricted mode, also the database of useable mixcascades for the client is updated immediately. Attention: Calling this method does not automatically activate the restricted mode. So you have to do this by the call of the setAllowAllMixCascades() method explicitly.

Parameters:
a_mixCascade - The MixCascade which should added to the list of allowed mixcascades for the restricted mode. If there is already a mixcascade with the same ID in the list, it is updated to this new cascade value.

removeFromAllowedMixCascades

public void removeFromAllowedMixCascades(java.lang.String a_mixCascadeId)
This removes a MixCascade from the list of allowed mixcascades for the clients of the local forwarding server. If we are in the restricted mode (accessing all available mixcascades is not enabled), clients can only connect to the mixcascades specified in that list, which are also running at the moment of the client connection. If JAPRoutingSettings is in server routing mode (mixcascade management thread is running) and we are in the restricted mode, also the database of useable mixcascades for the client is updated immediately. Attention: Calling this method does not automatically activate the restricted mode. So you have to do this by the call of the setAllowAllMixCascades() method explicitly.

Parameters:
a_mixCascadeId - The MixCascade which should removed from the list of allowed mixcascades for the restricted mode. If there is no mixcascade with this ID is in the list, nothing is done.

getAllowedMixCascades

public java.util.Vector getAllowedMixCascades()
Returns a clone of the list of allowed mixcascades for the forwarding server.

Returns:
A clone of the allowed mixcascades list for the clients of the local forwarding server.

setAllowAllAvailableMixCascades

public void setAllowAllAvailableMixCascades(boolean a_allowAllAvailableCascades)
This changes the restriction mode for the clients between no restriction (access to all running mixcascades is allowed) or restriction to the list of allowed mixcascades, which needs to be also running. If the forwarding server is running and the mode was changed, also the database of useable mixcascades for the forwarding server is updated.

Parameters:
a_allowAllAvailableCascades - Whether access to all available mixcascades shall be granted (true) or only to set of explicitly allowed mixcascades (false).

getAllowAllAvailableMixCascades

public boolean getAllowAllAvailableMixCascades()
Returns the restriction mode. This method returns true, if the clients of the local forwarding server have access to all available mixcascades or false, if they have only access to a set of allowed mixcascades.

Returns:
Whether all mixcascades are allowed to access for the clients of the local forwarding server.

getSettingsAsXml

public org.w3c.dom.Element getSettingsAsXml(org.w3c.dom.Document a_doc)
Returns the current settings for the allowed forwarding mixcascades (allowed cascades, whether all running mixcascades are allowed) for storage within an XML document.

Parameters:
a_doc - The context document for the forwarding mixcascades settings.
Returns:
An XML node (AllowedMixCascadesSettings) with the allowed forwarding mixcascades related settings.

loadSettingsFromXml

public boolean loadSettingsFromXml(org.w3c.dom.Element a_allowedMixCascadesSettingsNode)
This method loads all settings for the allowed mixcascades for the forwarding server from a prior created XML structure. If there is an error while loading the settings, it is still tried to load as much settings as possible.

Parameters:
a_infoServiceRegistrationSettingsNode - The AllowedMixCascadesSettings XML node, which was created by the getSettingsAsXml() method.
Returns:
True, if there was no error while loading the settings and false, if there was one.

run

public void run()
This is the implementation of the mixcascades management thread for the local forwarding server. It fetches the currently running mixcascades once per update interval from the infoservices and updates with that information the database of currently running and allowed mixcascades for the clients of the local forwarding server.

Specified by:
run in interface java.lang.Runnable

updateUseableCascadesDatabase

private void updateUseableCascadesDatabase()
Updates the ForwardServerDatabase, which contains the currently useable mixcascades for the clients of the local forwarding server. This method adds new and allowed cascades to that database and removes all currently not running or not allowed cascades from there.


startMixCascadesListUpdateThread

private void startMixCascadesListUpdateThread()
This starts the management thread for the useable mixcascades of the local forwarding server, if it is not already running.


stopMixCascadesListUpdateThread

private void stopMixCascadesListUpdateThread()
This stops the management thread for the useable mixcascades of the local forwarding server, if it is running.