Bully Task (12.12.2005)

at.jku.fim.datalinksimulation.layer7.Bully
Class BullyApplication

java.lang.Object
  extended by at.jku.fim.datalinksimulation.layer7.Application
      extended by at.jku.fim.datalinksimulation.layer7.Bully.BullyApplication
All Implemented Interfaces:
IncomingNetworkStackObserver, java.lang.Runnable

public class BullyApplication
extends Application
implements java.lang.Runnable

The Bully Application running on the individual stations

Copyright: (c) 2004,2005

Company: FIM@JKU, www.fim.uni-linz.ac.at

Version:
$Id$
Author:
Michael Sonntag

Field Summary
static int BULLY_STATE_ELECTION
          Election messages have been sent; waiting for the first OK message
static int BULLY_STATE_INIT
          Initialization: When the algorithm starts; before sending the election messages
static int BULLY_STATE_MASTER
          We are the master
static int BULLY_STATE_SLAVE
          We are a slave
static int BULLY_STATE_UNKNOWN
          Current state of Bully algorithm is unknown
static int BULLY_STATE_WAIT
          At least one OK message received; we are waiting for a coordinator message
 
Fields inherited from class at.jku.fim.datalinksimulation.layer7.Application
networkStackReference
 
Constructor Summary
BullyApplication(int stationId, int stationCount)
          Constructor
 
Method Summary
 Logger getLogger()
          Retrieve the object's logger
 int getMasterID()
          Retrieve the ID of our current master.
 int getStationId()
          Retrieve the station ID
 void informAboutNewData(NetworkStackParameters params, RawData data)
          Receive data from the network
 void run()
          Run this application.
 void setGui(BullyPanel gui)
          Set GUI panel so we can notify it about state changes.
 void terminate()
          Stop this thread.
 
Methods inherited from class at.jku.fim.datalinksimulation.layer7.Application
getNetworkStack, setNetworkStack
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BULLY_STATE_UNKNOWN

public static final int BULLY_STATE_UNKNOWN
Current state of Bully algorithm is unknown

See Also:
Constant Field Values

BULLY_STATE_INIT

public static final int BULLY_STATE_INIT
Initialization: When the algorithm starts; before sending the election messages

See Also:
Constant Field Values

BULLY_STATE_ELECTION

public static final int BULLY_STATE_ELECTION
Election messages have been sent; waiting for the first OK message

See Also:
Constant Field Values

BULLY_STATE_WAIT

public static final int BULLY_STATE_WAIT
At least one OK message received; we are waiting for a coordinator message

See Also:
Constant Field Values

BULLY_STATE_SLAVE

public static final int BULLY_STATE_SLAVE
We are a slave

See Also:
Constant Field Values

BULLY_STATE_MASTER

public static final int BULLY_STATE_MASTER
We are the master

See Also:
Constant Field Values
Constructor Detail

BullyApplication

public BullyApplication(int stationId,
                        int stationCount)
Constructor

Parameters:
stationId - Station ID of host
stationCount - total number of stations
Method Detail

getStationId

public int getStationId()
Retrieve the station ID

Returns:
the ID of this station

getMasterID

public int getMasterID()
Retrieve the ID of our current master. This is our number if we are the master, a different one if we are a slave, or -1 if there is currently no master (e.g. during an election). Used for showing it in the GUI.

Returns:
the master's ID

setGui

public void setGui(BullyPanel gui)
Set GUI panel so we can notify it about state changes. Called by the application.

Parameters:
gui - the GUI panel

run

public void run()
Run this application. Starts immediately an election and then starts the message loop to wait for incoming messages.

Specified by:
run in interface java.lang.Runnable

terminate

public void terminate()
Stop this thread. Used in case the application "fails" (when the user disables it through the GUI). The thread is terminated and the state set to "unknown". Pinging the master stops too, if the thread is currently doing this.


informAboutNewData

public void informAboutNewData(NetworkStackParameters params,
                               RawData data)
Receive data from the network

Specified by:
informAboutNewData in interface IncomingNetworkStackObserver
Parameters:
params - network parameters
data - raw data

getLogger

public Logger getLogger()
Retrieve the object's logger

Specified by:
getLogger in class Application
Returns:
the logger instance

Bully Task (12.12.2005)

Submit a bug

Copyright 2004-2008 Michael Sonntag & Institute for Information Processing and Microprocessor Technology (FIM), Johannes-Kepler-University Linz, Altenbergerstr. 69, A-4040 Linz, Austria.