java.lang.Object
org.glassfish.grizzly.filterchain.FilterChainContext
- All Implemented Interfaces:
AttributeStorage
FilterChain
Context
implementation.- Author:
- Alexey Stashok
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
The interface, which represents a listener, which will be notified, onceFilterChainContext
processing is complete.static interface
The interface, which represents a listener, which will be notified, aftercopy()
is called.static enum
static enum
static final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected FilterChainEvent
Context associated event, if EVENT operationstatic final int
protected CompletionHandler<FilterChainContext>
CompletionHandler
, which will be notified, when operation will be complete. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal void
Add theFilterChainContext.CompletionListener
, which will be notified, when thisFilterChainContext
processing will be completed.final void
Add theFilterChainContext.CopyListener
, which will be notified, right after thiscopy()
is called.void
void
copy()
static FilterChainContext
create
(Connection connection) static FilterChainContext
create
(Connection connection, Closeable closeable) void
void
flush
(CompletionHandler completionHandler) void
fork()
This method invocation suggests theFilterChain
to create a copy of thisFilterChainContext
and resume/fork its execution starting from the currentFilter
.void
fork
(NextAction nextAction) This method invocation suggests theFilterChain
to create a copy of thisFilterChainContext
and resume/fork its execution starting from the currentFilter
.Get address, associated with the currentIOEvent
processing.Holder<?>
Get associatedAttributeHolder
.Get theCloseable
, associated with the current processing.Get theConnection
, associated with the current processing.int
GetFilterChain
, which runs theFilter
.int
getForkAction
(NextAction nextAction) final Context
Get the general GrizzlyContext
this filter context wraps.<E> NextAction
getInvokeAction
(E incompleteChunk, Appender<E> appender) getInvokeAction
(Object unparsedChunk) final MemoryManager
A simple alias forFilterChainContext.getConnection().getMemoryManager()
.<T> T
Get message object, associated with the current processing.GetNextAction
, which instructsFilterChain
to rerun the filter.protected final Runnable
int
GetNextAction
implementation, which instructsFilterChain
to stop executing phase.<E> NextAction
getStopAction
(E incompleteChunk, Appender<E> appender) GetNextAction
implementation, which instructsFilterChain
stop executing phase.getStopAction
(Object incompleteChunk) GetNextAction
implementation, which instructsFilterChain
stop executing phase.GetNextAction
, which instructsFilterChain
to suspend filter chain execution.Deprecated.Get theTransportFilter
related context.int
void
notifyDownstream
(FilterChainEvent event) void
notifyDownstream
(FilterChainEvent event, CompletionHandler<FilterChainContext> completionHandler) void
notifyUpstream
(FilterChainEvent event) void
notifyUpstream
(FilterChainEvent event, CompletionHandler<FilterChainContext> completionHandler) int
read()
Performs a blocking read.final boolean
Remove theFilterChainContext.CompletionListener
.final boolean
Remove theFilterChainContext.CopyListener
.void
reset()
Release the context associated resources.void
resume()
Resume processing of the current taskvoid
resume
(NextAction nextAction) Resume the current FilterChain task processing by completing the currentFilter
(the Filter, which suspended the processing) with the passedNextAction
.void
Resume processing of the current task starting from the Filter, which follows the Filter, which suspend the processing.void
setAddress
(Object address) Set address, associated with the currentIOEvent
processing.void
setAddressHolder
(Holder<?> addressHolder) Set address, associated with the currentIOEvent
processing.void
setEndIdx
(int endIdx) void
setFilterIdx
(int index) void
setMessage
(Object message) Set message object, associated with the current processing.void
setStartIdx
(int startIdx) state()
Get the current processing task state.suspend()
Suspend processing of the current tasktoString()
void
void
void
write
(Object address, Object message, CompletionHandler<WriteResult> completionHandler) void
write
(Object address, Object message, CompletionHandler<WriteResult> completionHandler, boolean blocking) void
write
(Object address, Object message, CompletionHandler<WriteResult> completionHandler, MessageCloner cloner) void
write
(Object address, Object message, CompletionHandler<WriteResult> completionHandler, MessageCloner cloner, boolean blocking) void
write
(Object address, Object message, CompletionHandler<WriteResult> completionHandler, PushBackHandler pushBackHandler) Deprecated.void
write
(Object address, Object message, CompletionHandler<WriteResult> completionHandler, PushBackHandler pushBackHandler, boolean blocking) Deprecated.void
write
(Object address, Object message, CompletionHandler<WriteResult> completionHandler, PushBackHandler pushBackHandler, MessageCloner cloner) Deprecated.void
write
(Object address, Object message, CompletionHandler<WriteResult> completionHandler, PushBackHandler pushBackHandler, MessageCloner cloner, boolean blocking) Deprecated.void
write
(Object message, CompletionHandler<WriteResult> completionHandler) void
write
(Object message, CompletionHandler<WriteResult> completionHandler, boolean blocking)
-
Field Details
-
NO_FILTER_INDEX
public static final int NO_FILTER_INDEX- See Also:
-
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
Context associated event, if EVENT operation
-
-
Constructor Details
-
FilterChainContext
public FilterChainContext()
-
-
Method Details
-
create
-
create
-
suspend
Suspend processing of the current task -
resume
public void resume()Resume processing of the current task -
resumeNext
public void resumeNext()Resume processing of the current task starting from the Filter, which follows the Filter, which suspend the processing. -
resume
Resume the current FilterChain task processing by completing the currentFilter
(the Filter, which suspended the processing) with the passedNextAction
.- Parameters:
nextAction
- theNextAction
, based on whichFilterChain
will continue processing.
-
fork
public void fork()This method invocation suggests theFilterChain
to create a copy of thisFilterChainContext
and resume/fork its execution starting from the currentFilter
. -
fork
This method invocation suggests theFilterChain
to create a copy of thisFilterChainContext
and resume/fork its execution starting from the currentFilter
. IfnextAction
parameter is not null - then its value is treated as a result of the currentFilter
execution on the forkedFilterChain
processing. So during the forkedFilterChain
processing the currentFilter
will not be invoked, but the processing will be continued as if the currentFilter
returnednextAction
as a result. For example if we callfork(ctx.getInvokeAction());
the forkedFilterChain
processing will start with the nextFilter
in chain. -
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
GetFilterChain
, which runs theFilter
.- Returns:
FilterChain
, which runs theFilter
.
-
getConnection
Get theConnection
, associated with the current processing.- Returns:
Connection
object, associated with the current processing.
-
getCloseable
Get theCloseable
, associated with the current processing. TheCloseable
object might be used to close/terminate an entity associated with theFilterChain
processing in response to an error occurred during the processing. If not customized theCloseable
object represents aConnection
associated with theFilterChain
processing.- Returns:
Closeable
object, associated with the current processing.
-
getMessage
public <T> T getMessage()Get message object, associated with the current processing. UsuallyFilterChain
represents sequence of parser and processFilter
s. Each parser can change the message representation until it will come to processorFilter
.- Returns:
- message object, associated with the current processing.
-
setMessage
Set message object, associated with the current processing. UsuallyFilterChain
represents sequence of parser and processFilter
s. Each parser can change the message representation until it will come to processorFilter
.- Parameters:
message
- message object, associated with the current processing.
-
getAddressHolder
Get aHolder
, which contains address, associated with the currentIOEvent
processing. When we processIOEvent.READ
event - it represents sender address, or when processIOEvent.WRITE
- address of receiver. -
setAddressHolder
Set address, associated with the currentIOEvent
processing. When we processIOEvent.READ
event - it represents sender address, or when processIOEvent.WRITE
- address of receiver. -
getAddress
Get address, associated with the currentIOEvent
processing. When we processIOEvent.READ
event - it represents sender address, or when processIOEvent.WRITE
- address of receiver.- Returns:
- address, associated with the current
IOEvent
processing.
-
setAddress
Set address, associated with the currentIOEvent
processing. When we processIOEvent.READ
event - it represents sender address, or when processIOEvent.WRITE
- address of receiver.- Parameters:
address
- address, associated with the currentIOEvent
processing.
-
getRunnable
-
getTransportContext
Get theTransportFilter
related context.- Returns:
TransportFilter
.
-
getInternalContext
Get the general GrizzlyContext
this filter context wraps.- Returns:
- the general Grizzly
Context
this filter context wraps.
-
getInvokeAction
GetNextAction
implementation, which instructsFilterChain
to process nextFilter
in chain. Normally, after receiving this instruction fromFilter
,FilterChain
executes next filter.- Returns:
NextAction
implementation, which instructsFilterChain
to process nextFilter
in chain.
-
getInvokeAction
GetNextAction
implementation, which instructsFilterChain
to process nextFilter
in chain. Normally, after receiving this instruction fromFilter
,FilterChain
executes next filter.- Parameters:
unparsedChunk
- signals, that there is some unparsed data remaining in the source message, soFilterChain
could be rerun.- Returns:
NextAction
implementation, which instructsFilterChain
to process nextFilter
in chain.
-
getInvokeAction
GetNextAction
implementation, which instructsFilterChain
to process nextFilter
in chain. Normally, after receiving this instruction fromFilter
,FilterChain
executes next filter.- Parameters:
incompleteChunk
- signals, that there is a data chunk remaining, which doesn't represent complete message. As more data becomes available but beforeFilterChain
calls the currentFilter
, it will check if theFilter
has any data stored after the last invocation. If a remainder is present it will append the new data to the stored one and pass the result as the FilterChainContext message.appender
- theAppender
, which knows how to append chunks of type<E>
.- Returns:
NextAction
implementation, which instructsFilterChain
to process nextFilter
in chain.- Throws:
IllegalArgumentException
- if appender isnull
and remainder's type is notBuffer
orAppendable
.
-
getStopAction
GetNextAction
implementation, which instructsFilterChain
to stop executing phase.- Returns:
NextAction
implementation, which instructsFilterChain
to stop executing phase.
-
getStopAction
GetNextAction
implementation, which instructsFilterChain
stop executing phase.- Parameters:
incompleteChunk
- signals, that there is a data chunk remaining, which doesn't represent complete message. As more data becomes available but beforeFilterChain
calls the currentFilter
, it will check if theFilter
has any data stored after the last invocation. If a remainder is present it will append the new data to the stored one and pass the result as the FilterChainContext message.- Returns:
NextAction
implementation, which instructsFilterChain
to stop executing phase.- Throws:
IllegalArgumentException
- if remainder's type is notBuffer
orAppendable
.
-
getStopAction
GetNextAction
implementation, which instructsFilterChain
stop executing phase.- Parameters:
incompleteChunk
- signals, that there is a data chunk remaining, which doesn't represent complete message. As more data becomes available but beforeFilterChain
calls the currentFilter
, it will check if theFilter
has any data stored after the last invocation. If a remainder is present it will append the new data to the stored one and pass the result as the FilterChainContext message.appender
- theAppender
, which knows how to append chunks of type<E>
.- Returns:
NextAction
implementation, which instructsFilterChain
to stop executing phase.- Throws:
IllegalArgumentException
- if appender isnull
and remainder's type is notBuffer
orAppendable
.
-
getForkAction
- Returns:
NextAction
implementation, which suggests theFilterChain
to forget about the currentFilterChainContext
, create a copy of it and continue/forkFilterChain
processing using the copiedFilterChainContext
starting from the currentFilter
.
-
getForkAction
- Returns:
NextAction
implementation, which suggests theFilterChain
to forget about the currentFilterChainContext
, create a copy of it and continue/forkFilterChain
processing using the copiedFilterChainContext
starting from the currentFilter
. IfnextAction
parameter is not null - then its value is treated as a result of the currentFilter
execution on the forkedFilterChain
processing. So during the forkedFilterChain
processing the currentFilter
will not be invoked, but the processing will be continued as if the currentFilter
returnednextAction
as a result. For example if we callfork(ctx.getInvokeAction());
the forkedFilterChain
processing will start with the nextFilter
in chain.
-
getSuspendingStopAction
Deprecated.usegetForkAction()
- Returns:
NextAction
implementation, which instructs theFilterChain
to suspend the currentFilterChainContext
and invoke similar logic as instructed byStopAction
with a cleanFilterChainContext
.
-
getSuspendAction
GetNextAction
, which instructsFilterChain
to suspend filter chain execution.- Returns:
NextAction
, which instructsFilterChain
to suspend filter chain execution.
-
getRerunFilterAction
GetNextAction
, which instructsFilterChain
to rerun the filter.- Returns:
NextAction
, which instructsFilterChain
to rerun the filter.
-
read
Performs a blocking read.
- Returns:
- the result of the read operation.
- Throws:
IOException
- if an I/O error occurs.
-
write
-
write
-
write
-
write
public void write(Object message, CompletionHandler<WriteResult> completionHandler, boolean blocking) -
write
-
write
public void write(Object address, Object message, CompletionHandler<WriteResult> completionHandler, boolean blocking) -
write
@Deprecated public void write(Object address, Object message, CompletionHandler<WriteResult> completionHandler, PushBackHandler pushBackHandler) Deprecated. -
write
@Deprecated public void write(Object address, Object message, CompletionHandler<WriteResult> completionHandler, PushBackHandler pushBackHandler, boolean blocking) Deprecated. -
write
public void write(Object address, Object message, CompletionHandler<WriteResult> completionHandler, MessageCloner cloner) -
write
@Deprecated public void write(Object address, Object message, CompletionHandler<WriteResult> completionHandler, PushBackHandler pushBackHandler, MessageCloner cloner) Deprecated. -
write
public void write(Object address, Object message, CompletionHandler<WriteResult> completionHandler, MessageCloner cloner, boolean blocking) -
write
@Deprecated public void write(Object address, Object message, CompletionHandler<WriteResult> completionHandler, PushBackHandler pushBackHandler, MessageCloner cloner, boolean blocking) Deprecated. -
flush
-
notifyUpstream
-
notifyUpstream
public void notifyUpstream(FilterChainEvent event, CompletionHandler<FilterChainContext> completionHandler) -
notifyDownstream
-
notifyDownstream
public void notifyDownstream(FilterChainEvent event, CompletionHandler<FilterChainContext> completionHandler) -
fail
-
getAttributes
Get associatedAttributeHolder
. Implementation may return null ifAttributeHolder
wasn't initialized yet.- Specified by:
getAttributes
in interfaceAttributeStorage
- Returns:
- associated
AttributeHolder
. Implementation may return null ifAttributeHolder
wasn't initialized yet.
-
addCompletionListener
Add theFilterChainContext.CompletionListener
, which will be notified, when thisFilterChainContext
processing will be completed.- Parameters:
listener
- theFilterChainContext.CompletionListener
, which will be notified, when thisFilterChainContext
processing will be completed.
-
removeCompletionListener
Remove theFilterChainContext.CompletionListener
.- Parameters:
listener
- theFilterChainContext.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
Add theFilterChainContext.CopyListener
, which will be notified, right after thiscopy()
is called.- Parameters:
listener
- theFilterChainContext.CopyListener
, which will be notified, right after thiscopy()
is called.
-
removeCopyListener
Remove theFilterChainContext.CopyListener
.- Parameters:
listener
- theFilterChainContext.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
A simple alias for
FilterChainContext.getConnection().getMemoryManager()
.- Returns:
- the
MemoryManager
associated with theConnection
of thisFilterChainContext
.
-
copy
-
reset
public void reset()Release the context associated resources. -
completeAndRecycle
public void completeAndRecycle() -
completeAndRelease
public void completeAndRelease() -
toString
-
getForkAction()