bp
Class BProgram

java.lang.Object
  extended by bp.BProgram

public class BProgram
extends java.lang.Object


Field Summary
(package private) static java.util.TreeMap<java.lang.Double,BThread> allBThreads
          A set containing all the b-threads in the system.
(package private) static int busyBThreads
          A counter that counts how many of the b-thread is allBThreads are busy.
static int eventCounter
          A variable counting the number of events fired since the beginning of the execution
static Event lastEvent
          A variable containing the last fired event, for reference.
 
Constructor Summary
BProgram()
           
 
Method Summary
static BThread add(BThread bt, java.lang.Double priority)
          Add a scenario.
private static boolean awakeWaitingBThreads(BThread thisBT)
          Awake or interrupt all scenarios that are affected by lastEvent.
protected static void bpSync(BThread bt)
          Wait for the next event.
private static void chooseNextEvent()
          Choose the next event to be fired.
private static boolean isBlocked(Event e)
          A function that checks if an event is blocked by some scenario.
(package private) static void printAllScenarios()
          Utility function (for debugging purposes) that prints the ordered list of active scenarios.
static void startAll()
          Start all added scenarios.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

allBThreads

static java.util.TreeMap<java.lang.Double,BThread> allBThreads
A set containing all the b-threads in the system. A b-thread adds itself to the list in its constructor and removes itself when its run() function finishes


busyBThreads

static int busyBThreads
A counter that counts how many of the b-thread is allBThreads are busy. B-Threads decrement this counter when they get into bpSync just before they become dormant and wait to be awaken. When the counter gets to zero, the scenario that decremented it from one to zero, awakes other scenarios and sets the counter to the number of scenarios that it awakes (the number of scenarios that are waiting to the next event)


eventCounter

public static int eventCounter
A variable counting the number of events fired since the beginning of the execution


lastEvent

public static Event lastEvent
A variable containing the last fired event, for reference.

Constructor Detail

BProgram

public BProgram()
Method Detail

add

public static BThread add(BThread bt,
                          java.lang.Double priority)
                   throws DuplicatedPrioritiesException
Add a scenario. Hereafter, the scenario is counted in the list of all scenarios as busy. This allows, for example, to add a new scenario dynamically (based on a precondition) in a way that assures that new events are not triggered before the thread of the new scenario starts running.

Returns:
Throws:
DuplicatedPrioritiesException

awakeWaitingBThreads

private static boolean awakeWaitingBThreads(BThread thisBT)
Awake or interrupt all scenarios that are affected by lastEvent. The calling scenario is a special case because it cannot be awaken (since it is not waiting yet). For the calling scenario, we use the return value which indicates whether it has to wait for another scenario to awake it or it is awaken by itself, i.e., it does not need to wait.

Returns:
A flag that indicates whether this scenario awakes itself, i.e., does not need to wait for another scenario to awake it

bpSync

protected static void bpSync(BThread bt)
                      throws java.lang.InterruptedException
Wait for the next event. Sleep until all b-threads call this function.

Parameters:
bt - The b-thread that called this function.
Throws:
java.lang.InterruptedException
NotAScenarioException - Raised if the current context is not a scenario.
java.lang.InterruptedException - Raised when an outside thread interrupts this scenario.

chooseNextEvent

private static void chooseNextEvent()
Choose the next event to be fired. The chosen event and the triggering scenario are stored in the global variables lastEvent and requestingBThreadForLastEvent and eventCounter is incremented. In case there is no event to choose, lastEvent and requestingBThreadForLastEvent become null and the counter is not incremented.


isBlocked

private static boolean isBlocked(Event e)
A function that checks if an event is blocked by some scenario.

Parameters:
e - An event.
Returns:
true if the event is blocked by some scenario.

printAllScenarios

static void printAllScenarios()
Utility function (for debugging purposes) that prints the ordered list of active scenarios.


startAll

public static void startAll()
Start all added scenarios.