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 interfaceThe interface, which represents a listener, which will be notified, onceFilterChainContextprocessing is complete.static interfaceThe interface, which represents a listener, which will be notified, aftercopy()is called.static enumstatic enumstatic final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected FilterChainEventContext associated event, if EVENT operationstatic final intprotected CompletionHandler<FilterChainContext>CompletionHandler, which will be notified, when operation will be complete. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidAdd theFilterChainContext.CompletionListener, which will be notified, when thisFilterChainContextprocessing will be completed.final voidAdd theFilterChainContext.CopyListener, which will be notified, right after thiscopy()is called.voidvoidcopy()static FilterChainContextcreate(Connection connection) static FilterChainContextcreate(Connection connection, Closeable closeable) voidvoidflush(CompletionHandler completionHandler) voidfork()This method invocation suggests theFilterChainto create a copy of thisFilterChainContextand resume/fork its execution starting from the currentFilter.voidfork(NextAction nextAction) This method invocation suggests theFilterChainto create a copy of thisFilterChainContextand resume/fork its execution starting from the currentFilter.Get address, associated with the currentIOEventprocessing.Holder<?>Get associatedAttributeHolder.Get theCloseable, associated with the current processing.Get theConnection, associated with the current processing.intGetFilterChain, which runs theFilter.intgetForkAction(NextAction nextAction) final ContextGet the general GrizzlyContextthis filter context wraps.<E> NextActiongetInvokeAction(E incompleteChunk, Appender<E> appender) getInvokeAction(Object unparsedChunk) final MemoryManagerA simple alias forFilterChainContext.getConnection().getMemoryManager().<T> TGet message object, associated with the current processing.GetNextAction, which instructsFilterChainto rerun the filter.protected final RunnableintGetNextActionimplementation, which instructsFilterChainto stop executing phase.<E> NextActiongetStopAction(E incompleteChunk, Appender<E> appender) GetNextActionimplementation, which instructsFilterChainstop executing phase.getStopAction(Object incompleteChunk) GetNextActionimplementation, which instructsFilterChainstop executing phase.GetNextAction, which instructsFilterChainto suspend filter chain execution.Deprecated.Get theTransportFilterrelated context.intvoidnotifyDownstream(FilterChainEvent event) voidnotifyDownstream(FilterChainEvent event, CompletionHandler<FilterChainContext> completionHandler) voidnotifyUpstream(FilterChainEvent event) voidnotifyUpstream(FilterChainEvent event, CompletionHandler<FilterChainContext> completionHandler) intread()Performs a blocking read.final booleanRemove theFilterChainContext.CompletionListener.final booleanRemove theFilterChainContext.CopyListener.voidreset()Release the context associated resources.voidresume()Resume processing of the current taskvoidresume(NextAction nextAction) Resume the current FilterChain task processing by completing the currentFilter(the Filter, which suspended the processing) with the passedNextAction.voidResume processing of the current task starting from the Filter, which follows the Filter, which suspend the processing.voidsetAddress(Object address) Set address, associated with the currentIOEventprocessing.voidsetAddressHolder(Holder<?> addressHolder) Set address, associated with the currentIOEventprocessing.voidsetEndIdx(int endIdx) voidsetFilterIdx(int index) voidsetMessage(Object message) Set message object, associated with the current processing.voidsetStartIdx(int startIdx) state()Get the current processing task state.suspend()Suspend processing of the current tasktoString()voidvoidvoidwrite(Object address, Object message, CompletionHandler<WriteResult> completionHandler) voidwrite(Object address, Object message, CompletionHandler<WriteResult> completionHandler, boolean blocking) voidwrite(Object address, Object message, CompletionHandler<WriteResult> completionHandler, MessageCloner cloner) voidwrite(Object address, Object message, CompletionHandler<WriteResult> completionHandler, MessageCloner cloner, boolean blocking) voidwrite(Object address, Object message, CompletionHandler<WriteResult> completionHandler, PushBackHandler pushBackHandler) Deprecated.voidwrite(Object address, Object message, CompletionHandler<WriteResult> completionHandler, PushBackHandler pushBackHandler, boolean blocking) Deprecated.voidwrite(Object address, Object message, CompletionHandler<WriteResult> completionHandler, PushBackHandler pushBackHandler, MessageCloner cloner) Deprecated.voidwrite(Object address, Object message, CompletionHandler<WriteResult> completionHandler, PushBackHandler pushBackHandler, MessageCloner cloner, boolean blocking) Deprecated.voidwrite(Object message, CompletionHandler<WriteResult> completionHandler) voidwrite(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 whichFilterChainwill continue processing.
-
fork
public void fork()This method invocation suggests theFilterChainto create a copy of thisFilterChainContextand resume/fork its execution starting from the currentFilter. -
fork
This method invocation suggests theFilterChainto create a copy of thisFilterChainContextand resume/fork its execution starting from the currentFilter. IfnextActionparameter is not null - then its value is treated as a result of the currentFilterexecution on the forkedFilterChainprocessing. So during the forkedFilterChainprocessing the currentFilterwill not be invoked, but the processing will be continued as if the currentFilterreturnednextActionas a result. For example if we callfork(ctx.getInvokeAction());the forkedFilterChainprocessing will start with the nextFilterin 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:
Connectionobject, associated with the current processing.
-
getCloseable
Get theCloseable, associated with the current processing. TheCloseableobject might be used to close/terminate an entity associated with theFilterChainprocessing in response to an error occurred during the processing. If not customized theCloseableobject represents aConnectionassociated with theFilterChainprocessing.- Returns:
Closeableobject, associated with the current processing.
-
getMessage
public <T> T getMessage()Get message object, associated with the current processing. UsuallyFilterChainrepresents sequence of parser and processFilters. 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. UsuallyFilterChainrepresents sequence of parser and processFilters. 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 currentIOEventprocessing. When we processIOEvent.READevent - it represents sender address, or when processIOEvent.WRITE- address of receiver. -
setAddressHolder
Set address, associated with the currentIOEventprocessing. When we processIOEvent.READevent - it represents sender address, or when processIOEvent.WRITE- address of receiver. -
getAddress
Get address, associated with the currentIOEventprocessing. When we processIOEvent.READevent - it represents sender address, or when processIOEvent.WRITE- address of receiver.- Returns:
- address, associated with the current
IOEventprocessing.
-
setAddress
Set address, associated with the currentIOEventprocessing. When we processIOEvent.READevent - it represents sender address, or when processIOEvent.WRITE- address of receiver.- Parameters:
address- address, associated with the currentIOEventprocessing.
-
getRunnable
-
getTransportContext
Get theTransportFilterrelated context.- Returns:
TransportFilter.
-
getInternalContext
Get the general GrizzlyContextthis filter context wraps.- Returns:
- the general Grizzly
Contextthis filter context wraps.
-
getInvokeAction
GetNextActionimplementation, which instructsFilterChainto process nextFilterin chain. Normally, after receiving this instruction fromFilter,FilterChainexecutes next filter.- Returns:
NextActionimplementation, which instructsFilterChainto process nextFilterin chain.
-
getInvokeAction
GetNextActionimplementation, which instructsFilterChainto process nextFilterin chain. Normally, after receiving this instruction fromFilter,FilterChainexecutes next filter.- Parameters:
unparsedChunk- signals, that there is some unparsed data remaining in the source message, soFilterChaincould be rerun.- Returns:
NextActionimplementation, which instructsFilterChainto process nextFilterin chain.
-
getInvokeAction
GetNextActionimplementation, which instructsFilterChainto process nextFilterin chain. Normally, after receiving this instruction fromFilter,FilterChainexecutes next filter.- Parameters:
incompleteChunk- signals, that there is a data chunk remaining, which doesn't represent complete message. As more data becomes available but beforeFilterChaincalls the currentFilter, it will check if theFilterhas 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:
NextActionimplementation, which instructsFilterChainto process nextFilterin chain.- Throws:
IllegalArgumentException- if appender isnulland remainder's type is notBufferorAppendable.
-
getStopAction
GetNextActionimplementation, which instructsFilterChainto stop executing phase.- Returns:
NextActionimplementation, which instructsFilterChainto stop executing phase.
-
getStopAction
GetNextActionimplementation, which instructsFilterChainstop executing phase.- Parameters:
incompleteChunk- signals, that there is a data chunk remaining, which doesn't represent complete message. As more data becomes available but beforeFilterChaincalls the currentFilter, it will check if theFilterhas 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:
NextActionimplementation, which instructsFilterChainto stop executing phase.- Throws:
IllegalArgumentException- if remainder's type is notBufferorAppendable.
-
getStopAction
GetNextActionimplementation, which instructsFilterChainstop executing phase.- Parameters:
incompleteChunk- signals, that there is a data chunk remaining, which doesn't represent complete message. As more data becomes available but beforeFilterChaincalls the currentFilter, it will check if theFilterhas 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:
NextActionimplementation, which instructsFilterChainto stop executing phase.- Throws:
IllegalArgumentException- if appender isnulland remainder's type is notBufferorAppendable.
-
getForkAction
- Returns:
NextActionimplementation, which suggests theFilterChainto forget about the currentFilterChainContext, create a copy of it and continue/forkFilterChainprocessing using the copiedFilterChainContextstarting from the currentFilter.
-
getForkAction
- Returns:
NextActionimplementation, which suggests theFilterChainto forget about the currentFilterChainContext, create a copy of it and continue/forkFilterChainprocessing using the copiedFilterChainContextstarting from the currentFilter. IfnextActionparameter is not null - then its value is treated as a result of the currentFilterexecution on the forkedFilterChainprocessing. So during the forkedFilterChainprocessing the currentFilterwill not be invoked, but the processing will be continued as if the currentFilterreturnednextActionas a result. For example if we callfork(ctx.getInvokeAction());the forkedFilterChainprocessing will start with the nextFilterin chain.
-
getSuspendingStopAction
Deprecated.usegetForkAction()- Returns:
NextActionimplementation, which instructs theFilterChainto suspend the currentFilterChainContextand invoke similar logic as instructed byStopActionwith a cleanFilterChainContext.
-
getSuspendAction
GetNextAction, which instructsFilterChainto suspend filter chain execution.- Returns:
NextAction, which instructsFilterChainto suspend filter chain execution.
-
getRerunFilterAction
GetNextAction, which instructsFilterChainto rerun the filter.- Returns:
NextAction, which instructsFilterChainto 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 ifAttributeHolderwasn't initialized yet.- Specified by:
getAttributesin interfaceAttributeStorage- Returns:
- associated
AttributeHolder. Implementation may return null ifAttributeHolderwasn't initialized yet.
-
addCompletionListener
Add theFilterChainContext.CompletionListener, which will be notified, when thisFilterChainContextprocessing will be completed.- Parameters:
listener- theFilterChainContext.CompletionListener, which will be notified, when thisFilterChainContextprocessing will be completed.
-
removeCompletionListener
Remove theFilterChainContext.CompletionListener.- Parameters:
listener- theFilterChainContext.CompletionListenerto 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.CopyListenerto 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
MemoryManagerassociated with theConnectionof thisFilterChainContext.
-
copy
-
reset
public void reset()Release the context associated resources. -
completeAndRecycle
public void completeAndRecycle() -
completeAndRelease
public void completeAndRelease() -
toString
-
getForkAction()