public interface IOSession
The channel associated with implementations of this interface can be used to read data from and write data to the session.
I/O sessions are not bound to an execution thread, therefore one cannot use the context of the thread to store a session's state. All details about a particular session must be stored within the session itself, usually using execution context associated with it.
Implementations of this interface are expected to be threading safe.
Modifier and Type | Field and Description |
---|---|
static int |
ACTIVE |
static String |
ATTACHMENT_KEY
Name of the context attribute key, which can be used to obtain the
session attachment object.
|
static int |
CLOSED |
static int |
CLOSING |
Modifier and Type | Method and Description |
---|---|
ByteChannel |
channel()
Returns the underlying I/O channel associated with this session.
|
void |
clearEvent(int op)
Clears interest in a particular I/O event type by updating the event
mask associated with the session.
|
void |
close()
Terminates the session gracefully and closes the underlying I/O channel.
|
Object |
getAttribute(String name)
Returns the value of the attribute with the given name.
|
int |
getEventMask()
Returns mask of I/O evens this session declared interest in.
|
SocketAddress |
getLocalAddress()
Returns local address.
|
SocketAddress |
getRemoteAddress()
Returns address of the remote peer.
|
int |
getSocketTimeout()
Returns value of the socket timeout in milliseconds.
|
int |
getStatus()
Returns status of the session:
|
boolean |
hasBufferedInput()
Determines if the input buffer associated with the session contains data.
|
boolean |
hasBufferedOutput()
Determines if the output buffer associated with the session contains
data.
|
boolean |
isClosed()
Determines if the session has been terminated.
|
Object |
removeAttribute(String name)
Removes attribute with the given name.
|
void |
setAttribute(String name,
Object obj)
This method can be used to associate a particular object with the
session by the given attribute name.
|
void |
setBufferStatus(SessionBufferStatus status)
Quite often I/O sessions need to maintain internal I/O buffers in order
to transform input / output data prior to returning it to the consumer or
writing it to the underlying channel.
|
void |
setEvent(int op)
Declares interest in a particular I/O event type by updating the event
mask associated with the session.
|
void |
setEventMask(int ops)
Declares interest in I/O event notifications by setting the event mask
associated with the session
|
void |
setSocketTimeout(int timeout)
Sets value of the socket timeout in milliseconds.
|
void |
shutdown()
Terminates the session by shutting down the underlying I/O channel.
|
static final String ATTACHMENT_KEY
static final int ACTIVE
static final int CLOSING
static final int CLOSED
ByteChannel channel()
SocketAddress getRemoteAddress()
SocketAddress getLocalAddress()
int getEventMask()
void setEventMask(int ops)
ops
- new I/O event mask.void setEvent(int op)
op
- I/O event type.void clearEvent(int op)
op
- I/O event type.void close()
void shutdown()
int getStatus()
ACTIVE
: session is active.
CLOSING
: session is being closed.
CLOSED
: session has been terminated.
boolean isClosed()
true
if the session has been terminated,
false
otherwise.int getSocketTimeout()
0
signifies the session cannot time out.void setSocketTimeout(int timeout)
0
signifies the session cannot time out.timeout
- socket timeout.void setBufferStatus(SessionBufferStatus status)
I/O sessions can be made aware of the status of external session buffers
using the SessionBufferStatus
interface.
boolean hasBufferedInput()
true
if the session input buffer contains data,
false
otherwise.boolean hasBufferedOutput()
true
if the session output buffer contains data,
false
otherwise.void setAttribute(String name, Object obj)
I/O sessions are not bound to an execution thread, therefore one cannot use the context of the thread to store a session's state. All details about a particular session must be stored within the session itself.
name
- name of the attribute.obj
- value of the attribute.Object getAttribute(String name)
null
if not set.
The value of the session attachment object can be obtained using
ATTACHMENT_KEY
name.
name
- name of the attribute.setAttribute(String, Object)
Object removeAttribute(String name)
name
- name of the attribute to be removed.setAttribute(String, Object)
Copyright © 2010 - 2020 Adobe. All Rights Reserved