|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface IConnection
A connection (session) between two endpoints. It encapsulates the underlying socket channel.
Nested Class Summary | |
---|---|
static class |
IConnection.FlushMode
|
Field Summary | |
---|---|
static boolean |
INITIAL_AUTOFLUSH
|
static java.lang.String |
INITIAL_DEFAULT_ENCODING
|
static java.lang.String |
SO_KEEPALIVE
|
static java.lang.String |
SO_LINGER
|
static java.lang.String |
SO_RCVBUF
|
static java.lang.String |
SO_REUSEADDR
|
static java.lang.String |
SO_SNDBUF
|
static java.lang.String |
TCP_NODELAY
|
Method Summary | |
---|---|
void |
activateSecuredMode()
ad hoc activation of a secured mode (SSL). |
java.lang.Object |
attach(java.lang.Object obj)
Deprecated. use setAttachment(Object) instead |
java.lang.Object |
attachment()
Deprecated. use getAttachment() instead |
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...) |
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 |
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 |
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. |
byte |
readByte()
read a byte |
java.nio.ByteBuffer[] |
readByteBufferByDelimiter(java.lang.String delimiter)
read a ByteBuffer by using a delimiter. |
java.nio.ByteBuffer[] |
readByteBufferByDelimiter(java.lang.String delimiter,
int maxLength)
read a ByteBuffer by using a delimiter. |
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. readByteBufferByDelimiter(String, int) To avoid memory leaks the 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. readByteBufferByDelimiter(String, int) 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 |
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 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 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 encoding)
sets the default encoding for this connection (used by string related methods like readString...) |
void |
setIdleTimeoutSec(int timeoutInSec)
sets the idle timeout in sec |
IConnection |
setOption(java.lang.String name,
java.lang.Object value)
sets the value of a option |
void |
suspendRead()
suspend reading data from the underlying subsystem |
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. |
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(java.lang.String message)
sends a message to the remote endpoint by using the connection default encoding |
int |
write(java.lang.String message,
java.lang.String encoding)
sends a message to the remote endpoint |
Methods inherited from interface org.xsocket.IDataSource |
---|
readShort |
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 |
Methods inherited from interface java.nio.channels.ReadableByteChannel |
---|
read |
Field Detail |
---|
static final java.lang.String INITIAL_DEFAULT_ENCODING
static final boolean INITIAL_AUTOFLUSH
static final java.lang.String SO_SNDBUF
static final java.lang.String SO_RCVBUF
static final java.lang.String SO_REUSEADDR
static final java.lang.String SO_KEEPALIVE
static final java.lang.String SO_LINGER
static final java.lang.String TCP_NODELAY
Method Detail |
---|
java.lang.String getId()
boolean isOpen()
IDataHandler.onData(INonBlockingConnection)
isOpen
in interface java.nio.channels.Channel
void flush() throws ClosedConnectionException, java.io.IOException
flush
in interface java.io.Flushable
java.io.IOException
- If some other I/O error occurs
ClosedConnectionException
- if the underlying channel is closedint getLocalPort()
java.net.InetAddress getLocalAddress()
java.net.InetAddress getRemoteAddress()
int getRemotePort()
void setDefaultEncoding(java.lang.String encoding)
encoding
- the default encodingvoid suspendRead() throws java.io.IOException
java.io.IOException
- If some other I/O error occursvoid resumeRead() throws java.io.IOException
java.io.IOException
- If some other I/O error occursjava.lang.String getDefaultEncoding()
void setAutoflush(boolean autoflush)
autoflush
- true if autoflush should be activatedboolean getAutoflush()
int getIdleTimeoutSec()
void setIdleTimeoutSec(int timeoutInSec)
timeoutInSec
- idle timeout in secint getConnectionTimeoutSec()
void setConnectionTimeoutSec(int timeoutSec)
timeoutSec
- the connection timeout in secint getPendingWriteDataSize()
void activateSecuredMode() throws java.io.IOException
java.io.IOException
- If some other I/O error occursint write(java.lang.String message, java.lang.String encoding) throws ClosedConnectionException, java.io.IOException
write
in interface IDataSink
message
- the message to sendencoding
- the encoding which should be used th encode the chars into byte (e.g. `US-ASCII` or `UTF-8`)
java.io.IOException
- If some other I/O error occurs
ClosedConnectionException
- if the underlying channel is closedint write(java.lang.String message) throws ClosedConnectionException, java.io.IOException
write
in interface IDataSink
message
- the message to send
java.io.IOException
- If some other I/O error occurs
ClosedConnectionException
- if the underlying channel is closedint write(byte b) throws ClosedConnectionException, java.io.IOException
write
in interface IDataSink
b
- the byte to send
java.io.IOException
- If some other I/O error occurs
ClosedConnectionException
- if the underlying channel is closedint write(byte... bytes) throws ClosedConnectionException, java.io.IOException
write
in interface IDataSink
bytes
- the bytes to send
java.io.IOException
- If some other I/O error occurs
ClosedConnectionException
- if the underlying channel is closedint write(byte[] bytes, int offset, int length) throws ClosedConnectionException, java.io.IOException
write
in interface IDataSink
bytes
- the bytes to sendoffset
- 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.
java.io.IOException
- If some other I/O error occurs
ClosedConnectionException
- if the underlying channel is closedint write(java.nio.ByteBuffer buffer) throws ClosedConnectionException, java.io.IOException
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.
write
in interface IDataSink
write
in interface java.nio.channels.WritableByteChannel
buffer
- the bytes to send
java.io.IOException
- If some other I/O error occurs
ClosedConnectionException
- if the underlying channel is closedlong write(java.nio.ByteBuffer[] buffers) throws ClosedConnectionException, java.io.IOException
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.
write
in interface java.nio.channels.GatheringByteChannel
write
in interface IDataSink
buffers
- the bytes to send
java.io.IOException
- If some other I/O error occurs
ClosedConnectionException
- if the underlying channel is closedint write(int i) throws ClosedConnectionException, java.io.IOException
write
in interface IDataSink
i
- the int value to send
java.io.IOException
- If some other I/O error occurs
ClosedConnectionException
- if the underlying channel is closedint write(long l) throws ClosedConnectionException, java.io.IOException
write
in interface IDataSink
l
- the int value to send
java.io.IOException
- If some other I/O error occurs
ClosedConnectionException
- if the underlying channel is closedint write(double d) throws ClosedConnectionException, java.io.IOException
write
in interface IDataSink
d
- the int value to send
java.io.IOException
- If some other I/O error occurs
ClosedConnectionException
- if the underlying channel is closedbyte readByte() throws java.io.IOException, ClosedConnectionException
readByte
in interface IDataSource
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occursint readInt() throws java.io.IOException, ClosedConnectionException
readInt
in interface IDataSource
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occurslong readLong() throws java.io.IOException, ClosedConnectionException
readLong
in interface IDataSource
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occursdouble readDouble() throws java.io.IOException, ClosedConnectionException
readDouble
in interface IDataSource
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occursjava.nio.ByteBuffer[] readByteBufferByDelimiter(java.lang.String delimiter) throws java.io.IOException, ClosedConnectionException
readByteBufferByDelimiter(String, int)
method is generally preferable
delimiter
- the delimiter
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occursjava.nio.ByteBuffer[] readByteBufferByDelimiter(java.lang.String delimiter, int maxLength) throws java.io.IOException, ClosedConnectionException, MaxReadSizeExceededException
delimiter
- the delimitermaxLength
- the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
MaxReadSizeExceededException
- If the max read length has been exceeded and the delimiter hasn’t been found
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occursjava.nio.ByteBuffer[] readByteBufferByDelimiter(java.lang.String delimiter, java.lang.String encoding, int maxLength) throws java.io.IOException, ClosedConnectionException, MaxReadSizeExceededException
delimiter
- the delimiterencoding
- the encoding of the delimitermaxLength
- the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
MaxReadSizeExceededException
- If the max read length has been exceeded and the delimiter hasn’t been found
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occursjava.nio.ByteBuffer[] readByteBufferByLength(int length) throws java.io.IOException, ClosedConnectionException
length
- the amount of bytes to read
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occursbyte[] readBytesByDelimiter(java.lang.String delimiter) throws java.io.IOException, ClosedConnectionException
readBytesByDelimiter(String, int)
method is generally preferable
delimiter
- the delimiter
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occursbyte[] readBytesByDelimiter(java.lang.String delimiter, int maxLength) throws java.io.IOException, ClosedConnectionException, MaxReadSizeExceededException
readBytesByDelimiter
in interface IDataSource
delimiter
- the delimitermaxLength
- the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
MaxReadSizeExceededException
- If the max read length has been exceeded and the delimiter hasn’t been found
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occursbyte[] readBytesByDelimiter(java.lang.String delimiter, java.lang.String encoding, int maxLength) throws java.io.IOException, ClosedConnectionException, MaxReadSizeExceededException
delimiter
- the delimiterencoding
- the encoding of the delimitermaxLength
- the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
MaxReadSizeExceededException
- If the max read length has been exceeded and the delimiter hasn’t been found
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occursbyte[] readBytesByLength(int length) throws java.io.IOException, ClosedConnectionException
readBytesByLength
in interface IDataSource
length
- the amount of bytes to read
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occursjava.lang.String readStringByDelimiter(java.lang.String delimiter) throws java.io.IOException, ClosedConnectionException, java.io.UnsupportedEncodingException
readStringByDelimiter(String, int)
method is generally preferable
readStringByDelimiter
in interface IDataSource
delimiter
- the delimiter
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 supportedjava.lang.String readStringByDelimiter(java.lang.String delimiter, int maxLength) throws java.io.IOException, ClosedConnectionException, java.io.UnsupportedEncodingException, MaxReadSizeExceededException
readStringByDelimiter
in interface IDataSource
delimiter
- the delimitermaxLength
- the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
MaxReadSizeExceededException
- If the max read length has been exceeded and the delimiter hasn’t been found
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 supportedjava.lang.String readStringByLength(int length) throws java.io.IOException, ClosedConnectionException, java.io.UnsupportedEncodingException
readStringByLength
in interface IDataSource
length
- the amount of bytes to read
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 supportedjava.lang.String readStringByDelimiter(java.lang.String delimiter, java.lang.String encoding) throws java.io.IOException, ClosedConnectionException, java.io.UnsupportedEncodingException
readStringByDelimiter(String, String, int)
method is generally preferable
delimiter
- the delimiterencoding
- the encodin to use
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 supportedjava.lang.String readStringByDelimiter(java.lang.String delimiter, java.lang.String encoding, int maxLength) throws java.io.IOException, ClosedConnectionException, java.io.UnsupportedEncodingException, MaxReadSizeExceededException
readStringByDelimiter
in interface IDataSource
delimiter
- the delimiterencoding
- the encodin to usemaxLength
- the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
MaxReadSizeExceededException
- If the max read length has been exceeded and the delimiter hasn’t been found
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 supportedjava.lang.String readStringByLength(int length, java.lang.String encoding) throws java.io.IOException, ClosedConnectionException, java.io.UnsupportedEncodingException
readStringByLength
in interface IDataSource
length
- the amount of bytes to readencoding
- the encodin to use
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 supportedint getIndexOf(java.lang.String str) throws java.io.IOException, ClosedConnectionException
str
- any string
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occursint getIndexOf(java.lang.String str, int maxLength) throws java.io.IOException, ClosedConnectionException, MaxReadSizeExceededException
str
- any stringmaxLength
- the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
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 foundint getIndexOf(java.lang.String str, java.lang.String encoding, int maxLength) throws java.io.IOException, ClosedConnectionException, MaxReadSizeExceededException
str
- any stringencoding
- the encoding of the stringmaxLength
- the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
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 foundvoid markWritePosition()
... 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) … *
void removeWriteMark()
boolean resetToWriteMark()
void markReadPosition()
void removeReadMark()
boolean resetToReadMark()
void setAttachment(java.lang.Object obj)
obj
- The object to be attached; may be nulljava.lang.Object getAttachment()
java.lang.Object attach(java.lang.Object obj)
setAttachment(Object)
instead
java.lang.Object attachment()
getAttachment()
instead
IConnection setOption(java.lang.String name, java.lang.Object value) throws java.io.IOException
name
- the name of the optionvalue
- the value of the option
java.io.IOException
- In an I/O error occursjava.lang.Object getOption(java.lang.String name) throws java.io.IOException
name
- the name of the option
java.io.IOException
- In an I/O error occursjava.util.Map<java.lang.String,java.lang.Class> getOptions()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |