org.xsocket.stream
Class NonBlockingConnection

Package class diagram package NonBlockingConnection
java.lang.Object
  extended by org.xsocket.stream.NonBlockingConnection
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, java.nio.channels.Channel, java.nio.channels.GatheringByteChannel, java.nio.channels.ReadableByteChannel, java.nio.channels.WritableByteChannel, IDataSink, IDataSource, IConnection, INonBlockingConnection

public final class NonBlockingConnection
extends java.lang.Object
implements INonBlockingConnection

Implementation of the INonBlockingConnection interface.

A newly created connection is in the open state. Write or rad methods can be called immediately The methods of this class are not thread-safe.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.xsocket.stream.INonBlockingConnection
INonBlockingConnection.TransferResult
 
Nested classes/interfaces inherited from interface org.xsocket.stream.IConnection
IConnection.FlushMode
 
Field Summary
 
Fields inherited from interface org.xsocket.stream.INonBlockingConnection
INITIAL_FLUSH_MODE, UNLIMITED
 
Fields inherited from interface org.xsocket.stream.IConnection
INITIAL_AUTOFLUSH, INITIAL_DEFAULT_ENCODING, SO_KEEPALIVE, SO_LINGER, SO_RCVBUF, SO_REUSEADDR, SO_SNDBUF, TCP_NODELAY
 
Constructor Summary
NonBlockingConnection(java.net.InetAddress address, int port)
          constructor.
NonBlockingConnection(java.net.InetAddress address, int port, IHandler appHandler)
          constructor.
NonBlockingConnection(java.net.InetAddress address, int port, IHandler appHandler, java.util.concurrent.Executor workerPool)
          constructor.
NonBlockingConnection(java.net.InetAddress address, int port, IHandler appHandler, java.util.concurrent.Executor workerPool, int preallocationMemorySize)
          Deprecated.  
NonBlockingConnection(java.net.InetAddress address, int port, java.util.Map<java.lang.String,java.lang.Object> options)
          constructor.
NonBlockingConnection(java.net.InetAddress address, int port, java.util.Map<java.lang.String,java.lang.Object> options, IHandler appHandler)
          constructor.
NonBlockingConnection(java.net.InetAddress address, int port, java.util.Map<java.lang.String,java.lang.Object> options, javax.net.ssl.SSLContext sslContext, boolean sslOn)
          constructor.
NonBlockingConnection(java.net.InetAddress address, int port, javax.net.ssl.SSLContext sslContext, boolean sslOn)
          constructor.
NonBlockingConnection(java.net.InetAddress address, int port, StreamSocketConfiguration socketConfiguration)
          Deprecated.  
NonBlockingConnection(java.net.InetAddress address, int port, StreamSocketConfiguration socketConfiguration, IHandler appHandler)
          Deprecated.  
NonBlockingConnection(java.net.InetAddress address, int port, StreamSocketConfiguration socketConfiguration, IHandler appHandler, int preallocationMemorySize)
          Deprecated.  
NonBlockingConnection(java.net.InetAddress address, int port, StreamSocketConfiguration socketConfiguration, javax.net.ssl.SSLContext sslContext, boolean sslOn)
          Deprecated.  
NonBlockingConnection(java.lang.String hostname, int port)
          constructor.
NonBlockingConnection(java.lang.String hostname, int port, IHandler appHandler)
          constructor

constructor.
NonBlockingConnection(java.lang.String hostname, int port, java.util.Map<java.lang.String,java.lang.Object> options, IHandler appHandler)
          constructor

constructor.
NonBlockingConnection(java.lang.String hostname, int port, java.util.Map<java.lang.String,java.lang.Object> options, javax.net.ssl.SSLContext sslContext, boolean sslOn)
          constructor.
NonBlockingConnection(java.lang.String hostname, int port, javax.net.ssl.SSLContext sslContext, boolean sslOn)
          constructor.
NonBlockingConnection(java.lang.String hostname, int port, StreamSocketConfiguration socketConfiguration)
          Deprecated.  
NonBlockingConnection(java.lang.String hostname, int port, StreamSocketConfiguration socketConfiguration, IHandler appHandler)
           
NonBlockingConnection(java.lang.String hostname, int port, StreamSocketConfiguration socketConfiguration, IHandler appHandler, int preallocationMemorySize)
           
NonBlockingConnection(java.lang.String hostname, int port, StreamSocketConfiguration socketConfiguration, javax.net.ssl.SSLContext sslContext, boolean sslOn)
          Deprecated.  
 
Method Summary
 void activateSecuredMode()
          ad hoc activation of a secured mode (SSL).
 java.lang.Object attach(java.lang.Object obj)
          
 java.lang.Object attachment()
          
 void close()
          
 void flush()
          flush the send buffer.
 java.lang.Object getAttachment()
          Retrieves the current attachment.
 boolean getAutoflush()
          get autoflush
 int getConnectionTimeoutSec()
          gets the connection timeout
 java.lang.String getDefaultEncoding()
          gets the default encoding for this connection (used by string related methods like readString...)
 IConnection.FlushMode getFlushmode()
          get the flushmode
 java.lang.String getId()
          returns the id
 int getIdleTimeoutSec()
          returns the idle timeout in sec.
 int getIndexOf(java.lang.String str)
          Returns the index of the first occurrence of the given string.
 int getIndexOf(java.lang.String str, int maxLength)
          Returns the index of the first occurrence of the given string.
 int getIndexOf(java.lang.String str, java.lang.String encoding, int maxLength)
          Returns the index of the first occurrence of the given string.
 java.net.InetAddress getLocalAddress()
          returns the local address
 int getLocalPort()
          returns the local port
 int getNumberOfAvailableBytes()
          get the number of available bytes to read
 java.lang.Object getOption(java.lang.String name)
          returns the value of a option
 java.util.Map<java.lang.String,java.lang.Class> getOptions()
          Returns an unmodifiable map of the options supported by this endpoint.
 int getPendingWriteDataSize()
          returns the size of the data which have already been written, but not yet transferred to the underlying socket.
 java.net.InetAddress getRemoteAddress()
          returns the remote address
 int getRemotePort()
          returns the port of the remote endpoint
 int indexOf(java.lang.String str)
          Deprecated. uses getIndexOf instead
 boolean isOpen()
          returns, if the connection is open.
 void markReadPosition()
          Marks the present read position in the connection.
 void markWritePosition()
          Marks the present write position in the connection.
 void onWriteException(java.io.IOException ioException)
           
 void onWritten()
           
 int read(java.nio.ByteBuffer buffer)
          
 java.nio.ByteBuffer[] readAvailable()
          read all received bytes
 boolean readAvailableByDelimiter(java.lang.String delimiter, java.lang.String encoding, java.nio.channels.WritableByteChannel outputChannel)
          
 boolean readAvailableByDelimiter(java.lang.String delimiter, java.nio.channels.WritableByteChannel outputChannel)
          
 byte readByte()
          read a byte
 java.nio.ByteBuffer[] readByteBufferByDelimiter(java.lang.String delimiter)
          read a ByteBuffer by using a delimiter To avoid memory leaks the INonBlockingConnection.readByteBufferByDelimiter(String, int) method is generally preferable
