forward.server
Interface IProtocolHandler

All Known Implementing Classes:
DefaultProtocolHandler

public interface IProtocolHandler

This interface describes the methods needed from ForwardConnection. Implementations of this interface must check the incoming stream for messages, react on this messages or forward them to the server.


Method Summary
 int available()
          Returns the number of bytes which are ready to read without blocking by the next call of read().
 void close()
          Closes the connection to the server and stops handling of protocol messages.
 int read(byte[] a_buffer)
          Read a_buffer.length bytes from the server in the buffer a_buffer.
 void write(byte[] a_buffer)
          Writes the bytes in a_buffer to the server or the protocol handler.
 

Method Detail

available

int available()
              throws java.lang.Exception
Returns the number of bytes which are ready to read without blocking by the next call of read(). This call throws an exception, if there is something wrong with the connection to the server.

Returns:
The number of bytes which can be read.
Throws:
java.lang.Exception

read

int read(byte[] a_buffer)
         throws java.lang.Exception
Read a_buffer.length bytes from the server in the buffer a_buffer. This call blocks until a_buffer.length bytes could be read. This call throws an exception, if there is something wrong with the connection to the server.

Parameters:
a_buffer - A buffer for the read bytes.
Returns:
The bytes really read in the buffer or -1, if the end of the stream is reached.
Throws:
java.lang.Exception

write

void write(byte[] a_buffer)
           throws java.lang.Exception
Writes the bytes in a_buffer to the server or the protocol handler. This call blocks until the bytes could be written in the send queue. This call throws an exception, if there is something wrong with the connection to the server.

Parameters:
a_buffer - A buffer with the bytes to write.
Throws:
java.lang.Exception

close

void close()
Closes the connection to the server and stops handling of protocol messages. All later calls of available(), read(), write() will throw an exception.