com.distributed.api
Class Clock

java.lang.Object
  |
  +--com.distributed.api.Clock

public class Clock
extends java.lang.Object

Clock Used to implement Vector Clock


Field Summary
static int LAMPORT_CLOCK
          Constant used within the class
static int NO_CLOCK
          Constant used within the class
static int VECTOR_CLOCK
          Constant used within the class
 
Constructor Summary
Clock()
          Default Constructor
Clock(Clock c)
          Copy Constructor
Clock(int n, int id)
          Constructor to be normally used by Environment
Clock(int n, int id, java.lang.String c)
          Constructor to be normally used by Environment
 
Method Summary
 int compare(Clock c)
          Method to compare a clock with this object
static int compare(Clock myClock, Clock hisClock)
          Method to compare two clocks
 void incrClock(Event e, Clock r)
          Method used to increment Clock
 boolean isComparable(Clock c)
          Method to see if this object and another clock are comparable or not
static boolean isComparable(Clock myClock, Clock hisClock)
          Method to check if two clocks are comparable or not
 int lamportClock()
          Method to return value of Lamport's clock at this point
static int lamportClock(java.lang.String c)
          methos to return Lamport Clock value from String
 java.lang.String toString(int convertion_type)
          Method to convert Clock into String
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LAMPORT_CLOCK

public static final int LAMPORT_CLOCK
Constant used within the class

See Also:
Constant Field Values

NO_CLOCK

public static final int NO_CLOCK
Constant used within the class

See Also:
Constant Field Values

VECTOR_CLOCK

public static final int VECTOR_CLOCK
Constant used within the class

See Also:
Constant Field Values
Constructor Detail

Clock

public Clock()
Default Constructor


Clock

public Clock(Clock c)
Copy Constructor

Parameters:
c - The Clock to be Copied from

Clock

public Clock(int n,
             int id)
      throws java.lang.Exception
Constructor to be normally used by Environment

Parameters:
n - No. of Processes in system
id - Id of this process
Throws:
java.lang.Exception - Wrong Parameters

Clock

public Clock(int n,
             int id,
             java.lang.String c)
      throws java.lang.Exception
Constructor to be normally used by Environment

Parameters:
n - No. of Processes in system
id - Id of this process
c - Contains Clock vector in string form
Throws:
java.lang.Exception - Wrong Parameters
Method Detail

compare

public int compare(Clock c)
Method to compare a clock with this object

Parameters:
c - Object to be compared to
Returns:
1 if our clock < c, 2 if our clock > c, 0 if clocks incomparable

compare

public static int compare(Clock myClock,
                          Clock hisClock)
Method to compare two clocks

Parameters:
myClock - First Clock
hisClock - Second Clock
Returns:
1 if myClock < hisClock, 2 if myClock > hisClock, 0 if clocks incomparable

incrClock

public void incrClock(Event e,
                      Clock r)
               throws java.lang.Exception
Method used to increment Clock

Parameters:
e - Type of Event
r - Clock value if used to increment after receive event
Throws:
java.lang.Exception - On mismatch of any Parameters

isComparable

public boolean isComparable(Clock c)
Method to see if this object and another clock are comparable or not

Parameters:
c - Object to be check with
Returns:
True if comparable, False otherwise

isComparable

public static boolean isComparable(Clock myClock,
                                   Clock hisClock)
Method to check if two clocks are comparable or not

Parameters:
myClock - First Clock
hisClock - Second Clock
Returns:
True if comparable, False otherwise

lamportClock

public int lamportClock()
Method to return value of Lamport's clock at this point

Returns:
Value of Lamport Clock

lamportClock

public static int lamportClock(java.lang.String c)
                        throws java.lang.NumberFormatException
methos to return Lamport Clock value from String

Parameters:
c - Contains Clock value
Returns:
Lamport Clock Value from c
Throws:
java.lang.NumberFormatException - if unable to extract lamports clock

toString

public java.lang.String toString(int convertion_type)
Method to convert Clock into String

Returns:
String form of clock as specified by conversion_type