MutualExclusion
Class Prog

java.lang.Object
  |
  +--daj.Program
        |
        +--MutualExclusion.Prog

class Prog
extends daj.Program

The code that will be executed on each node.


Field Summary
static int C
          possible value for region: critical region entered
protected  int clock
          the current clock value
protected  java.util.Vector[] deferred_ok
          for every neighbour, the buffer for remembering deferred ok messages until critical region has been left
protected  java.util.Vector[] history
          for every node, the message history
protected  int index
          the node number
protected  LogicalTime lastTryTime
          the logical time of the last "try" message that has been sent
static int R
          possible value for region: idle
protected  int region
          the region can be either R, T, C or E
static int T
          possible value for region: try to get the ressource
 
Fields inherited from class daj.Program
node
 
Constructor Summary
Prog(int index)
          the default constructor initializes the index and the arrays
 
Method Summary
private  boolean checkOkMsgsReceived()
          This is a helper function that checks if all "OK" messages have been recieved for the last try message.
 void freeRessource()
          the user function for freeing the ressource (exiting the critical region)
 java.lang.String getText()
           
private  void handleTryMessage(int received, Msg msg)
          This is a helper function that responds properly to a received "try" message.
 void main()
          this method performs the node's main functions
 void ressourceAvailable()
          this function is called when the ressource can be taken (the critical region can be entered)
 void ressourceFreed()
          this function is called when the ressource has been freed (the critical region has been left)
 void tryRessource()
          the user function for trying to get the ressource (getting the permission to enter the critical region)
 
Methods inherited from class daj.Program
assert, exit, getTime, in, in, interrupt, out, out, setNode, sleep, yield
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

R

public static final int R
possible value for region: idle

T

public static final int T
possible value for region: try to get the ressource

C

public static final int C
possible value for region: critical region entered

index

protected int index
the node number

region

protected int region
the region can be either R, T, C or E

clock

protected int clock
the current clock value

history

protected java.util.Vector[] history
for every node, the message history

deferred_ok

protected java.util.Vector[] deferred_ok
for every neighbour, the buffer for remembering deferred ok messages until critical region has been left

lastTryTime

protected LogicalTime lastTryTime
the logical time of the last "try" message that has been sent
Constructor Detail

Prog

public Prog(int index)
the default constructor initializes the index and the arrays
Method Detail

tryRessource

public void tryRessource()
the user function for trying to get the ressource (getting the permission to enter the critical region)

freeRessource

public void freeRessource()
the user function for freeing the ressource (exiting the critical region)

ressourceAvailable

public void ressourceAvailable()
this function is called when the ressource can be taken (the critical region can be entered)

ressourceFreed

public void ressourceFreed()
this function is called when the ressource has been freed (the critical region has been left)

main

public void main()
this method performs the node's main functions
Overrides:
main in class daj.Program

getText

public java.lang.String getText()
Overrides:
getText in class daj.Program

handleTryMessage

private void handleTryMessage(int received,
                              Msg msg)
This is a helper function that responds properly to a received "try" message.

checkOkMsgsReceived

private boolean checkOkMsgsReceived()
This is a helper function that checks if all "OK" messages have been recieved for the last try message.