For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes
 java.nio.ByteBuffer[] readByteBufferByDelimiter(java.lang.String delimiter, int maxLength)
          read a ByteBuffer by using a delimiter For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes
 java.nio.ByteBuffer[] readByteBufferByDelimiter(java.lang.String delimiter, java.lang.String encoding, int maxLength)
          read a ByteBuffer by using a delimiter For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes
 java.nio.ByteBuffer[] readByteBufferByLength(int length)
          read a ByteBuffer by using a length defintion For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes
 byte[] readBytesByDelimiter(java.lang.String delimiter)
          read a byte array by using a delimiter To avoid memory leaks the INonBlockingConnection.readBytesByDelimiter(String, int) method is generally preferable
For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes
 byte[] readBytesByDelimiter(java.lang.String delimiter, int maxLength)
          read a byte array by using a delimiter For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes
 byte[] readBytesByDelimiter(java.lang.String delimiter, java.lang.String encoding, int maxLength)
          read a byte array by using a delimiter For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes
 byte[] readBytesByLength(int length)
          read bytes by using a length defintion For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes
 double readDouble()
          read a double
 int readInt()
          read an int
 long readLong()
          read a long
 short readShort()
          read a short value
 java.lang.String readStringByDelimiter(java.lang.String delimiter)
          read a string by using a delimiter and the connection default encoding To avoid memory leaks the INonBlockingConnection.readStringByDelimiter(String, int) method is generally preferable
 java.lang.String readStringByDelimiter(java.lang.String delimiter, int maxLength)
          read a string by using a delimiter and the connection default encoding
 java.lang.String readStringByDelimiter(java.lang.String delimiter, java.lang.String encoding)
          read a string by using a delimiter To avoid memory leaks the INonBlockingConnection.readStringByDelimiter(String, String, int) method is generally preferable
 java.lang.String readStringByDelimiter(java.lang.String delimiter, java.lang.String encoding, int maxLength)
          read a string by using a delimiter
 java.lang.String readStringByLength(int length)
          read a string by using a length definition and the connection default encoding
 java.lang.String readStringByLength(int length, java.lang.String encoding)
          read a string by using a length definition
 void removeReadMark()
          remove the mark the present read position in the connection.
 void removeWriteMark()
          remove the mark the present write position in the connection.
 boolean resetToReadMark()
          Resets to the marked read position.
 boolean resetToWriteMark()
          Resets to the marked write position.
 void resumeRead()
          resume reading data from the underlying subsystem
 void setAttachment(java.lang.Object obj)
          Attaches the given object to this connection
 void setAutoflush(boolean autoflush)
          set autoflush.
 void setConnectionTimeoutSec(int timeoutSec)
          sets the max time for a connections.
 void setDefaultEncoding(java.lang.String defaultEncoding)
          sets the default encoding for this connection (used by string related methods like readString...)
 void setFlushmode(IConnection.FlushMode flushMode)
          set the flushmode
 void setIdleTimeoutSec(int timeoutInSec)
          sets the idle timeout in sec
 INonBlockingConnection setOption(java.lang.String name, java.lang.Object value)
          sets the value of a option
 void setWriteTransferRate(int bytesPerSecond)
          set the send delay time.
 void suspendRead()
          suspend reading data from the underlying subsystem
 java.lang.String toString()
          
 INonBlockingConnection.TransferResult transferToAvailableByDelimiter(java.lang.String delimiter, java.lang.String encoding, java.nio.channels.WritableByteChannel outputChannel)
          transfers bytes from this connection to the given writable byte channel.
 INonBlockingConnection.TransferResult transferToAvailableByDelimiter(java.lang.String delimiter, java.nio.channels.WritableByteChannel outputChannel)
          transfers bytes from this connection to the given writable byte channel.
 int write(byte... bytes)
          sends bytes to the remote endpoint
 int write(byte b)
          sends a byte to the remote endpoint
 int write(byte[] bytes, int offset, int length)
          sends bytes to the remote endpoint
 int write(java.nio.ByteBuffer buffer)
          sends a byte buffer to the remote endpoint.
 long write(java.nio.ByteBuffer[] buffers)
          sends an array of byte buffer to the remote endpoint.
 long write(java.nio.ByteBuffer[] srcs, int offset, int length)
          
 int write(double d)
          sends a double to the remote endpoint
 int write(int i)
          sends an int to the remote endpoint
 int write(long l)
          sends a long to the remote endpoint
 int write(short s)
          writes a short to the data sink
 int write(java.lang.String s)
          sends a message to the remote endpoint by using the connection default encoding
 int write(java.lang.String s, java.lang.String encoding)
          sends a message to the remote endpoint
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.xsocket.stream.INonBlockingConnection
flush, getFlushmode, indexOf, setFlushmode, write, write
 
Methods inherited from interface org.xsocket.stream.IConnection
activateSecuredMode, attach, attachment, getAttachment, getAutoflush, getConnectionTimeoutSec, getDefaultEncoding, getId, getIdleTimeoutSec, getLocalAddress, getLocalPort, getOption, getOptions, getPendingWriteDataSize, getRemoteAddress, getRemotePort, isOpen, markReadPosition, markWritePosition, removeReadMark, removeWriteMark, resetToReadMark, resetToWriteMark, resumeRead, setAttachment, setAutoflush, setConnectionTimeoutSec, setDefaultEncoding, setIdleTimeoutSec, suspendRead, write, write, write, write, write, write, write, write
 
Methods inherited from interface org.xsocket.IDataSink
write
 
Methods inherited from interface java.nio.channels.GatheringByteChannel
write
 
Methods inherited from interface java.nio.channels.Channel
close
 

Constructor Detail

NonBlockingConnection

public NonBlockingConnection(java.lang.String hostname,
                             int port)
                      throws java.io.IOException
constructor. This constructor will be used to create a non blocking client-side connection.

For multithreading issues see NonBlockingConnection(InetAddress, int, IHandler, Executor).

Parameters:
hostname - the remote host
port - the port of the remote host to connect
Throws:
java.io.IOException - If some other I/O error occurs

NonBlockingConnection

public NonBlockingConnection(java.lang.String hostname,
                             int port,
                             StreamSocketConfiguration socketConfiguration)
                      throws java.io.IOException
Deprecated. 

Throws:
java.io.IOException

NonBlockingConnection

public NonBlockingConnection(java.net.InetAddress address,
                             int port)
                      throws java.io.IOException
constructor. This constructor will be used to create a non blocking client-side connection.

For multithreading issues see NonBlockingConnection(InetAddress, int, IHandler, Executor).

Parameters:
address - the remote host
port - the port of the remote host to connect
Throws:
java.io.IOException - If some other I/O error occurs

