org.hebe.mps
Class Connection

java.lang.Object
  |
  +--org.hebe.mps.Connection

class Connection
extends java.lang.Object

Manages client-side connections to an MPS server. Contains the looked-up/resolved address of the remote server (ie. the canonical name of the server), and a Socket for communication with the server. This class is only used internally, and should never be exposed to client objects outside this package.

Author:
Tony Garnock-Jones
See Also:
Proxy, InputStream, OutputStream

Field Summary
private  java.net.Socket connection
          Socket that connects us to the remote server
private  java.lang.String hostname
          Hostname of the remote server - taken from resolvedName
private  java.lang.String method
          Transport name - always "inet", for the Java implementation, currently
private  int oid
          OID (Object ID) of the remote server - taken from resolvedName
private  int portnumber
          Port number of the remote server - taken from resolvedName
private  java.lang.String resolvedName
          mps:inet::: - server's canonical (bound) name
 
Constructor Summary
Connection(java.lang.String name)
          Creates a fresh Connection given the resolved name of a remote object to connect to.
 
Method Summary
 void close()
          Closes the connection to the remote server.
 java.io.InputStream getInputStream()
          Allows clients access to the input (server-to-client) facilities of the socket connected to the remote server.
(package private)  int getOid()
          Returns the OID of the remote object.
 java.io.OutputStream getOutputStream()
          Allows clients access to the output (client-to-server) facilities of the socket connected to the remote server.
 java.lang.String getResolvedName()
          Allows clients to inspect the canonical name for the server we are connected to.
 void open()
          Opens the connection to the remote server.
private  void parseResolvedName()
          Splits up the resolvedName of this object into its components.
 java.lang.String toString()
          Obtains a (simple) human-readable representation of this connection object.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

resolvedName

private java.lang.String resolvedName
mps:inet::: - server's canonical (bound) name

connection

private java.net.Socket connection
Socket that connects us to the remote server

method

private java.lang.String method
Transport name - always "inet", for the Java implementation, currently

hostname

private java.lang.String hostname
Hostname of the remote server - taken from resolvedName

portnumber

private int portnumber
Port number of the remote server - taken from resolvedName

oid

private int oid
OID (Object ID) of the remote server - taken from resolvedName
Constructor Detail

Connection

public Connection(java.lang.String name)
           throws MPSException
Creates a fresh Connection given the resolved name of a remote object to connect to.
Parameters:
name - the resolved name of the MPS server to connect to
Throws:
MPSException - if the resolved name is ill-formed or unsupported
Method Detail

toString

public java.lang.String toString()
Obtains a (simple) human-readable representation of this connection object.
Overrides:
toString in class java.lang.Object
Returns:
the printable string

parseResolvedName

private void parseResolvedName()
                        throws MPSException
Splits up the resolvedName of this object into its components.
Throws:
MPSException - if the resolvedName of this object is ill-formed or unsupported

open

public void open()
          throws MPSException
Opens the connection to the remote server. Only called on demand.
Throws:
MPSException - if the resolvedName of this object is ill-formed or unsupported
MPSException - if the server is refusing connections

close

public void close()
           throws MPSException
Closes the connection to the remote server.
Throws:
MPSException - if there was a problem closing the socket.

getInputStream

public java.io.InputStream getInputStream()
                                   throws MPSException
Allows clients access to the input (server-to-client) facilities of the socket connected to the remote server.
Returns:
a Java input stream for reading bytes from the server
Throws:
MPSException - from open() if the connection was closed and wouldn't open
MPSException - if the socket failed to create an InputStream for us

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws MPSException
Allows clients access to the output (client-to-server) facilities of the socket connected to the remote server.
Returns:
a Java output stream for reading bytes from the server
Throws:
MPSException - from open() if the connection was closed and wouldn't open
MPSException - if the socket failed to create an OutputStream for us

getResolvedName

public java.lang.String getResolvedName()
Allows clients to inspect the canonical name for the server we are connected to.

getOid

int getOid()
Returns the OID of the remote object. For use by {Input,Output}Stream's constructors.