org.glassfish.grizzly.filterchain
Class FilterChainContext

java.lang.Object
  extended by org.glassfish.grizzly.filterchain.FilterChainContext
All Implemented Interfaces:
AttributeStorage

public final class FilterChainContext
extends java.lang.Object
implements AttributeStorage

FilterChain Context implementation.

Author:
Alexey Stashok
See Also:
Context, FilterChain

Nested Class Summary
static interface FilterChainContext.CompletionListener
          The interface, which represents a listener, which will be notified, once FilterChainContext processing is complete.
static interface FilterChainContext.CopyListener
          The interface, which represents a listener, which will be notified, after copy() is called.
static class FilterChainContext.Operation
           
static class FilterChainContext.State
           
static class FilterChainContext.TransportContext
           
 
Field Summary
protected  FilterChainEvent event
          Context associated event, if EVENT operation
static int NO_FILTER_INDEX
           
protected  CompletionHandler<FilterChainContext> operationCompletionHandler
          CompletionHandler, which will be notified, when operation will be complete.
 
Constructor Summary
FilterChainContext()
           
 
Method Summary
 void addCompletionListener(FilterChainContext.CompletionListener listener)
          Add the FilterChainContext.CompletionListener, which will be notified, when this FilterChainContext processing will be completed.
 void addCopyListener(FilterChainContext.CopyListener listener)
          Add the FilterChainContext.CopyListener, which will be notified, right after this copy() is called.
 void completeAndRecycle()
           
 FilterChainContext copy()
           
static FilterChainContext create(Connection connection)
           
 void fail(java.lang.Throwable error)
           
 void flush(CompletionHandler completionHandler)
           
 java.lang.Object getAddress()
          Get address, associated with the current IOEvent processing.
 AttributeHolder getAttributes()
          Get associated AttributeHolder.
 Connection getConnection()
          Get the Connection, associated with the current processing.
 int getEndIdx()
           
 FilterChain getFilterChain()
          Get FilterChain, which runs the Filter.
 int getFilterIdx()
           
 NextAction getForkAction()
           
 Context getInternalContext()
          Get the general Grizzly Context this filter context wraps.
 NextAction getInvokeAction()
          Get NextAction implementation, which instructs FilterChain to process next Filter in chain.
 NextAction getInvokeAction(java.lang.Object remainder)
          Get NextAction implementation, which instructs FilterChain to process next Filter in chain.
 MemoryManager getMemoryManager()
          A simple alias for FilterChainContext.getConnection().getTransport().getMemoryManager().
<T> T
getMessage()
          Get message object, associated with the current processing.
 NextAction getRerunFilterAction()
          Get NextAction, which instructs FilterChain to rerun the filter.
protected  java.lang.Runnable getRunnable()
           
 int getStartIdx()
           
 NextAction getStopAction()
          Get NextAction implementation, which instructs FilterChain to stop executing phase.
 NextAction getStopAction(Appendable appendable)
          Get NextAction implementation, which instructs FilterChain stop executing phase.
