Class FilterChainContext
- java.lang.Object
-
- org.glassfish.grizzly.filterchain.FilterChainContext
-
- All Implemented Interfaces:
AttributeStorage
public class FilterChainContext extends Object implements AttributeStorage
FilterChainContextimplementation.- Author:
- Alexey Stashok
- See Also:
Context,FilterChain
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceFilterChainContext.CompletionListenerThe interface, which represents a listener, which will be notified, onceFilterChainContextprocessing is complete.static interfaceFilterChainContext.CopyListenerThe interface, which represents a listener, which will be notified, aftercopy()is called.static classFilterChainContext.Operationstatic classFilterChainContext.Statestatic classFilterChainContext.TransportContext
-
Field Summary
Fields Modifier and Type Field Description protected FilterChainEventeventContext associated event, if EVENT operationstatic intNO_FILTER_INDEXprotected CompletionHandler<FilterChainContext>operationCompletionHandlerCompletionHandler, which will be notified, when operation will be complete.
-
Constructor Summary
Constructors Constructor Description FilterChainContext()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddCompletionListener(FilterChainContext.CompletionListener listener)Add theFilterChainContext.CompletionListener, which will be notified, when thisFilterChainContextprocessing will be completed.voidaddCopyListener(FilterChainContext.CopyListener listener)Add theFilterChainContext.CopyListener, which will be notified, right after thiscopy()is called.voidcompleteAndRecycle()voidcompleteAndRelease()FilterChainContextcopy()static FilterChainContextcreate(Connection connection)static FilterChainContextcreate(Connection connection, Closeable closeable)voidfail(Throwable error)voidflush(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.ObjectgetAddress()Get address, associated with the currentIOEventprocessing.Holder<?>getAddressHolder()AttributeHoldergetAttributes()Get associatedAttributeHolder.CloseablegetCloseable()Get theCloseable, associated with the current processing.ConnectiongetConnection()Get theConnection, associated with the current processing.intgetEndIdx()FilterChaingetFilterChain()GetFilterChain, which runs theFilter.intgetFilterIdx()NextActiongetForkAction()NextActiongetForkAction(NextAction nextAction)ContextgetInternalContext()Get the general GrizzlyContextthis filter context wraps.NextActiongetInvokeAction()<E> NextActiongetInvokeAction(E incompleteChunk, Appender<E> appender)NextActiongetInvokeAction(Object unparsedChunk)MemoryManagergetMemoryManager()A simple alias forFilterChainContext.getConnection().getMemoryManager().<T> TgetMessage()Get message object, associated with the current processing.NextActiongetRerunFilterAction()GetNextAction, which instructsFilterChainto rerun the filter.protected RunnablegetRunnable()intgetStartIdx()NextActiongetStopAction()GetNextActionimplementation, which instructsFilterChainto stop executing phase.<E> NextActiongetStopAction(E incompleteChunk, Appender<E> appender)GetNextActionimplementation, which instructsFilterChainstop executing phase.NextActiongetStopAction(Object incompleteChunk)GetNextActionimplementation, which instructsFilterChainstop executing phase.NextActiongetSuspendAction()GetNextAction, which instructsFilterChainto suspend filter chain execution.NextActiongetSuspendingStopAction()Deprecated.usegetForkAction()FilterChainContext.TransportContextgetTransportContext()Get theTransportFilterrelated context.intnextFilterIdx()voidnotifyDownstream(FilterChainEvent event)voidnotifyDownstream(FilterChainEvent event, CompletionHandler<FilterChainContext> completionHandler)voidnotifyUpstream(FilterChainEvent event)voidnotifyUpstream(FilterChainEvent event, CompletionHandler<FilterChainContext> completionHandler)intpreviousFilterIdx()ReadResultread()Performs a blocking read.booleanremoveCompletionListener(FilterChainContext.CompletionListener listener)Remove theFilterChainContext.CompletionListener.booleanremoveCopyListener(FilterChainContext.CopyListener listener)Remove 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.voidresumeNext()Resume 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)FilterChainContext.Statestate()Get the current processing task state.Runnablesuspend()Suspend processing of the current taskStringtoString()voidwrite(Object message)voidwrite(Object message, boolean blocking)voidwrite(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 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
-
-
Method Detail
-
create
public static FilterChainContext create(Connection connection)
-
create
public static FilterChainContext create(Connection connection, Closeable closeable)
-
suspend
public Runnable 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
public void resume(NextAction nextAction)
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
public void fork(NextAction nextAction)
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
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()
GetFilterChain, which runs theFilter.- Returns:
FilterChain, which runs theFilter.
-
getConnection
public Connection getConnection()
Get theConnection, associated with the current processing.- Returns:
Connectionobject, associated with the current processing.
-
getCloseable
public Closeable 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
public void setMessage(Object message)
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
public Holder<?> 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
public void setAddressHolder(Holder<?> addressHolder)
Set address, associated with the currentIOEventprocessing. When we processIOEvent.READevent - it represents sender address, or when processIOEvent.WRITE- address of receiver.
-
getAddress
public Object 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
public void setAddress(Object address)
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
protected final Runnable getRunnable()
-
getTransportContext
public FilterChainContext.TransportContext getTransportContext()
Get theTransportFilterrelated context.- Returns:
TransportFilter.
-
getInternalContext
public final Context getInternalContext()
Get the general GrizzlyContextthis filter context wraps.- Returns:
- the general Grizzly
Contextthis filter context wraps.
-
getInvokeAction
public NextAction getInvokeAction()
GetNextActionimplementation, which instructsFilterChainto process nextFilterin chain. Normally, after receiving this instruction fromFilter,FilterChainexecutes next filter.- Returns:
NextActionimplementation, which instructsFilterChainto process nextFilterin chain.
-
getInvokeAction
public NextAction getInvokeAction(Object unparsedChunk)
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
public <E> NextAction getInvokeAction(E incompleteChunk, Appender<E> appender)
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
public NextAction getStopAction()
GetNextActionimplementation, which instructsFilterChainto stop executing phase.- Returns:
NextActionimplementation, which instructsFilterChainto stop executing phase.
-
getStopAction
public NextAction getStopAction(Object incompleteChunk)
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
public <E> NextAction getStopAction(E incompleteChunk, Appender<E> appender)
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
public NextAction 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
public NextAction getForkAction(NextAction nextAction)
- 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 public NextAction getSuspendingStopAction()
Deprecated.usegetForkAction()- Returns:
NextActionimplementation, which instructs theFilterChainto suspend the currentFilterChainContextand invoke similar logic as instructed byStopActionwith a cleanFilterChainContext.
-
getSuspendAction
public NextAction getSuspendAction()
GetNextAction, which instructsFilterChainto suspend filter chain execution.- Returns:
NextAction, which instructsFilterChainto suspend filter chain execution.
-
getRerunFilterAction
public NextAction getRerunFilterAction()
GetNextAction, which instructsFilterChainto rerun the filter.- Returns:
NextAction, which instructsFilterChainto rerun the filter.
-
read
public ReadResult read() throws IOException
Performs a blocking read.
- Returns:
- the result of the read operation.
- Throws:
IOException- if an I/O error occurs.
-
write
public void write(Object message)
-
write
public void write(Object message, boolean blocking)
-
write
public void write(Object message, CompletionHandler<WriteResult> completionHandler)
-
write
public void write(Object message, CompletionHandler<WriteResult> completionHandler, boolean blocking)
-
write
public void write(Object address, Object message, CompletionHandler<WriteResult> completionHandler)
-
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
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(Throwable error)
-
getAttributes
public AttributeHolder 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
public final void addCompletionListener(FilterChainContext.CompletionListener listener)
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
public final boolean removeCompletionListener(FilterChainContext.CompletionListener listener)
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
public final void addCopyListener(FilterChainContext.CopyListener listener)
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
public final boolean removeCopyListener(FilterChainContext.CopyListener listener)
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
public final MemoryManager getMemoryManager()
A simple alias for
FilterChainContext.getConnection().getMemoryManager().- Returns:
- the
MemoryManagerassociated with theConnectionof thisFilterChainContext.
-
copy
public FilterChainContext copy()
-
reset
public void reset()
Release the context associated resources.
-
completeAndRecycle
public void completeAndRecycle()
-
completeAndRelease
public void completeAndRelease()
-
-