peersim.core
Class CommonState

java.lang.Object
  extended by peersim.core.CommonState
Direct Known Subclasses:
CDState

public class CommonState
extends java.lang.Object

This is the common state of the simulation all objects see. Static singleton. One of its purposes is simplification of parameter structures and increasing efficiency by putting state information here instead of passing parameters.

The set methods should not be used by applications, they are for system components. Use them only if you know exactly what you are doing, e.g. if you are so advanced that you can write your own simulation engine. Ideally, they should not be visible, but due to the lack of more flexibility in java access rights, we are forced to make them public.


Parameter Summary
random
          Configuration parameter used to define which random generator class should be used.
random.seed
          Configuration parameter used to initialize the random seed.
 
Field Summary
static int PHASE_UNKNOWN
          Constant that can be used as a value of simulation phase.
static int POST_SIMULATION
          Constant that can be used as a value of simulation phase.
static ExtendedRandom r
          This source of randomness should be used by all components.
 
Constructor Summary
protected CommonState()
          Does nothing.
 
Method Summary
static long getEndTime()
          Returns endtime.
static int getIntTime()
          Returns current time in integer format.
static Node getNode()
          Returns the current node.
static int getPhase()
          Returns the simulation phase.
static int getPid()
          Returns the current protocol identifier.
static long getTime()
          Returns current time.
static void initializeRandom(long seed)
           
static void setEndTime(long t)
          Sets the endtime.
static void setNode(Node n)
          Sets the current node
static void setPhase(int p)
           
static void setPid(int p)
          Sets the current protocol identifier.
static void setTime(long t)
          Sets the current time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Parameter Detail

random

Configuration parameter used to define which random generator class should be used. If not specified, the default implementation ExtendedRandom is used. User-specified random generators must extend class ExtendedRandom.


random.seed

Configuration parameter used to initialize the random seed. If it is not specified the current time is used.

Field Detail

POST_SIMULATION

public static final int POST_SIMULATION
Constant that can be used as a value of simulation phase. It means that the simulation has finished.

See Also:
getPhase(), Constant Field Values

PHASE_UNKNOWN

public static final int PHASE_UNKNOWN
Constant that can be used as a value of simulation phase. It means that the simulation phase information has not been set (unknown).

See Also:
getPhase(), Constant Field Values

r

public static ExtendedRandom r
This source of randomness should be used by all components. This field is public because it doesn't matter if it changes during an experiment (although it shouldn't) until no other sources of randomness are used within the system. Besides, we can save the cost of calling a wrapper method, which is important because this is needed very often.

Constructor Detail

CommonState

protected CommonState()
Does nothing. To avoid construction but allow extension.

Method Detail

getTime

public static long getTime()
Returns current time. In event-driven simulations, returns the current time (a long-value). In cycle-driven simulations, returns the current cycle (a long that can safely be cast into an integer).


getIntTime

public static int getIntTime()
Returns current time in integer format. The purpose is to enhance the performance of protocols (ints are smaller and faster) when absolute precision is not required. It assumes that endtime has been set via setEndTime(long) by the simulation engine. It uses the endtime for the optimal mapping to get the maximal precision. In particular, in the cycle based model, time is the same as cycle which can be safely cast into integer, so no precision is lost.


setTime

public static void setTime(long t)
Sets the current time.


getEndTime

public static long getEndTime()
Returns endtime. It is the maximal value getTime() ever returns. If it's negative, it means the endtime is not known.


setEndTime

public static void setEndTime(long t)
Sets the endtime.


getPhase

public static int getPhase()
Returns the simulation phase. Currently the following phases are understood.


setPhase

public static void setPhase(int p)

getPid

public static int getPid()
Returns the current protocol identifier. In other words, control is held by the indicated protocol on node getNode().


setPid

public static void setPid(int p)
Sets the current protocol identifier.


getNode

public static Node getNode()
Returns the current node. When a protocol is executing, it is the node hosting the protocol.


setNode

public static void setNode(Node n)
Sets the current node


initializeRandom

public static void initializeRandom(long seed)