NonBlockingConnection

public NonBlockingConnection(java.net.InetAddress address,
                             int port,
                             StreamSocketConfiguration socketConfiguration)
                      throws java.io.IOException
Deprecated. 

Throws:
java.io.IOException

NonBlockingConnection

public NonBlockingConnection(java.net.InetAddress address,
                             int port,
                             java.util.Map<java.lang.String,java.lang.Object> options)
                      throws java.io.IOException
constructor. This constructor will be used to create a non blocking client-side connection.

For multithreading issues see NonBlockingConnection(InetAddress, int, IHandler, Executor).

Parameters:
address - the remote host
port - the port of the remote host to connect
options - the socket options
Throws:
java.io.IOException - If some other I/O error occurs

NonBlockingConnection

public NonBlockingConnection(java.net.InetAddress address,
                             int port,
                             IHandler appHandler)
                      throws java.io.IOException
constructor. This constructor will be used to create a non blocking client-side connection.

For multithreading issues see NonBlockingConnection(InetAddress, int, IHandler, Executor).

Parameters:
address - the remote address
port - the remote port
appHandler - the application handler (supported: IConnectHandler, IDisconnectHandler, IDataHandler and ITimeoutHandler)
Throws:
java.io.IOException - If some other I/O error occurs

NonBlockingConnection

public NonBlockingConnection(java.net.InetAddress address,
                             int port,
                             StreamSocketConfiguration socketConfiguration,
                             IHandler appHandler)
                      throws java.io.IOException
Deprecated. 

Throws:
java.io.IOException

NonBlockingConnection

public NonBlockingConnection(java.net.InetAddress address,
                             int port,
                             StreamSocketConfiguration socketConfiguration,
                             IHandler appHandler,
                             int preallocationMemorySize)
                      throws java.io.IOException
Deprecated. 

Throws:
java.io.IOException

NonBlockingConnection

public NonBlockingConnection(java.net.InetAddress address,
                             int port,
                             java.util.Map<java.lang.String,java.lang.Object> options,
                             IHandler appHandler)
                      throws java.io.IOException
constructor. This constructor will be used to create a non blocking client-side connection.

For multithreading issues see NonBlockingConnection(InetAddress, int, IHandler, Executor).

Parameters:
address - the remote address
port - the remote port
options - the socket options
appHandler - the application handler (supported: IConnectHandler, IDisconnectHandler, IDataHandler and ITimeoutHandler)
Throws:
java.io.IOException - If some other I/O error occurs

NonBlockingConnection

public NonBlockingConnection(java.lang.String hostname,
                             int port,
                             IHandler appHandler)
                      throws java.io.IOException
constructor

constructor. This constructor will be used to create a non blocking client-side connection.

For multithreading issues see NonBlockingConnection(InetAddress, int, IHandler, Executor).

Parameters:
hostname - the remote host
port - the remote port
appHandler - the application handler (supported: IConnectHandler, IDisconnectHandler, IDataHandler and ITimeoutHandler)
Throws:
java.io.IOException - If some other I/O error occurs

NonBlockingConnection

public NonBlockingConnection(java.lang.String hostname,
                             int port,
                             StreamSocketConfiguration socketConfiguration,
                             IHandler appHandler)
                      throws java.io.IOException
Throws:
java.io.IOException

NonBlockingConnection

public NonBlockingConnection(java.lang.String hostname,
                             int port,
                             StreamSocketConfiguration socketConfiguration,
                             IHandler appHandler,
                             int preallocationMemorySize)
                      throws java.io.IOException
Throws:
java.io.IOException

NonBlockingConnection

public NonBlockingConnection(java.lang.String hostname,
                             int port,
                             java.util.Map<java.lang.String,java.lang.Object> options,
                             IHandler appHandler)
                      throws java.io.IOException
constructor

constructor. This constructor will be used to create a non blocking client-side connection.

For multithreading issues see NonBlockingConnection(InetAddress, int, IHandler, Executor).

Parameters:
hostname - the remote host
port - the remote port
options - the socket options
appHandler - the application handler (supported: IConnectHandler, IDisconnectHandler, IDataHandler and ITimeoutHandler)
Throws:
java.io.IOException - If some other I/O error occurs

NonBlockingConnection

public NonBlockingConnection(java.net.InetAddress address,
                             int port,
                             javax.net.ssl.SSLContext sslContext,
                             boolean sslOn)
                      throws java.io.IOException
constructor. This constructor will be used to create a non blocking client-side connection.

For multithreading issues see NonBlockingConnection(InetAddress, int, IHandler, Executor).

Parameters:
address - the remote address
port - the remote port
sslContext - the ssl context to use
sslOn - true, activate SSL mode. false, ssl can be activated by user (see IConnection.activateSecuredMode())
Throws:
java.io.IOException - If some other I/O error occurs

NonBlockingConnection

public NonBlockingConnection(java.net.InetAddress address,
                             int port,
                             StreamSocketConfiguration socketConfiguration,
                             javax.net.ssl.SSLContext sslContext,
                             boolean sslOn)
                      throws java.io.IOException
Deprecated. 

Throws:
java.io.IOException

NonBlockingConnection

public NonBlockingConnection(java.net.InetAddress address,
                             int port,
                             java.util.Map<java.lang.String,java.lang.Object> options,
                             javax.net.ssl.SSLContext sslContext,
                             boolean sslOn)
                      throws java.io.IOException
constructor. This constructor will be used to create a non blocking client-side connection.

For multithreading issues see NonBlockingConnection(InetAddress, int, IHandler, Executor).

Parameters:
address - the remote address
port - the remote port
options - the socket options
sslContext - the ssl context to use
sslOn - true, activate SSL mode. false, ssl can be activated by user (see IConnection.activateSecuredMode())
Throws:
java.io.IOException - If some other I/O error occurs

NonBlockingConnection

public NonBlockingConnection(java.lang.String hostname,
                             int port,
                             javax.net.ssl.SSLContext sslContext,
                             boolean sslOn)
                      throws java.io.IOException
constructor. This constructor will be used to create a non blocking client-side connection.

For multithreading issues see NonBlockingConnection(InetAddress, int, IHandler, Executor).

Parameters:
hostname - the remote host
port - the remote port
sslContext - the ssl context to use
sslOn - true, activate SSL mode. false, ssl can be activated by user (see IConnection.activateSecuredMode())
Throws:
java.io.IOException - If some other I/O error occurs

NonBlockingConnection

public NonBlockingConnection(java.lang.String hostname,
                             int port,
                             StreamSocketConfiguration socketConfiguration,
                             javax.net.ssl.SSLContext sslContext,
                             boolean sslOn)
                      throws java.io.IOException
Deprecated. 

Throws:
java.io.IOException

NonBlockingConnection

public NonBlockingConnection(java.lang.String hostname,
                             int port,
                             java.util.Map<java.lang.String,java.lang.Object> options,
                             javax.net.ssl.SSLContext sslContext,
                             boolean sslOn)
                      throws java.io.IOException
constructor. This constructor will be used to create a non blocking client-side connection.

For multithreading issues see NonBlockingConnection(InetAddress, int, IHandler, Executor).

Parameters:
hostname - the remote host
port - the remote port
options - the socket options
sslContext - the ssl context to use
sslOn - true, activate SSL mode. false, ssl can be activated by user (see IConnection.activateSecuredMode())
Throws:
java.io.IOException - If some other I/O error occurs

NonBlockingConnection

public NonBlockingConnection(java.net.InetAddress address,
                             int port,
                             IHandler appHandler,
                             java.util.concurrent.Executor workerPool)
                      throws java.io.IOException
constructor. This constructor will be used to create a non blocking client-side connection.

Multithreading note
The data of the NonBlockingConnection will be read and written by using a central dispatcher (selector) thread. The handler`s call back methods (onData, onConnect, ...) will be call by the worker pool`s worker thread. By using this (client-side) constructor, the workerpool will be set manually. For a construtor which doesn`t support the workerpool parameter, a default (vm singleton) CachedThreadPool Executors.newCachedThreadPool() will be used.
By setting the workerPool with null, the multithreading is "switched off". This means the call back methods will be executed by the central dispatcher thread. The workerPool can also be shared with a server, which runs in the same process. E.g.
 ...
 // create a new server instance (a associated WorkerPool will be created automatically)
 IMultithreadedServer server = new MultithreadedServer(new TestHandler());
 StreamUtils.start(server);
 ...

 INonBlockingConnection connection = new NonBlockingConnection(host, port, clientHandler, server.getWorkerpool());
 ...

 

Parameters:
address - the remote address
port - the remote port
appHandler - the application handler (supported: IConnectHandler, IDisconnectHandler, IDataHandler and ITimeoutHandler)
workerPool - the worker pool to use or to
Throws:
java.io.IOException - If some other I/O error occurs

NonBlockingConnection

public NonBlockingConnection(java.net.InetAddress address,
                             int port,
                             IHandler appHandler,
                             java.util.concurrent.Executor workerPool,
                             int preallocationMemorySize)
                      throws java.io.IOException
Deprecated. 

Throws:
java.io.IOException
Method Detail

setWriteTransferRate

public void setWriteTransferRate(int bytesPerSecond)
                          throws ClosedConnectionException,
                                 java.io.IOException
set the send delay time. WData to write will be buffered internally and be written to the underlying subsystem based on the given write rate. The write methods will not block for this time.
By default the write transfer rate is set with UNLIMITED

Reduced write transfer is only supported for FlushMode.ASYNC. see INonBlockingConnection.setFlushmode(org.xsocket.stream.IConnection.FlushMode)

Specified by:
setWriteTransferRate in interface INonBlockingConnection
Parameters:
bytesPerSecond - the transfer rate of the outgoing data
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs

getNumberOfAvailableBytes

public int getNumberOfAvailableBytes()
get the number of available bytes to read

Specified by:
getNumberOfAvailableBytes in interface INonBlockingConnection
Returns:
the umber of available bytes

readAvailable

public java.nio.ByteBuffer[] readAvailable()
                                    throws java.io.IOException,
                                           ClosedConnectionException
read all received bytes

Specified by:
readAvailable in interface INonBlockingConnection
Returns:
the received bytes
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs

readAvailableByDelimiter

public boolean readAvailableByDelimiter(java.lang.String delimiter,
                                        java.nio.channels.WritableByteChannel outputChannel)
                                 throws java.io.IOException,
                                        ClosedConnectionException

Specified by:
readAvailableByDelimiter in interface INonBlockingConnection
Throws:
java.io.IOException
ClosedConnectionException

readAvailableByDelimiter

public boolean readAvailableByDelimiter(java.lang.String delimiter,
                                        java.lang.String encoding,
                                        java.nio.channels.WritableByteChannel outputChannel)
                                 throws java.io.IOException,
                                        ClosedConnectionException

Specified by:
readAvailableByDelimiter in interface INonBlockingConnection
Throws:
java.io.IOException
ClosedConnectionException

transferToAvailableByDelimiter

public final INonBlockingConnection.TransferResult transferToAvailableByDelimiter(java.lang.String delimiter,
                                                                                  java.nio.channels.WritableByteChannel outputChannel)
                                                                           throws java.io.IOException,
                                                                                  ClosedConnectionException
transfers bytes from this connection to the given writable byte channel. All available bytes buffers terminated by the delimiter will be transfered. if the delimiter has been found the INonBlockingConnection.TransferResult.delimiterFound is set with true. The INonBlockingConnection.TransferResult.written contains the The number of bytes, possibly zero, that were actually transferred
The default encoding will be used to decode the delimiter

Specified by:
transferToAvailableByDelimiter in interface INonBlockingConnection
Parameters:
delimiter - the delimiter to use
outputChannel - the output channel to write the available bytes
Returns:
transfer result
Throws:
java.io.IOException - If some other I/O error occurs
java.net.SocketTimeoutException - If the receive timeout has been reached (will only been thrown if autoflush = true)
ClosedConnectionException - if the underlying channel is closed

transferToAvailableByDelimiter

public final INonBlockingConnection.TransferResult transferToAvailableByDelimiter(java.lang.String delimiter,
                                                                                  java.lang.String encoding,
                                                                                  java.nio.channels.WritableByteChannel outputChannel)
                                                                           throws java.io.IOException,
                                                                                  ClosedConnectionException
transfers bytes from this connection to the given writable byte channel. All available bytes buffers terminated by the delimiter will be transfered. if the delimiter has been found the INonBlockingConnection.TransferResult.delimiterFound is set with true. The INonBlockingConnection.TransferResult.written contains the The number of bytes, possibly zero, that were actually transferred

Specified by:
transferToAvailableByDelimiter in interface INonBlockingConnection
Parameters:
delimiter - the delimiter to use
encoding - the encoding of the delimiter
outputChannel - the output channel to write the available bytes
Returns:
transfer the transfer result
Throws:
java.io.IOException - If some other I/O error occurs
java.net.SocketTimeoutException - If the receive timeout has been reached (will only been thrown if autoflush = true)
ClosedConnectionException - if the underlying channel is closed

read

public int read(java.nio.ByteBuffer buffer)
         throws java.io.IOException

Specified by:
read in interface java.nio.channels.ReadableByteChannel
Throws:
java.io.IOException

readByte

public byte readByte()
              throws java.io.IOException,
                     ClosedConnectionException,
                     java.nio.BufferUnderflowException
read a byte

Specified by:
readByte in interface IDataSource
Specified by:
readByte in interface IConnection
Specified by:
readByte in interface INonBlockingConnection
Returns:
the byte value
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs
java.nio.BufferUnderflowException - if the buffer`s limit has been reached

readByteBufferByDelimiter

public java.nio.ByteBuffer[] readByteBufferByDelimiter(java.lang.String delimiter)
                                                throws java.io.IOException,
                                                       ClosedConnectionException,
                                                       java.nio.BufferUnderflowException
read a ByteBuffer by using a delimiter To avoid memory leaks the INonBlockingConnection.readByteBufferByDelimiter(String, int) method is generally preferable
For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes

Specified by:
readByteBufferByDelimiter in interface IConnection
Specified by:
readByteBufferByDelimiter in interface INonBlockingConnection
Parameters:
delimiter - the delimiter
Returns:
the ByteBuffer
Throws:
java.io.IOException - If some other I/O error occurs
ClosedConnectionException - If the underlying socket is already closed
java.nio.BufferUnderflowException - if the delimiter has not been found

readByteBufferByDelimiter

public java.nio.ByteBuffer[] readByteBufferByDelimiter(java.lang.String delimiter,
                                                       int maxLength)
                                                throws java.io.IOException,
                                                       ClosedConnectionException,
                                                       MaxReadSizeExceededException,
                                                       java.nio.BufferUnderflowException
read a ByteBuffer by using a delimiter For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes

Specified by:
readByteBufferByDelimiter in interface IConnection
Specified by:
readByteBufferByDelimiter in interface INonBlockingConnection
Parameters:
delimiter - the delimiter
maxLength - the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
Returns:
the ByteBuffer
Throws:
java.io.IOException - If some other I/O error occurs
ClosedConnectionException - If the underlying socket is already closed
MaxReadSizeExceededException - If the max read length has been exceeded and the delimiter hasn’t been found * @throws ClosedConnectionException If the underlying socket is already closed
java.nio.BufferUnderflowException - if the delimiter has not been found

readByteBufferByDelimiter

public java.nio.ByteBuffer[] readByteBufferByDelimiter(java.lang.String delimiter,
                                                       java.lang.String encoding,
                                                       int maxLength)
                                                throws java.io.IOException,
                                                       ClosedConnectionException,
                                                       MaxReadSizeExceededException
read a ByteBuffer by using a delimiter For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes

Specified by:
readByteBufferByDelimiter in interface IConnection
Parameters:
delimiter - the delimiter
encoding - the encoding of the delimiter
maxLength - the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
Returns:
the ByteBuffer
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs
MaxReadSizeExceededException - If the max read length has been exceeded and the delimiter hasn’t been found

readByteBufferByLength

public java.nio.ByteBuffer[] readByteBufferByLength(int length)
                                             throws java.io.IOException,
                                                    ClosedConnectionException,
                                                    java.nio.BufferUnderflowException
read a ByteBuffer by using a length defintion For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes

Specified by:
readByteBufferByLength in interface IConnection
Specified by:
readByteBufferByLength in interface INonBlockingConnection
Parameters:
length - the amount of bytes to read
Returns:
the ByteBuffer
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs
java.nio.BufferUnderflowException - if the buffer`s limit has been reached

readBytesByDelimiter

public byte[] readBytesByDelimiter(java.lang.String delimiter)
                            throws java.io.IOException,
                                   ClosedConnectionException,
                                   java.nio.BufferUnderflowException
read a byte array by using a delimiter To avoid memory leaks the INonBlockingConnection.readBytesByDelimiter(String, int) method is generally preferable
For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes

Specified by:
readBytesByDelimiter in interface IConnection
Specified by:
readBytesByDelimiter in interface INonBlockingConnection
Parameters:
delimiter - the delimiter
Returns:
the read bytes
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs
java.nio.BufferUnderflowException - if the delimiter has not been found

readBytesByDelimiter

public byte[] readBytesByDelimiter(java.lang.String delimiter,
                                   int maxLength)
                            throws java.io.IOException,
                                   ClosedConnectionException,
                                   MaxReadSizeExceededException,
                                   java.nio.BufferUnderflowException
read a byte array by using a delimiter For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes

Specified by:
readBytesByDelimiter in interface IDataSource
Specified by:
readBytesByDelimiter in interface IConnection
Specified by:
readBytesByDelimiter in interface INonBlockingConnection
Parameters:
delimiter - the delimiter
maxLength - the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
Returns:
the read bytes
Throws:
java.io.IOException - If some other I/O error occurs
ClosedConnectionException - If the underlying socket is already closed
MaxReadSizeExceededException - If the max read length has been exceeded and the delimiter hasn’t been found * @throws ClosedConnectionException If the underlying socket is already closed
java.nio.BufferUnderflowException - if the delimiter has not been found

readBytesByDelimiter

public byte[] readBytesByDelimiter(java.lang.String delimiter,
                                   java.lang.String encoding,
                                   int maxLength)
                            throws java.io.IOException,
                                   ClosedConnectionException,
                                   MaxReadSizeExceededException
read a byte array by using a delimiter For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes

Specified by:
readBytesByDelimiter in interface IConnection
Parameters:
delimiter - the delimiter
encoding - the encoding of the delimiter
maxLength - the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
Returns:
the read bytes
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs
MaxReadSizeExceededException - If the max read length has been exceeded and the delimiter hasn’t been found

readBytesByLength

public byte[] readBytesByLength(int length)
                         throws java.io.IOException,
                                ClosedConnectionException,
                                java.nio.BufferUnderflowException
read bytes by using a length defintion For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes

Specified by:
readBytesByLength in interface IDataSource
Specified by:
readBytesByLength in interface IConnection
Specified by:
readBytesByLength in interface INonBlockingConnection
Parameters:
length - the amount of bytes to read
Returns:
the read bytes
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs
java.nio.BufferUnderflowException - if the buffer`s limit has been reached

readDouble

public double readDouble()
                  throws java.io.IOException,
                         ClosedConnectionException,
                         java.nio.BufferUnderflowException
read a double

Specified by:
readDouble in interface IDataSource
Specified by:
readDouble in interface IConnection
Specified by:
readDouble in interface INonBlockingConnection
Returns:
the double value
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs
java.nio.BufferUnderflowException - if the buffer`s limit has been reached

readInt

public int readInt()
            throws java.io.IOException,
                   ClosedConnectionException,
                   java.nio.BufferUnderflowException
read an int

Specified by:
readInt in interface IDataSource
Specified by:
readInt in interface IConnection
Specified by:
readInt in interface INonBlockingConnection
Returns:
the int value
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs
java.nio.BufferUnderflowException - if the buffer`s limit has been reached

readShort

public short readShort()
                throws java.io.IOException,
                       ClosedConnectionException,
                       java.nio.BufferUnderflowException
read a short value

Specified by:
readShort in interface IDataSource
Returns:
the short value
Throws:
java.io.IOException - If some other I/O error occurs
ClosedConnectionException
java.nio.BufferUnderflowException

readLong

public long readLong()
              throws java.io.IOException,
                     ClosedConnectionException,
                     java.nio.BufferUnderflowException
read a long

Specified by:
readLong in interface IDataSource
Specified by:
readLong in interface IConnection
Specified by:
readLong in interface INonBlockingConnection
Returns:
the long value
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs
java.nio.BufferUnderflowException - if the buffer`s limit has been reached

readStringByDelimiter

public java.lang.String readStringByDelimiter(java.lang.String delimiter)
                                       throws java.io.IOException,
                                              ClosedConnectionException,
                                              java.nio.BufferUnderflowException,
                                              java.io.UnsupportedEncodingException
read a string by using a delimiter and the connection default encoding To avoid memory leaks the INonBlockingConnection.readStringByDelimiter(String, int) method is generally preferable

Specified by:
readStringByDelimiter in interface IDataSource
Specified by:
readStringByDelimiter in interface IConnection
Specified by:
readStringByDelimiter in interface INonBlockingConnection
Parameters:
delimiter - the delimiter
Returns:
the string
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs
java.io.UnsupportedEncodingException - if the default encoding is not supported
java.nio.BufferUnderflowException - if the delimiter has not been found

readStringByDelimiter

public java.lang.String readStringByDelimiter(java.lang.String delimiter,
                                              int maxLength)
                                       throws java.io.IOException,
                                              ClosedConnectionException,
                                              java.nio.BufferUnderflowException,
                                              java.io.UnsupportedEncodingException,
                                              MaxReadSizeExceededException
read a string by using a delimiter and the connection default encoding

Specified by:
readStringByDelimiter in interface IDataSource
Specified by:
readStringByDelimiter in interface IConnection
Specified by:
readStringByDelimiter in interface INonBlockingConnection
Parameters:
delimiter - the delimiter
maxLength - the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
Returns:
the string
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs
java.io.UnsupportedEncodingException - if the default encoding is not supported
MaxReadSizeExceededException - If the max read length has been exceeded and the delimiter hasn’t been found
java.nio.BufferUnderflowException - if the delimiter has not been found

readStringByDelimiter

public java.lang.String readStringByDelimiter(java.lang.String delimiter,
                                              java.lang.String encoding)
                                       throws java.io.IOException,
                                              ClosedConnectionException,
                                              java.nio.BufferUnderflowException,
                                              java.io.UnsupportedEncodingException
read a string by using a delimiter To avoid memory leaks the INonBlockingConnection.readStringByDelimiter(String, String, int) method is generally preferable

Specified by:
readStringByDelimiter in interface IConnection
Specified by:
readStringByDelimiter in interface INonBlockingConnection
Parameters:
delimiter - the delimiter
encoding - the encodin to use
Returns:
the string
Throws:
java.io.IOException - If some other I/O error occurs
java.io.UnsupportedEncodingException - If the given encoding is not supported
ClosedConnectionException - If the underlying socket is already closed
java.nio.BufferUnderflowException - if the buffer`s limit has been reached

readStringByDelimiter

public java.lang.String readStringByDelimiter(java.lang.String delimiter,
                                              java.lang.String encoding,
                                              int maxLength)
                                       throws java.io.IOException,
                                              ClosedConnectionException,
                                              java.nio.BufferUnderflowException,
                                              java.io.UnsupportedEncodingException,
                                              MaxReadSizeExceededException
read a string by using a delimiter

Specified by:
readStringByDelimiter in interface IDataSource
Specified by:
readStringByDelimiter in interface IConnection
Specified by:
readStringByDelimiter in interface INonBlockingConnection
Parameters:
delimiter - the delimiter
encoding - the encodin to use
maxLength - the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
Returns:
the string
Throws:
java.io.IOException - If some other I/O error occurs
java.io.UnsupportedEncodingException - If the given encoding is not supported
ClosedConnectionException - If the underlying socket is already closed
MaxReadSizeExceededException - If the max read length has been exceeded and the delimiter hasn’t been found * @throws ClosedConnectionException If the underlying socket is already closed
java.nio.BufferUnderflowException - if the buffer`s limit has been reached

readStringByLength

public java.lang.String readStringByLength(int length)
                                    throws java.io.IOException,
                                           ClosedConnectionException,
                                           java.nio.BufferUnderflowException,
                                           java.io.UnsupportedEncodingException
read a string by using a length definition and the connection default encoding

Specified by:
readStringByLength in interface IDataSource
Specified by:
readStringByLength in interface IConnection
Specified by:
readStringByLength in interface INonBlockingConnection
Parameters:
length - the amount of bytes to read
Returns:
the string
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs
java.io.UnsupportedEncodingException - if the given encoding is not supported
java.nio.BufferUnderflowException - if the buffer`s limit has been reached

readStringByLength

public java.lang.String readStringByLength(int length,
                                           java.lang.String encoding)
                                    throws java.io.IOException,
                                           ClosedConnectionException,
                                           java.nio.BufferUnderflowException,
                                           java.io.UnsupportedEncodingException
read a string by using a length definition

Specified by:
readStringByLength in interface IDataSource
Specified by:
readStringByLength in interface IConnection
Specified by:
readStringByLength in interface INonBlockingConnection
Parameters:
length - the amount of bytes to read
encoding - the encodin to use
Returns:
the string
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs
java.io.UnsupportedEncodingException - if the given encoding is not supported
java.nio.BufferUnderflowException - if the buffer`s limit has been reached

getIndexOf

public int getIndexOf(java.lang.String str)
               throws java.io.IOException,
                      ClosedConnectionException,
                      java.nio.BufferUnderflowException
Returns the index of the first occurrence of the given string.

Specified by:
getIndexOf in interface IConnection
Specified by:
getIndexOf in interface INonBlockingConnection
Parameters:
str - any string
Returns:
if the string argument occurs as a substring within this object, then the index of the first character of the first such substring is returned;
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs
java.nio.BufferUnderflowException - if the given string has not been found

getIndexOf

public int getIndexOf(java.lang.String str,
                      int maxLength)
               throws java.io.IOException,
                      ClosedConnectionException,
                      java.nio.BufferUnderflowException,
                      MaxReadSizeExceededException
Returns the index of the first occurrence of the given string.

Specified by:
getIndexOf in interface IConnection
Specified by:
getIndexOf in interface INonBlockingConnection
Parameters:
str - any string
maxLength - the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
Returns:
if the string argument occurs as a substring within this object, then the index of the first character of the first such substring is returned;
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs
MaxReadSizeExceededException - If the max read length has been exceeded and the delimiter hasn’t been found
java.nio.BufferUnderflowException - if the given string has not been found

getIndexOf

public int getIndexOf(java.lang.String str,
                      java.lang.String encoding,
                      int maxLength)
               throws java.io.IOException,
                      ClosedConnectionException,
                      MaxReadSizeExceededException
Returns the index of the first occurrence of the given string.

Specified by:
getIndexOf in interface IConnection
Parameters:
str - any string
encoding - the encoding of the string
maxLength - the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
Returns:
if the string argument occurs as a substring within this object, then the index of the first character of the first such substring is returned;
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs
MaxReadSizeExceededException - If the max read length has been exceeded and the delimiter hasn’t been found

setOption

public INonBlockingConnection setOption(java.lang.String name,
                                        java.lang.Object value)
                                 throws java.io.IOException
sets the value of a option

Specified by:
setOption in interface IConnection
Specified by:
setOption in interface INonBlockingConnection
Parameters:
name - the name of the option
value - the value of the option
Returns:
the IConnection
Throws:
java.io.IOException - In an I/O error occurs

getPendingWriteDataSize

public final int getPendingWriteDataSize()
returns the size of the data which have already been written, but not yet transferred to the underlying socket.

Specified by:
getPendingWriteDataSize in interface IConnection
Returns:
the size of the pending data to write

close

public final void close()
                 throws java.io.IOException

Specified by:
close in interface java.io.Closeable
Specified by:
close in interface java.nio.channels.Channel
Throws:
java.io.IOException

isOpen

public final boolean isOpen()
returns, if the connection is open.

Please note, that a connection could be closed, but reading of already received (and internally buffered) data wouldn`t fail. See also IDataHandler.onData(INonBlockingConnection)

Specified by:
isOpen in interface java.nio.channels.Channel
Specified by:
isOpen in interface IConnection
Returns:
true if the connection is open

suspendRead

public void suspendRead()
                 throws java.io.IOException
suspend reading data from the underlying subsystem

Specified by:
suspendRead in interface IConnection
Throws:
java.io.IOException - If some other I/O error occurs

resumeRead

public void resumeRead()
                throws java.io.IOException
resume reading data from the underlying subsystem

Specified by:
resumeRead in interface IConnection
Throws:
java.io.IOException - If some other I/O error occurs

flush

public void flush()
           throws ClosedConnectionException,
                  java.io.IOException
flush the send buffer.

Specified by:
flush in interface java.io.Flushable
Specified by:
flush in interface IConnection
Throws:
ClosedConnectionException - if the underlying channel is closed
java.io.IOException - If some other I/O error occurs

setFlushmode

public final void setFlushmode(IConnection.FlushMode flushMode)
set the flushmode

Parameters:
flushMode - the flushmode

getFlushmode

public final IConnection.FlushMode getFlushmode()
get the flushmode

Returns:
the flushmode

setIdleTimeoutSec

public void setIdleTimeoutSec(int timeoutInSec)
sets the idle timeout in sec

Specified by:
setIdleTimeoutSec in interface IConnection
Parameters:
timeoutInSec - idle timeout in sec

setConnectionTimeoutSec

public void setConnectionTimeoutSec(int timeoutSec)
sets the max time for a connections. By exceeding this time the connection will be terminated

Specified by:
setConnectionTimeoutSec in interface IConnection
Parameters:
timeoutSec - the connection timeout in sec

getConnectionTimeoutSec

public int getConnectionTimeoutSec()
gets the connection timeout

Specified by:
getConnectionTimeoutSec in interface IConnection
Returns:
connection timeout

getIdleTimeoutSec

public int getIdleTimeoutSec()
returns the idle timeout in sec.

Specified by:
getIdleTimeoutSec in interface IConnection
Returns:
idle timeout in sec

getDefaultEncoding

public final java.lang.String getDefaultEncoding()
gets the default encoding for this connection (used by string related methods like readString...)

Specified by:
getDefaultEncoding in interface IConnection
Returns:
the default encoding

setDefaultEncoding

public final void setDefaultEncoding(java.lang.String defaultEncoding)
sets the default encoding for this connection (used by string related methods like readString...)

Specified by:
setDefaultEncoding in interface IConnection
Parameters:
defaultEncoding - the default encoding

setAutoflush

public final void setAutoflush(boolean autoflush)
set autoflush. If autoflush is activated, each write call will cause a flush.

By default the autoflush is deactivated

Specified by:
setAutoflush in interface IConnection
Parameters:
autoflush - true if autoflush should be activated

getAutoflush

public final boolean getAutoflush()
get autoflush

Specified by:
getAutoflush in interface IConnection
Returns:
true, if autoflush is activated

getId

public final java.lang.String getId()
returns the id

Specified by:
getId in interface IConnection
Returns:
id

getLocalAddress

public final java.net.InetAddress getLocalAddress()
returns the local address

Specified by:
getLocalAddress in interface IConnection
Returns:
the local IP address or InetAddress.anyLocalAddress() if the socket is not bound yet.

getLocalPort

public final int getLocalPort()
returns the local port

Specified by:
getLocalPort in interface IConnection
Returns:
the local port

getRemoteAddress

public final java.net.InetAddress getRemoteAddress()
returns the remote address

Specified by:
getRemoteAddress in interface IConnection
Returns:
the remote address

getRemotePort

public final int getRemotePort()
returns the port of the remote endpoint

Specified by:
getRemotePort in interface IConnection
Returns:
the remote port

activateSecuredMode

public void activateSecuredMode()
                         throws java.io.IOException
ad hoc activation of a secured mode (SSL). By perfoming of this method all remaining data to send will be flushed. After this all data will be sent and received in the secured mode

Specified by:
activateSecuredMode in interface IConnection
Throws:
java.io.IOException - If some other I/O error occurs

write

public final int write(java.lang.String s)
                throws ClosedConnectionException,
                       java.io.IOException
sends a message to the remote endpoint by using the connection default encoding

Specified by:
write in interface IDataSink
Specified by:
write in interface IConnection
Parameters:
s - the message to send
Returns:
the number of send bytes
Throws:
ClosedConnectionException - if the underlying channel is closed
java.io.IOException - If some other I/O error occurs

write

public final int write(java.lang.String s,
                       java.lang.String encoding)
                throws ClosedConnectionException,
                       java.io.IOException
sends a message to the remote endpoint

Specified by:
write in interface IDataSink
Specified by:
write in interface IConnection
Parameters:
s - the message to send
encoding - the encoding which should be used th encode the chars into byte (e.g. `US-ASCII` or `UTF-8`)
Returns:
the number of send bytes
Throws:
ClosedConnectionException - if the underlying channel is closed
java.io.IOException - If some other I/O error occurs

write

public final int write(byte b)
                throws ClosedConnectionException,
                       java.io.IOException
sends a byte to the remote endpoint

Specified by:
write in interface IDataSink
Specified by:
write in interface IConnection
Parameters:
b - the byte to send
Returns:
the number of send bytes
Throws:
ClosedConnectionException - if the underlying channel is closed
java.io.IOException - If some other I/O error occurs

write

public final int write(byte... bytes)
                throws ClosedConnectionException,
                       java.io.IOException
sends bytes to the remote endpoint

Specified by:
write in interface IDataSink
Specified by:
write in interface IConnection
Parameters:
bytes - the bytes to send
Returns:
the number of send bytes
Throws:
ClosedConnectionException - if the underlying channel is closed
java.io.IOException - If some other I/O error occurs

write

public final int write(byte[] bytes,
                       int offset,
                       int length)
                throws ClosedConnectionException,
                       java.io.IOException
