Class Emulator

java.lang.Object
  extended byManager
      extended byEmulator

public class Emulator
extends Manager

Manages an emulated node


Field Summary
 
Fields inherited from class Manager
parser, reader, sortedEvents
 
Constructor Summary
Emulator(java.lang.String trawlerName, int trawlerPort, int localUDPPort)
          Create a new emulator
 
Method Summary
 long now()
          Retrieve current time in milliseconds
 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 start()
           Starts the emulated node do: Read commands from the fishnet file if there is one Process any defered events Process 1 pending incoming message.
 
Methods inherited from class Manager
addEvent, addTimer, addTimerAt, readFishFile, setFishnetFile, setParser, setTimescale, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Emulator

public Emulator(java.lang.String trawlerName,
                int trawlerPort,
                int localUDPPort)
         throws java.net.UnknownHostException,
                java.net.SocketException,
                java.io.IOException,
                java.lang.IllegalArgumentException
Create a new emulator

Parameters:
trawlerName - Name of the machine that the Trawler is on
trawlerPort - The port that the Trawler is listening on
localUDPPort - The UDP port that this node should use to talk to its neighbors
Throws:
java.net.UnknownHostException - If the trawlerName cannot be resolved
java.net.SocketException - If there is an error in creating a TCP socket
java.io.IOException - If there is an error in writing to the TCP socket
java.lang.IllegalArgumentException - If the local port given is already in use
Method Detail

start

public void start()
   
 Starts the emulated node
 do:
   Read commands from the fishnet file if there is one
   Process any defered events
   Process 1 pending incoming message. Timeout when next event is supposed to occur
 loop
 

Specified by:
start in class Manager

sendPkt

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

Overrides:
sendPkt in class Manager
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

sendNodeMsg

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

Specified by:
sendNodeMsg in class Manager
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

now

public long now()
Retrieve current time in milliseconds

Specified by:
now in class Manager
Returns:
Current time in milliseconds