|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfr.dyade.aaa.agent.Driver
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 |
protected java.lang.Thread thread
protected int id
public volatile boolean isRunning
public volatile boolean canStop
protected org.objectweb.util.monolog.api.Logger logmon
protected java.lang.String name
protected static java.util.Hashtable drivers
Constructor Detail |
protected Driver(int id)
id
- identifier local to the driver creatorprotected Driver()
Method Detail |
public java.lang.String getName()
public java.lang.String toString()
public abstract void run() throws java.lang.Exception
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.
java.lang.Exception
- unspecialized exceptionprotected void end()
finally
clause of driver thread.
May be overloaded in derived classes.
public void start()
public void stop()
public abstract void close()
protected final void sendTo(AgentId to, Notification not) throws java.io.IOException
Provides a similar function as the sendTo
function in
Agent
class, except that the notification is sent directly
via a directSendTo
method.
to
- target agentnot
- notification to send
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |