All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class eduni.simjava.Sim_entity

java.lang.Object
   |
   +----java.lang.Thread
           |
           +----eduni.simjava.Sim_entity

public class Sim_entity
extends Thread
This class represents entities, or processes, running in the system. To create a new type of entity, it should be extended and a definition for the body() method given. The body() method is called by the Sim_system and defines the behaviour of the entity during the simulation.

The methods with names starting with the prefix sim_ are runtime methods, and should only be called from within the entity's body() method.

See Also:
Sim_system

Constructor Index

 o Sim_entity(String)
The standard constructor.
 o Sim_entity(String, String, int, int)
The constructor for use with the eduni.simanim animation package.

Method Index

 o add_param(Anim_param)
Add a parameter to this entity.
 o add_port(Sim_port)
Add a port to this entity.
 o body()
The method which defines the behavior of the entity.
 o get_id()
Get the unique id number assigned to this entity
 o get_name()
Get the name of this entity
 o get_port(Sim_event)
Search through this entity's ports, for the one which sent this event.
 o get_port(String)
Search through this entity's ports, for one called name.
 o run()
Internal method - don't overide
 o send_on(Sim_event, Sim_port)
Send on an event to an other entity, through a port.
 o set_invisible(boolean)
Make entity icon invisible
 o sim_cancel(Sim_predicate, Sim_event)
Cancel the first event waiting for this entity on the future queue, matched by the predicate p.
 o sim_current()
Get the id of the currently running entity
 o sim_get_next(Sim_event)
Get the first event from the deferred queue waiting on the entity, or, if there are none, wait for an event to arrive.
 o sim_get_next(Sim_predicate, Sim_event)
Get the first event matching a predicate from the deferred queue, or, if none match, wait for a matching event to arrive.
 o sim_hold(double)
Causes the entity to hold for delay units of simulation time.
 o sim_putback(Sim_event)
Put an event back on the defered queue.
 o sim_schedule(int, double, int)
Send an event to another entity, by id number and with no data.
 o sim_schedule(int, double, int, Object)
Send an event to another entity, by id number with data.
 o sim_schedule(Sim_port, double, int)
Send an event to another entity, by a port reference with no data.
 o sim_schedule(Sim_port, double, int, Object)
Send an event to another entity, by a port reference with data.
 o sim_schedule(String, double, int)
Send an event to another entity, by a port name with no data.
 o sim_schedule(String, double, int, Object)
Send an event to another entity, by a port name with data.
 o sim_select(Sim_predicate, Sim_event)
Extract the first event waiting for this entity on the deferred queue, matched by the predicate p.
 o sim_trace(int, String)
Write a trace message.
 o sim_wait(Sim_event)
Hold until the entity recieves an event.
 o sim_wait_for(Sim_predicate, Sim_event)
Repeatedly sim_wait() until the entity receives an event matched by a predicate, all other received events are discarded.
 o sim_waiting()
Count how many events are waiting of this entity on the deferred queue
 o sim_waiting(Sim_predicate)
Count how many events matching a predicate are waiting for this entity on the deferred queue.

Constructors

 o Sim_entity
 public Sim_entity(String name)
The standard constructor.

Parameters:
name - The name to be associated with this entity
Returns:
A new instance of the class Sim_entity
 o Sim_entity
 public Sim_entity(String name,
                   String image_name,
                   int x,
                   int y)
The constructor for use with the eduni.simanim animation package.

Parameters:
name - The name to be associated with this entity
image_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 drawn
y - The Y co-ordinate at which the entity should be drawn

Methods

 o set_invisible
 public void set_invisible(boolean b)
Make entity icon invisible

 o get_name
 public String get_name()
Get the name of this entity

Returns:
The entity's name
 o get_id
 public int get_id()
Get the unique id number assigned to this entity

Returns:
The id number
 o get_port
 public Sim_port get_port(Sim_event ev)
Search through this entity's ports, for the one which sent this event.

Parameters:
ev - The event
Returns:
A reference to the port which sent the event, or null if it could not be found
 o get_port
 public Sim_port get_port(String name)
Search through this entity's ports, for one called name.

Parameters:
name - The name of the port to search for
Returns:
A reference to the port, or null if it could not be found
 o add_port
 public void add_port(Sim_port port)
Add a port to this entity.

Parameters:
port - A reference to the port to add
 o add_param
 public void add_param(Anim_param param)
Add a parameter to this entity. Used with the eduni.simanim package for animation.

Parameters:
param - A reference to the parameter to add
 o body
 public void body()
The method which defines the behavior of the entity. This method should be overidden in subclasses of Sim_entity.

 o sim_hold
 public void sim_hold(double delay)
Causes the entity to hold for delay units of simulation time.

