com.distributed.api
Class Environment

java.lang.Object
  |
  +--com.distributed.api.Environment
All Implemented Interfaces:
MessageReceiverListener

public class Environment
extends java.lang.Object
implements MessageReceiverListener

Defines all methods that can be used by any distributed appication process


Field Summary
static int CONTROL_PORT
          Default port number
 int N
          Number of processes in distributed system
 
Constructor Summary
Environment(java.lang.String filename, EnvironmentListener up)
          establishes the connections with other processes & starts listening on the channel
 
Method Summary
protected  void allSnapsReceived(int sendsnapto, java.lang.String chanstate)
          Sends the global picture of distributed system to the requesting process
protected  void appendState(java.lang.String s)
          Appends to present global state
 Clock getClock()
          Returns the internal clock of the application process
 void getConsensus(int val)
          Proposes consensus value of this application process & achieves consensus
 int getPid()
          Returns process id of the application process in distributed system
protected  EnvironmentListener getUserProcess()
          Returns EnvironmentListener of application process
 void holdElection()
          Does the election using protocol 1
 void holdElection2()
          Does the election using protocol 2
 void messageReceived(Message m)
          Handles both control & application messages
 void releaseLock()
          Exits critical sections & releases lock
 void requestCsEntry()
          Enters the application process in critical section
protected  void saveLocalState(int source, int sendsnapto)
          Saves local state & turns red
 void sendTo(int despid, java.lang.String messgtext)
          Sends messgtext message to particular destination
protected  void sendTo(int despid, java.lang.String messgtext, int messgtype, boolean clock_required, int clock_type)
          Environment uses this method to send message to a particular destination
 void sendToAllNeighbours(java.lang.String messgtext)
          Broadcasts message
protected  void sendToAllNeighbours(java.lang.String messgtext, int messgtype, boolean clock_required, int clock_type)
          Used by Environment to broadcast messages
 java.lang.String takeSnapshot()
          Returns global picture of the entire distributed system
 void terminate()
          Closes all connection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTROL_PORT

public static final int CONTROL_PORT
Default port number

See Also:
Constant Field Values

N

public int N
Number of processes in distributed system

Constructor Detail

Environment

public Environment(java.lang.String filename,
                   EnvironmentListener up)
            throws java.lang.Exception
establishes the connections with other processes & starts listening on the channel

Parameters:
filename - configuration file of the network
up - application process Environment listener
Method Detail

allSnapsReceived

protected void allSnapsReceived(int sendsnapto,
                                java.lang.String chanstate)
Sends the global picture of distributed system to the requesting process

Parameters:
sendsnapto - process to which snapshot has to be sent
chanstate - state of the channel

appendState

protected void appendState(java.lang.String s)
Appends to present global state

Parameters:
s - string to be appended to global state

getClock

public Clock getClock()
Returns the internal clock of the application process


getConsensus

public void getConsensus(int val)
Proposes consensus value of this application process & achieves consensus

Parameters:
val - value to be proposed

getPid

public int getPid()
Returns process id of the application process in distributed system


getUserProcess

protected EnvironmentListener getUserProcess()
Returns EnvironmentListener of application process


holdElection

public void holdElection()
Does the election using protocol 1


holdElection2

public void holdElection2()
Does the election using protocol 2


messageReceived

public void messageReceived(Message m)
Handles both control & application messages

Specified by:
messageReceived in interface MessageReceiverListener
Parameters:
m - Message that has been received

releaseLock

public void releaseLock()
Exits critical sections & releases lock


requestCsEntry

public void requestCsEntry()
Enters the application process in critical section


saveLocalState

protected void saveLocalState(int source,
                              int sendsnapto)
Saves local state & turns red

Parameters:
source - process from which the marker was received
sendsnapto - process to which snapshot has to be sent

sendTo

public void sendTo(int despid,
                   java.lang.String messgtext)
Sends messgtext message to particular destination

Parameters:
messgtext - message to be sent

sendTo

protected void sendTo(int despid,
                      java.lang.String messgtext,
                      int messgtype,
                      boolean clock_required,
                      int clock_type)
Environment uses this method to send message to a particular destination

Parameters:
messgtext - message to be sent
messgtype - type of the message
clock_required - says whether clock is required or not
clock_type - type of clock(lamport or vector)

sendToAllNeighbours

public void sendToAllNeighbours(java.lang.String messgtext)
Broadcasts message

Parameters:
messgtext - message to be broadcasted

sendToAllNeighbours

protected void sendToAllNeighbours(java.lang.String messgtext,
                                   int messgtype,
                                   boolean clock_required,
                                   int clock_type)
Used by Environment to broadcast messages

Parameters:
messgtext - message to be sent
messgtype - type of the message
clock_required - says whether clock is required or not
clock_type - type of clock(lamport or vector)

takeSnapshot

public java.lang.String takeSnapshot()
Returns global picture of the entire distributed system


terminate

public void terminate()
Closes all connection