<E> NextAction
getStopAction(E remainder, Appender<E> appender)
          Get NextAction implementation, which instructs FilterChain stop executing phase.
 NextAction getStopAction(java.lang.Object unknownObject)
          Get NextAction implementation, which instructs FilterChain stop executing phase.
 NextAction getSuspendAction()
          Get NextAction, which instructs FilterChain to suspend filter chain execution.
 NextAction getSuspendingStopAction()
          Deprecated. use getForkAction()
 FilterChainContext.TransportContext getTransportContext()
          Get the TransportFilter related context.
 int nextFilterIdx()
           
 void notifyDownstream(FilterChainEvent event)
           
 void notifyDownstream(FilterChainEvent event, CompletionHandler<FilterChainContext> completionHandler)
           
 void notifyUpstream(FilterChainEvent event)
           
 void notifyUpstream(FilterChainEvent event, CompletionHandler<FilterChainContext> completionHandler)
           
 int previousFilterIdx()
           
 ReadResult read()
           Performs a blocking read.
 boolean removeCompletionListener(FilterChainContext.CompletionListener listener)
          Remove the FilterChainContext.CompletionListener.
 boolean removeCopyListener(FilterChainContext.CopyListener listener)
          Remove the FilterChainContext.CopyListener.
 void reset()
          Release the context associated resources.
 void resume()
          Resume processing of the current task
 void setAddress(java.lang.Object address)
          Set address, associated with the current IOEvent processing.
 void setEndIdx(int endIdx)
           
 void setFilterIdx(int index)
           
 void setMessage(java.lang.Object message)
          Set message object, associated with the current processing.
 void setStartIdx(int startIdx)
           
 FilterChainContext.State state()
          Get the current processing task state.
 java.lang.Runnable suspend()
          Suspend processing of the current task
 java.lang.String toString()
           
 void write(java.lang.Object message)
           
 void write(java.lang.Object message, boolean blocking)
           
 void write(java.lang.Object message, CompletionHandler<WriteResult> completionHandler)
           
 void write(java.lang.Object message, CompletionHandler<WriteResult> completionHandler, boolean blocking)
           
 void write(java.lang.Object address, java.lang.Object message, CompletionHandler<WriteResult> completionHandler)
           
 void write(java.lang.Object address, java.lang.Object message, CompletionHandler<WriteResult> completionHandler, boolean blocking)
           
 void write(java.lang.Object address, java.lang.Object message, CompletionHandler<WriteResult> completionHandler, PushBackHandler pushBackHandler)
           
 void write(java.lang.Object address, java.lang.Object message, CompletionHandler<WriteResult> completionHandler, PushBackHandler pushBackHandler, boolean blocking)
           
 void write(java.lang.Object address, java.lang.Object message, CompletionHandler<WriteResult> completionHandler, PushBackHandler pushBackHandler, MessageCloner cloner)
           
 void write(java.lang.Object address, java.lang.Object message, CompletionHandler<WriteResult> completionHandler, PushBackHandler pushBackHandler, MessageCloner cloner, boolean blocking)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NO_FILTER_INDEX

public static final int NO_FILTER_INDEX
See Also:
Constant Field Values

operationCompletionHandler

protected CompletionHandler<FilterChainContext> operationCompletionHandler
CompletionHandler, which will be notified, when operation will be complete. For WRITE it means the data will be written on wire, for other operations - the last Filter has finished the processing.


event

protected FilterChainEvent event
Context associated event, if EVENT operation

Constructor Detail

FilterChainContext

public FilterChainContext()
Method Detail

create

public static FilterChainContext create(Connection connection)

suspend

public java.lang.Runnable suspend()
Suspend processing of the current task


resume

public void resume()
Resume processing of the current task


state

public FilterChainContext.State state()
Get the current processing task state.

Returns:
the current processing task state.

nextFilterIdx

public int nextFilterIdx()

previousFilterIdx

public int previousFilterIdx()

getFilterIdx

public int getFilterIdx()

setFilterIdx

public void setFilterIdx(int index)

getStartIdx

public int getStartIdx()

setStartIdx

public void setStartIdx(int startIdx)

getEndIdx

public int getEndIdx()

setEndIdx

public void setEndIdx(int endIdx)

getFilterChain

public FilterChain getFilterChain()
Get FilterChain, which runs the Filter.

Returns:
FilterChain, which runs the Filter.

getConnection

public Connection getConnection()
Get the Connection, associated with the current processing.

Returns:
Connection object, associated with the current processing.

getMessage

public <T> T getMessage()
Get message object, associated with the current processing. Usually FilterChain represents sequence of parser and process Filters. Each parser can change the message representation until it will come to processor Filter.

Returns:
message object, associated with the current processing.

setMessage

public void setMessage(java.lang.Object message)
Set message object, associated with the current processing. Usually FilterChain represents sequence of parser and process Filters. Each parser can change the message representation until it will come to processor Filter.

