## com.sun.grizzly
Class Context

    java.lang.Object
      com.sun.grizzly.Context

All Implemented Interfaces:
  AttributeHolder, Copyable

    public class Context

extends Object
implements AttributeHolder, Copyable

This Object is used to share information between the Grizzly Framework classes and `ProtocolFilter` implementation.

Author:
  Jeanfrancois Arcand

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

Constructor Summary
`Context()` Constructor

Method Summary
`protected void` `configureOpType(SelectionKey key)` Configure the `currentOpType` based on the `SelectionKey.readyOps()` values.
`void` `copyTo(Copyable copy)` Copies current object content to copy object
`void` `execute()` Deprecated.
`void` `execute(ContextTask contextTask)` Execute this Context using the Controller's Pipeline
`void` `execute(ContextTask contextTask, boolean runInSeparateThread)` Execute this Context using either Controller's Pipeline or current thread
`AsyncQueueReadable` `getAsyncQueueReadable()` Returns `AsyncQueueReadable`, assciated with the current `Context`.
`protected 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 `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.
`protected IOEvent` `getIOEvent()` Return the current `IOEvent` associated with this instance.
`Context.KeyRegistrationState` `getKeyRegistrationState()` Return `SelectionKey`'s next registration state.
`Pipeline` `getPipeline()` Return the `Pipeline` executing this instance.
`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.
`void` `recycle()` Recycle this instance.
`Object` `removeAttribute(String key)` Remove a key/value object.
`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.
`protected void` `setIOEvent(IOEvent<Context> ioEvent)` Set an optional CallbackHandler.
`void` `setKeyRegistrationState(Context.KeyRegistrationState keyRegistrationState)` Set the `SelectionKey`'s next registration state
`void` `setPipeline(Pipeline pipeline)` Set the `Pipeline` that will execute this instance.
`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.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### THROWABLE

    public static final String THROWABLE

  Constant 'throwable' String

  See Also:
    Constant Field Values

Constructor Detail

### Context

    public Context()

  Constructor

Method Detail

### copyTo

    public void copyTo(Copyable copy)

  Description copied from interface: `Copyable`
  Copies current object content to copy object

  Specified by:
    `copyTo` in interface `Copyable`
  Parameters:
    `copy` - represents target object, where current object's content will be copied

### removeAttribute

    public Object removeAttribute(String key)

  Remove a key/value object.

  Specified by:
    `removeAttribute` in interface `AttributeHolder`
  Parameters:
    `key` - - name of an attribute
  Returns:
    attribute which has been removed

### setAttribute

    public void setAttribute(String key,
                             Object value)

  Set a key/value object.

  Specified by:
    `setAttribute` in interface `AttributeHolder`
  Parameters:
    `key` - - name of an attribute
    `value` - - value of named attribute

### getAttribute

    public Object getAttribute(String key)

  Return an object based on a key.

  Specified by:
    `getAttribute` in interface `AttributeHolder`
  Parameters:
    `key` - - name of an attribute
  Returns:
    - attribute value for the `key`, null if `key` does not exist in `attributes`

### getAttributeHolderByScope

    public AttributeHolder getAttributeHolderByScope(Context.AttributeScope scope)

  Return `AttributeHolder`, which corresponds to the given `Context.AttributeScope`>

  Parameters:
    `scope` - - `Context.AttributeScope`>
  Returns:
    - `AttributeHolder` instance, which contains `Context.AttributeScope`> attributes

### setAttributes

    public void setAttributes(Map<String,Object> attributes)

  Set a `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`.

  Specified by:
    `setAttributes` in interface `AttributeHolder`
  Parameters:
    `attributes` - - map of name/value pairs

### getAttributes

    public Map<String,Object> getAttributes()

  Return a `Map` of attribute name/value pairs. Updates, performed on the returned `Map` will be reflected in this `AttributeHolder`

  Specified by:
    `getAttributes` in interface `AttributeHolder`
  Returns:
    - `Map` of attribute name/value pairs

### getSelectionKey

    public SelectionKey getSelectionKey()

  Return the current `SelectionKey`.

  Returns:
    - this Context's SelectionKey

### setSelectionKey

    public void setSelectionKey(SelectionKey key)

  Set the connection `SelectionKey`.

  Parameters:
    `key` - - set this Context's SelectionKey

### getController

    public Controller getController()

  Return the current `Controller`.

  Returns:
    - this Context's current `Controller`

### setController

    public void setController(Controller controller)

  Set the current `Controller`.

  Parameters:
    `{@link` - Controller}

### recycle

    public void recycle()

  Recycle this instance.

### getKeyRegistrationState

    public Context.KeyRegistrationState getKeyRegistrationState()

  Return `SelectionKey`'s next registration state.

  Returns:
    this Context's SelectionKey registration state

### setKeyRegistrationState

    public void setKeyRegistrationState(Context.KeyRegistrationState keyRegistrationState)

  Set the `SelectionKey`'s next registration state

  Parameters:
    `{@link` - keyRegistrationState} - set this Context's SelectionKey registration state

### getProtocolChain

    public ProtocolChain getProtocolChain()

  Return `ProtocolChain` executed by this instance.

  Returns:
    `ProtocolChain` instance

### setProtocolChain

    public void setProtocolChain(ProtocolChain protocolChain)

  Set the `ProtocolChain` used by this `Context`.

  Parameters:
    `protocolChain` - instance of `ProtocolChain` to be used by the Context

### getCurrentOpType

    public Context.OpType getCurrentOpType()

  Get the current `SelectionKey` interest ops this instance is executing.

  Returns:
    OpType the currentOpType.

### setCurrentOpType

    public void setCurrentOpType(Context.OpType currentOpType)

  Set the current OpType value.

  Parameters:
    `currentOpType` - sets current operation type

### configureOpType

    protected void configureOpType(SelectionKey key)

  Configure the `currentOpType` based on the `SelectionKey.readyOps()` values.

  Parameters:
    `key` -

### execute

    public void execute()
                 throws PipelineFullException

  Deprecated.

  Execute this Context using the Controller's Pipeline

  Throws:
    `{@link` - PipelineFullException}
    `PipelineFullException`

### execute

    public void execute(ContextTask contextTask)
                 throws PipelineFullException

  Execute this Context using the Controller's Pipeline

  Parameters:
    `contextTask` - `ContextTask`, which will be executed by `Pipeline`
  Throws:
    `{@link` - PipelineFullException}
    `PipelineFullException`

### execute

    public void execute(ContextTask contextTask,
                        boolean runInSeparateThread)
                 throws PipelineFullException

  Execute this Context using either Controller's Pipeline or current thread

  Parameters:
    `contextTask` - `ContextTask`, which will be executed by `Pipeline`
    `runInSeparateThread` - if true - `ContextTask` will be executed in separate thread, false - in current thread.
  Throws:
    `{@link` - PipelineFullException}
    `PipelineFullException`

### getProtocolChainInstanceHandler

    public ProtocolChainInstanceHandler getProtocolChainInstanceHandler()

  Return the `ProtocolChainInstanceListener` associated with this `Context`

  Returns:
    ProtocolChainInstanceListener

### getPipeline

    public Pipeline getPipeline()

  Return the `Pipeline` executing this instance.

  Returns:
    `Pipeline`

### setPipeline

    public void setPipeline(Pipeline pipeline)

  Set the `Pipeline` that will execute this instance.

  Parameters:
    `pipeline` - the `Pipeline` to set

### setIOEvent

    protected void setIOEvent(IOEvent<Context> ioEvent)

  Set an optional CallbackHandler.

  Parameters:
    `ioEvent` - the `IOEvent` to set

### getIOEvent

    protected IOEvent getIOEvent()

  Return the current `IOEvent` associated with this instance.

  Returns:
    IOEvent the current `IOEvent` associated with this instance.

### getProtocol

    public Controller.Protocol getProtocol()

  Return the current `Controller#Protocol` this instance is executing.

  Returns:
    the current Controller.Protocol this instance is executing.

### setProtocol

    public void setProtocol(Controller.Protocol protocol)

  Parameters:
    `protocol` - The current protocol.

### getSelectorHandler

    public SelectorHandler getSelectorHandler()

  Return the current `SelectorHandler` this instance is executing.

  Returns:
    the current `SelectorHandler` this instance is executing.

### setSelectorHandler

    public void setSelectorHandler(SelectorHandler selectorHandler)

  Set the current `SelectorHandler` this instance is executing.

  Parameters:
    `selectorHandler` - `SelectorHandler`

### getAsyncQueueReadable

    public AsyncQueueReadable getAsyncQueueReadable()

  Returns `AsyncQueueReadable`, assciated with the current `Context`. This method is not threadsafe.

  Returns:
    `AsyncQueueReadable`

### getAsyncQueueWritable

    public AsyncQueueWritable getAsyncQueueWritable()

  Returns `AsyncQueueWritable`, assciated with the current `Context`. This method is not threadsafe.

  Returns:
    `AsyncQueueWritable`

### getAsyncQueueReader

    protected AsyncQueueReader getAsyncQueueReader()

  Return the

  Returns:
    the

### setAsyncQueueReader

    protected void setAsyncQueueReader(AsyncQueueReader asyncQueueReader)

  Set the

  Parameters:
    `asyncQueueReader` -

### getAsyncQueueWriter

    protected AsyncQueueWriter getAsyncQueueWriter()

  Return the

  Returns:
    the

### setAsyncQueueWriter

    protected void setAsyncQueueWriter(AsyncQueueWriter asyncQueueWriter)

  Set the

  Parameters:
    `asyncQueueWriter` -

Copyright © 2008 SUN Microsystems. All Rights Reserved.