|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object examples.communication.Agent
This class represents three types of agents which jump subseqeuently to remote hosts, and communicate with each other:
SENDER - the sender agent only sends messages
RECEWIVER - the receiver agent only receives messages
TRANSCEIVER - the transceiver agent sends and receives messages
Every agent publishes its own AgentService
which makes
possible for the Launcher
to send this agent the implicit
names of all other "friend" agents or to signal for termination when an
error occurs.
The agent (no matter what type) goes through the following states:
STATE_INIT_VARIABLES: in this state the agent initialises the
varibles, set from the Launcher
, its implicit name, etc..
STATE_REPORT_FEEDBACK: the agent reports to the Launcher
errors(if they have occurred) and its implict name, nickname, the
key of the service it has published and its type.
STATE_COMMUNICATE: if the agent is from type SENDER or TRANSCEIVER it tries to send message to one of the RECEIVER agents; if the agent is from type RECEIVER it checks constantly for a new message in the time between each migration.
STATE_TERMINATE: the agent terminates because of error or it has gone through its "lifecycle". Before the termination each agent should "report" the information about how many messages it has received/ sent and how many of them have benn received/not received.
This class implements the interface Resumable
. This means
if there was an error, which appeared during the program execution, and
the agent is not in STATE_TERMINATE, it will try to migrate to the host
where it was first launched and report the information it has gathered.
Field Summary | |
static String |
COMM_TYPE_PROP
String representation of TYPE property in agent's
properties. |
static String |
COMM_TYPE_RECEIVER
String representation of the agent's type RECEIVER. |
static String |
COMM_TYPE_SENDER
String representation of the agent's type SENDER. |
static String |
COMM_TYPE_TRANSCEIVER
String representation of the agent's type TRANSCEIVER. |
static int |
CT_RECEIVER
int representation of the agent's type RECEIVER. |
static int |
CT_SENDER
int representation of the agent's type SENDER. |
static int |
CT_TRANSCEIVER
int representation of the agent's type TRANSCEIVER. |
private URL |
home_
The de.fhg.igd.util.URL of the "home" of the agent(where
the agent was first started). |
private String |
id_
The id of the agent used for log messages. |
private String |
implicitName_
The implicit name of the agent. |
private ArrayList |
implicitNames_
The list with the names of the "receiver" agents. |
static String |
JUMP_COUNT_PROP
String representation of the property
"count of jumps". |
private int |
jumpCount_
Current number of successfull jumps.. |
private int |
jumps_
The number of times which the agent must migrate. |
private Object |
lock_
Lock object for internal synchronization. |
private int |
messagesNotDelivered_
The number of the messages which were not delivered. |
private int |
messagesReceived_
The number of the received messages. |
private int |
messagesSent_
The number of the sent messages. |
private String |
nickName_
The nickname of the agent. |
static String |
NICKNAME_PREFIX
This is the prefix of each agent's nickname. |
private HashMap |
notDeliveredNotices_
The HashMap object which contains the messages
from the exceptions of not delivered messages. |
private static long |
serialVersionUID
Use serialVersionUID for interoperability. |
static String |
SERVER_PREFIX_PROP
String representation of the prefix of all urls
in the agent's properties. |
private int |
state_
The state of the agent. |
static int |
STATE_COMMUNICATE
Represents the third(main) state of the agent's lifecycle. |
static int |
STATE_INIT_VARIABLES
Represents the first state of the agent's lifecycle. |
static int |
STATE_REPORT_FEEDBACK
Represents the second state of the agent's lifecycle. |
static int |
STATE_TERMINATE
Represents the last state(termination) of the agent's lifecycle. |
private ArrayList |
targets_
The ArrayList with the urls where the agent can migrate. |
private boolean |
terminate_
The state of the agent. |
private long |
time_
The time(in milliseconds) which the agent has before each migration. |
private int |
type_
The type of this agent. |
static String |
WAIT_TIME_PROP
String representation of the "waiting time
before each migration" property. |
Fields inherited from interface examples.communication.AgentService |
PUBLISH_KEY_PREFIX |
Constructor Summary | |
Agent()
Default constructor. |
Method Summary | |
protected ArrayList |
findValidTargets()
Initializes the URL array from the Vicinity service. |
protected URL |
getLocalHost()
Resolves the localhost url. |
protected URL |
getNextTarget()
Finds a random reachable target for the next agent's migration. |
void |
initImplicitNames(ArrayList implicitNames)
Initialises the implicit name of the agent's "friends" |
protected void |
migrate()
Sets the Ticket according to the random
choice of examples.communication.Agent#getNextTarget(). |
protected void |
migrateHome()
Sets the next migration target the host whrere the agent was first started. |
void |
resume(ErrorCode error)
See class description. |
void |
run()
See class description. |
void |
signalTermination()
Sends a terminating signal to the agent. |
protected boolean |
stateCommunicate()
Describes the state: STATE_COMMUNICATE. |
protected boolean |
stateInitVariables()
Describes the state: STATE_INIT_VARIABLES. |
protected boolean |
stateReportFeedback()
Describes the state: STATE_REPORT_FEEDBACK. |
protected void |
terminate()
The agent reports the information about how many messages it has received/sent and how many of them have been received/not received and terminates. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static final long serialVersionUID
public static final int STATE_INIT_VARIABLES
description
,
Constant Field Valuespublic static final int STATE_REPORT_FEEDBACK
description
,
Constant Field Valuespublic static final int STATE_COMMUNICATE
description
,
Constant Field Valuespublic static final int STATE_TERMINATE
description
,
Constant Field Valuespublic static final String NICKNAME_PREFIX
Launcher
and "type" is a string
representation of the agent's type.
public static final int CT_SENDER
int
representation of the agent's type SENDER.
public static final int CT_RECEIVER
int
representation of the agent's type RECEIVER.
public static final int CT_TRANSCEIVER
int
representation of the agent's type TRANSCEIVER.
public static final String COMM_TYPE_SENDER
String
representation of the agent's type SENDER.
public static final String COMM_TYPE_RECEIVER
String
representation of the agent's type RECEIVER.
public static final String COMM_TYPE_TRANSCEIVER
String
representation of the agent's type TRANSCEIVER.
public static final String COMM_TYPE_PROP
String
representation of TYPE property in agent's
properties.
public static final String SERVER_PREFIX_PROP
String
representation of the prefix of all urls
in the agent's properties.
public static final String WAIT_TIME_PROP
String
representation of the "waiting time
before each migration" property.
public static final String JUMP_COUNT_PROP
String
representation of the property
"count of jumps".
private ArrayList implicitNames_
private ArrayList targets_
ArrayList
with the urls where the agent can migrate.
private HashMap notDeliveredNotices_
HashMap
object which contains the messages
from the exceptions of not delivered messages.
private String nickName_
private String implicitName_
private long time_
private int jumps_
private URL home_
de.fhg.igd.util.URL
of the "home" of the agent(where
the agent was first started).
private int type_
description
private int jumpCount_
private String id_
private transient Object lock_
private int messagesNotDelivered_
private int messagesReceived_
private int messagesSent_
private int state_
private boolean terminate_
Constructor Detail |
public Agent()
Method Detail |
protected URL getLocalHost()
protected ArrayList findValidTargets()
Vicinity
service.
ArrayList
of found targets or
null
, if Vicinity
is not installed.protected URL getNextTarget()
public void resume(ErrorCode error) throws Exception
resume
in interface Resumable
error
- DOCUMENT ME!
Exception
- DOCUMENT ME!public void run()
run
in interface Runnable
protected void migrate()
Ticket
according to the random
choice of examples.communication.Agent#getNextTarget().
If no valid destination was found the agent terminates.
terminate()
protected void migrateHome()
protected void terminate()
protected boolean stateInitVariables()
protected boolean stateReportFeedback()
protected boolean stateCommunicate()
public void initImplicitNames(ArrayList implicitNames)
AgentService
initImplicitNames
in interface AgentService
implicitNames
- DOCUMENT ME!AgentService.initImplicitNames(ArrayList)
public void signalTermination()
AgentService
signalTermination
in interface AgentService
AgentService.signalTermination()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |