Class Manager

java.lang.Object
  extended byManager
Direct Known Subclasses:
Emulator, Simulator

public abstract class Manager
extends java.lang.Object

   
 Abstract class defining generic routines for running network code under Fishnet
 


Field Summary
protected  CommandsParser parser
           
protected  java.io.BufferedReader reader
           
protected  SortedEventQueue sortedEvents
           
 
Constructor Summary
protected Manager(long time)
          Initialize Manager.
 
Method Summary
protected  void addEvent(long timeToOccur, java.lang.String methodName, java.lang.Object obj, java.lang.String[] paramTypes, java.lang.Object[] params)
           
 void addTimer(int nodeAddr, long deltaT, Callback callback)
          Adds a timer to be fired at deltaT milliseconds in the future
 void addTimerAt(int nodeAddr, long t, Callback callback)
          Adds a timer to be fired at time t
abstract  long now()
          Retrieve current time in milliseconds
protected  long readFishFile(long deferTill)
          Reads one line of the fish commands file and returns how long to delay further parsing if time command was found Call this function after now > 0
abstract  boolean sendNodeMsg(int nodeAddr, java.lang.String msg)
          Sends the msg to the the specified node
 boolean sendPkt(int from, int to, byte[] pkt)
          Send the pkt to the specified node
 void setFishnetFile(java.lang.String filename)
          Sets the fishnet file that commands should be read from
protected  void setParser(CommandsParser parser)
           
 void setTimescale(double timescale)
          Sets the amount to scale real time by.
abstract  void start()
          Starts the Manager.
 void stop()
          Stops Fishnet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sortedEvents

protected SortedEventQueue sortedEvents

parser

protected CommandsParser parser

reader

protected java.io.BufferedReader reader
Constructor Detail

Manager

protected Manager(long time)
Initialize Manager.

Parameters:
time - Starting time in microseconds
Method Detail

start

public abstract void start()
Starts the Manager. This runs in an infinite loop until network is stopped Instantiates nodes and gets them running


stop

public void stop()
Stops Fishnet. Normally this method should not return


setFishnetFile

public void setFishnetFile(java.lang.String filename)
                    throws java.io.FileNotFoundException
Sets the fishnet file that commands should be read from

Parameters:
filename - The name of the file that commands should be read from
Throws:
java.io.FileNotFoundException - If the named filed does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading

sendPkt

public boolean sendPkt(int from,
                       int to,
                       byte[] pkt)
                throws java.lang.IllegalArgumentException
Send the pkt to the specified node

Parameters:
from - The node that is sending the packet
to - Int spefying the destination node
pkt - The packet to be sent, serialized to a byte array
Returns:
True if the packet was sent, false otherwise
Throws:
java.lang.IllegalArgumentException - If the arguments are invalid

addTimerAt

public void addTimerAt(int nodeAddr,
                       long t,
                       Callback callback)
Adds a timer to be fired at time t

Parameters:
nodeAddr - Addr of node that is registering this timer
t - The time when the timer should fire. In milliseconds
callback - The callback to be invoked when the timer fires

addTimer

public void addTimer(int nodeAddr,
                     long deltaT,
                     Callback callback)
Adds a timer to be fired at deltaT milliseconds in the future

Parameters:
nodeAddr - Addr of node that is registering this timer
deltaT - The time interval after which the timer should fire. In milliseconds
callback - The callback to be invoked when the timer fires

now

public abstract long now()
Retrieve current time in milliseconds

Returns:
Current time in milliseconds

sendNodeMsg

public abstract boolean sendNodeMsg(int nodeAddr,
                                    java.lang.String msg)
Sends the msg to the the specified node

Parameters:
nodeAddr - Address of the node to whom the message should be sent
msg - The msg to send to the node
Returns:
True if msg sent, false if address is not valid

setTimescale

public void setTimescale(double timescale)
Sets the amount to scale real time by. Is only valid for simiulator

Parameters:
timescale - The amount to scale real time by

setParser

protected void setParser(CommandsParser parser)

readFishFile

protected long readFishFile(long deferTill)
Reads one line of the fish commands file and returns how long to delay further parsing if time command was found Call this function after now > 0

Parameters:
deferTill - Should be the value returned by this function. Can be initialized to 0 for first invocation
Returns:
How long (in microseconds) to defer further parsing till. -1 if reached eof. 0 if no delay

addEvent

protected void addEvent(long timeToOccur,
                        java.lang.String methodName,
                        java.lang.Object obj,
                        java.lang.String[] paramTypes,
                        java.lang.Object[] params)