|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.edustructures.sifworks.Agent
public class Agent
The base class for a SIF Agent.
Derive your own class from this one and pass the SourceId to the
superclass constructor. Call the initialize method to initialize
the agent prior to use.
| Field Summary | |
|---|---|
static java.lang.String |
LOG_IDENTIFIER
|
| Constructor Summary | |
|---|---|
Agent(java.lang.String agentId)
Constructor |
|
| Method Summary | |
|---|---|
void |
addMessagingListener(MessagingListener listener)
Register a MessagingListener to listen to messages received by the message handlers of this class. |
HttpProperties |
getDefaultHttpProperties()
Convenience method to get the default HTTP transport properties |
HttpsProperties |
getDefaultHttpsProperties()
Convenience method to get the default HTTPS transport properties |
TransportProperties |
getDefaultTransportProperties(java.lang.String protocol)
Gets the default properties for a transport protocol. |
AgentProperties |
getDefaultZoneProperties()
Gets the default properties for Zones created by the ZoneFactory. |
UndeliverableMessageHandler |
getErrorHandler()
Gets the UndeliverableMessageHandler for this agent. |
java.lang.String |
getHomeDir()
Gets the agent's home directory. |
java.lang.String |
getId()
Gets the agent's SourceId |
static org.apache.log4j.Logger |
getLog()
Gets the root Log4j Category for this agent. |
static org.apache.log4j.Logger |
getLog(Zone zone)
Gets the Log4j Category for a specific zone. |
java.util.List<MessagingListener> |
getMessagingListeners()
Return a list of all MessagingListeners registered with the agent |
java.lang.String |
getName()
Gets the descriptive name of the SIF Agent. |
AgentProperties |
getProperties()
Gets the properties for this agent. |
Publisher |
getPublisher(SIFContext context,
ElementDef objectType)
Gets the global Publisher message handler registered with the Agent for the specified SIF object type |
QueryResults |
getQueryResults(SIFContext context,
ElementDef objectType)
Gets the global QueryResults message handler registered with the Agent for the specified SIF object type. |
ReportPublisher |
getReportPublisher(SIFContext context)
Gets the global ReportPublisher message handler registered with the Agent. |
static ServerLog |
getServerLog()
Gets the agent-global ServerLog instance. |
static ServerLog |
getServerLog(Zone zone)
Gets the ServerLog for a specific zone. |
Subscriber |
getSubscriber(SIFContext context,
ElementDef objectType)
Gets the global Subscriber message handler registered with the Agent for the specified SIF object type. |
TopicFactory |
getTopicFactory()
Gets the TopicFactory for this agent. |
ZoneFactory |
getZoneFactory()
Gets the ZoneFactory for this agent. |
void |
initialize()
Initialize the agent. |
boolean |
isInitialized()
Determines if the agent has been initialized |
boolean |
isShutdown()
Determines if the agent has been shutdown. |
static java.lang.String |
makeGUID()
Utility method to generate a GUID for SIF Data Objects and messages |
void |
purgeQueue(boolean incoming,
boolean outgoing)
Purge all pending incoming and/or outgoing messages from this agent's queue. |
void |
removeMessagingListener(MessagingListener listener)
Remove a MessagingListener previously registered with the addMessagingListener method. |
void |
setErrorHandler(UndeliverableMessageHandler handler)
Sets the UndeliverableMessageHandler to be called when a dispatching error occurs on a zone but no handler is registered with that zone. |
void |
setId(java.lang.String sourceId)
Sets the agent's SourceId |
void |
setName(java.lang.String name)
Sets the descriptive name of the SIF Agent. |
void |
setPublisher(Publisher publisher)
Register a global Publisher message handler with this agent for all SIF object types. |
void |
setPublisher(Publisher publisher,
ElementDef objectType)
Register a global Publisher message handler with the agent for the specified SIF object type. |
void |
setQueryResults(QueryResults queryResults)
Register a global QueryResults message handler with this agent for all SIF object types and only for the default SIF Context |
void |
setQueryResults(QueryResults queryResults,
ElementDef objectType)
Register a global QueryResults message handler object with this agent for the specified SIF object type and only for the default SIF Context |
void |
setReportPublisher(ReportPublisher publisher)
Register a global ReportPublisher message handler with the agent. |
void |
setSubscriber(Subscriber subscriber)
Register a global Subscriber message handler with the agent for all SIF object types. |
void |
setSubscriber(Subscriber subscriber,
ElementDef objectType)
Register a global Subscriber message handler with this agent for the specified SIF object type and only for the default SIF Context |
void |
shutdown()
Shutdown the agent. |
void |
shutdown(int provisioningOptions)
Shutdown the agent. |
void |
sleep()
Puts all connected zones into sleep mode. |
void |
wakeup()
Wakes up all connected zones if currently in sleep mode. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String LOG_IDENTIFIER
| Constructor Detail |
|---|
public Agent(java.lang.String agentId)
sourceId - The string name that uniquely identifies this agent in SIF Zones.
This string is used as the SourceId in all SIF message
headers created by the agent.| Method Detail |
|---|
public ZoneFactory getZoneFactory()
public TopicFactory getTopicFactory()
public AgentProperties getProperties()
The agent properties serve as defaults for new Zone objects created by the ZoneFactory. Properties may be customized on a zone-by-zone basis. If a property is not specified for a given zone, its value is inherited from the AgentProperties object returned by this method. Note this method returns the same object as getDefaultZoneProperties.
Agent properties should be set prior to calling the Agent.initialize method.
public TransportProperties getDefaultTransportProperties(java.lang.String protocol)
throws ADKTransportException
Each transport protocol supported by the ADK is represented by a class that implements the Transport interface. Transports are identified by a string such as "http" or "https". Like Zones, each Transport instance is associated with a set of properties specific to the transport protocol. Such properties may include IP address, port, SSL security attributes, and so on. The default properties for a given transport protocol may be obtained by calling this method.
ADKTransportException - is thrown if the protocol is not supported
by the ADKpublic HttpProperties getDefaultHttpProperties()
public HttpsProperties getDefaultHttpsProperties()
public AgentProperties getDefaultZoneProperties()
public java.lang.String getHomeDir()
The Agent Runtime creates all work directories and files relative to the home directory. In some cases the Class Framework creates workspaces even when the Agent Runtime is not enabled.
public java.lang.String getId()
public void setId(java.lang.String sourceId)
sourceId - A string name that uniquely identifies this agent in
a SIF Zone. SIF does not specify any restrictions on the length or
characters that may appear in the SourceId.public java.lang.String getName()
This string is used to identify the agent whenever a descriptive name is preferred over the agent ID. If the @link #getAgentInfo() method is not overrident, The class framework uses this string for the value of the <SIF_Name> element during agent registration.
By default, the agent ID is returned.
getId(),
setName(String)public void setName(java.lang.String name)
This string is used to identify the agent whenever a descriptive name is preferred over the agent ID. The class framework uses this string for the value of the <SIF_Name> element during agent registration.
By default, the agent ID is used as the descriptive name. This method must be called at agent initialization time prior to connecting to zones.
name - A descriptive name for the agentgetName()
public void initialize()
throws java.lang.Exception
An application must call this method to initialize the class framework
and runtime. No other methods can be called until the agent has been
successfully initialized. When the agent exits it is important that the
shutdown method be called to safely release the resources
allocated by the runtime.
If an application overrides this method, it should call the superclass implementation after performing its own initialization.
InitializerException - is thrown if the agent has already
been initialized
java.lang.Exceptionshutdown()
public void shutdown()
throws ADKException
This method should always be called before the application ends. It closes resources held by the class framework and runtime.
Calling this form of shutdown does not send any provisioning messages.
ADKException
public void shutdown(int provisioningOptions)
throws ADKException
This method should always be called before the application ends. It closes resources held by the ADK Class Framework and ADK Agent Runtime.
Provisioning messages are sent as follows:
<
SIF_Unregister> message is sent to each zone to which
the agent is connected if the ADKFlags.PROV_UNREGISTER
flag is specified. <SIF_Unsubscribe> and
<SIF_Unprovide> messages are sent to each
zone joined to a Topic when the ADKFlags.PROV_UNSUBSCRIBE
and ADKFlags.PROV_UNPROVIDE flags are specified, respectively.
When ADK-managed provisioning is disabled, no provisioning
messages are sent to zones.
ADKExceptioninitialize()public boolean isInitialized()
initialize method was called successfully;
false if that method has not been called successfully or the agent
has since been shut down.public boolean isShutdown()
shutdown method was called and the
agent is either in the process of shutting down or has finished
shutting down. Note the agent is considered to be shutdown even
if the shutdown method fails.
public void sleep()
throws ADKException
For each zone in the connected state, a SIF_Sleep message is sent to the
Zone Integration Server to request that this agent's queue be put into
sleep mode for that zone. If successful, the ZIS should not deliver
further messages to this agent until it is receives a SIF_Register or
SIF_Wakeup message from the agent. Note the ADK keeps an internal sleep
flag for each zone, which is initialized when the connect
method is called by sending a SIF_Ping to the ZIS. This flag is set so
that the ADK will return a Status Code 8 ("Receiver is sleeping") in
response to any message received by the ZIS for the duration of the
session.
ADKException - thrown if the SIF_Sleep message is unsuccessful.
The ADK will attempt to send a SIF_Sleep to all connected zones; the
exception describes the zone or zones that failed
public void wakeup()
throws ADKException
For each connected zone, a SIF_Wakeup message is sent to the Zone
Integration Server to request that sleep mode be removed from this agent's
queue for that zone. Note the ADK keeps an internal sleep flag for each
zone, which is initialized when the connect method is called
by sending a SIF_Ping to the ZIS. This flag is cleared so that the ADK
will no longer return a Status Code 8 ("Receiver is sleeping") in response
to messages received by the ZIS.
ADKException - thrown if the SIF_Wakeup message is unsuccessful.
The ADK will attempt to send a SIF_Wakeup to all connected zones; the
exception describes the zone or zones that failedpublic void setPublisher(Publisher publisher)
Note agents typically register message handlers with Topics or with Zones instead of with the Agent. The message dispatcher first delivers messages to Topics, then to Zones, and finally to the Agent itself.
In order to receive SIF_Request messages, the agent is expected to be registered as a Provider of one or more object types in at least one zone. This method does not send SIF_Provide messages to any zones.
publisher - An object that implements the Publisher
interface to respond to SIF_Request queries received by the agent.
This object will be called whenever a SIF_Request is received by
and no other object in the message dispatching chain has processed
the message.
public void setPublisher(Publisher publisher,
ElementDef objectType)
Note agents typically register message handlers with Topics or with Zones instead of with the Agent. The message dispatcher first delivers messages to Topics, then to Zones, and finally to the Agent itself.
In order to receive SIF_Request messages, the agent is expected to be registered as a Provider of one or more object types in at least one zone. This method does not send SIF_Provide messages to any zones.
publisher - An object that implements the Publisher
interface to respond to SIF_Request queries received by the agent,
where the SIF object type referenced by the request matches the
specified objectType. This Publisher will be called whenever a
SIF_Request is received and no other object in the message dispatching
chain has processed the message.objectType - A constant from the SIFDTD class that identifies the
type of SIF Data Object this Publisher will respond to.public void setReportPublisher(ReportPublisher publisher)
Note agents typically register message handlers with Topics or with Zones instead of with the Agent. The message dispatcher first delivers messages to Topics, then to Zones, and finally to the Agent itself. In order to receive SIF_Request messages, the agent is expected to be registered as a Provider of one or more object types in at least one zone. This method does not send SIF_Provide messages to any zones.
publisher - An object that implements the ReportPublisher
interface to respond to SIF_Request queries received for SIF_ReportObject
objects. This Publisher will be called whenever a request is received
and no other object in the message dispatching chain has processed
the message.public void setSubscriber(Subscriber subscriber)
Note agents typically register message handlers with Topics or with Zones instead of with the Agent. The message dispatcher first delivers messages to Topics, then to Zones, and finally to the Agent itself.
In order to receive SIF_Event messages, the agent is expected to be registered as a Subscriber of one or more object types in at least one zone. This method does not send SIF_Subscribe messages to any zones.
subscriber - An object that implements the Subscriber
interface to respond to SIF_Event notifications received by the agent.
This object will be called whenever a SIF_Event is received and no
other object in the message dispatching chain has processed the
message.
public void setSubscriber(Subscriber subscriber,
ElementDef objectType)
Note agents typically register message handlers with Topics or with Zones instead of with the Agent. The message dispatcher first delivers messages to Topics, then to Zones, and finally to the Agent itself.
In order to receive SIF_Event messages, the agent is expected to be registered as a Subscriber of one or more object types in at least one zone. This method does not send SIF_Subscribe messages to any zones.
subscriber - An object that implements the Subscriber
interface to respond to SIF_Event notifications received by the agent,
where the SIF object type referenced by the request matches the
specified objectType. This Subscriber will be called whenever a
SIF_Event is received and no other object in the message dispatching
chain has processed the message.objectType - A constant from the SIFDTD class that identifies the
type of SIF Data Object this Subscriber will respond to.Provisioner.setSubscriber(Subscriber, ElementDef, SubscriptionOptions),
Topic.setSubscriber(Subscriber, SubscriptionOptions)public void setQueryResults(QueryResults queryResults)
Note agents typically register message handlers with Topics or with Zones instead of with the Agent. The message dispatcher first delivers messages to Topics, then to Zones, and finally to the Agent itself.
queryResults - An object that implements the QueryResults
interface to respond to SIF_Response query results received by the
agent. This object will be called whenever a SIF_Response is received
and no other object in the message dispatching chain has processed
the message.Provisioner.setQueryResults(QueryResults),
Topic.setQueryResults(QueryResults, QueryResultsOptions)
public void setQueryResults(QueryResults queryResults,
ElementDef objectType)
Note agents typically register message handlers with Topics or with Zones instead of with the Agent. The message dispatcher first delivers messages to Topics, then to Zones, and finally to the Agent itself.
queryResults - An object that implements the QueryResults
interface to respond to SIF_Response query results received by the agent,
where the SIF object type referenced by the request matches the
specified objectType. This QueryResults object will be called whenever
a SIF_Response is received and no other object in the message
dispatching chain has processed the message.objectType - A constant from the SIFDTD class that identifies the
type of SIF Data Object this QueryResults message handler will
respond to.Provisioner.setQueryResults(QueryResults, ElementDef, QueryResultsOptions),
Topic.setQueryResults(QueryResults, QueryResultsOptions)
public Publisher getPublisher(SIFContext context,
ElementDef objectType)
context - The SIF context to look up the Publisher handler for.
The default implementation of Agent only returns handlers for
SIFContext.DEFAULTobjectType - A SIFDTD constant identifying a SIF Data Object type
(e.g. SIFDTD.STUDENTPERSONAL)
setPublisher method, or null if
no Publisher has been registered for the specified object type.public ReportPublisher getReportPublisher(SIFContext context)
context - The SIF context to look up the ReportPublisher handler for.
The default implementation of Agent only returns handlers for
SIFContext.DEFAULT
setReportPublisher method, or null
if no ReportPublisher has been registered
public Subscriber getSubscriber(SIFContext context,
ElementDef objectType)
context - The SIF context to look up the Subscriber handler for.
The default implementation of Agent only returns handlers for
SIFContext.DEFAULTobjectType - A SIFDTD constant identifying a SIF Data Object type
(e.g. SIFDTD.STUDENTPERSONAL)
setSubscriber method, or null
if no Subscriber has been registered for the specified object type.
public QueryResults getQueryResults(SIFContext context,
ElementDef objectType)
context - The SIF context to look up the QueryResults handler for.
The default implementation of Agent only returns handlers for
SIFContext.DEFAULTobjectType - A SIFDTD constant identifying a SIF Data Object type
(e.g. SIFDTD.STUDENTPERSONAL)
setQueryResults method, or
null if no QueryResults object has been registered
for the specified object type.public void addMessagingListener(MessagingListener listener)
NOTE: Agents may register a MessagingListener with the Agent or Zone classes. When a listener is registered with both classes, it will be called twice. Consequently, it is recommended that most implementations choose to register MessagingListeners with only one of these classes depending on whether the agent is interested in receiving global notifications or notifications on only a subset of zones.
listener - a MessagingListener implementationpublic void removeMessagingListener(MessagingListener listener)
addMessagingListener method.
listener - a MessagingListener implementationpublic java.util.List<MessagingListener> getMessagingListeners()
public void purgeQueue(boolean incoming,
boolean outgoing)
throws ADKException
incoming - true to purge incoming messagesoutgoing - true to purge outgoing messages (e.g. pending SIF_Events)
when the Agent Local Queue is enabled
ADKExceptionpublic static java.lang.String makeGUID()
GUIDGeneratorpublic void setErrorHandler(UndeliverableMessageHandler handler)
handler - The handler to call when the ADK cannot dispatch an
inbound messagepublic UndeliverableMessageHandler getErrorHandler()
setErrorHandler(com.edustructures.sifworks.UndeliverableMessageHandler)public static org.apache.log4j.Logger getLog()
public static org.apache.log4j.Logger getLog(Zone zone)
public static ServerLog getServerLog()
Agents that wish to customize server-side logging may call this method to obtain the global Agent ServerLog instance. Call any of the following methods to set up the chain of loggers that will be inherited by all Zones:
addLoggerremoveLoggerclearLoggersgetLoggers
public static ServerLog getServerLog(Zone zone)
This form of getServerLog is provided for consistency with
the getLog method. Note you may also call the
Zone.getServerLog method directly to obtain a ServerLog for
for a zone.
zone - The zone to obtain a ServerLog instance for
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||