Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
fr.dyade.aaa.agent.Driver
public abstract class Driver
extends java.lang.Object
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 | |
protected static Hashtable | |
protected int |
|
boolean |
|
protected Logger | |
protected String | |
protected Thread |
|
Method Summary | |
void |
|
protected void |
|
String |
|
void |
|
protected void |
|
void |
|
void |
|
String |
|
public boolean canStop
protected static Hashtable drivers
protected int id
identifier local to the driver creator
public boolean isRunning
Boolean variable used to stop the driver properly. If this variable is true then it indicates that the driver is stopping.
protected Logger logmon
protected String name
protected Thread thread
separate thread running the driver
protected Driver()
Constructor with default id.
protected Driver(int id)
Constructor.
- Parameters:
id
- identifier local to the driver creator
public void close()
protected void end()
Finalizes driver; called infinally
clause of driver thread. May be overloaded in derived classes.
public String getName()
Returns name of driver, actually classname and driver id. It should be overloaded in subclass to take in account the proxy name.
public void run() throws 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 functionsendTo
, 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.
protected final void sendTo(AgentId to, Notification not) throws IOException
Sends a notification to an agent. Provides a similar function as thesendTo
function inAgent
class, except that the notification is sent directly via adirectSendTo
method.
- Parameters:
to
- target agentnot
- notification to send
public void start()
Starts the driver execution.
public void stop()
Stops the driver execution.
public String toString()
Provides a string image for this object.
- Returns:
- printable image of this object