|
SimJava v2.0 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.Thread | +--eduni.simjava.Sim_entity
This class represents the types of entities or processes of the simulation.
To define an entity type for the simulation this class needs to be extended.
The subclass needs to override body()
to define the entity's
behaviour. Methods beginning with the prefix sim_
are runtime
methods to be called within body()
.
Since version 2.0, entities don't need to check transient or termination
conditions. These are all maintained and checked by Sim_system
.
To check whether the termination condition has been satisfied, entities
should use the Sim_system.running()
method. As such. entities
that exhibit a continuous, looping behaviour should have a body()
as follows:
...
public void body() {
while (Sim_system.running()) {
...
// Entity's behaviour
...
}
}
...
Entities are provided with a selection of runtime methods to implement their behaviour. The main runtime method families are the following:
sim_schedule
methods. These methods are used to schedule events to other
entities in the simulation.
sim_wait
methods. These methods are used to wait for an incoming event.
Alternatively, sim_select
or sim_get_next
methods may be
used to check also for events that arrived while the entity was busy.
sim_pause
methods. These methods are used when the entity is inactive.
Examples of such behaviour are timeouts and delay intervals between event scheduling.
sim_process
methods. These methods are used when the entity is to
be considered active. The difference between these methods and those of the
sim_pause
family is related to statistical measurements. If utilisation
is being measured by the entity then a sim_process
method should be used
when the entity is considered to be busy processing.
In order to collect statistical measurements from entities a Sim_stat
object needs
to be defined for the entity. This is the object in charge of collecting observations and
calculating measurements. Measures of interest could be default of custom. Default measures are
those which can be considered in most simulations and whose update can be automatically carried
out without user effort. Custom measures on the other hand are measures with simulation specific
meaning that need to be updated by the user. An example of an entity defining and updating measures
of interest follows:
class AnEntityType extends Sim_entity {
...
Sim_stat stat;
...
AnEntityType(String name) {
...
stat = new Sim_stat();
stat.add_measure(Sim_stat.UTILISATION); // A default measure
stat.add_measure(Sim_stat.RESIDENCE_TIME); // Another default measure
stat.add_measure("Loss rate", Sim_stat.RATE_BASED); // A rate-based custom measure
set_stat(stat);
...
}
...
public void body() {
...
if (aLossOccured) {
stat.update("Loss rate", Sim_system.sim_clock()); // The custom measure is updated
}
...
sim_completed(e); // An event has completed service
...
}
...
}
The sim_completed
method seen above, is used to specify when a received event
is considered to have completed all service at the entity. This method needs to be called to
notify the entity's Sim_stat
object and to notify Sim_system
that
an event has completed service. More details on statistical measurements can be found in
the SimJava Tutorial.
One additional note concerning entities' behaviour has to do with output analysis. In the case
of independent replications having been defined as an output analysis method, it could be
necessary to provide code with which to reset an entity's fields. This is required since, for
each replication, the entities must be reset to their original state. This is not required for
primitive types or immutable objects. However if objects such as a Vector
have been
modified during the simulation run, they should be reset to their original state. This would take
place at the end of the body()
method. For example:
class AnEntityType extends Sim_entity {
...
Vector aVector = new Vector();
...
public void body() {
while (Sim_system.running()) {
...
aVector.add(anObject); // The Vector's contents are modified
...
}
aVector.clear(); // The Vector is reset to its original state
}
...
}
Sim_event
,
Sim_stat
,
Sim_system
Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
Sim_entity(java.lang.String name)
Creates a new entity. |
|
Sim_entity(java.lang.String name,
java.lang.String image_name,
int x,
int y)
The constructor for use with the eduni.simanim animation package. |
Method Summary | |
void |
add_generator(Generator generator)
Add a sample generator to this entity. |
void |
add_param(Anim_param param)
Add a parameter to this entity. |
void |
add_port(Sim_port port)
Add a port to this entity. |
void |
body()
The method which defines the behaviour of the entity. |
protected java.lang.Object |
clone()
Get a clone of the entity. |
int |
get_id()
Get the unique id number assigned to this entity |
java.lang.String |
get_name()
Get the name of this entity |
Sim_port |
get_port(Sim_event ev)
Get the port through which an event arrived. |
Sim_port |
get_port(java.lang.String name)
Get the port with a given name. |
Sim_stat |
get_stat()
Get the entity's Sim_stat object. |
void |
send_on(Sim_event ev,
Sim_port p)
Send on an event to an other entity through a port. |
void |
set_invisible(boolean b)
Make entity icon invisible |
void |
set_stat(Sim_stat stat)
Define a Sim_stat object for this entity. |
int |
sim_cancel(Sim_predicate p,
Sim_event ev)
Cancel the first event matching a predicate waiting in the entity's future queue. |
void |
sim_completed(Sim_event e)
Signal that an event has completed service. |
int |
sim_current()
Get the id of the currently running entity |
void |
sim_get_next(Sim_event ev)
Get the first event waiting in the entity's deferred queue, or if there are none, wait for an event to arrive. |
void |
sim_get_next(Sim_predicate p,
Sim_event ev)
Get the first event matching a predicate from the deferred queue, or if none match, wait for a matching event to arrive. |
double |
sim_hold_for(double delay,
Sim_event ev)
Deprecated. As of SimJava version 2.0, replaced by sim_pause_for(double delay, Sim_event ev) .
This method was deprecated because of the new statistical support present to entities. When an
entity holds it must now be specified if the hold corrssponds to the entity being active or
inactive. The original sim_hold() methods are equivalent to their respective
sim_pause() methods. |
void |
sim_hold(double delay)
Deprecated. As of SimJava version 2.0, replaced by sim_pause(double delay) .
This method was deprecated because of the new statistical support present to entities. When an
entity holds it must now be specified if the hold corrssponds to the entity being active or
inactive. The original sim_hold() methods are equivalent to their respective
sim_pause() methods. |
double |
sim_pause_for(double delay,
Sim_event ev)
Set the entity to be inactive for a time period or until it is interrupted by the arrival of an event. |
double |
sim_pause_for(Sim_predicate p,
double delay,
Sim_event ev)
Set the entity to be inactive for a time period or until it is interrupted by the arrival of an event matching a predicate. |
void |
sim_pause_until(Sim_event ev)
Set the entity to be inactive until it receives an event. |
void |
sim_pause_until(Sim_predicate p,
Sim_event ev)
Set the entity to eb inactive until it receives an event matching a specific predicate. |
void |
sim_pause(double delay)
Set the entity to be inactive for a time period. |
double |
sim_process_for(double delay,
Sim_event ev)
Set the entity to be active for a time period or until it is interrupted by the arrival of an event. |
double |
sim_process_for(Sim_predicate p,
double delay,
Sim_event ev)
Set the entity to be active for a time period or until it is interrupted by the arrival of an event matching a predicate. |
void |
sim_process_until(Sim_event ev)
Set the entity to be active until it receives an event. |
void |
sim_process_until(Sim_predicate p,
Sim_event ev)
Set the entity to be active until it receives an event matching a specific predicate. |
void |
sim_process(double delay)
Set the entity to be active for a given time period. |
void |
sim_putback(Sim_event ev)
Put an event back on the deferred queue. |
void |
sim_schedule(int dest,
double delay,
int tag)
Send an event to another entity by id number and with no data. |
void |
sim_schedule(int dest,
double delay,
int tag,
java.lang.Object data)
Send an event to another entity by id number, with data. |
void |
sim_schedule(Sim_port dest,
double delay,
int tag)
Send an event to another entity through a port, with no data. |
void |
sim_schedule(Sim_port dest,
double delay,
int tag,
java.lang.Object data)
Send an event to another entity through a port, with data. |
void |
sim_schedule(java.lang.String dest,
double delay,
int tag)
Send an event to another entity through a port with a given name, with no data. |
void |
sim_schedule(java.lang.String dest,
double delay,
int tag,
java.lang.Object data)
Send an event to another entity through a port with a given name, with data. |
void |
sim_select(Sim_predicate p,
Sim_event ev)
Extract the first event matching a predicate waiting in the entity's deferred queue. |
void |
sim_trace(int level,
java.lang.String msg)
Write a trace message. |
double |
sim_wait_for(double delay,
Sim_event ev)
Wait for an event to arrive or until a time period elapsed. |
double |
sim_wait_for(Sim_predicate p,
double delay,
Sim_event ev)
Wait for an event matching a specific predicate to arrive or until a time period elapses. |
void |
sim_wait_for(Sim_predicate p,
Sim_event ev)
Wait for an event matching a specific predicate. |
void |
sim_wait(Sim_event ev)
Wait for an event to arrive. |
int |
sim_waiting()
Count how many events are waiting in the entiy's deferred queue |
int |
sim_waiting(Sim_predicate p)
Count how many events matching a predicate are waiting in the entity's deferred queue. |
Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, run, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public Sim_entity(java.lang.String name)
name
- The name to be associated with this entitypublic Sim_entity(java.lang.String name, java.lang.String image_name, int x, int y)
eduni.simanim
animation package.name
- The name to be associated with this entityimage_name
- The name of the gif image file for this entity's
icon (without the .gif extension).x
- The X co-ordinate at which the entity should be drawny
- The Y co-ordinate at which the entity should be drawnMethod Detail |
public void set_invisible(boolean b)
public java.lang.String get_name()
public int get_id()
public Sim_port get_port(Sim_event ev)
ev
- The eventnull
if
it could not be foundpublic Sim_port get_port(java.lang.String name)
name
- The name of the port to search fornull
if it could not be foundpublic void add_port(Sim_port port)
port
- The port to addpublic void add_param(Anim_param param)
eduni.simanim
package for animation.
param
- The parameter to addpublic void set_stat(Sim_stat stat)
Sim_stat
object for this entity.
param
- The Sim_stat
objectpublic Sim_stat get_stat()
Sim_stat
object.
Sim_stat
object defined for this entity or null
if none is defined.public void body()
public void sim_trace(int level, java.lang.String msg)
level
- The level at which the trace should be printed, used
with Sim_system.set_trace_level()
to control
what traces are printedmsg
- The message to be printedpublic void sim_completed(Sim_event e)
e
- The event that has completed servicepublic void sim_schedule(int dest, double delay, int tag, java.lang.Object data)
9999
is reserved.
dest
- The unique id number of the destination entitydelay
- How long from the current simulation time the event
should be senttag
- An user-defined number representing the type of event.data
- The data to be sent with the event.public void sim_schedule(int dest, double delay, int tag)
9999
is reserved.
dest
- The unique id number of the destination entitydelay
- How long from the current simulation time the event
should be senttag
- An user-defined number representing the type of event.public void sim_schedule(Sim_port dest, double delay, int tag, java.lang.Object data)
9999
is reserved.
dest
- The port to send the event throughdelay
- How long from the current simulation time the event
should be senttag
- An user-defined number representing the type of event.data
- The data to be sent with the event.public void sim_schedule(Sim_port dest, double delay, int tag)
9999
is reserved.
dest
- The port to send the event throughdelay
- How long from the current simulation time the event
should be senttag
- An user-defined number representing the type of event.public void sim_schedule(java.lang.String dest, double delay, int tag, java.lang.Object data)
9999
is reserved.
dest
- The name of the port to send the event throughdelay
- How long from the current simulation time the event
should be senttag
- An user-defined number representing the type of event.data
- The data to be sent with the event.public void sim_schedule(java.lang.String dest, double delay, int tag)
9999
is reserved.
dest
- The name of the port to send the event throughdelay
- How long from the current simulation time the event
should be senttag
- An user-defined number representing the type of event.public int sim_waiting(Sim_predicate p)
p
- The event selection predicatepublic int sim_waiting()
public void sim_select(Sim_predicate p, Sim_event ev)
p
- The event selection predicateev
- The event matched is copied into <body>ev</body> if it points to a blank event,
or discarded if ev
is null
public int sim_cancel(Sim_predicate p, Sim_event ev)
p
- The event selection predicateev
- The event matched is copied into ev
if it points to a blank event,
or discarded if ev
is null
public void sim_putback(Sim_event ev)
ev
- The event to put backpublic void sim_get_next(Sim_predicate p, Sim_event ev)
p
- The predicate to matchev
- The event matched is copied into ev
if it points to a blank event,
or discarded if ev
is null
public void sim_get_next(Sim_event ev)
ev
- The event matched is copied into ev
if it points to a blank event,
or discarded if ev
is null
public int sim_current()
public void send_on(Sim_event ev, Sim_port p)
ev
- The event to sendp
- The port through which to send the eventprotected java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
public void add_generator(Generator generator)
Sim_system
to reseed the generator. This is performed when independent replications have been selected
as an output analysis method. If this method is not used for a generator then the seed used in the
subsequent replication will be the last one produced by the generator in the previous run.
generator
- The sample generator to be added to the entitypublic void sim_process(double delay)
delay
- The time period for which the entity will be activepublic void sim_process_until(Sim_event ev)
ev
- The event to which the arriving event will be copied topublic void sim_process_until(Sim_predicate p, Sim_event ev)
p
- The predicate to matchev
- The event to which the arriving event will be copied topublic double sim_process_for(double delay, Sim_event ev)
delay
- The time period for which the entity will be active unless interruptedev
- The event to which the arriving event will be copied topublic double sim_process_for(Sim_predicate p, double delay, Sim_event ev)
p
- The predicate to matchdelay
- The time period for which the entity will be active unless interruptedev
- The event to which the arriving event will be copied topublic void sim_pause(double delay)
delay
- The time period for which the entity will be inactivepublic void sim_pause_until(Sim_event ev)
ev
- The event to which the arriving event will be copied topublic void sim_pause_until(Sim_predicate p, Sim_event ev)
p
- The predicate to matchev
- The event to which the arriving event will be copied topublic double sim_pause_for(double delay, Sim_event ev)
delay
- The time period for which the entity will be inactive unless interruptedev
- The event to which the arriving event will be copied topublic double sim_pause_for(Sim_predicate p, double delay, Sim_event ev)
p
- The predicate to matchdelay
- The time period for which the entity will be inactive unless interruptedev
- The event to which the arriving event will be copied topublic void sim_wait(Sim_event ev)
ev
- The event to which the arriving event will be copied topublic void sim_wait_for(Sim_predicate p, Sim_event ev)
Since 2.0 Sim_syztem
checks the predicate for the entity. This avoids unnecessary context
switches for non-matching events.
p
- The predicate to matchev
- The event to which the arriving event will be copied topublic double sim_wait_for(double delay, Sim_event ev)
delay
- The maximum time to waitev
- The event to which the arrving event will be copied topublic double sim_wait_for(Sim_predicate p, double delay, Sim_event ev)
p
- The predicate to matchdelay
- The maximum time period for which to waitev
- The event to which the arriving event will be copied topublic void sim_hold(double delay)
sim_pause(double delay)
.
This method was deprecated because of the new statistical support present to entities. When an
entity holds it must now be specified if the hold corrssponds to the entity being active or
inactive. The original sim_hold()
methods are equivalent to their respective
sim_pause()
methods.
delay
- The time period for which to holdpublic double sim_hold_for(double delay, Sim_event ev)
sim_pause_for(double delay, Sim_event ev)
.
This method was deprecated because of the new statistical support present to entities. When an
entity holds it must now be specified if the hold corrssponds to the entity being active or
inactive. The original sim_hold()
methods are equivalent to their respective
sim_pause()
methods.
delay
- The maximum time period for which to holdev
- The event to which the arriving event will be copied to
|
SimJava v2.0 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |