|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface ProtocolChain
This class implement the "Chain of Responsibility" pattern (for more info, take a look at the classic "Gang of Four" design patterns book). Towards that end, the Chain API models a computation as a series of "protocol filter" that can be combined into a "protocol chain".
The API for ProtocolFilter consists of a two methods (execute() and postExecute) which is passed a "protocol context" parameter containing the dynamic state of the computation, and whose return value is a boolean that determines whether or not processing for the current chain has been completed (false), or whether processing should be delegated to the next ProtocolFilter in the chain (true). The owning ProtocolChain must call the postExectute() method of each ProtocolFilter in a ProtocolChain in reverse order of the invocation of their execute() methods.
The following picture describe how it ProtocolFilter(s)
-----------------------------------------------------------------------------
- ProtocolFilter1.execute() --> ProtocolFilter2.execute() -------| -
- | -
- | -
- | -
- ProtocolFilter1.postExecute() <-- ProtocolFilter2.postExecute()| -
-----------------------------------------------------------------------------
The "context" abstraction is designed to isolate ProtocolFilter implementations from the environment in which they are run (such as a ProtocolFilter that can be used in either IIOP or HTTP parsing, without being tied directly to the API contracts of either of these environments). For ProtocolFilter that need to allocate resources prior to delegation, and then release them upon return (even if a delegated-to ProtocolFilter throws an exception), the "postExecute" method can be used for cleanup.
Field Summary | |
---|---|
static String |
PROTOCOL_CHAIN_POST_INSTRUCTION
ProtocolChain result attribute name. |
Method Summary | |
---|---|
void |
addFilter(int pos,
ProtocolFilter protocolFilter)
Insert a ProtocolFilter to the list at position 'pos'. |
boolean |
addFilter(ProtocolFilter protocolFilter)
Add a ProtocolFilter to the list. |
void |
execute(Context context)
Execute using the Context instance. |
boolean |
removeFilter(ProtocolFilter theFilter)
Remove the ProtocolFilter from this chain. |
Field Detail |
---|
static final String PROTOCOL_CHAIN_POST_INSTRUCTION
ProtocolChain
result attribute name.
Method Detail |
---|
boolean addFilter(ProtocolFilter protocolFilter)
ProtocolFilter
to the list. ProtocolFilter
will be invoked in the order they have been added.
protocolFilter
- ProtocolFilter
ProtocolFilter
added successfully (yes/no) ?boolean removeFilter(ProtocolFilter theFilter)
ProtocolFilter
from this chain.
theFilter
- ProtocolFilter
ProtocolFilter
removed successfully (yes/no) ?void addFilter(int pos, ProtocolFilter protocolFilter)
ProtocolFilter
to the list at position 'pos'.
pos
- The insertion positionprotocolFilter
- ProtocolFilter
void execute(Context context) throws Exception
Context
instance.
context
- Context
- Throws:
Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |