|
MATES 3.0-rc2 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.mates.sim.Agent
Class from which all agents must be extended.
Field Summary | |
protected Host |
host
The current host on which this agent resides. |
Constructor Summary | |
Agent(Host host)
Constructor for an agent with a priority of 0 and no name. |
|
Agent(java.lang.String name,
Host host)
Constructor for an agent with a priority of 0. |
|
Agent(java.lang.String name,
Host host,
int priority)
Primary constructor for an agent. |
Method Summary | |
void |
die()
Kills this agent. |
boolean |
getDieOnMigrationFailure()
Returns whether or not an agent will die if its migration fails. |
java.awt.Component |
getGUI()
Returns a graphical component for the interface of this agent. |
Host |
getHost()
Returns the current host this agent is on. |
int |
getMigrationTimeout()
Accessor for the migration timeout of this agent |
java.lang.String |
getName()
Returns the name of this agent. |
int |
getPriority()
Accessor for the priority of this agent. |
protected Simulator |
getSimulator()
Internal accessor for the simulator that this agent is currently running within. |
double |
getTransmissionSize()
Accessor for the virtual size of this agent. |
UniqueID |
getUniqueID()
Returns the unique identifier for this agent. |
boolean |
isAlive()
Returns true if this agent is currently alive. |
boolean |
isAsleep()
Returns true if this agent is currently asleep. |
boolean |
isConsumingProcessor()
Returns whether or not this agent will consume its hosts processor while it is sleeping. |
void |
iterate()
This function is called once every time the agent is scheduled (by its host) to run. |
void |
log(java.lang.String message)
Prints a log message attributed to this agent. |
protected boolean |
migrate(Host new_host)
Instructs this agent to migrate to a new host. |
abstract void |
run()
This function contains the execution code of the agent. |
void |
setDieOnMigrationFailure(boolean die)
Sets whether or not an agent will die if its migration fails. |
void |
setHost(Host new_host)
Sets the host of this agent. |
void |
setMigrationTimeout(int migration_timeout)
Sets the migration timeout for this agent. |
void |
setPriority(int priority)
Sets the priority of this agent. |
void |
setTransmissionSize(double size)
Sets the virtual size of this agent. |
void |
sleep(long iterations)
Instructs this agent to sleep for a specified number of iterations. |
void |
sleep(long iterations,
boolean consume_processor)
Instructs this agent to sleep for a specified number of iterations. |
java.lang.String |
toString()
|
void |
yield()
Yeilds execution of this agent to all other agents, for one iteration. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected Host host
Constructor Detail |
public Agent(java.lang.String name, Host host, int priority)
name
- a not-necessarily-unique name for this agent. This is mostly for debugging and conveniance. This may be null
.host
- the host on which this agent is to be spawned.priority
- any integer value for the priority of this
agent.setPriority(int)
public Agent(java.lang.String name, Host host)
Agent(String, Host, int)
public Agent(Host host)
Agent(String, Host, int)
Method Detail |
public void log(java.lang.String message)
getSimulator
().
log
(this, message)
.
message
- the message to be logged.Simulator.log(Object, String)
public void setDieOnMigrationFailure(boolean die)
false
, the default, an agent will return to its
sender if its migration fails.
public boolean getDieOnMigrationFailure()
false
, the default, an agent will
return to its sender if its migration fails.
public void setTransmissionSize(double size)
size
- roughly equates to the number of iterations
required to transmit this agent with maximum connectivity.public double getTransmissionSize()
setTransmissionSize(double)
public int getMigrationTimeout()
setMigrationTimeout(int migration_timeout)
public void setMigrationTimeout(int migration_timeout)
migration_timeout
- the number of iterations this agent
will wait before giving up on migrating to another host.migrate(Host)
protected Simulator getSimulator()
host
.getSimulator
().
public abstract void run()
run()
is called once, the first time an agent is
scheduled to execute by its host. The simulator will block
while this function is executing. It is intended that the
implementation of this function will use blocking functions
like sleep(long)
and migrate(Host)
to return control to the simulation.
Whenever execution reaches the end of this function
(i.e. whenever run()
returns), this agent will
die.
run
in interface java.lang.Runnable
public final void iterate()
public void yield()
sleep
(1, false)
.
public void sleep(long iterations)
sleep
(iterations,
false)
.
iterations
- The number of iterations to sleep.public void sleep(long iterations, boolean consume_processor)
iterations
.
If called from within this agent's run()
function,
this function will block until the specified number of
iterations have elapsed.
iterations
- The number of iterations to sleep.consume_processor
- if true, while this agent is sleeping
it will still consume the processing power of its host (thus
reducing the amount of processing time that goes to other
agents on that host). This provides a means of simulating
agent processes that would be processor intensive.public int getPriority()
setPriority(int)
public boolean isAlive()
true
if this agent is currently alive.
true
if this agent is currently alive.die()
public boolean isAsleep()
true
if this agent is currently asleep.
public void die()
getSimulator
().
killAgent
(this)
protected boolean migrate(Host new_host)
run()
function of this agent, it will block until the agent has
arrived at the new host. Otherwise, if this function is called
from anywhere else, this agent will simply be instructed to
migrate and the function will ensure that the agent's current
host and new_host
are in communication range.
host
is null
while the agent is in
transit.
If caled from outside the run()
function, this
function will immediately schedule the migration, even if the
agent is currently sleeping.
new_host
- the host to migrate to
run()
function
of this agent, true
will be returned when and if
the migration is completed and successful. If called from any
other location, this function returns true
if the
migration is valid. In other words, new_host
is a
valid destination and this agent is not already in the process
of migrating. This return value ensures that the migration
process has started; it has nothing to do with the success or
completion of the migration.Simulator.migrate(Agent, Host)
public void setHost(Host new_host)
migrate(Host)
.
new_host
- the new host for this agent.migrate(Host)
public Host getHost()
public void setPriority(int priority)
priority
- an integer value for the priority of this agent.public java.lang.String getName()
null
.
null
).public UniqueID getUniqueID()
public java.awt.Component getGUI()
GraphicalUserInterface
is used.
This function defaults to return null
.
getGUI()
is intended for child classes that extend
Agent
to re-implement this function and return a
GUI object.
public boolean isConsumingProcessor()
public java.lang.String toString()
|
MATES 3.0-rc2 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |