edu.UCL.xmiddle.framework.controller
Class Network

java.lang.Object
  |
  +--edu.UCL.xmiddle.framework.controller.Network
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
UDPNetwork

public abstract class Network
extends java.lang.Object
implements java.lang.Runnable

Network.java Network is the basic networking module at the controller core of the xmiddle platform. It provides methods to connect and disconnect to/from the network, send and receive data, negotiate the initiation of protocol sessions and more. Network is also expected to receive protocol requests (e.g. reconciliation requests) from other hosts and service them. Created: Fri Jul 20 13:23:14 2001


Field Summary
protected  java.util.Hashtable activeSessions
          Contains the active ProtocolChooser sessions, as registered with the registerSession() call
protected  Manager caller
          Holds a reference to the Manager of the platform.
static boolean CONNECTED
          represents the "connected to the network" state
static boolean DISCONNECTED
          Represents the "network disconnected" state
protected  LocalHost localhost
          A reference to the LocalHost object.
protected  Locator locator
          A reference to the locator object, as set by setLocator()
protected  boolean status
          The status of the network.
 
Constructor Summary
Network()
           
 
Method Summary
abstract  boolean connect()
          Connects to the network (and can receive & send data)
abstract  Listener createListener(Host host, java.lang.Object sessionID)
          Creates and negotiates a Listener object to receive information from the given Host.
abstract  Sender createSender(Host host, java.lang.Object sessionID)
          Creates and negotiates a Sender object to send information from the given Host.
abstract  void disconnect()
          Explicitly disconnects from the network
abstract  void exit()
          Signifies that the platform is about to stop operating.
 boolean getStatus()
          Returns the connection status of the platform
abstract  void registerSession(ProtocolChooser session)
          Registers a new ProtocolChooser session.
abstract  void removeSession(java.lang.Object sessionID)
          Removes a formelly active session from the list of registered sessions.
abstract  void run()
          What to do when the Network Thread is started.
abstract  boolean send(Data data)
          Sends the given packet.
 void setLocator(Locator locator)
          Gives a reference to the local Locator object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

activeSessions

protected java.util.Hashtable activeSessions
Contains the active ProtocolChooser sessions, as registered with the registerSession() call


status

protected boolean status
The status of the network. Either CONNECTED or DISCONNECTED. The implementation is assumed to be responsible for maintaining this value.


caller

protected Manager caller
Holds a reference to the Manager of the platform. Can be used to update status, print debugging info, etc.


locator

protected Locator locator
A reference to the locator object, as set by setLocator()


localhost

protected LocalHost localhost
A reference to the LocalHost object. This can be used to queue protocol requests.


DISCONNECTED

public static boolean DISCONNECTED
Represents the "network disconnected" state


CONNECTED

public static boolean CONNECTED
represents the "connected to the network" state

Constructor Detail

Network

public Network()
Method Detail

connect

public abstract boolean connect()
Connects to the network (and can receive & send data)

Returns:
TRUE if connection is possible and succedded; false otherwise

disconnect

public abstract void disconnect()
Explicitly disconnects from the network


getStatus

public boolean getStatus()
Returns the connection status of the platform

Returns:
CONNECTED or DISCONNECTED

exit

public abstract void exit()
Signifies that the platform is about to stop operating.


send

public abstract boolean send(Data data)
Sends the given packet.

Parameters:
data - The Data packet to send. Note that Data also contains the target Host
Returns:
This is left up to the implementation. it could signify whether the message was sent, or whether it was received and acknowledged etc.

registerSession

public abstract void registerSession(ProtocolChooser session)
                              throws ExistingSessionIDException
Registers a new ProtocolChooser session. Each session must be identified by a unique sessionID. Sessions are registered to the networking layer as to allow:
  • a) aborting them if the network is disconnected and
  • b) genetating senders and listeners

    Parameters:
    session - The ProtocolChooser managing this session
    Throws:
    ExistingSessionIDException - if a session with the same session ID is already registered.

  • removeSession

    public abstract void removeSession(java.lang.Object sessionID)
                                throws InvalidSessionIDException
    Removes a formelly active session from the list of registered sessions. It is assumed that each ProtocolChooser session will de-register itself after finishing.

    Parameters:
    sessionID - The session's unique ID
    Throws:
    InvalidSessionIDException - if no session with the given ID is registered

    createListener

    public abstract Listener createListener(Host host,
                                            java.lang.Object sessionID)
    Creates and negotiates a Listener object to receive information from the given Host. The Object is generated for a particular protocol session.

    Parameters:
    host - The host with which the Listener needs to be negotiated
    sessionID - The session ID identifying the session for which this Listener is generated
    Returns:
    a Listener value

    createSender

    public abstract Sender createSender(Host host,
                                        java.lang.Object sessionID)
    Creates and negotiates a Sender object to send information from the given Host. The Object is generated for a particular protocol session.

    Parameters:
    host - The host with which the Sender needs to be negotiated
    sessionID - The session ID identifying the session for which this Sender is generated
    Returns:
    a Sender value

    setLocator

    public void setLocator(Locator locator)
    Gives a reference to the local Locator object. This can be used by Network to retreive information on hosts in reach.

    Parameters:
    locator - The local Locator reference

    run

    public abstract void run()
    What to do when the Network Thread is started. It is assumed that the thread will receive data from the network when we are connected.

    Specified by:
    run in interface java.lang.Runnable