gov.sandia.ccaffeine.dc.distributed
Class SocketConnectionMgr

java.lang.Object
  extended by gov.sandia.ccaffeine.dc.distributed.SocketConnectionMgr

public class SocketConnectionMgr
extends java.lang.Object

This class manages a set of connections (either one client connection to a server or many connections from clients). The connections in this manager are implemented using sockets, and can be reconnected through the manager. Reconnection of a socket connection does not always mean you get a socket connected to the same client you had before you disconnected - the client sockets may connect in a different order. Last modified by: $Author: baallan $


Constructor Summary
SocketConnectionMgr(int numClients, int port)
          Construct a socket connection manager that acts as a server for the given number of clients on the given port.
SocketConnectionMgr(int myProcNumber, int serverPort, ProcessorInfo[] machines)
          Construct a socket connection manager based on an array of ProcessorInfo objects.
SocketConnectionMgr(java.lang.String serverName, int port)
          Construct a socket connection manager that acts as a client for the given server name and port.
SocketConnectionMgr(java.lang.String processorName, java.lang.String procFile, int port)
          Construct a socket connection manager based on a processor file.
 
Method Summary
 void acceptConnections(int timeout)
           
 void connect(int timeout)
           
 void connectToServer()
           
 void disableConnection(Connection connection)
          temporarily takes the connection out of service
 java.util.Vector getConnections()
           
 int getNumConnected()
           
 boolean isConnected()
           
 boolean isServer()
           
 void reconnect(int timeout)
           
protected  void reconnectConnection(gov.sandia.ccaffeine.dc.distributed.SocketConnection connect, int timeout)
           
 void removeConnection(Connection connection)
           
 void setConnectionNotification(gov.sandia.ccaffeine.dc.distributed.ConnectionNotification notif)
           
 void shutdown()
          Disconnect all connections and close the serverSocket, if one exists.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SocketConnectionMgr

public SocketConnectionMgr(int numClients,
                           int port)
Construct a socket connection manager that acts as a server for the given number of clients on the given port.


SocketConnectionMgr

public SocketConnectionMgr(java.lang.String serverName,
                           int port)
Construct a socket connection manager that acts as a client for the given server name and port.


SocketConnectionMgr

public SocketConnectionMgr(java.lang.String processorName,
                           java.lang.String procFile,
                           int port)
                    throws java.lang.Exception
Construct a socket connection manager based on a processor file. The manager may turn out to be a server or client, depending on the processor file and processor name given. A processor file consists of several lines in the following format: <"server" or "client"> A typical file might look like: 127.0.0.1 server 0 client 1 client

Throws:
java.lang.Exception

SocketConnectionMgr

public SocketConnectionMgr(int myProcNumber,
                           int serverPort,
                           ProcessorInfo[] machines)
Construct a socket connection manager based on an array of ProcessorInfo objects. Typically the array will have been constructed using a processor file (see previous constructor).

Method Detail

shutdown

public void shutdown()
              throws java.io.IOException
Disconnect all connections and close the serverSocket, if one exists.

Throws:
java.io.IOException

acceptConnections

public void acceptConnections(int timeout)
                       throws java.lang.Exception
Throws:
java.lang.Exception

connectToServer

public void connectToServer()
                     throws java.lang.Exception
Throws:
java.lang.Exception

reconnectConnection

protected void reconnectConnection(gov.sandia.ccaffeine.dc.distributed.SocketConnection connect,
                                   int timeout)
                            throws java.lang.Exception
Throws:
java.lang.Exception

isServer

public boolean isServer()

isConnected

public boolean isConnected()

connect

public void connect(int timeout)

getConnections

public java.util.Vector getConnections()

disableConnection

public void disableConnection(Connection connection)
temporarily takes the connection out of service


removeConnection

public void removeConnection(Connection connection)

reconnect

public void reconnect(int timeout)
               throws java.lang.Exception
Throws:
java.lang.Exception

getNumConnected

public int getNumConnected()

setConnectionNotification

public void setConnectionNotification(gov.sandia.ccaffeine.dc.distributed.ConnectionNotification notif)