Parameters:
delay - The amount of time to hold
 o sim_trace
 public void sim_trace(int level,
                       String msg)
Write a trace message.

Parameters:
level - The level at which the trace should be printed, used with Sim_system.set_trc_level() to control what traces are printed
msg - The message to be printed
 o sim_schedule
 public void sim_schedule(int dest,
                          double delay,
                          int tag,
                          Object data)
Send an event to another entity, by id number with data.

Parameters:
dest - The unique id number of the destination entity
delay - How long from the current simulation time the event should be sent
tag - An user-defined number representing the type of event.
data - A reference to data to be sent with the event.
 o sim_schedule
 public void sim_schedule(int dest,
                          double delay,
                          int tag)
Send an event to another entity, by id number and with no data.

Parameters:
dest - The unique id number of the destination entity
delay - How long from the current simulation time the event should be sent
tag - An user-defined number representing the type of event.
 o sim_schedule
 public void sim_schedule(Sim_port dest,
                          double delay,
                          int tag,
                          Object data)
Send an event to another entity, by a port reference with data.

Parameters:
dest - A reference to the port to send the event out of
delay - How long from the current simulation time the event should be sent
tag - An user-defined number representing the type of event.
data - A reference to data to be sent with the event.
 o sim_schedule
 public void sim_schedule(Sim_port dest,
                          double delay,
                          int tag)
Send an event to another entity, by a port reference with no data.

Parameters:
dest - A reference to the port to send the event out of
delay - How long from the current simulation time the event should be sent
tag - An user-defined number representing the type of event.
 o sim_schedule
 public void sim_schedule(String dest,
                          double delay,
                          int tag,
                          Object data)
Send an event to another entity, by a port name with data.

Parameters:
dest - The name of the port to send the event out of
delay - How long from the current simulation time the event should be sent
tag - An user-defined number representing the type of event.
data - A reference to data to be sent with the event.
 o sim_schedule
 public void sim_schedule(String dest,
                          double delay,
                          int tag)
Send an event to another entity, by a port name with no data.

Parameters:
dest - The name of the port to send the event out of
delay - How long from the current simulation time the event should be sent
tag - An user-defined number representing the type of event.
 o sim_wait
 public void sim_wait(Sim_event ev)
Hold until the entity recieves an event.

Parameters:
ev - The event recieved is copied into ev if it points to an blank event, or discarded if ev is null
 o sim_waiting
 public int sim_waiting(Sim_predicate p)
Count how many events matching a predicate are waiting for this entity on the deferred queue.

Parameters:
p - The event selection predicate
Returns:
The count of matching events
 o sim_waiting
 public int sim_waiting()
Count how many events are waiting of this entity on the deferred queue

Returns:
The count of events
 o sim_select
 public void sim_select(Sim_predicate p,
                        Sim_event ev)
Extract the first event waiting for this entity on the deferred queue, matched by the predicate p.

Parameters:
p - An event selection predicate
ev - The event matched is copied into ev if it points to a blank event, or discarded if ev is null
 o sim_cancel
 public int sim_cancel(Sim_predicate p,
                       Sim_event ev)
Cancel the first event waiting for this entity on the future queue, matched by the predicate p. Returns the number of events cancelled (0 or 1).

Parameters:
p - An event selection predicate
ev - The event matched is copied into ev if it points to a blank event, or discarded if ev is null
 o sim_wait_for
 public void sim_wait_for(Sim_predicate p,
                          Sim_event ev)
Repeatedly sim_wait() until the entity receives an event matched by a predicate, all other received events are discarded.

Parameters:
p - The event selection predicate
ev - The event matched is copied into ev if it points to a blank event, or discarded if ev is null
 o sim_putback
 public void sim_putback(Sim_event ev)
Put an event back on the defered queue.

Parameters:
ev - The event to reinsert
 o sim_get_next
 public 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.

Parameters:
p - The predicate to match
ev - The event matched is copied into ev if it points to a blank event, or discarded if ev is null
 o sim_get_next
 public void sim_get_next(Sim_event ev)
Get the first event from the deferred queue waiting on the entity, or, if there are none, wait for an event to arrive.

Parameters:
ev - The event matched is copied into ev if it points to a blank event, or discarded if ev is null
 o sim_current
 public int sim_current()
Get the id of the currently running entity

Returns:
A unique entity id number
 o send_on
 public void send_on(Sim_event ev,
                     Sim_port p)
Send on an event to an other entity, through a port.

Parameters:
ev - A reference to the event to send
p - A reference to the port through which to send
 o run
 public final void run()
Internal method - don't overide

Overrides:
run in class Thread

All Packages  Class Hierarchy  This Package  Previous  Next  Index