Parameters:
message - message object, associated with the current processing.

getAddress

public java.lang.Object getAddress()
Get address, associated with the current IOEvent processing. When we process IOEvent.READ event - it represents sender address, or when process IOEvent.WRITE - address of receiver.

Returns:
address, associated with the current IOEvent processing.

setAddress

public void setAddress(java.lang.Object address)
Set address, associated with the current IOEvent processing. When we process IOEvent.READ event - it represents sender address, or when process IOEvent.WRITE - address of receiver.

Parameters:
address - address, associated with the current IOEvent processing.

getRunnable

protected final java.lang.Runnable getRunnable()

getTransportContext

public FilterChainContext.TransportContext getTransportContext()
Get the TransportFilter related context.

Returns:
TransportFilter.

getInternalContext

public final Context getInternalContext()
Get the general Grizzly Context this filter context wraps.

Returns:
the general Grizzly Context this filter context wraps.

getInvokeAction

public NextAction getInvokeAction(java.lang.Object remainder)
Get NextAction implementation, which instructs FilterChain to process next Filter in chain. Parameter remaining signals, that there is some data remaining in the source message, so FilterChain could be rerun. Normally, after receiving this instruction from Filter, FilterChain executes next filter.

Parameters:
remainder - signals, that there is some data remaining in the source message, so FilterChain could be rerun.
Returns:
NextAction implementation, which instructs FilterChain to process next Filter in chain.

getInvokeAction

public NextAction getInvokeAction()
Get NextAction implementation, which instructs FilterChain to process next Filter in chain. Normally, after receiving this instruction from Filter, FilterChain executes next filter.

Returns:
NextAction implementation, which instructs FilterChain to process next Filter in chain.

getStopAction

public NextAction getStopAction()
Get NextAction implementation, which instructs FilterChain to stop executing phase.

Returns:
NextAction implementation, which instructs FilterChain to stop executing phase.

getForkAction

public NextAction getForkAction()
Returns:
NextAction implementation, which instructs the FilterChain to suspend the current FilterChainContext, but does not disable correspondent IOEvent, so if the same IOEvent occurs on the Connection - it will be processed using new FilterChainContext.

getSuspendingStopAction

public NextAction getSuspendingStopAction()
Deprecated. use getForkAction()

Returns:
NextAction implementation, which instructs the FilterChain to suspend the current FilterChainContext and invoke similar logic as instructed by StopAction with a clean FilterChainContext.

getStopAction

public <E> NextAction getStopAction(E remainder,
                                    Appender<E> appender)
Get NextAction implementation, which instructs FilterChain stop executing phase. Passed Appendable data will be saved and reused during the next FilterChain invocation.

Returns:
NextAction implementation, which instructs FilterChain to stop executing phase. Passed Appendable data will be saved and reused during the next FilterChain invocation.

getStopAction

public NextAction getStopAction(Appendable appendable)
Get NextAction implementation, which instructs FilterChain stop executing phase. Passed Appendable data will be saved and reused during the next FilterChain invocation.

Returns:
NextAction implementation, which instructs FilterChain to stop executing phase. Passed Appendable data will be saved and reused during the next FilterChain invocation.

getStopAction

public NextAction getStopAction(java.lang.Object unknownObject)
Get NextAction implementation, which instructs FilterChain stop executing phase. Passed Buffer data will be saved and reused during the next FilterChain invocation.

Returns:
NextAction implementation, which instructs FilterChain to stop executing phase. Passed Buffer data will be saved and reused during the next FilterChain invocation.

getSuspendAction

public NextAction getSuspendAction()
Get NextAction, which instructs FilterChain to suspend filter chain execution.

Returns:
NextAction, which instructs FilterChain to suspend filter chain execution.

getRerunFilterAction

public NextAction getRerunFilterAction()
Get NextAction, which instructs FilterChain to rerun the filter.

Returns:
NextAction, which instructs FilterChain to rerun the filter.

read

public ReadResult read()
                throws java.io.IOException

Performs a blocking read.