sends bytes to the remote endpoint

Specified by:
write in interface IDataSink
Specified by:
write in interface IConnection
Parameters:
bytes - the bytes to send
offset - The offset of the subarray to be used; must be non-negative and no larger than array.length. The new buffer`s position will be set to this value.
length - The length of the subarray to be used; must be non-negative and no larger than array.length - offset. The new buffer`s limit will be set to offset + length.
Returns:
the number of send bytes
Throws:
ClosedConnectionException - if the underlying channel is closed
java.io.IOException - If some other I/O error occurs

write

public final long write(java.nio.ByteBuffer[] buffers)
                 throws ClosedConnectionException,
                        java.io.IOException
sends an array of byte buffer to the remote endpoint. In case of activated autoflush (for default see IConnection.INITIAL_AUTOFLUSH) the behaviour is according to the WritableByteChannel specification. In case of user managed flushing (autoflush is off) the passed over buffers will only be queued internally and written after flushing the connection.

Specified by:
write in interface java.nio.channels.GatheringByteChannel
Specified by:
write in interface IDataSink
Specified by:
write in interface IConnection
Parameters:
buffers - the bytes to send
Returns:
the number of send bytes
Throws:
ClosedConnectionException - if the underlying channel is closed
java.io.IOException - If some other I/O error occurs

write

public final int write(java.nio.ByteBuffer buffer)
                throws ClosedConnectionException,
                       java.io.IOException
sends a byte buffer to the remote endpoint. In case of activated autoflush (for default see IConnection.INITIAL_AUTOFLUSH) the behaviour is according to the WritableByteChannel specification. In case of user managed flushing (autoflush is off) the passed over buffers will only be queued internally and written after flushing the connection.

Specified by:
write in interface java.nio.channels.WritableByteChannel
Specified by:
write in interface IDataSink
Specified by:
write in interface IConnection
Parameters:
buffer - the bytes to send
Returns:
the number of send bytes
Throws:
ClosedConnectionException - if the underlying channel is closed
java.io.IOException - If some other I/O error occurs

write

public final int write(int i)
                throws ClosedConnectionException,
                       java.io.IOException
sends an int to the remote endpoint

Specified by:
write in interface IDataSink
Specified by:
write in interface IConnection
Parameters:
i - the int value to send
Returns:
the number of send bytes
Throws:
ClosedConnectionException - if the underlying channel is closed
java.io.IOException - If some other I/O error occurs

write

public final int write(short s)
                throws ClosedConnectionException,
                       java.io.IOException
writes a short to the data sink

Specified by:
write in interface IDataSink
Parameters:
s - the short value to write
Returns:
the number of send bytes
Throws:
java.io.IOException - If some other I/O error occurs
ClosedConnectionException

write

public final int write(long l)
                throws ClosedConnectionException,
                       java.io.IOException
sends a long to the remote endpoint

Specified by:
write in interface IDataSink
Specified by:
write in interface IConnection
Parameters:
l - the int value to send
Returns:
the number of send bytes
Throws:
ClosedConnectionException - if the underlying channel is closed
java.io.IOException - If some other I/O error occurs

write

public final int write(double d)
                throws ClosedConnectionException,
                       java.io.IOException
sends a double to the remote endpoint

Specified by:
write in interface IDataSink
Specified by:
write in interface IConnection
Parameters:
d - the int value to send
Returns:
the number of send bytes
Throws:
ClosedConnectionException - if the underlying channel is closed
java.io.IOException - If some other I/O error occurs

write

public final long write(java.nio.ByteBuffer[] srcs,
                        int offset,
                        int length)
                 throws java.io.IOException

Specified by:
write in interface java.nio.channels.GatheringByteChannel
Throws:
java.io.IOException

indexOf

public int indexOf(java.lang.String str)
Deprecated. uses getIndexOf instead

Returns the index within this string of the first occurrence of the specified substring

Parameters:
str - any string
Returns:
if the string argument occurs as a substring within this object, then the index of the first character of the first such substring is returned; if it does not occur as a substring, -1 is returned.

attach

public final java.lang.Object attach(java.lang.Object obj)

Specified by:
attach in interface IConnection

attachment

public final java.lang.Object attachment()

Specified by:
attachment in interface IConnection

setAttachment

public final void setAttachment(java.lang.Object obj)
Attaches the given object to this connection

Specified by:
setAttachment in interface IConnection
Parameters:
obj - The object to be attached; may be null

getAttachment

public final java.lang.Object getAttachment()
Retrieves the current attachment.

Specified by:
getAttachment in interface IConnection
Returns:
The object currently attached to this key, or null if there is no attachment

markReadPosition

public void markReadPosition()
Marks the present read position in the connection. Subsequent calls to resetToReadMark() will attempt to reposition the connection to this point.

Specified by:
markReadPosition in interface IConnection

markWritePosition

public void markWritePosition()
Marks the present write position in the connection. Subsequent calls to resetToReadMark() will attempt to reposition the connection to this point. The write read become in valid by flushing the connection.

write mark is only supported for autoflush off. E.g.
 ...
 con.setAutoflush(false);

 con.markWritePosition();  // mark current position
 con.write((int) 0);       // write "emtpy" length field

 int written = con.write("hello world");
 written += con.write(" it’s nice to be here");
 ...

 con.resetToWriteMark();  // return to length field position
 con.write(written);      // and update it

 con.flush(); // flush (marker will be removed implicit)
…    * 

Specified by:
markWritePosition in interface IConnection

resetToWriteMark

public boolean resetToWriteMark()
Resets to the marked write position. If the connection has been marked, then attempt to reposition it at the mark.

Specified by:
resetToWriteMark in interface IConnection
Returns:
true, if reset was successful

resetToReadMark

public boolean resetToReadMark()
Resets to the marked read position. If the connection has been marked, then attempt to reposition it at the mark.

Specified by:
resetToReadMark in interface IConnection
Returns:
true, if reset was successful

removeReadMark

public void removeReadMark()
remove the mark the present read position in the connection.

Specified by:
removeReadMark in interface IConnection

removeWriteMark

public void removeWriteMark()
remove the mark the present write position in the connection.

Specified by:
removeWriteMark in interface IConnection

onWritten

public void onWritten()

onWriteException

public void onWriteException(java.io.IOException ioException)

getOption

public final java.lang.Object getOption(java.lang.String name)
                                 throws java.io.IOException
returns the value of a option

Specified by:
getOption in interface IConnection
Parameters:
name - the name of the option
Returns:
the value of the option
Throws:
java.io.IOException - In an I/O error occurs

getOptions

public final java.util.Map<java.lang.String,java.lang.Class> getOptions()
Returns an unmodifiable map of the options supported by this endpoint. The key in the returned map is the name of a option, and its value is the type of the option value. The returned map will never contain null keys or values.

Specified by:
getOptions in interface IConnection
Returns:
An unmodifiable map of the options supported by this channel

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object