fr.dyade.aaa.agent
Class Driver

java.lang.Object
  extended byfr.dyade.aaa.agent.Driver
Direct Known Subclasses:
AgentDriver

public abstract class Driver
extends java.lang.Object

Abstract base class for drivers such as DriverIn used by ProxyAgent.

Multithreading in the agent server is special, as the code executed outside of the main engine thread is no longer part of a transaction. The class Driver has been designed to help programming in a separate thread in the agent server.

A key difference between the main thread and a driver thread is the semantics of sending a notification. When in the main thread of the agent server, a notification is sent as part of an agent reaction. It is then part of a transaction, and is actually sent only when the transaction commits. When in a separate thread, the directSendto function of class Channel is used instead, actually creating a new transaction for the single purpose of sending the notification. When the function returns the notification sending has been committed. The function sendTo in this class encapsulates the call to the special Channel function, and should be used by derived classes.

This class is designed to be derived. Derived classes should define the function run, providing the actual code to be executed in the separate thread, and may define the function end, providing finalizing code executed when the thread terminates. The end function is always called, even when the run function raises an exception.


Field Summary
 boolean canStop
           
protected static java.util.Hashtable drivers
           
protected  int id
          identifier local to the driver creator
 boolean isRunning
          Boolean variable used to stop the driver properly.
protected  org.objectweb.util.monolog.api.Logger logmon
           
protected  java.lang.String name
           
protected  java.lang.Thread thread
          separate thread running the driver
 
Constructor Summary
protected Driver()
          Constructor with default id.
protected Driver(int id)
          Constructor.
 
Method Summary
abstract  void close()
           
protected  void end()
          Finalizes driver; called in finally clause of driver thread.
 java.lang.String getName()
          Returns name of driver, actually classname and driver id.
abstract  void run()
          Actually executes the driver code.
protected  void sendTo(AgentId to, Notification not)
          Sends a notification to an agent.
 void start()
          Starts the driver execution.
 void stop()
          Stops the driver execution.
 java.lang.String toString()
          Provides a string image for this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

thread

protected java.lang.Thread thread
separate thread running the driver


id

protected int id
identifier local to the driver creator


isRunning

public volatile boolean isRunning
Boolean variable used to stop the driver properly. If this variable is true then it indicates that the driver is stopping.


canStop

public volatile boolean canStop

logmon

protected org.objectweb.util.monolog.api.Logger logmon

name

protected java.lang.String name

drivers

protected static java.util.Hashtable drivers
Constructor Detail

Driver

protected Driver(int id)
Constructor.

Parameters:
id - identifier local to the driver creator

Driver

protected Driver()
Constructor with default id.

Method Detail

getName

public java.lang.String getName()
Returns name of driver, actually classname and driver id. It should be overloaded in subclass to take in account the proxy name.


toString

public java.lang.String toString()
Provides a string image for this object.

Returns:
printable image of this object

run

public abstract void run()
                  throws java.lang.Exception
Actually executes the driver code. To be defined in derived classes.

Beware: this code is executed in a separate thread, outside from any transaction. Notifications may be sent using function sendTo, and they will actually be sent as soon as the function is called; there is no atomic treatment as there is in an agent reaction.

Throws:
java.lang.Exception - unspecialized exception

end

protected void end()
Finalizes driver; called in finally clause of driver thread. May be overloaded in derived classes.


start

public void start()
Starts the driver execution.


stop

public void stop()
Stops the driver execution.


close

public abstract void close()

sendTo

protected final void sendTo(AgentId to,
                            Notification not)
                     throws java.io.IOException
Sends a notification to an agent.

Provides a similar function as the sendTo function in Agent class, except that the notification is sent directly via a directSendTo method.

Parameters:
to - target agent
not - notification to send
Throws:
java.io.IOException


Copyright ? 2004 Scalagent - All rights reserved