Returns:
the result of the read operation.
Throws:
java.io.IOException - if an I/O error occurs.

write

public void write(java.lang.Object message)

write

public void write(java.lang.Object message,
                  boolean blocking)

write

public void write(java.lang.Object message,
                  CompletionHandler<WriteResult> completionHandler)

write

public void write(java.lang.Object message,
                  CompletionHandler<WriteResult> completionHandler,
                  boolean blocking)

write

public void write(java.lang.Object address,
                  java.lang.Object message,
                  CompletionHandler<WriteResult> completionHandler)

write

public void write(java.lang.Object address,
                  java.lang.Object message,
                  CompletionHandler<WriteResult> completionHandler,
                  boolean blocking)

write

public void write(java.lang.Object address,
                  java.lang.Object message,
                  CompletionHandler<WriteResult> completionHandler,
                  PushBackHandler pushBackHandler)

write

public void write(java.lang.Object address,
                  java.lang.Object message,
                  CompletionHandler<WriteResult> completionHandler,
                  PushBackHandler pushBackHandler,
                  boolean blocking)

write

public void write(java.lang.Object address,
                  java.lang.Object message,
                  CompletionHandler<WriteResult> completionHandler,
                  PushBackHandler pushBackHandler,
                  MessageCloner cloner)

write

public void write(java.lang.Object address,
                  java.lang.Object message,
                  CompletionHandler<WriteResult> completionHandler,
                  PushBackHandler pushBackHandler,
                  MessageCloner cloner,
                  boolean blocking)

flush

public void flush(CompletionHandler completionHandler)

notifyUpstream

public void notifyUpstream(FilterChainEvent event)

notifyUpstream

public void notifyUpstream(FilterChainEvent event,
                           CompletionHandler<FilterChainContext> completionHandler)

notifyDownstream

public void notifyDownstream(FilterChainEvent event)

notifyDownstream

public void notifyDownstream(FilterChainEvent event,
                             CompletionHandler<FilterChainContext> completionHandler)

fail

public void fail(java.lang.Throwable error)

getAttributes

public AttributeHolder getAttributes()
Get associated AttributeHolder. Implementation may return null if AttributeHolder wasn't initialized yet.

Specified by:
getAttributes in interface AttributeStorage
Returns:
associated AttributeHolder. Implementation may return null if AttributeHolder wasn't initialized yet.

addCompletionListener

public final void addCompletionListener(FilterChainContext.CompletionListener listener)
Add the FilterChainContext.CompletionListener, which will be notified, when this FilterChainContext processing will be completed.

Parameters:
listener - the FilterChainContext.CompletionListener, which will be notified, when this FilterChainContext processing will be completed.

removeCompletionListener

public final boolean removeCompletionListener(FilterChainContext.CompletionListener listener)
Remove the FilterChainContext.CompletionListener.

Parameters:
listener - the FilterChainContext.CompletionListener to be removed.
Returns:
true, if the listener was removed from the list, or false, if the listener wasn't on the list.

addCopyListener

public final void addCopyListener(FilterChainContext.CopyListener listener)
Add the FilterChainContext.CopyListener, which will be notified, right after this copy() is called.

Parameters:
listener - the FilterChainContext.CopyListener, which will be notified, right after this copy() is called.

removeCopyListener

public final boolean removeCopyListener(FilterChainContext.CopyListener listener)
Remove the FilterChainContext.CopyListener.

Parameters:
listener - the FilterChainContext.CopyListener to be removed.
Returns:
true, if the listener was removed from the list, or false, if the listener wasn't on the list.

getMemoryManager

public final MemoryManager getMemoryManager()

A simple alias for FilterChainContext.getConnection().getTransport().getMemoryManager().

Returns:
the MemoryManager associated with the Connection of this FilterChainContext.

copy

public FilterChainContext copy()

reset

public void reset()
Release the context associated resources.


completeAndRecycle

public void completeAndRecycle()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2012 Oracle Corporation. All Rights Reserved.