Package org.apache.http.impl.nio.reactor
Class IOSessionImpl
- java.lang.Object
-
- org.apache.http.impl.nio.reactor.IOSessionImpl
-
- All Implemented Interfaces:
IOSession
,SocketAccessor
@Contract(threading=SAFE) public class IOSessionImpl extends java.lang.Object implements IOSession, SocketAccessor
Default implementation ofIOSession
.- Since:
- 4.0
-
-
Field Summary
-
Fields inherited from interface org.apache.http.nio.reactor.IOSession
ACTIVE, ATTACHMENT_KEY, CLOSED, CLOSING
-
-
Constructor Summary
Constructors Constructor Description IOSessionImpl(java.nio.channels.SelectionKey key, org.apache.http.impl.nio.reactor.InterestOpsCallback interestOpsCallback, SessionClosedCallback sessionClosedCallback)
Creates new instance of IOSessionImpl.IOSessionImpl(java.nio.channels.SelectionKey key, SessionClosedCallback sessionClosedCallback)
Creates new instance of IOSessionImpl.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.nio.channels.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.java.lang.Object
getAttribute(java.lang.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.long
getLastAccessTime()
long
getLastReadTime()
long
getLastWriteTime()
java.net.SocketAddress
getLocalAddress()
Returns local address.java.net.SocketAddress
getRemoteAddress()
Returns address of the remote peer.java.net.Socket
getSocket()
Return the underlying socketint
getSocketTimeout()
Returns value of the socket timeout in milliseconds.long
getStartedTime()
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.java.lang.Object
removeAttribute(java.lang.String name)
Removes attribute with the given name.void
setAttribute(java.lang.String name, java.lang.Object obj)
This method can be used to associate a particular object with the session by the given attribute name.void
setBufferStatus(SessionBufferStatus bufferStatus)
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 sessionvoid
setSocketTimeout(int timeout)
Sets value of the socket timeout in milliseconds.void
shutdown()
Terminates the session by shutting down the underlying I/O channel.java.lang.String
toString()
-
-
-
Constructor Detail
-
IOSessionImpl
public IOSessionImpl(java.nio.channels.SelectionKey key, org.apache.http.impl.nio.reactor.InterestOpsCallback interestOpsCallback, SessionClosedCallback sessionClosedCallback)
Creates new instance of IOSessionImpl.- Parameters:
key
- the selection key.interestOpsCallback
- interestOps callback.sessionClosedCallback
- session closed callback.- Since:
- 4.1
-
IOSessionImpl
public IOSessionImpl(java.nio.channels.SelectionKey key, SessionClosedCallback sessionClosedCallback)
Creates new instance of IOSessionImpl.- Parameters:
key
- the selection key.sessionClosedCallback
- session closed callback.
-
-
Method Detail
-
channel
public java.nio.channels.ByteChannel channel()
Description copied from interface:IOSession
Returns the underlying I/O channel associated with this session.
-
getLocalAddress
public java.net.SocketAddress getLocalAddress()
Description copied from interface:IOSession
Returns local address.- Specified by:
getLocalAddress
in interfaceIOSession
- Returns:
- socket address.
-
getRemoteAddress
public java.net.SocketAddress getRemoteAddress()
Description copied from interface:IOSession
Returns address of the remote peer.- Specified by:
getRemoteAddress
in interfaceIOSession
- Returns:
- socket address.
-
getEventMask
public int getEventMask()
Description copied from interface:IOSession
Returns mask of I/O evens this session declared interest in.- Specified by:
getEventMask
in interfaceIOSession
- Returns:
- I/O event mask.
-
setEventMask
public void setEventMask(int ops)
Description copied from interface:IOSession
Declares interest in I/O event notifications by setting the event mask associated with the session- Specified by:
setEventMask
in interfaceIOSession
- Parameters:
ops
- new I/O event mask.
-
setEvent
public void setEvent(int op)
Description copied from interface:IOSession
Declares interest in a particular I/O event type by updating the event mask associated with the session.
-
clearEvent
public void clearEvent(int op)
Description copied from interface:IOSession
Clears interest in a particular I/O event type by updating the event mask associated with the session.- Specified by:
clearEvent
in interfaceIOSession
- Parameters:
op
- I/O event type.
-
getSocketTimeout
public int getSocketTimeout()
Description copied from interface:IOSession
Returns value of the socket timeout in milliseconds. The value of0
signifies the session cannot time out.- Specified by:
getSocketTimeout
in interfaceIOSession
- Returns:
- socket timeout.
-
setSocketTimeout
public void setSocketTimeout(int timeout)
Description copied from interface:IOSession
Sets value of the socket timeout in milliseconds. The value of0
signifies the session cannot time out.- Specified by:
setSocketTimeout
in interfaceIOSession
- Parameters:
timeout
- socket timeout.
-
close
public void close()
Description copied from interface:IOSession
Terminates the session gracefully and closes the underlying I/O channel. This method ensures that session termination handshake, such as the one used by the SSL/TLS protocol, is correctly carried out.
-
getStatus
public int getStatus()
Description copied from interface:IOSession
Returns status of the session:IOSession.ACTIVE
: session is active.IOSession.CLOSING
: session is being closed.IOSession.CLOSED
: session has been terminated.
-
isClosed
public boolean isClosed()
Description copied from interface:IOSession
Determines if the session has been terminated.
-
shutdown
public void shutdown()
Description copied from interface:IOSession
Terminates the session by shutting down the underlying I/O channel.
-
hasBufferedInput
public boolean hasBufferedInput()
Description copied from interface:IOSession
Determines if the input buffer associated with the session contains data.- Specified by:
hasBufferedInput
in interfaceIOSession
- Returns:
true
if the session input buffer contains data,false
otherwise.
-
hasBufferedOutput
public boolean hasBufferedOutput()
Description copied from interface:IOSession
Determines if the output buffer associated with the session contains data.- Specified by:
hasBufferedOutput
in interfaceIOSession
- Returns:
true
if the session output buffer contains data,false
otherwise.
-
setBufferStatus
public void setBufferStatus(SessionBufferStatus bufferStatus)
Description copied from interface:IOSession
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. Memory management in HttpCore NIO is based on the fundamental principle that the data consumer can read only as much input data as it can process without having to allocate more memory. That means, quite often some input data may remain unread in one of the internal or external session buffers. The I/O reactor can query the status of these session buffers, and make sure the consumer gets notified correctly as more data gets stored in one of the session buffers, thus allowing the consumer to read the remaining data once it is able to process itI/O sessions can be made aware of the status of external session buffers using the
SessionBufferStatus
interface.- Specified by:
setBufferStatus
in interfaceIOSession
-
getAttribute
public java.lang.Object getAttribute(java.lang.String name)
Description copied from interface:IOSession
Returns the value of the attribute with the given name. The value can benull
if not set.The value of the session attachment object can be obtained using
IOSession.ATTACHMENT_KEY
name.- Specified by:
getAttribute
in interfaceIOSession
- Parameters:
name
- name of the attribute.- Returns:
- value of the attribute.
- See Also:
IOSession.setAttribute(String, Object)
-
removeAttribute
public java.lang.Object removeAttribute(java.lang.String name)
Description copied from interface:IOSession
Removes attribute with the given name.- Specified by:
removeAttribute
in interfaceIOSession
- Parameters:
name
- name of the attribute to be removed.- Returns:
- value of the removed attribute.
- See Also:
IOSession.setAttribute(String, Object)
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.Object obj)
Description copied from interface:IOSession
This method can be used to associate a particular object with the session by the given attribute name.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.
- Specified by:
setAttribute
in interfaceIOSession
- Parameters:
name
- name of the attribute.obj
- value of the attribute.
-
getStartedTime
public long getStartedTime()
-
getLastReadTime
public long getLastReadTime()
-
getLastWriteTime
public long getLastWriteTime()
-
getLastAccessTime
public long getLastAccessTime()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getSocket
public java.net.Socket getSocket()
Description copied from interface:SocketAccessor
Return the underlying socket- Specified by:
getSocket
in interfaceSocketAccessor
- Returns:
- - the underlying Socket, may be
null
.
-
-