com.sun.jaw.impl.adaptor.comm
Class AdaptorSocket

java.lang.Object
  |
  +--com.sun.jaw.impl.adaptor.comm.AdaptorSocket
Direct Known Subclasses:
AdaptorSocket, AdaptorSocket, AdaptorSocket

public abstract class AdaptorSocket
extends java.lang.Object
implements java.lang.Cloneable

The AdaptorSocket class provides a wrap-up of the socket to be used for HTTP-based adaptors.


Field Summary
protected  int port
          The local port number.
 
Constructor Summary
AdaptorSocket()
           
 
Method Summary
 java.lang.Object clone()
          Creates a new object of the same class as this object.
abstract  AdaptorSocket createClientSocket()
          Creates a socket to be used on the client side.
abstract  AdaptorSocket createServerSocket(int port)
          Creates a socket to be used on the server side with the given port.
abstract  void doBind()
          Binds to receive requests (usually used on server side).
abstract  void doConnect(java.lang.String serverName, int serverPort)
          Connects to send a request (usually used on client side).
abstract  void doDisconnect()
          Can be used on both server and client sides.
abstract  java.io.InputStream doGetInputStream()
          Returns an input stream for this socket.
abstract  java.io.InputStream doReceive()
          Waits for an incoming message.
abstract  void doSend(java.lang.String header, byte[] content)
          Sends the given header and content to the peer.
abstract  void doUnbind()
          Unbinds (usually used on server side).
abstract  java.net.InetAddress getLocalAddress()
          Gets the local IP address.
abstract  int getLocalPort()
          Gets the local port number.
abstract  java.lang.String getProtocol()
          Gets the name of the protocol used.
abstract  java.net.InetAddress getRemoteAddress()
          Gets the remote IP address.
abstract  int getRemotePort()
          Gets the remote port number.
 int getTimeout()
          Gets setting for Timeout.
 void setTimeout(int value)
          Enables/disables Timeout with the specified timeout, in milliseconds.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

port

protected int port
The local port number.
Constructor Detail

AdaptorSocket

public AdaptorSocket()
Method Detail

clone

public java.lang.Object clone()
Creates a new object of the same class as this object. It then initializes each of the new object's fields by assigning it the same value as the corresponding field in this object. No constructor is called.
Returns:
The new object.
Overrides:
clone in class java.lang.Object

createServerSocket

public abstract AdaptorSocket createServerSocket(int port)
Creates a socket to be used on the server side with the given port.
Parameters:
port - The port number.
Returns:
The adaptor socket.

createClientSocket

public abstract AdaptorSocket createClientSocket()
Creates a socket to be used on the client side. No port is provided as the client does not "bind".
Returns:
The adaptor socket.

getProtocol

public abstract java.lang.String getProtocol()
Gets the name of the protocol used.
Returns:
The name of the protocol.

doBind

public abstract void doBind()
                     throws java.io.IOException
Binds to receive requests (usually used on server side).
Throws:
java.io.IOException - Signals that an I/O exception of some sort has occurred.

doUnbind

public abstract void doUnbind()
                       throws java.io.IOException
Unbinds (usually used on server side).
Throws:
java.io.IOException - Signals that an I/O exception of some sort has occurred.

doConnect

public abstract void doConnect(java.lang.String serverName,
                               int serverPort)
                        throws java.net.UnknownHostException,
                               java.io.IOException,
                               CommunicationException
Connects to send a request (usually used on client side).
Parameters:
serverName - The name of the server to connect the socket to.
serverPort - The port number of the specified server.
Throws:
java.net.UnknownHostException - The IP address of the specified host could not be determined.
java.io.IOException - Signals that an I/O exception of some sort has occurred.
CommunicationException - A communications problem occurred.

doDisconnect

public abstract void doDisconnect()
                           throws java.io.IOException,
                                  CommunicationException
Can be used on both server and client sides.

On the client side, disconnects the socket used when connecting.

On the server side, disconnects the socket involved in the communication with the client; it's not usually the socket used for binding.

Throws:
java.io.IOException - Signals that an I/O exception of some sort has occurred.
CommunicationException - A communications problem occurred.

doSend

public abstract void doSend(java.lang.String header,
                            byte[] content)
                     throws java.io.IOException
Sends the given header and content to the peer. On the client side, it's usually the initiated request, and on the server side, it's the reply to the client's request.
Parameters:
header - The header to be sent.
content - The content to be sent.
Throws:
java.io.IOException - Signals that an I/O exception of some sort has occurred.

doGetInputStream

public abstract java.io.InputStream doGetInputStream()
                                              throws java.io.IOException
Returns an input stream for this socket.
Returns:
The input stream for this adaptor socket.
Throws:
java.io.IOException - Signals that an I/O exception of some sort has occurred.

doReceive

public abstract java.io.InputStream doReceive()
                                       throws java.io.IOException
Waits for an incoming message.

On the server side, waits for a request from the client, and on the client side, waits for the reply to the client's request.

Returns:
The input stream for this adaptor socket.
Throws:
java.io.IOException - Signals that an I/O exception of some sort has occurred.

getLocalAddress

public abstract java.net.InetAddress getLocalAddress()
Gets the local IP address.
Returns:
The local IP address.

getLocalPort

public abstract int getLocalPort()
Gets the local port number.
Returns:
The local port number.

getRemoteAddress

public abstract java.net.InetAddress getRemoteAddress()
Gets the remote IP address.
Returns:
The remote IP address.

getRemotePort

public abstract int getRemotePort()
Gets the remote port number.
Returns:
The remote port number.

getTimeout

public int getTimeout()
Gets setting for Timeout. 0 returns implies that the option is disabled (i.e. timeout of infinity).
Returns:
The current value of the Timeout property.

setTimeout

public void setTimeout(int value)
Enables/disables Timeout with the specified timeout, in milliseconds. With this option set to a non-zero timeout, a read() call on the InputStream associated with this Socket will block for only this amount of time. If the timeout expires, a java.io.InterruptedIOException is raised, though the Socket is still valid. The option must be enabled prior to entering the blocking operation to have effect. The timeout must be > 0. A timeout of zero is interpreted as an infinite timeout.
Parameters:
value - The new value of the property.