systemic.sif.sifcommon.publisher
Class BasePublisher

java.lang.Object
  extended by systemic.sif.sifcommon.BaseInfo
      extended by systemic.sif.sifcommon.publisher.BasePublisher
All Implemented Interfaces:
java.lang.Runnable, openadk.library.Publisher

public abstract class BasePublisher
extends BaseInfo
implements openadk.library.Publisher, java.lang.Runnable

All publishers should extend this class. It ensures that resources are dealt with correctly.

Author:
Joerg Huber

Constructor Summary
BasePublisher(java.lang.String publisherID)
          This class is a basic initialiser of a publisher.
 
Method Summary
 void broadcastEvents()
          This method retrieves all events to be published by calling the abstract method getSIFEvents().
abstract  void finalise()
          This method should release all resources associated with the given publisher.
 java.util.List<SIFEvent> getEventsFromFile()
           
 java.util.List<openadk.library.SIFDataObject> getObjectsFromFile()
           
 openadk.library.PublishingOptions getOptions()
           
abstract  SIFResponseIterator getRequestedSIFObjects(openadk.library.Query query, openadk.library.Zone zone)
          This method must returns a SIFResponseIterator.
abstract  SIFEventIterator getSIFEvents()
          This method returns a SIFEventIterator.
 java.lang.String loadXMLFileData(java.lang.String fullPathAndName)
           
 void onRequest(openadk.library.DataObjectOutputStream dataobjectoutputstream, openadk.library.Query query, openadk.library.Zone zone, openadk.library.MessageInfo msgInfo)
          This is the implementation of the SIFWorks ADK method.
 void run()
          This method is all that is needed to run the publisher in its own thread.
 void setOptions(openadk.library.PublishingOptions options)
           
 void shutdownPublisher()
          This method shuts down this publisher gracefully.
 
Methods inherited from class systemic.sif.sifcommon.BaseInfo
getAgentConfig, getAgentID, getAgentProperties, getAgentProperty, getApplicationID, getDtd, getFrameworkProperties, getId, getMappings, getZoneByID, getZones, isValidZone, setAgentConfig, setAgentID, setAgentProperties, setApplicationID, setDtd, setFrameworkProperties, setId, setMappings, setZones
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasePublisher

public BasePublisher(java.lang.String publisherID)
This class is a basic initialiser of a publisher. No properties except the publisherID and DTD for the applicable publisher are expected to be set in this method. The BaseAgent will call this method first, then set appropriate properties of the BaseInfo class.

Parameters:
publisherID - The unique ID of this publisher. Ideally this is the class name but this is not necessary. This ID is used throughout the SIFCommon Framework classes to access properties in the SIFAgent.properties file. This ID must match the reference in this property file for the given publisher.
Method Detail

getSIFEvents

public abstract SIFEventIterator getSIFEvents()
                                       throws openadk.library.ADKException
This method returns a SIFEventIterator. This needs to be implemented (i.e. not returning null) if the Agent should publish events. The method broadcastEvents() will utilise this method to retrieve all the events to be published. It is up to the Agent that implements a publisher to decide the following:
a) Do events need to be published (ie. if not then this method can be implemented as 'return null')
b) The frequency/method (i.e. event driven or polling) how events are published.

Returns:
SIFEventIterator An iterator through which the broadcast() method retrieve event by event and publish it to all the zones listed in the Agent's configuration file.
Throws:
openadk.library.ADKException - If there is an error with retrieving data.

getRequestedSIFObjects

public abstract SIFResponseIterator getRequestedSIFObjects(openadk.library.Query query,
                                                           openadk.library.Zone zone)
                                                    throws openadk.library.ADKException,
                                                           openadk.library.SIFException
This method must returns a SIFResponseIterator. This needs to be implemented (i.e. not returning null) if the should respond to SIF Requests from a subscriber. The internal method onRequest() will utilise this method to finally send the objects to the ZIS. The returned object must meet the given SIFQuery.

Parameters:
query - The query this agent is requested to meet.
zone - The Zone that for which the request has been received.
Returns:
SIFResponseIterator An iterator through which the onRequest() method retrieve SIF Objects one by one and responses to the original request.
Throws:
openadk.library.ADKException - If there is an error with retrieving data.
openadk.library.SIFException - If the query cannot be dealt with (ie not supported). In this case the following fields must be set:
Error Category of SIFErrorCodes.CAT_REQRSP_8 and
An Error Code of SIFErrorCodes.REQRSP_UNSUPPORTED_QUERY_9

finalise

public abstract void finalise()
This method should release all resources associated with the given publisher. It will be called as part of the shutdown process of the agent.


getOptions

public openadk.library.PublishingOptions getOptions()

setOptions

public void setOptions(openadk.library.PublishingOptions options)

run

public final void run()
This method is all that is needed to run the publisher in its own thread. The thread is executed at given intervals driven by a property in the SIFCommonFramework property file. The interval/frequency defined in there is used to determine how often this thread is run.

Specified by:
run in interface java.lang.Runnable

onRequest

public final void onRequest(openadk.library.DataObjectOutputStream dataobjectoutputstream,
                            openadk.library.Query query,
                            openadk.library.Zone zone,
                            openadk.library.MessageInfo msgInfo)
                     throws openadk.library.ADKException
This is the implementation of the SIFWorks ADK method. It calls the abstract method getRequestedSIFObjects() that is defined in this class. It iterates through all objects and sends it as a response to the subscriber that requested the data.
It is not expected that any sub-classes call this method at all.

Specified by:
onRequest in interface openadk.library.Publisher
Throws:
openadk.library.ADKException
See Also:
getRequestedSIFObjects(openadk.library.Query, openadk.library.Zone)

broadcastEvents

public void broadcastEvents()
This method retrieves all events to be published by calling the abstract method getSIFEvents(). The returned list is then broadcasted to all zones known to the implementing agent.

See Also:
getSIFEvents()

shutdownPublisher

public final void shutdownPublisher()
This method shuts down this publisher gracefully. It is called by the Agent when a shutdown request has been issued to the agent. It is not expected that sub-classes of this class call this method. Specifics of the sub-class shutdowns must be handled in the finalise() method of the sub-class. The finalise() method is called as part of this method.


loadXMLFileData

public java.lang.String loadXMLFileData(java.lang.String fullPathAndName)

getObjectsFromFile

public java.util.List<openadk.library.SIFDataObject> getObjectsFromFile()

getEventsFromFile

public java.util.List<SIFEvent> getEventsFromFile()