|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sun.grizzly.NIOContext
public class NIOContext
This Object is used to share information between the Grizzly Framework
classes and ProtocolFilter
implementation. Since Context
is a pooled resource
Controller#pollContext(java.nio.channels.SelectionKey)
transactions using Context
outside its ProtocolChain
must invoke incrementRefCount()
and
Controller.returnContext(com.sun.grizzly.Context)
to keep its pooling
intact.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface com.sun.grizzly.Context |
---|
Context.AttributeScope, Context.KeyRegistrationState, Context.OpType |
Field Summary |
---|
Fields inherited from interface com.sun.grizzly.Context |
---|
THROWABLE |
Constructor Summary | |
---|---|
NIOContext()
Constructor |
Method Summary | |
---|---|
void |
cancel()
Cancel a suspend() ed Context . |
void |
configureOpType(SelectionKey key)
Configure the currentOpType based on the
SelectionKey.readyOps() values. |
void |
copyTo(Copyable copy)
Copies current object content to copy object |
int |
decrementRefCount()
Decrements the reference count of this Context . |
void |
execute()
Deprecated. |
void |
execute(ContextTask contextTask)
Execute this Context using the Controller's thread pool |
void |
execute(ContextTask contextTask,
boolean runInSeparateThread)
Execute this Context using either Controller's thread pool or current thread |
AsyncQueueReadable |
getAsyncQueueReadable()
Returns AsyncQueueReadable , assciated with the current
Context . |
AsyncQueueReader |
getAsyncQueueReader()
Return the |
AsyncQueueReaderContextTask |
getAsyncQueueReaderContextTask(AsyncQueueReader asyncQueueReader)
|
AsyncQueueWritable |
getAsyncQueueWritable()
Returns AsyncQueueWritable , assciated with the current
Context . |
protected AsyncQueueWriter |
getAsyncQueueWriter()
Return the |
AsyncQueueWriterContextTask |
getAsyncQueueWriterContextTask(AsyncQueueWriter asyncQueueWriter)
|
Object |
getAttribute(String key)
Return an object based on a key. |
AttributeHolder |
getAttributeHolderByScope(Context.AttributeScope scope)
Return AttributeHolder , which corresponds to the
given AttributeScope > |
Map<String,Object> |
getAttributes()
Return a Map of attribute name/value pairs. |
CallbackHandlerContextTask |
getCallbackHandlerContextTask(CallbackHandler callbackHandler)
|
Controller |
getController()
Return the current Controller . |
Context.OpType |
getCurrentOpType()
Get the current SelectionKey interest ops this instance is executing. |
IOEvent |
getIOEvent()
Return the current IOEvent associated with this
instance. |
Context.KeyRegistrationState |
getKeyRegistrationState()
Return SelectionKey 's next registration state. |
Controller.Protocol |
getProtocol()
Return the current Controller#Protocol this instance is executing. |
ProtocolChain |
getProtocolChain()
Return ProtocolChain executed by this instance. |
ProtocolChainContextTask |
getProtocolChainContextTask()
|
ProtocolChainInstanceHandler |
getProtocolChainInstanceHandler()
Return the ProtocolChainInstanceListener associated with this
Context |
SelectionKey |
getSelectionKey()
Return the current SelectionKey . |
SelectorHandler |
getSelectorHandler()
Return the current SelectorHandler this instance is executing, or
null if not supported. |
ExecutorService |
getThreadPool()
Return the ExecutorService executing this instance. |
void |
incrementRefCount()
Called by outer Threads that are not instances of WorkerThread to
indicate that this Context should not be
recycle() or offered back to its pool. |
boolean |
isSuspended()
Return true if this Context has been suspended by invoking suspend . |
void |
recycle()
Recycle this instance. |
Object |
removeAttribute(String key)
Remove a key/value object. |
void |
resume()
Resume a suspend() ed Context . |
protected void |
setAsyncQueueReader(AsyncQueueReader asyncQueueReader)
Set the |
protected void |
setAsyncQueueWriter(AsyncQueueWriter asyncQueueWriter)
Set the |
void |
setAttribute(String key,
Object value)
Set a key/value object. |
void |
setAttributes(Map<String,Object> attributes)
Set a Map of attribute name/value pairs. |
void |
setController(Controller controller)
Set the current Controller . |
void |
setCurrentOpType(Context.OpType currentOpType)
Set the current OpType value. |
void |
setIOEvent(IOEvent<Context> ioEvent)
Set an optional CallbackHandler. |
void |
setKeyRegistrationState(Context.KeyRegistrationState keyRegistrationState)
Set the SelectionKey 's next registration state |
void |
setProtocol(Controller.Protocol protocol)
|
void |
setProtocolChain(ProtocolChain protocolChain)
Set the ProtocolChain used by this Context . |
void |
setSelectionKey(SelectionKey key)
Set the connection SelectionKey . |
void |
setSelectorHandler(SelectorHandler selectorHandler)
Set the current SelectorHandler this instance is executing. |
void |
setThreadPool(ExecutorService threadPool)
Set the ExecutorService that will execute this instance. |
void |
suspend()
Suspend the execution of this Context . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public NIOContext()
Method Detail |
---|
public void copyTo(Copyable copy)
Copyable
copyTo
in interface Copyable
copy
- represents target object, where current object's content will be copiedpublic ProtocolChainContextTask getProtocolChainContextTask()
public CallbackHandlerContextTask getCallbackHandlerContextTask(CallbackHandler callbackHandler)
public AsyncQueueReaderContextTask getAsyncQueueReaderContextTask(AsyncQueueReader asyncQueueReader)
public AsyncQueueWriterContextTask getAsyncQueueWriterContextTask(AsyncQueueWriter asyncQueueWriter)
public Object removeAttribute(String key)
removeAttribute
in interface Context
removeAttribute
in interface AttributeHolder
key
- - name of an attribute
public void setAttribute(String key, Object value)
setAttribute
in interface AttributeHolder
key
- - name of an attributevalue
- - value of named attributepublic Object getAttribute(String key)
getAttribute
in interface AttributeHolder
key
- - name of an attribute
public AttributeHolder getAttributeHolderByScope(Context.AttributeScope scope)
AttributeHolder
, which corresponds to the
given AttributeScope
>
getAttributeHolderByScope
in interface Context
scope
- - AttributeScope
>
AttributeHolder
instance, which contains
AttributeScope
> attributespublic void setAttributes(Map<String,Object> attributes)
Map
of attribute name/value pairs.
Old AttributeHolder
values will not be available.
Later changes of this Map
will lead to changes to the current
AttributeHolder
.
setAttributes
in interface Context
setAttributes
in interface AttributeHolder
attributes
- - map of name/value pairspublic Map<String,Object> getAttributes()
Map
of attribute name/value pairs.
Updates, performed on the returned Map
will be reflected in
this AttributeHolder
getAttributes
in interface Context
getAttributes
in interface AttributeHolder
Map
of attribute name/value pairspublic SelectionKey getSelectionKey()
SelectionKey
.
getSelectionKey
in interface Context
public void setSelectionKey(SelectionKey key)
SelectionKey
.
key
- - set this Context's SelectionKeypublic Controller getController()
Controller
.
getController
in interface Context
Controller
public void setController(Controller controller)
Controller
.
{@link
- Controller}public void recycle()
recycle
in interface Context
public Context.KeyRegistrationState getKeyRegistrationState()
SelectionKey
's next registration state.
getKeyRegistrationState
in interface Context
public void setKeyRegistrationState(Context.KeyRegistrationState keyRegistrationState)
SelectionKey
's next registration state
setKeyRegistrationState
in interface Context
{@link
- keyRegistrationState} - set this Context's SelectionKey
registration statepublic ProtocolChain getProtocolChain()
ProtocolChain
executed by this instance.
getProtocolChain
in interface Context
ProtocolChain
instancepublic void setProtocolChain(ProtocolChain protocolChain)
ProtocolChain
used by this Context
.
setProtocolChain
in interface Context
protocolChain
- instance of ProtocolChain
to be used by the Contextpublic Context.OpType getCurrentOpType()
SelectionKey
interest ops this instance is executing.
getCurrentOpType
in interface Context
public void setCurrentOpType(Context.OpType currentOpType)
currentOpType
- sets current operation typepublic void configureOpType(SelectionKey key)
currentOpType
based on the
SelectionKey.readyOps()
values.
key
- public void execute()
execute
in interface Context
public void execute(ContextTask contextTask)
execute
in interface Context
contextTask
- ContextTask
, which will be
executed by ExecutorService
public void execute(ContextTask contextTask, boolean runInSeparateThread)
execute
in interface Context
contextTask
- ContextTask
, which will be
executed by ExecutorService
runInSeparateThread
- if true - ContextTask
will
be executed in separate thread, false - in current thread.public ProtocolChainInstanceHandler getProtocolChainInstanceHandler()
ProtocolChainInstanceListener
associated with this
Context
public ExecutorService getThreadPool()
ExecutorService
executing this instance.
getThreadPool
in interface Context
ExecutorService
public void setThreadPool(ExecutorService threadPool)
ExecutorService
that will execute this instance.
setThreadPool
in interface Context
threadPool
- the ExecutorService
to setpublic void setIOEvent(IOEvent<Context> ioEvent)
setIOEvent
in interface Context
ioEvent
- the IOEvent
to setpublic IOEvent getIOEvent()
IOEvent
associated with this
instance.
getIOEvent
in interface Context
IOEvent
associated with this
instance.public Controller.Protocol getProtocol()
Controller#Protocol
this instance is executing.
getProtocol
in interface Context
public void setProtocol(Controller.Protocol protocol)
protocol
- The current protocol.public SelectorHandler getSelectorHandler()
Context
SelectorHandler
this instance is executing, or
null if not supported.
getSelectorHandler
in interface Context
SelectorHandler
this instance is executing.public void setSelectorHandler(SelectorHandler selectorHandler)
SelectorHandler
this instance is executing.
selectorHandler
- SelectorHandler
public AsyncQueueReadable getAsyncQueueReadable()
AsyncQueueReadable
, assciated with the current
Context
. This method is not threadsafe.
AsyncQueueReadable
public AsyncQueueWritable getAsyncQueueWritable()
AsyncQueueWritable
, assciated with the current
Context
. This method is not threadsafe.
getAsyncQueueWritable
in interface Context
AsyncQueueWritable
public AsyncQueueReader getAsyncQueueReader()
getAsyncQueueReader
in interface Context
protected void setAsyncQueueReader(AsyncQueueReader asyncQueueReader)
asyncQueueReader
- protected AsyncQueueWriter getAsyncQueueWriter()
protected void setAsyncQueueWriter(AsyncQueueWriter asyncQueueWriter)
asyncQueueWriter
- public void suspend()
Context
. Suspending the execution
allow application to store the current instance, and re-use it later
by not only the Thread used when called suspend, but also from any other Thread.
A suspended Context will not be re-used by any other transaction and Thread.
A suspended Context will keep its current state intact, meaning its
SelectionKey, attributes, SelectorHandler, etc, will not change. Internally,
The Context will not be recyled and will not be re-used by any Thread.
When invoked this method will automatically set the
Context.setKeyRegistrationState(com.sun.grizzly.Context.KeyRegistrationState)
to KeyRegistrationState
to KeyRegistrationState.NONE.
Invoking this method many times as not effect once suspended.
suspend
in interface Context
public boolean isSuspended()
suspend
. When suspended, invoking Context.recycle()
will throw an IllegalStateException
isSuspended
in interface Context
public void resume()
suspend()
ed Context
.
Resume will not call Context.recycle()
. So
after the caller is finished using Context caller must
call Controller.returnContext(com.sun.grizzly.Context)
to mark it as a candidate for being re-used by another Thread and connection.
Important. When resumed, all operations done on this
object are not thread-safe and there is probability that another
thread is already using this object. Never use this object once resumed.
When invoked this method will automatically set the
Context.setKeyRegistrationState(com.sun.grizzly.Context.KeyRegistrationState)
to KeyRegistrationState
to KeyRegistrationState.REGISTER and automatically re-enable read and
write operations.
If the Context hasn't been suspended, calling that method has no effet.
resume
in interface Context
public void cancel()
suspend()
ed Context
. Invoking this method will
automatically clean the state of this Context and mark it as a candidate
for being re-used by another Thread and connection.
Important. When cancelled, all operations done on this
object are not thread-safe and there is probability that another
thread is already using this object. Never use this object once cancelled.
When invoked this method will automatically close the underlying
connection (represented by its SelectionKey
.
If the Context hasn't been suspended, calling that method has no effet.
cancel
in interface Context
public void incrementRefCount()
WorkerThread
to
indicate that this Context
should not be
recycle()
or offered back to its pool.
When a outer Thread is done with Context
it must call
Controller#returnContext(com.sun.grizzly.Context) to
ensure that {@link Context} will be properly recycled.
incrementRefCount
in interface Context
public int decrementRefCount()
Context
.
Threads wanting to release Context
should not call
this method but instead use
Controller.returnContext(com.sun.grizzly.Context)
decrementRefCount
in interface Context
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |