|
||||||||||
| 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. |
protected void |
configureOpType(SelectionKey key)
Configure the currentOpType based on the
SelectionKey.readyOps() values. |
void |
copyTo(Copyable copy)
|
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 |
AsyncQueueWritable |
getAsyncQueueWritable()
Returns AsyncQueueWritable, assciated with the current
Context. |
protected AsyncQueueWriter |
getAsyncQueueWriter()
Return the |
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. |
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. |
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)
copyTo in interface Copyablepublic Object removeAttribute(String key)
removeAttribute in interface ContextremoveAttribute in interface AttributeHolderkey - - name of an attribute
public void setAttribute(String key,
Object value)
setAttribute in interface AttributeHolderkey - - name of an attributevalue - - value of named attributepublic Object getAttribute(String key)
getAttribute in interface AttributeHolderkey - - name of an attribute
public AttributeHolder getAttributeHolderByScope(Context.AttributeScope scope)
AttributeHolder, which corresponds to the
given AttributeScope>
getAttributeHolderByScope in interface Contextscope - - 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 ContextsetAttributes in interface AttributeHolderattributes - - 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 ContextgetAttributes in interface AttributeHolderMap of attribute name/value pairspublic SelectionKey getSelectionKey()
SelectionKey.
getSelectionKey in interface Contextpublic void setSelectionKey(SelectionKey key)
SelectionKey.
key - - set this Context's SelectionKeypublic Controller getController()
Controller.
getController in interface ContextControllerpublic void setController(Controller controller)
Controller.
{@link - Controller}public void recycle()
recycle in interface Contextpublic Context.KeyRegistrationState getKeyRegistrationState()
SelectionKey's next registration state.
getKeyRegistrationState in interface Contextpublic 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 ContextProtocolChain instancepublic void setProtocolChain(ProtocolChain protocolChain)
ProtocolChain used by this Context.
setProtocolChain in interface ContextprotocolChain - instance of ProtocolChain to be used by the Contextpublic Context.OpType getCurrentOpType()
SelectionKey interest ops this instance is executing.
getCurrentOpType in interface Contextpublic void setCurrentOpType(Context.OpType currentOpType)
currentOpType - sets current operation typeprotected void configureOpType(SelectionKey key)
currentOpType based on the
SelectionKey.readyOps() values.
key - public void execute()
execute in interface Contextpublic void execute(ContextTask contextTask)
execute in interface ContextcontextTask - ContextTask, which will be
executed by ExecutorService
public void execute(ContextTask contextTask,
boolean runInSeparateThread)
execute in interface ContextcontextTask - ContextTask, which will be
executed by ExecutorServicerunInSeparateThread - 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 ContextExecutorServicepublic void setThreadPool(ExecutorService threadPool)
ExecutorService that will execute this instance.
setThreadPool in interface ContextthreadPool - the ExecutorService to setpublic void setIOEvent(IOEvent<Context> ioEvent)
setIOEvent in interface ContextioEvent - the IOEvent to setpublic IOEvent getIOEvent()
IOEvent associated with this
instance.
getIOEvent in interface ContextIOEvent associated with this
instance.public Controller.Protocol getProtocol()
Controller#Protocol this instance is executing.
getProtocol in interface Contextpublic void setProtocol(Controller.Protocol protocol)
protocol - The current protocol.public SelectorHandler getSelectorHandler()
ContextSelectorHandler this instance is executing, or
null if not supported.
getSelectorHandler in interface ContextSelectorHandler this instance is executing.public void setSelectorHandler(SelectorHandler selectorHandler)
SelectorHandler this instance is executing.
selectorHandler - SelectorHandlerpublic AsyncQueueReadable getAsyncQueueReadable()
AsyncQueueReadable, assciated with the current
Context. This method is not threadsafe.
AsyncQueueReadablepublic AsyncQueueWritable getAsyncQueueWritable()
AsyncQueueWritable, assciated with the current
Context. This method is not threadsafe.
getAsyncQueueWritable in interface ContextAsyncQueueWritablepublic AsyncQueueReader getAsyncQueueReader()
getAsyncQueueReader in interface Contextprotected 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 Contextpublic boolean isSuspended()
suspend. When suspended, invoking Context.recycle()
will throw an IllegalStateException
isSuspended in interface Contextpublic 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 Contextpublic 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 Contextpublic 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 Contextpublic 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 | |||||||||