jap.forward
Class JAPRoutingRegistrationInfoServices

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

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

This class manages the infoservices, where the registration of the local forwarding server is tried.


Field Summary
private static long INFOSERVICELIST_UPDATE_INTERVAL
          If the automatic management of the registration infoservices (registrate at all available infoservices) is enabled, this constant is the update interval of the infoservice list in milliseconds.
(package private)  boolean m_propagandaIsRunning
          This stores, whether propaganda for the local forwarding server is running at the moment (true) or not (false).
(package private)  boolean m_registerAtAllAvailableInfoServices
          This stores, whether the automatic management mode for the registration at the infoservices is used (true) or the manual mode with the stored list of registration infoservices is used (false).
(package private)  java.util.Hashtable m_registrationInfoServices
          This stores the list of infoservices, where the registration is tried, if we are not in the automatic management mode.
(package private)  java.util.Vector m_runningInfoServiceRegistrations
          This stores the list of infoservice IDs, where the local forwarding server is already registrated or it is tried to registrate.
(package private)  java.lang.Thread m_updateInfoServiceListThread
          This stores the instance of the automatic infoservice registration management thread.
 
Constructor Summary
JAPRoutingRegistrationInfoServices()
          This creates a new instance of JAPRoutingRegistrationInfoServices.
 
Method Summary
 void addToRegistrationInfoServices(InfoServiceDBEntry a_infoService)
          This adds a primary InfoService to the list of registration infoservices, which is used, if we are in manual infoservice registration mode.
 boolean getRegisterAtAllAvailableInfoServices()
          Returns the current setting of the management mode.
 java.util.Vector getRegistrationInfoServices()
          Returns a clone of the list of infoservices, which shall be used, if we are in manual infoservice registration management mode.
 java.util.Vector getRegistrationInfoServicesForStartup()
          This returns a list of infoservices, where the startPropaganda() method of JAPRoutingSettings shall try the registration.
 org.w3c.dom.Element getSettingsAsXml(org.w3c.dom.Document a_doc)
          Returns the current settings for the registration of the forwarding server at the infoservice system (registration infoservices, whether to registrate at all running primary infoservices) for storage within an XML document.
 boolean loadSettingsFromXml(org.w3c.dom.Element a_infoServiceRegistrationSettingsNode)
          This method loads all settings for the registration of the forwarding server at the infoservice system (registration infoservices, whether to registrate at all running primary infoservices) from a prior created XML structure.
 void removeFromRegistrationInfoServices(java.lang.String a_infoServiceId)
          This removes an InfoService from the list of registration infoservices, which is used, if we are in manual infoservice registration mode.
 void run()
          This is the implementation of the automatic infoservice registration management thread.
 void setRegisterAtAllAvailableInfoServices(boolean a_registerAtAllAvailableInfoServices)
          This changes the management mode between automatic infoservice registration and manual infoservice registration.
 void setRegistrationInfoServices(java.util.Vector a_infoServices)
          This changes the list of registration infoservices, which are used, if we are in manual infoservice registration mode.
private  void startInfoServiceListUpdateThread()
          This starts the automatic infoservice registration thread, if it is not already running.
private  void stopInfoServiceListUpdateThread()
          This stops the automatic infoservice registration thread, 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.
 
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

INFOSERVICELIST_UPDATE_INTERVAL

private static final long INFOSERVICELIST_UPDATE_INTERVAL
If the automatic management of the registration infoservices (registrate at all available infoservices) is enabled, this constant is the update interval of the infoservice list in milliseconds. The list is fetched via the InfoServiceHolder's getInfoServices() command and new discovered infoservices with a forwarder list are used for new registration instances. The default is 10 minutes.

See Also:
Constant Field Values

m_registrationInfoServices

java.util.Hashtable m_registrationInfoServices
This stores the list of infoservices, where the registration is tried, if we are not in the automatic management mode. So if registration at all available primary infoservices is enabled, this list is not used. The usage of the hashtable has only comfort reasons. So accessing the InfoServices by the ID is much easier.


m_registerAtAllAvailableInfoServices

boolean m_registerAtAllAvailableInfoServices
This stores, whether the automatic management mode for the registration at the infoservices is used (true) or the manual mode with the stored list of registration infoservices is used (false).


m_propagandaIsRunning

boolean m_propagandaIsRunning
This stores, whether propaganda for the local forwarding server is running at the moment (true) or not (false).


m_runningInfoServiceRegistrations

java.util.Vector m_runningInfoServiceRegistrations
This stores the list of infoservice IDs, where the local forwarding server is already registrated or it is tried to registrate.


m_updateInfoServiceListThread

java.lang.Thread m_updateInfoServiceListThread
This stores the instance of the automatic infoservice registration management thread. If it is not running at the moment, this value is null.

Constructor Detail

JAPRoutingRegistrationInfoServices

public JAPRoutingRegistrationInfoServices()
This creates a new instance of JAPRoutingRegistrationInfoServices. Some initialization is done here. The new instance is configured for automatic management mode.

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 propaganda status here. If the propaganda is started and we are in automatic infoservice registration management mode, also the management thread is started, so if there appear new infoservices with a forwarder list, the registration of the local forwarding server is done automatically there. If the propaganda is started and we are in automatic management mode, also the management thread is halted.

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.

setRegistrationInfoServices

public void setRegistrationInfoServices(java.util.Vector a_infoServices)
This changes the list of registration infoservices, which are used, if we are in manual infoservice registration mode. If we are currently in the manual mode, also for the new infoservices, where we are not registrated in the moment, a new propaganda instance is started. But running instances are not stopped, even if the corresponding infoservice is not in the new list any more. If we are automatic management mode at the moment, only the internal manual infoservices list is updated, but nothing else is done (especially no propaganda instances are started).

Parameters:
a_infoServices - A Vector of primary infoservices, which shall be used for registration, if we are in manual management mode.

addToRegistrationInfoServices

public void addToRegistrationInfoServices(InfoServiceDBEntry a_infoService)
This adds a primary InfoService to the list of registration infoservices, which is used, if we are in manual infoservice registration mode. If we are currently in the manual mode and we don't have a registration at the new InfoService, a new propaganda instance for that InfoService is started. If we are automatic management mode at the moment, only the internal stored manual registration list is updated, but nothing else is done (especially no propaganda instance is started).

Parameters:
a_infoServices - A primary Infoservice, which shall be added to the list of registration infoservices for the manual management mode. If there is already an InfoService with the same ID is in the list, it is updated to this new value (but the propaganda keeps running with the old instance until a restart of the whole propaganda system).

removeFromRegistrationInfoServices

public void removeFromRegistrationInfoServices(java.lang.String a_infoServiceId)
This removes an InfoService from the list of registration infoservices, which is used, if we are in manual infoservice registration mode. Attention: Even if we are in manual registration mode and there is a running propaganda instance for this InfoService, the propaganda instance is not removed until the whole propaganda system is stopped. If we are automatic management mode at the moment, only the internal stored manual registration list is updated.

Parameters:
a_infoServiceId - The InfoService which should be removed from the list of registration infoservices for the manual registration mode. If there is no infoservice with this ID is in the list, nothing is done.

getRegistrationInfoServices

public java.util.Vector getRegistrationInfoServices()
Returns a clone of the list of infoservices, which shall be used, if we are in manual infoservice registration management mode.

Returns:
A clone of the manual configurated registration infoservices.

getRegistrationInfoServicesForStartup

public java.util.Vector getRegistrationInfoServicesForStartup()
This returns a list of infoservices, where the startPropaganda() method of JAPRoutingSettings shall try the registration. If we are in automatic management mode, all already known infoservices with a forwarder list (obtained from the InfoServiceDatabase via InfoServiceHolder) are returned (maybe this list is not up-to-date, so new infoservices with a forwarder list will be found after the first cycle of the management thread). If we are in manual registration mode, the clone of the list of manual registration infoservices is returned.

Returns:
The list of infoservices (depending on the management mode), where startPropaganda() shall try to registrate at.

setRegisterAtAllAvailableInfoServices

public void setRegisterAtAllAvailableInfoServices(boolean a_registerAtAllAvailableInfoServices)
This changes the management mode between automatic infoservice registration and manual infoservice registration. If the propaganda is running at the moment and the mode is changed, also the automatic management thread is started or halted.

Parameters:
a_registerAtAllAvailableInfoService - Is this value is true, the automatic management mode is used, if it is false, the manual management mode is used.

getRegisterAtAllAvailableInfoServices

public boolean getRegisterAtAllAvailableInfoServices()
Returns the current setting of the management mode.

Returns:
True, if the automatic infoservice management mode is used or false, if the manual infoservice registration mode is used.

getSettingsAsXml

public org.w3c.dom.Element getSettingsAsXml(org.w3c.dom.Document a_doc)
Returns the current settings for the registration of the forwarding server at the infoservice system (registration infoservices, whether to registrate at all running primary infoservices) for storage within an XML document.

Parameters:
a_doc - The context document for the infoservice registration settings.
Returns:
An XML node (InfoServiceRegistrationSettings) with the infoservice registration related settings.

loadSettingsFromXml

public boolean loadSettingsFromXml(org.w3c.dom.Element a_infoServiceRegistrationSettingsNode)
This method loads all settings for the registration of the forwarding server at the infoservice system (registration infoservices, whether to registrate at all running primary infoservices) 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 InfoServiceRegistrationSettings 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 automatic infoservice registration management thread. It looks periodically for new infoservices with a forwarder list (via InfoServiceHolder.getInfoServices()), where the local forwarding server is not registrated (or is tried to be registrated) at the moment. It creates the needed propaganda instances for those new infoservices automatically. This thread is only running in the automatic infoservice registration mode and when the propaganda is running (see startPropaganda() and stopPropaganda() in JAPRoutingSettings).

Specified by:
run in interface java.lang.Runnable

startInfoServiceListUpdateThread

private void startInfoServiceListUpdateThread()
This starts the automatic infoservice registration thread, if it is not already running.


stopInfoServiceListUpdateThread

private void stopInfoServiceListUpdateThread()
This stops the automatic infoservice registration thread, if it is running.