org.openorb.orb.iiop
Class IIOPTransport

java.lang.Object
  |
  +--org.openorb.orb.iiop.IIOPTransport
All Implemented Interfaces:
Transport

public class IIOPTransport
extends java.lang.Object
implements Transport

Interface for creating sockets.

Version:
$Revision: 1.18 $ $Date: 2004/11/17 15:26:08 $
Author:
Unknown

Constructor Summary
IIOPTransport(java.net.InetAddress host, int port, org.apache.avalon.framework.logger.Logger logger)
           
IIOPTransport(java.net.InetAddress host, int port, org.apache.avalon.framework.logger.Logger logger, SocketFactory socketFactory)
          Constructor.
IIOPTransport(java.net.Socket sock, int serverPort, org.apache.avalon.framework.logger.Logger logger)
          Constructor.
 
Method Summary
protected  int checkGIOPHeader(byte[] buf, int off)
          Check the IIOP header and return the length.
 void close()
          Close the connection this always succeeds.
protected  java.net.Socket createSocket(java.net.InetAddress host, int port)
          Open the socket to the specified host and port.
 boolean establishAssociation(Address addr)
          Check for applicability of channel for carrying messages for the specified address and setup any client transport binding.
protected  java.lang.String getConnString()
          This returns a string describing the connection endpoints.
protected  java.net.Socket getSocket()
          Return the socket.
 boolean isMessageError()
          Returns true if setMessageError has been called.
 boolean isOpen()
          Is is the transport open?
 void open()
          Open the connection.
protected  void read(byte[] buf, int off, int len)
          Read bytes into the array.
protected  StorageBuffer readBuffer(byte[] head, int off, int len, int total_len)
          Create a storage buffer from the passed buffer, reading extra bytes from the stream.
protected  boolean readMagic(int timeout, byte[] buf, int off)
          Reads four bytes from the input stream into the buffer at the specified offset.
 StorageBuffer recvMessage(int timeout)
          Read next message.
 void sendMessage(StorageBuffer msg)
          Write message to comms protocol.
 void setMessageError()
          If this gets called then the close operation will close by sending a MessageError message.
 java.lang.String toString()
          Print out socket information.
protected  void write(byte[] buf, int off, int len)
          Write bytes directly to socket.
protected  void writeCloseMessage()
          Send the close message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IIOPTransport

public IIOPTransport(java.net.InetAddress host,
                     int port,
                     org.apache.avalon.framework.logger.Logger logger)

IIOPTransport

public IIOPTransport(java.net.InetAddress host,
                     int port,
                     org.apache.avalon.framework.logger.Logger logger,
                     SocketFactory socketFactory)
Constructor.
Parameters:
host - Host of the endpoint.
port - Port of the endoint.

IIOPTransport

public IIOPTransport(java.net.Socket sock,
                     int serverPort,
                     org.apache.avalon.framework.logger.Logger logger)
Constructor.
Parameters:
sock - Client socket.
serverPort - Port of the endoint.
logger - The logger to use in this instance.
Method Detail

open

public void open()
Open the connection. This can throw a CORBA system exception. This is never called by server channels.
Specified by:
open in interface Transport
Following copied from interface: org.openorb.orb.net.Transport
Throws:
org.omg.CORBA.COMM_FAILURE - failed to open channel. This exception will be reported to clients.

createSocket

protected java.net.Socket createSocket(java.net.InetAddress host,
                                       int port)
                                throws java.io.IOException
Open the socket to the specified host and port.

getSocket

protected java.net.Socket getSocket()
Return the socket.
Returns:
The socket instance associated with this transport.

close

public void close()
Close the connection this always succeeds.
Specified by:
close in interface Transport

writeCloseMessage

protected void writeCloseMessage()
Send the close message.

isOpen

public boolean isOpen()
Is is the transport open?
Specified by:
isOpen in interface Transport

sendMessage

public void sendMessage(StorageBuffer msg)
Write message to comms protocol.
Specified by:
sendMessage in interface Transport
Parameters:
msg - The message to be sent.
Throws:
org.omg.CORBA.COMM_FAILURE - permanent transport failure occoured. Cleanup and then call close.

write

protected void write(byte[] buf,
                     int off,
                     int len)
Write bytes directly to socket. Not this function *is not* called for every write and is provided to allow arbitary data to be written to the socket.
Parameters:
buf - message buffer.
off - offset of beginning of message in buffer.
len - length of message in buffer.
Throws:
org.omg.CORBA.COMM_FAILURE - permanent transport failure occoured.

recvMessage

public StorageBuffer recvMessage(int timeout)
                          throws java.io.EOFException
Read next message. This function will be regularly serviced by a worker thread.
Specified by:
recvMessage in interface Transport
Parameters:
timeout - max time to wait before recieving a message.
Throws:
java.io.EOFException - end of file has been reached. Cleanup and call close.
org.omg.CORBA.COMM_FAILURE - permanent transport failure occoured. Cleanup and then call close.

setMessageError

public void setMessageError()
If this gets called then the close operation will close by sending a MessageError message.

isMessageError

public boolean isMessageError()
Returns true if setMessageError has been called.

readMagic

protected boolean readMagic(int timeout,
                            byte[] buf,
                            int off)
                     throws java.io.EOFException
Reads four bytes from the input stream into the buffer at the specified offset. Returns true if the read was successful before the timeout occoured.

checkGIOPHeader

protected int checkGIOPHeader(byte[] buf,
                              int off)
                       throws java.io.EOFException
Check the IIOP header and return the length.
Throws:
java.io.EOFException - If header is a CloseConnection message
org.omg.CORBA.COMM_FAILURE - If header is a MsgError message.

read

protected final void read(byte[] buf,
                          int off,
                          int len)
Read bytes into the array. Can be used but not overriden by subclasses.

readBuffer

protected StorageBuffer readBuffer(byte[] head,
                                   int off,
                                   int len,
                                   int total_len)
Create a storage buffer from the passed buffer, reading extra bytes from the stream.

establishAssociation

public boolean establishAssociation(Address addr)
Check for applicability of channel for carrying messages for the specified address and setup any client transport binding.
Specified by:
establishAssociation in interface Transport
Parameters:
addr - the address.
Returns:
true if this transport can carry messages for the target. Basic checks like checking the host and port will already be done, just check specifics. If false a new channel will be opened for requests.

toString

public java.lang.String toString()
Print out socket information.
Overrides:
toString in class java.lang.Object

getConnString

protected java.lang.String getConnString()
This returns a string describing the connection endpoints.