All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class oplan.acp3.KqmlWatcher

java.lang.Object
   |
   +----oplan.acp3.KqmlWatcher

public class KqmlWatcher
extends Object
A KqmlWatcher is used to look for significant Kqml messages and tell an implementation of WatcherListener about them.

Using a KqmlWatcher typically involves four steps:

    KqmlWatcher watcher = new KqmlWatcher();
    watcher.setListener(someWatcherListener);
    watcher.init();
    watcher.watcherMainLoop();
 
The listener can also be provided as an argument to new KqmlWatcher.

init() creates a Kqml agent called "ACP3" and creates message handlers for the Kqml performatives ACP3 expects to receive. It also creates a log file. The call to watcher.init() should be omitted in cases when it is not intended for ACP3 to receive Kqml messages.

Assignment to KqmlWatcher.kqmlAgentName before init() is called will change the name used when registering the Kqml agent.

watcherMainLoop() loops forever waiting for messages and interpreting them when they arrive. It should be called only if init() was called earlier.

See Also:
WatcherListener, MessageWatcher

Variable Index

 o creationDate
 o interp
 o kqmlAgent
 o kqmlAgentName
Our name as a Kqml agent
 o kqmlEvents
 o listener
 o logDirectoryName
 o logFileName
 o logWriter

Constructor Index

 o KqmlWatcher(WatcherListener)
Create a KqmlWatcher connected to a WatcherListener.

Method Index

 o analyseMessage(Message)
Performs the actual message analysis.
 o createLogFile()
Create a file for recording the messages we receive.
 o fatalException(Exception)
fatalException is called when an exception indicates that something that must happen has failed, and there isn't anything in the system that would enable it to fix the problem and try again.
 o init()
The init() method creates a KqmlAgent and then registers message handlers for the Kqml performatives we care about.
 o interpret(KqmlEvent)
A public interface to the Kqml message-interpretation code.
 o logMessage(Message)
Record the message in our log file.
 o pleaseAnalyse(Message)
Enqueues a Kqml Message for analysis in watcherMainLoop.
 o registerHandler(String, boolean)
 o setListener(WatcherListener)
Change the WatcherListener that the KqmlWatcher tells of status changes.
 o shutdown()
shutdown should be called before the system exits so that it can call kqmlAgent.shutdown().
 o watcherMainLoop()
Analyses messages enqueued by pleaseAnalyse.

Loops forever.

Variables

 o listener
 public WatcherListener listener
 o kqmlAgent
 public KqmlAgent kqmlAgent
 o interp
 protected KqmlInterpreter interp
 o kqmlEvents
 protected MessageQueue kqmlEvents
 o creationDate
 protected Date creationDate
 o logDirectoryName
 public String logDirectoryName
 o logFileName
 public String logFileName
 o logWriter
 public Writer logWriter
 o kqmlAgentName
 protected static String kqmlAgentName
Our name as a Kqml agent

Constructors

 o KqmlWatcher
 public KqmlWatcher(WatcherListener listener)
Create a KqmlWatcher connected to a WatcherListener.

Methods

 o setListener
 public void setListener(WatcherListener listener)
Change the WatcherListener that the KqmlWatcher tells of status changes.

 o init
 public void init()
The init() method creates a KqmlAgent and then registers message handlers for the Kqml performatives we care about. It also creates a log file. init() should not be called if there's no desire to receive actual KQML messages. A KqmlWatcher may still be useful in such cases, because there are other ways to give it messages to interpret.

 o registerHandler
 protected void registerHandler(String performative,
                                boolean analyse)
 o watcherMainLoop
 public void watcherMainLoop()
Analyses messages enqueued by pleaseAnalyse.

Loops forever.

 o pleaseAnalyse
 public void pleaseAnalyse(Message msg)
Enqueues a Kqml Message for analysis in watcherMainLoop.

 o analyseMessage
 protected void analyseMessage(Message msg)
Performs the actual message analysis.

 o interpret
 public void interpret(KqmlEvent event)
A public interface to the Kqml message-interpretation code.

 o createLogFile
 protected void createLogFile() throws IOException
Create a file for recording the messages we receive. The file name is based on the date and time when createLogFile was called and will be something like "acp3-log-18-mar-98-21:51:05".

 o logMessage
 protected void logMessage(Message msg)
Record the message in our log file.

 o shutdown
 public void shutdown()
shutdown should be called before the system exits so that it can call kqmlAgent.shutdown(). The main program class should define a shutdown method that calls our shutdown method, and ACP3.exit will then cause the right things to happen. That is, we should have something like: ACP3.exit --> main program class shutdown --> KqmlWatcher shutdown --> KqmlAgent shutdown.

 o fatalException
 static void fatalException(Exception e)
fatalException is called when an exception indicates that something that must happen has failed, and there isn't anything in the system that would enable it to fix the problem and try again.


All Packages  Class Hierarchy  This Package  Previous  Next  Index