Class MsgReceiver

java.lang.Object
  extended by java.rmi.server.RemoteObject
      extended by java.rmi.server.RemoteServer
          extended by java.rmi.server.UnicastRemoteObject
              extended by MsgReceiver
All Implemented Interfaces:
java.io.Serializable, java.lang.Runnable, java.rmi.Remote, Peer

public class MsgReceiver
extends java.rmi.server.UnicastRemoteObject
implements Peer, java.lang.Runnable

This is a RMI-specific class. It creates a rmi server and runs it until it is shut down from outside by the GNS server.

Since:
2.0
Version:
2.0 (RMI version, 10/2006)
Author:
Yin Xiong
See Also:
Serialized Form

Field Summary
(package private)  Flag flag
          the end of simulation flag that is shared by the rmi sender thread, the rmi receiver thread and the SchedulingLoop thread.
(package private)  java.util.concurrent.PriorityBlockingQueue<Message> msgQueue
          the queue that contains the incoming message and is shared with the SchedulingLoop
(package private)  java.lang.String myip
          the IP address of the machine on which this rmi server is running
(package private)  java.lang.String myMachineName
          the name of the machine on which this rmi server is running
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Constructor Summary
MsgReceiver(java.util.concurrent.PriorityBlockingQueue<Message> mq, Flag f)
          constructs a MsgReceiver object.
 
Method Summary
 int receiveMsg(Message message)
          Receives messages.
 void run()
          Runs this thread.
 void setEOSflag(int f)
          Sets the end of sim flag so any PE that enquires about the end of simulation will get the same value.
 void shutDown()
          Remotely shuts down the rmi servers running on the PEs.
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

msgQueue

java.util.concurrent.PriorityBlockingQueue<Message> msgQueue
the queue that contains the incoming message and is shared with the SchedulingLoop


myip

java.lang.String myip
the IP address of the machine on which this rmi server is running


myMachineName

java.lang.String myMachineName
the name of the machine on which this rmi server is running


flag

Flag flag
the end of simulation flag that is shared by the rmi sender thread, the rmi receiver thread and the SchedulingLoop thread.

Constructor Detail

MsgReceiver

public MsgReceiver(java.util.concurrent.PriorityBlockingQueue<Message> mq,
                   Flag f)
            throws java.rmi.RemoteException
constructs a MsgReceiver object.

Parameters:
mq - a PriorityBlockingQueue that contains the incoming message and is shared with the SchedulingLoop
f - a Flag object indicating the end of simulation and is shared among three threads running on this PE.
Throws:
java.rmi.RemoteException
Method Detail

run

public void run()
Runs this thread. It's mainly set up the rmi server offering remote method receiveMsg(Message msg). The server runs until somebody manually shuts it down or by invoking UnicastRemoteObject's unexportObject method

Specified by:
run in interface java.lang.Runnable

setEOSflag

public void setEOSflag(int f)
Sets the end of sim flag so any PE that enquires about the end of simulation will get the same value.

Specified by:
setEOSflag in interface Peer
Parameters:
f - int the value to be set to the flag. Negative value indicates the end of simulation.

shutDown

public void shutDown()
Remotely shuts down the rmi servers running on the PEs.

Specified by:
shutDown in interface Peer

receiveMsg

public int receiveMsg(Message message)
Receives messages. The message to be sent is send as the input parameter to a remote method.

Specified by:
receiveMsg in interface Peer
Parameters:
message - a Message object that is to be sent to a PE.