Class cam.netapp.NetworkConnection

java.lang.Object
   |
   +----cam.netapp.NetworkConnection

public class NetworkConnection
extends Object
An instance of this class is typically associated with the "front end" of a distributed application. The NetworkConnection class performs two important functions

The "back-end" does not require an instance of this class (it is only required to implement the Runnable interface and the SetStreams interface).

The remote class usually resides on another machine, but for development purposes, one can use a NetworkConnection to connect to a class on a local machine.

In order to establish a remote class instance on another machine, an instance of the ServerManager class must be executing on that machine.

Version:
9/18/98
Author:
Chris Anderson and Dan Delsol (C) UCLA 1997-98

Constructor Index

 o NetworkConnection()
Standard constructor.
 o NetworkConnection(Socket[])
Creates a network connection using the sockets passed in sArray for communication.

Method Index

 o connectRemoteApplication(String)
Creates a connection to a local class appName.
 o connectRemoteApplication(String, int, String)
Creates a connection to the application appName at (address,port).
 o connectRemoteApplication(String, int, String, int)
Creates a connection to the application appName at (address,port) with auxConnections auxillary socket connections.
 o createControlStreams()
Create streams to communicate with the control thread using sockets[1]
 o disconnectRemoteApplication()
Stops the remote class thread and closes connections to the remote class.
 o finalize()
Stops the remote class thread.
 o getAuxSocket(int)
Returns the the kth auxillary socket associated with the current connection.
 o getControlInputStream()
Returns the InputStream associated with the control Socket connection.
 o getControlOutputStream()
Returns the OutputStream associated with the control socket connection.
 o getControlSocket()
Returns the control socket connected to the remote class's control.
 o getInputStream()
Returns the InputStream associated with the socket connection to the remote instance.
 o getOutputStream()
Returns the OutputStream associated with the socket connection to the remote instance.
 o getRemoteApplicationStatus()
Returns the status of the remote class.
 o getSocket()
Returns the primary socket connected to the remote class.
 o pauseRemoteApplication()
Pauses the remote class thread.
 o resumeRemoteApplication()
Resumes the remote class thread.
 o setVerboseFlag(boolean)
If set true diagnostic messages are printed to System.out.
 o startRemoteApplication()
Creates a thread for the remote class and invokes the run() method of the remote class.
 o stopRemoteApplication()
Stops the remote class thread.

Constructors

 o NetworkConnection
 public NetworkConnection()
Standard constructor.

 o NetworkConnection
 public NetworkConnection(Socket sArray[])
Creates a network connection using the sockets passed in sArray for communication. The control streams are NOT created with this construction. Control commands (startRemoteApplication(), stopRemoteApplication()... have no effect. If the control streams are desired, then the createControlStreams() method should be called after the constructor. Use of the control streams presumes that there is a remote ControlThread instance connected to sockets[1].

Methods

 o connectRemoteApplication
 public void connectRemoteApplication(String address,
                                      int portnum,
                                      String appName) throws NetAppException
Creates a connection to the application appName at (address,port).

Parameters:
address - Address of remote machine upon which a ServerManager is executing
portnum - Port where the remote machine that the ServerManager is listening. (Default = 6789).
appName - Name of the class on the remote machine
Throws: NetAppException
if the connection can not be completed.
 o connectRemoteApplication
 public void connectRemoteApplication(String nameApp) throws NetAppException
Creates a connection to a local class appName. An appName instance is loaded and a cross-stream connection is made to it. A separate thread is then created for the instance and it's run() method is invoked.

Parameters:
appName - Name of the class on the remote machine
Throws: NetAppException
if the connection can not be completed.
 o connectRemoteApplication
 public void connectRemoteApplication(String address,
                                      int portnum,
                                      String appName,
                                      int auxConnections) throws NetAppException
Creates a connection to the application appName at (address,port) with auxConnections auxillary socket connections. Typically auxConnections = 1 for use in creating NetworkConnection callbacks from the application to the client.

Parameters:
address - Address of remote machine upon which a ServerManager is executing
portnum - Port where the remote machine that the ServerManager is listening. (Default = 6789).
appName - Name of the class on the remote machine
auxConnections - The number of auxillary connections to the remote class (typically 0, unless one is implementing callbacks).
Throws: NetAppException
if the connection can not be completed.
 o disconnectRemoteApplication
 public void disconnectRemoteApplication()
Stops the remote class thread and closes connections to the remote class.

 o startRemoteApplication
 public void startRemoteApplication()
Creates a thread for the remote class and invokes the run() method of the remote class.

 o stopRemoteApplication
 public void stopRemoteApplication()
Stops the remote class thread.

 o pauseRemoteApplication
 public void pauseRemoteApplication()
Pauses the remote class thread.

 o resumeRemoteApplication
 public void resumeRemoteApplication()
Resumes the remote class thread.

 o getRemoteApplicationStatus
 public String getRemoteApplicationStatus()
Returns the status of the remote class.

 o getSocket
 public Socket getSocket()
Returns the primary socket connected to the remote class.

 o getControlSocket
 public Socket getControlSocket()
Returns the control socket connected to the remote class's control.

 o getAuxSocket
 public Socket getAuxSocket(int k)
Returns the the kth auxillary socket associated with the current connection.

Parameters:
k - The index of the socket.
 o getOutputStream
 public OutputStream getOutputStream()
Returns the OutputStream associated with the socket connection to the remote instance. One writes to this stream to send data to the remote class.

 o getControlOutputStream
 public OutputStream getControlOutputStream()
Returns the OutputStream associated with the control socket connection. One writes to this stream to send data to the remote class's control.

 o getInputStream
 public InputStream getInputStream()
Returns the InputStream associated with the socket connection to the remote instance. One reads from this stream to obtain data from the remote class.

 o getControlInputStream
 public InputStream getControlInputStream()
Returns the InputStream associated with the control Socket connection. One reads from this stream to obtain data from the remote class's control.

 o setVerboseFlag
 public void setVerboseFlag(boolean v)
If set true diagnostic messages are printed to System.out.

 o createControlStreams
 public void createControlStreams()
Create streams to communicate with the control thread using sockets[1]

 o finalize
 protected void finalize()
Stops the remote class thread.

Overrides:
finalize in class Object