drm.agents
Class ContributorAgent
java.lang.Object
|
+--drm.agents.Agent
|
+--drm.agents.ContributorAgent
- All Implemented Interfaces:
- Contributor, IAgent, Observer, java.lang.Runnable, java.io.Serializable
- public abstract class ContributorAgent
- extends Agent
- implements Contributor, Observer
This is an agent that participates in a collective.
The name of the collective is the job name passed to the constructor.
- See Also:
- Serialized Form
Constructor Summary |
ContributorAgent(java.lang.String type,
java.lang.String job,
java.lang.String name)
Calls super constructor |
ContributorAgent(java.lang.String type,
java.lang.String job,
java.lang.String name,
Address root)
Calls super constructor. |
Methods inherited from class drm.agents.Agent |
fireMessage, fireMessage, fireMessage, getDRM, getJob, getName, getState, getType, setBase, suicide, toString, version |
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 |
collective
protected Collective collective
- The collective this object is a membet of.
root
protected Address root
- The root contributor. The presence of this is not crutial, it only provides
a fixed and reliable address to fall back to.
ContributorAgent
public ContributorAgent(java.lang.String type,
java.lang.String job,
java.lang.String name)
- Calls super constructor
ContributorAgent
public ContributorAgent(java.lang.String type,
java.lang.String job,
java.lang.String name,
Address root)
- Calls super constructor.
- Parameters:
root
- The fixed reliable address in the collective to fall back to
if no peers are known. Might be null, in that case connection to
the collective is possible only if this is a root, ie if other
contributors connect to this address. Might be a local address, in that case
this agent will change it to the correct remote address (ie to the address
of its old node) when arriving at a remote node.
onArrival
public final void onArrival(Address from,
Address to)
- Corrects root address if it is a local address and we are arriving from
a remote base. Connects to the collective.
Extending classes that override this method must make sure that
they call super.onArrival
.
The suggested practice is that every implementation must begin with the
line
super.onArrival(from,to);
- Overrides:
onArrival
in class Agent
- Following copied from interface:
drm.agentbase.IAgent
- Parameters:
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.- See Also:
IAgent.setBase(IBase)
onDestruction
public final void onDestruction()
- Closes connection with the collective.
Extending classes that override this method must make sure that
they call super.onDestruction
.
The suggested practice is that every implementation must begin with the
line
super.onDestruction();
- Overrides:
onDestruction
in class Agent
handleMessage
public boolean handleMessage(Message m,
java.lang.Object object)
- Handles message type
"collectiveUpdate-"+getJob()
. In fact
only forwards it to the collective.
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.
- Overrides:
handleMessage
in class Agent
- Following copied from interface:
drm.agentbase.IAgent
- Parameters:
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()
).- Returns:
- If the message could be handled succesfully (i.e. it was
known to the implementation and no errors occured)
returns true, otherwise false.
- See Also:
Message.setReply(Object)
,
IBase.fireMessage(Message)
getContribution
public java.lang.Object getContribution()
- The default implementation returns null. Extending classes must
redefine this method to be able to contribute to the collective.
- Specified by:
getContribution
in interface Contributor
collectiveUpdated
public void collectiveUpdated(ContributionBox peer)
- The default implementation does nothing.
- Specified by:
collectiveUpdated
in interface Observer
getPeerAddresses
public final Address[] getPeerAddresses()
- Returns the root address.
- Specified by:
getPeerAddresses
in interface Observer
selfTest
public void selfTest(java.io.PrintStream output)
- Overrides:
selfTest
in class Agent