Package org.apache.mina.handler.chain
Class IoHandlerChain
- java.lang.Object
-
- org.apache.mina.handler.chain.IoHandlerChain
-
- All Implemented Interfaces:
IoHandlerCommand
public class IoHandlerChain extends java.lang.Object implements IoHandlerCommand
A chain ofIoHandlerCommands.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classIoHandlerChain.EntryRepresents a name-command pair that anIoHandlerChaincontains.-
Nested classes/interfaces inherited from interface org.apache.mina.handler.chain.IoHandlerCommand
IoHandlerCommand.NextCommand
-
-
Field Summary
Fields Modifier and Type Field Description private IoHandlerChain.EntryheadThe head of the IoHandlerCommand chainprivate intidprivate java.util.Map<java.lang.String,IoHandlerChain.Entry>name2entryprivate java.lang.StringNEXT_COMMANDprivate static intnextIdprivate IoHandlerChain.EntrytailTHe tail of the IoHandlerCommand chain
-
Constructor Summary
Constructors Constructor Description IoHandlerChain()Creates a new, empty chain ofIoHandlerCommands.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAfter(java.lang.String baseName, java.lang.String name, IoHandlerCommand command)Adds a name-command after a given name-command in the chainvoidaddBefore(java.lang.String baseName, java.lang.String name, IoHandlerCommand command)Adds a name-command before a given name-command in the chainvoidaddFirst(java.lang.String name, IoHandlerCommand command)Adds a name-command pair into the chainvoidaddLast(java.lang.String name, IoHandlerCommand command)Adds a name-command at the end of the chainprivate voidcallNextCommand(IoHandlerChain.Entry entry, IoSession session, java.lang.Object message)private voidcheckAddable(java.lang.String name)Checks the specified filter name is already taken and throws an exception if already taken.private IoHandlerChain.EntrycheckOldName(java.lang.String baseName)Throws an exception when the specified filter name is not registered in this chain.voidclear()Remove all theIoHandlerCommandfrom the chainbooleancontains(java.lang.Class<? extends IoHandlerCommand> commandType)Checks if the chain ofIoHandlerCommandcontains a specificIoHandlerCommandbooleancontains(java.lang.String name)Checks if the chain ofIoHandlerCommandcontains aIoHandlerCommandby its namebooleancontains(IoHandlerCommand command)Checks if the chain ofIoHandlerCommandcontains a specificIoHandlerCommandprivate IoHandlerCommandcreateHeadCommand()private IoHandlerCommandcreateTailCommand()private voidderegister(IoHandlerChain.Entry entry)voidexecute(IoHandlerCommand.NextCommand next, IoSession session, java.lang.Object message)Execute a unit of processing work to be performed.IoHandlerCommandget(java.lang.String name)Retrieve aIoHandlerCommandby its namejava.util.List<IoHandlerChain.Entry>getAll()java.util.List<IoHandlerChain.Entry>getAllReversed()IoHandlerChain.EntrygetEntry(java.lang.String name)Retrieve a name-command pair by its nameIoHandlerCommand.NextCommandgetNextCommand(java.lang.String name)Retrieve theIoHandlerCommandfollowing theIoHandlerCommandwe fetched by its nameprivate voidregister(IoHandlerChain.Entry prevEntry, java.lang.String name, IoHandlerCommand command)IoHandlerCommandremove(java.lang.String name)Removes aIoHandlerCommandby its namejava.lang.StringtoString()
-
-
-
Field Detail
-
nextId
private static volatile int nextId
-
id
private final int id
-
NEXT_COMMAND
private final java.lang.String NEXT_COMMAND
-
name2entry
private final java.util.Map<java.lang.String,IoHandlerChain.Entry> name2entry
-
head
private final IoHandlerChain.Entry head
The head of the IoHandlerCommand chain
-
tail
private final IoHandlerChain.Entry tail
THe tail of the IoHandlerCommand chain
-
-
Constructor Detail
-
IoHandlerChain
public IoHandlerChain()
Creates a new, empty chain ofIoHandlerCommands.
-
-
Method Detail
-
createHeadCommand
private IoHandlerCommand createHeadCommand()
-
createTailCommand
private IoHandlerCommand createTailCommand()
-
getEntry
public IoHandlerChain.Entry getEntry(java.lang.String name)
Retrieve a name-command pair by its name- Parameters:
name- The name of theIoHandlerCommandwe are looking for- Returns:
- The associated name-command pair, if any, null otherwise
-
get
public IoHandlerCommand get(java.lang.String name)
Retrieve aIoHandlerCommandby its name- Parameters:
name- The name of theIoHandlerCommandwe are looking for- Returns:
- The associated
IoHandlerCommand, if any, null otherwise
-
getNextCommand
public IoHandlerCommand.NextCommand getNextCommand(java.lang.String name)
Retrieve theIoHandlerCommandfollowing theIoHandlerCommandwe fetched by its name- Parameters:
name- The name of theIoHandlerCommand- Returns:
- The
IoHandlerCommandwhich is next to teh ngiven name, if any, null otherwise
-
addFirst
public void addFirst(java.lang.String name, IoHandlerCommand command)Adds a name-command pair into the chain- Parameters:
name- The namecommand- The command
-
addLast
public void addLast(java.lang.String name, IoHandlerCommand command)Adds a name-command at the end of the chain- Parameters:
name- The namecommand- The command
-
addBefore
public void addBefore(java.lang.String baseName, java.lang.String name, IoHandlerCommand command)Adds a name-command before a given name-command in the chain- Parameters:
baseName- The IoHandlerCommand name before which we will inject a new name-commandname- The name The namecommand- The command The command
-
addAfter
public void addAfter(java.lang.String baseName, java.lang.String name, IoHandlerCommand command)Adds a name-command after a given name-command in the chain- Parameters:
baseName- TheIoHandlerCommandname after which we will inject a new name-commandname- The name The namecommand- The command The command
-
remove
public IoHandlerCommand remove(java.lang.String name)
Removes aIoHandlerCommandby its name- Parameters:
name- The name- Returns:
- The removed
IoHandlerCommand
-
clear
public void clear() throws java.lang.ExceptionRemove all theIoHandlerCommandfrom the chain- Throws:
java.lang.Exception- If we faced some exception during the cleanup
-
register
private void register(IoHandlerChain.Entry prevEntry, java.lang.String name, IoHandlerCommand command)
-
deregister
private void deregister(IoHandlerChain.Entry entry)
-
checkOldName
private IoHandlerChain.Entry checkOldName(java.lang.String baseName)
Throws an exception when the specified filter name is not registered in this chain.- Returns:
- An filter entry with the specified name.
-
checkAddable
private void checkAddable(java.lang.String name)
Checks the specified filter name is already taken and throws an exception if already taken.
-
execute
public void execute(IoHandlerCommand.NextCommand next, IoSession session, java.lang.Object message) throws java.lang.Exception
Execute a unit of processing work to be performed. This
IoHandlerCommandmay either complete the required processing and just return to stop the processing, or delegate remaining processing to the nextIoHandlerCommandin aIoHandlerChaincontaining thisIoHandlerCommandby callingIoHandlerCommand.NextCommand.execute(IoSession,Object).- Specified by:
executein interfaceIoHandlerCommand- Parameters:
next- an indirect reference to the nextIoHandlerCommandthat provides a way to forward the request to the nextIoHandlerCommand.session- theIoSessionwhich is associated with this requestmessage- the message object of this request- Throws:
java.lang.Exception- general purpose exception return to indicate abnormal termination
-
callNextCommand
private void callNextCommand(IoHandlerChain.Entry entry, IoSession session, java.lang.Object message) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getAll
public java.util.List<IoHandlerChain.Entry> getAll()
- Returns:
- The list of name-commands registered into the chain
-
getAllReversed
public java.util.List<IoHandlerChain.Entry> getAllReversed()
- Returns:
- A reverted list of the registered name-commands
-
contains
public boolean contains(java.lang.String name)
Checks if the chain ofIoHandlerCommandcontains aIoHandlerCommandby its name- Parameters:
name- TheIoHandlerCommandname- Returns:
TRUEif theIoHandlerCommandis found in the chain
-
contains
public boolean contains(IoHandlerCommand command)
Checks if the chain ofIoHandlerCommandcontains a specificIoHandlerCommand- Parameters:
command- TheIoHandlerCommandwe are looking for- Returns:
TRUEif theIoHandlerCommandis found in the chain
-
contains
public boolean contains(java.lang.Class<? extends IoHandlerCommand> commandType)
Checks if the chain ofIoHandlerCommandcontains a specificIoHandlerCommand- Parameters:
commandType- The type ofIoHandlerCommandwe are looking for- Returns:
TRUEif theIoHandlerCommandis found in the chain
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-