|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Context
This interface 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 | |
---|---|
static class |
Context.AttributeScope
|
static class |
Context.KeyRegistrationState
A SelectionKey 's registration state. |
static class |
Context.OpType
The list of possible SelectionKey .OP_XXXX. |
Field Summary | |
---|---|
static String |
THROWABLE
Constant 'throwable' String |
Method Summary | |
---|---|
void |
cancel()
Cancel a suspend() ed Context . |
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 |
AsyncQueueReader |
getAsyncQueueReader()
Return the |
AsyncQueueWritable |
getAsyncQueueWritable()
Returns AsyncQueueWritable , assciated with the current
Context . |
AttributeHolder |
getAttributeHolderByScope(Context.AttributeScope scope)
Return AttributeHolder , which corresponds to the
given Context.AttributeScope > |
Map<String,Object> |
getAttributes()
Return a Map of attribute name/value pairs. |
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, or null
if not supported. |
Controller.Protocol |
getProtocol()
Return the current Controller#Protocol this instance is executing. |
ProtocolChain |
getProtocolChain()
Return ProtocolChain executed by this instance. |
SelectionKey |
getSelectionKey()
Return the current SelectionKey or null if
{@link SelectionKey aren't supported. |
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 . |
void |
setAttributes(Map<String,Object> attributes)
Set a Map of attribute name/value pairs. |
void |
setIOEvent(IOEvent<Context> ioEvent)
Set an optional CallbackHandler. |
void |
setKeyRegistrationState(Context.KeyRegistrationState keyRegistrationState)
Set the SelectionKey 's next registration state |
void |
setProtocolChain(ProtocolChain protocolChain)
Set the ProtocolChain used by this Context . |
void |
setThreadPool(ExecutorService threadPool)
Set the ExecutorService that will execute this instance. |
void |
suspend()
Suspend the execution of this Context . |
Methods inherited from interface com.sun.grizzly.util.AttributeHolder |
---|
getAttribute, setAttribute |
Methods inherited from interface com.sun.grizzly.util.Copyable |
---|
copyTo |
Field Detail |
---|
static final String THROWABLE
Method Detail |
---|
IOEvent getIOEvent()
IOEvent
associated with this
instance.
IOEvent
associated with this
instance.Context.OpType getCurrentOpType()
SelectionKey
interest ops this instance is executing.
Controller getController()
Controller
.
Controller
void execute()
void execute(ContextTask contextTask)
contextTask
- ContextTask
, which will be
executed by ExecutorService
void execute(ContextTask contextTask, boolean runInSeparateThread)
contextTask
- ContextTask
, which will be
executed by ExecutorService
runInSeparateThread
- if true - ContextTask
will
be executed in separate thread, false - in current thread.void recycle()
SelectionKey getSelectionKey()
SelectionKey
or null if
{@link SelectionKey aren't supported.
Controller.Protocol getProtocol()
Controller#Protocol
this instance is executing.
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.
ProtocolChain getProtocolChain()
ProtocolChain
executed by this instance.
ProtocolChain
instancevoid setIOEvent(IOEvent<Context> ioEvent)
ioEvent
- the IOEvent
to setContext.KeyRegistrationState getKeyRegistrationState()
SelectionKey
's next registration state, or null
if not supported.
SelectorHandler getSelectorHandler()
SelectorHandler
this instance is executing, or
null if not supported.
SelectorHandler
this instance is executing.Object removeAttribute(String key)
removeAttribute
in interface AttributeHolder
key
- - name of an attribute
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 AttributeHolder
attributes
- - map of name/value pairsMap<String,Object> getAttributes()
Map
of attribute name/value pairs.
Updates, performed on the returned Map
will be reflected in
this AttributeHolder
getAttributes
in interface AttributeHolder
Map
of attribute name/value pairsvoid setKeyRegistrationState(Context.KeyRegistrationState keyRegistrationState)
SelectionKey
's next registration state
{@link
- keyRegistrationState} - set this Context's SelectionKey
registration stateAsyncQueueWritable getAsyncQueueWritable()
AsyncQueueWritable
, assciated with the current
Context
. This method is not threadsafe.
AsyncQueueWritable
AsyncQueueReader getAsyncQueueReader()
AttributeHolder getAttributeHolderByScope(Context.AttributeScope scope)
AttributeHolder
, which corresponds to the
given Context.AttributeScope
>
scope
- - Context.AttributeScope
>
AttributeHolder
instance, which contains
Context.AttributeScope
> attributesExecutorService getThreadPool()
ExecutorService
executing this instance.
ExecutorService
void setThreadPool(ExecutorService threadPool)
ExecutorService
that will execute this instance.
thread
- pool the ExecutorService
to setvoid setProtocolChain(ProtocolChain protocolChain)
ProtocolChain
used by this Context
.
protocolChain
- instance of ProtocolChain
to be used by the Contextvoid 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
setKeyRegistrationState(com.sun.grizzly.Context.KeyRegistrationState)
to Context.KeyRegistrationState
to KeyRegistrationState.NONE.
Invoking this method many times as not effect once suspended.
boolean isSuspended()
suspend
. When suspended, invoking recycle()
will throw an IllegalStateException
void resume()
suspend()
ed Context
.
Resume will not call 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
setKeyRegistrationState(com.sun.grizzly.Context.KeyRegistrationState)
to Context.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.
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.
int decrementRefCount()
Context
.
Threads wanting to release Context
should not call
this method but instead use
Controller.returnContext(com.sun.grizzly.Context)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |