|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--drm.agents.Agent
Base class for agents. The class is abstract because the run() method has no default implementation here.
It gives the most basic implementation of an agent possible. The implementation contains the following functionality that can be used by extending classes:
shouldLive
that must be used by extending classes
to properly shut down any threads when this flag becomes false.
selfTest(PrintStream)
and
getState()
. These functions can be invoked through messages
as well, see handleMessage(Message,Object)
for more information.
base
, and through the function getDRM()
.
Field Summary | |
protected IBase |
base
The Base that hosts the agent. |
protected java.lang.String |
job
This is the job name the agent participates in. |
protected java.lang.String |
name
This is the name of the agent. |
protected boolean |
shouldLive
If this flag is set the agent should stop executing. |
protected java.lang.String |
type
This is the type identifyer of the agent. |
protected static int |
VERSION
The drm version the agent is designed for. |
Constructor Summary | |
Agent(java.lang.String type,
java.lang.String job,
java.lang.String name)
Cosntructs an Agent with the given name, jobname and type. |
Method Summary | |
IRequest |
fireMessage(Address recipient,
java.lang.String type)
Creates a message and fires it to a local destination. |
IRequest |
fireMessage(Address recipient,
java.lang.String type,
java.lang.Object object)
Creates a message and fires it. |
IRequest |
fireMessage(java.lang.String recipient,
java.lang.String type,
java.lang.Object object)
Creates a message and fires it to a local destination. |
IDRM |
getDRM()
This returns a reference through which information about the hosting DRM can be requested. |
java.lang.String |
getJob()
Returns job name. |
java.lang.String |
getName()
Returns the name of the agent. |
java.lang.String |
getState()
This is the function that returns the reply to a message of type "getState" . |
java.lang.String |
getType()
Returns type identifier. |
boolean |
handleMessage(Message m,
java.lang.Object object)
Handles incoming messages. |
void |
onArrival(Address from,
Address to)
Extending classes that override this method must make sure that they call super.onArrival . |
void |
onDestruction()
Extending classes that override this method must make sure that they call super.onDestruction . |
void |
selfTest(java.io.PrintStream output)
|
void |
setBase(IBase b)
This is called by the base when the agent is received. |
void |
suicide()
Removes the agent from the base. |
java.lang.String |
toString()
|
int |
version()
Returns the version of the agent. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.lang.Runnable |
run |
Field Detail |
protected transient IBase base
protected transient volatile boolean shouldLive
onDestruction()
protected final java.lang.String name
protected final java.lang.String type
protected final java.lang.String job
protected static final int VERSION
Base.RELEASE_VERSION
Constructor Detail |
public Agent(java.lang.String type, java.lang.String job, java.lang.String name)
getName()
) is prefixed by type and job, in the format
type.job.name
, as required by the specification.type
- The type of the agent.job
- The job identifier.name
- The agent name. If null, a random name is generated.Method Detail |
public void onArrival(Address from, Address to)
super.onArrival
.
The suggested practice is that every implementation must begin with the
line
super.onArrival(from,to);
onArrival
in interface IAgent
drm.agentbase.IAgent
from
- The address of the base from which the agent was sent.
If the agent has never been on any base it is null.to
- The address of the local base at the time of the arrival.
It is not guaranteed to remain valid trough the lifetime of the
agent. If the agent has never been on a base it is null.IAgent.setBase(IBase)
public void onDestruction()
super.onDestruction
.
The suggested practice is that every implementation must begin with the
line
super.onDestruction();
onDestruction
in interface IAgent
public final java.lang.String getName()
IAgent
getName
in interface IAgent
public final java.lang.String getJob()
IAgent
getJob
in interface IAgent
public final java.lang.String getType()
IAgent
getType
in interface IAgent
public final void setBase(IBase b)
IAgent
setBase
in interface IAgent
drm.agentbase.IAgent
b
- The Base that hosts the agent.public boolean handleMessage(Message m, java.lang.Object object)
selfTest
Prints some debugging info on the standard error.
getState
Returns the output of getState()
.
Extending classes that override this method must make sure that
they call super.handleMessage
.
The suggested practice is that every implementation must begin with the
line
if( super.handleMessage(m,object) ) return true;and after that handling of the class specific messages.
handleMessage
in interface IAgent
drm.agentbase.IAgent
m
- The message to handle.object
- The object that is wrapped in the message. If null
then there is no binary content or it is not a serialized object
(in which case it can be read using Message.getBinary()
).Message.setReply(Object)
,
IBase.fireMessage(Message)
public final int version()
IAgent
version
in interface IAgent
drm.agentbase.IAgent
Base.RELEASE_VERSION
public final IRequest fireMessage(Address recipient, java.lang.String type, java.lang.Object object)
recipient
- Recipient of the message.type
- Type of the message.contstr
- The string content of the message.object
- Object to be wrapped in the message. If null, then
no object is wrapped, null is written.IBase.fireMessage(Message)
public final IRequest fireMessage(java.lang.String recipient, java.lang.String type, java.lang.Object object)
recipient
- The name of the recipient of the message. It is
assumed to be a local agent.type
- Type of the message.contstr
- The string content of the message.object
- Object to be wrapped in the message. If null, then
no object is wrapped, null is written.public final IRequest fireMessage(Address recipient, java.lang.String type)
recipient
- Recipient of the message.type
- Type of the message.public final void suicide()
base.destroyAgent(name)
.
So this method must be followed by exiting from the method explicitly
e.g. with a return
.public void selfTest(java.io.PrintStream output)
public final IDRM getDRM()
ClassCastException
- If the IDRM interface is not implemented
by the base proxy known by the agent.public java.lang.String getState()
"getState"
. This information that can be displayed
by eg a user interface. It is useful when debugging. If an implementation
wants to forbid answering getState requests it has to throw a runtime
exception. The requestor will get no answer this way, it will seem as if
the request was not understood. This is the default behaviour.public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |