Prism.extensions.port.distribution
Class SocketDistribution

java.lang.Object
  extended by Prism.extensions.port.distribution.AbstractDistribution
      extended by Prism.extensions.port.distribution.SocketDistribution

public class SocketDistribution
extends AbstractDistribution

This provides a socket based implementation of distribution over TCP/IP protocol. In practice, a SocketDistribution is assigned to an ExtensiblePort and maintains a list of network connections. A SocketDistribution may have a SocketServer listen for incoming connections on a specified port.

Version:
2.0
Author:
USC Soft. Arch. Group. Contact: Sam Malek malek@usc.edu

Constructor Summary
SocketDistribution()
           
SocketDistribution(ExtensiblePort pPort)
          Use this constructor if you don't want this distribution object to listen for incoming connections.
SocketDistribution(ExtensiblePort pPort, int pListeningPortNum)
          Use this constructor if you want this distribution object to listen for incoming connections.
SocketDistribution(int pListeningPortNum)
           
 
Method Summary
 void addConnection(AbstractConnection pConn)
          Adds a connection to the list of connections.
 AbstractConnection connect(java.lang.String hostName, int portNum)
          Creates a connection between this ExtensiblePort to the desired ExtensiblePort.
 java.util.Vector<AbstractConnection> getConnections()
          Returns list of connections that are affiliated with the parent port
 int getListeningPortNum()
          Returns the port number used to listen for incoming connection requests.
 ExtensiblePort getParentPort()
          Returns the parent ExtensiblePort, which is the ExtensiblePort that is associated with this distribution object.
 void readEvent(java.lang.Object eventObj)
          Gets the incoming event from the connection.
 void removeConnection(AbstractConnection pConn)
          Removes a connection from the list of connections.
 void setParentPort(ExtensiblePort port)
          Set the parent ExtensiblePort, which is the ExtensiblePort that is associated with this distribution object.
 void start()
          This method is called from the ExtensiblePort to initialized the distribution.
 void writeEvent(java.lang.Object eventObj)
          Sends the outgoing event to the connection.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SocketDistribution

public SocketDistribution()

SocketDistribution

public SocketDistribution(int pListeningPortNum)

SocketDistribution

public SocketDistribution(ExtensiblePort pPort)
Use this constructor if you don't want this distribution object to listen for incoming connections.

Parameters:
pPort - Parent ExtensiblePort of this distribution object

SocketDistribution

public SocketDistribution(ExtensiblePort pPort,
                          int pListeningPortNum)
Use this constructor if you want this distribution object to listen for incoming connections.

Parameters:
pPort - Parent ExtensiblePort of this distribution object
pListeningPortNum - Port number that this distribution object will listen on for incoming connections
Method Detail

getParentPort

public ExtensiblePort getParentPort()
Returns the parent ExtensiblePort, which is the ExtensiblePort that is associated with this distribution object.

Specified by:
getParentPort in class AbstractDistribution
Returns:
Parent ExtensiblePort

getListeningPortNum

public int getListeningPortNum()
Returns the port number used to listen for incoming connection requests.

Specified by:
getListeningPortNum in class AbstractDistribution
Returns:
port number

getConnections

public java.util.Vector<AbstractConnection> getConnections()
Returns list of connections that are affiliated with the parent port

Specified by:
getConnections in class AbstractDistribution
Returns:
list of connections

start

public void start()
This method is called from the ExtensiblePort to initialized the distribution.

Specified by:
start in class AbstractDistribution

connect

public AbstractConnection connect(java.lang.String hostName,
                                  int portNum)
Creates a connection between this ExtensiblePort to the desired ExtensiblePort.

Specified by:
connect in class AbstractDistribution
Parameters:
hostName - Name of the host to which this connector is connecting. It is in the form of IP address or hostname.
portNum - Port to which this connection will be binded.

writeEvent

public void writeEvent(java.lang.Object eventObj)
Sends the outgoing event to the connection.

Specified by:
writeEvent in class AbstractDistribution
Parameters:
eventObj - Outgoing event

readEvent

public void readEvent(java.lang.Object eventObj)
Gets the incoming event from the connection.

Specified by:
readEvent in class AbstractDistribution
Parameters:
eventObj - Incoming event

addConnection

public void addConnection(AbstractConnection pConn)
Adds a connection to the list of connections.

Specified by:
addConnection in class AbstractDistribution
Parameters:
pConn - Connection to be added

removeConnection

public void removeConnection(AbstractConnection pConn)
Removes a connection from the list of connections.

Specified by:
removeConnection in class AbstractDistribution
Parameters:
pConn - Connection to be removed

setParentPort

public void setParentPort(ExtensiblePort port)
Description copied from class: AbstractDistribution
Set the parent ExtensiblePort, which is the ExtensiblePort that is associated with this distribution object.

Specified by:
setParentPort in class AbstractDistribution