Package org.apache.mina.core.filterchain
Class DefaultIoFilterChain
- java.lang.Object
-
- org.apache.mina.core.filterchain.DefaultIoFilterChain
-
- All Implemented Interfaces:
IoFilterChain
- Direct Known Subclasses:
VmPipeFilterChain
public class DefaultIoFilterChain extends java.lang.Object implements IoFilterChain
A default implementation ofIoFilterChainthat provides all operations for developers who want to implement their own transport layer once used withAbstractIoSession.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classDefaultIoFilterChain.EntryImplprivate classDefaultIoFilterChain.HeadFilterprivate static classDefaultIoFilterChain.TailFilter-
Nested classes/interfaces inherited from interface org.apache.mina.core.filterchain.IoFilterChain
IoFilterChain.Entry
-
-
Field Summary
Fields Modifier and Type Field Description private DefaultIoFilterChain.EntryImplheadThe chain headprivate static org.slf4j.LoggerLOGGERThe logger for this classprivate java.util.Map<java.lang.String,IoFilterChain.Entry>name2entryThe mapping between the filters and their associated nameprivate AbstractIoSessionsessionThe associated sessionstatic AttributeKeySESSION_CREATED_FUTUREprivate DefaultIoFilterChain.EntryImpltailThe chain tail
-
Constructor Summary
Constructors Constructor Description DefaultIoFilterChain(AbstractIoSession session)Create a new default chain, associated with a session.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAfter(java.lang.String baseName, java.lang.String name, IoFilter filter)Adds the specified filter with the specified name just after the filter whose name isbaseNamein this chain.voidaddBefore(java.lang.String baseName, java.lang.String name, IoFilter filter)Adds the specified filter with the specified name just before the filter whose name isbaseNamein this chain.voidaddFirst(java.lang.String name, IoFilter filter)Adds the specified filter with the specified name at the beginning of this chain.voidaddLast(java.lang.String name, IoFilter filter)Adds the specified filter with the specified name at the end of this chain.private voidcallNextExceptionCaught(IoFilterChain.Entry entry, IoSession session, java.lang.Throwable cause)private voidcallNextFilterEvent(IoFilterChain.Entry entry, IoSession session, FilterEvent event)private voidcallNextInputClosed(IoFilterChain.Entry entry, IoSession session)private voidcallNextMessageReceived(IoFilterChain.Entry entry, IoSession session, java.lang.Object message)private voidcallNextMessageSent(IoFilterChain.Entry entry, IoSession session, WriteRequest writeRequest)private voidcallNextSessionClosed(IoFilterChain.Entry entry, IoSession session)private voidcallNextSessionCreated(IoFilterChain.Entry entry, IoSession session)private voidcallNextSessionIdle(IoFilterChain.Entry entry, IoSession session, IdleStatus status)private voidcallNextSessionOpened(IoFilterChain.Entry entry, IoSession session)private voidcallPreviousFilterClose(IoFilterChain.Entry entry, IoSession session)private voidcallPreviousFilterWrite(IoFilterChain.Entry entry, IoSession session, WriteRequest writeRequest)private voidcheckAddable(java.lang.String name)Checks the specified filter name is already taken and throws an exception if already taken.private DefaultIoFilterChain.EntryImplcheckOldName(java.lang.String baseName)Throws an exception when the specified filter name is not registered in this chain.voidclear()Removes all filters added to this chain.booleancontains(java.lang.Class<? extends IoFilter> filterType)booleancontains(java.lang.String name)booleancontains(IoFilter filter)private voidderegister(DefaultIoFilterChain.EntryImpl entry)private voidderegister0(DefaultIoFilterChain.EntryImpl entry)voidfireEvent(FilterEvent event)Fires aIoHandler.event(IoSession, FilterEvent)event.voidfireExceptionCaught(java.lang.Throwable cause)Fires aIoHandler.exceptionCaught(IoSession, Throwable)event.voidfireFilterClose()Fires aIoSession.closeNow()or aIoSession.closeOnFlush()event.voidfireFilterWrite(WriteRequest writeRequest)Fires aIoSession.write(Object)event.voidfireInputClosed()Fires aIoHandler.inputClosed(IoSession)event.voidfireMessageReceived(java.lang.Object message)Fires aIoHandler.messageReceived(IoSession, Object)event.voidfireMessageSent(WriteRequest request)Fires aIoHandler.messageSent(IoSession, Object)event.voidfireSessionClosed()Fires aIoHandler.sessionClosed(IoSession)event.voidfireSessionCreated()Fires aIoHandler.sessionCreated(IoSession)event.voidfireSessionIdle(IdleStatus status)Fires aIoHandler.sessionIdle(IoSession, IdleStatus)event.voidfireSessionOpened()Fires aIoHandler.sessionOpened(IoSession)event.IoFilterget(java.lang.Class<? extends IoFilter> filterType)Returns theIoFilterwith the specifiedfilterTypein this chain.IoFilterget(java.lang.String name)Returns theIoFilterwith the specifiednamein this chain.java.util.List<IoFilterChain.Entry>getAll()java.util.List<IoFilterChain.Entry>getAllReversed()IoFilterChain.EntrygetEntry(java.lang.Class<? extends IoFilter> filterType)Returns theIoFilterChain.Entrywith the specifiedfilterTypein this chain.IoFilterChain.EntrygetEntry(java.lang.String name)Returns theIoFilterChain.Entrywith the specifiednamein this chain.IoFilterChain.EntrygetEntry(IoFilter filter)Returns theIoFilterChain.Entrywith the specifiedfilterin this chain.IoFilter.NextFiltergetNextFilter(java.lang.Class<? extends IoFilter> filterType)Returns theIoFilter.NextFilterof the specifiedfilterTypein this chain.IoFilter.NextFiltergetNextFilter(java.lang.String name)IoFilter.NextFiltergetNextFilter(IoFilter filter)Returns theIoFilter.NextFilterof the specifiedIoFilterin this chain.IoSessiongetSession()private voidregister(DefaultIoFilterChain.EntryImpl prevEntry, java.lang.String name, IoFilter filter)Register the newly added filter, inserting it between the previous and the next filter in the filter's chain.IoFilterremove(java.lang.Class<? extends IoFilter> filterType)Replace the filter of the specified type with the specified new filter.IoFilterremove(java.lang.String name)Removes the filter with the specified name from this chain.voidremove(IoFilter filter)Replace the filter with the specified name with the specified new filter.IoFilterreplace(java.lang.Class<? extends IoFilter> oldFilterType, IoFilter newFilter)Replace the filter of the specified type with the specified new filter.IoFilterreplace(java.lang.String name, IoFilter newFilter)Replace the filter with the specified name with the specified new filter.voidreplace(IoFilter oldFilter, IoFilter newFilter)Replace the filter with the specified name with the specified new filter.java.lang.StringtoString()
-
-
-
Field Detail
-
SESSION_CREATED_FUTURE
public static final AttributeKey SESSION_CREATED_FUTURE
A session attribute that stores anIoFuturerelated with theIoSession.DefaultIoFilterChainclears this attribute and notifies the future whenfireSessionCreated()orfireExceptionCaught(Throwable)is invoked.
-
session
private final AbstractIoSession session
The associated session
-
name2entry
private final java.util.Map<java.lang.String,IoFilterChain.Entry> name2entry
The mapping between the filters and their associated name
-
head
private final DefaultIoFilterChain.EntryImpl head
The chain head
-
tail
private final DefaultIoFilterChain.EntryImpl tail
The chain tail
-
LOGGER
private static final org.slf4j.Logger LOGGER
The logger for this class
-
-
Constructor Detail
-
DefaultIoFilterChain
public DefaultIoFilterChain(AbstractIoSession session)
Create a new default chain, associated with a session. It will only contain a HeadFilter and a TailFilter.- Parameters:
session- The session associated with the created filter chain
-
-
Method Detail
-
getSession
public IoSession getSession()
- Specified by:
getSessionin interfaceIoFilterChain- Returns:
- the parent
IoSessionof this chain.
-
getEntry
public IoFilterChain.Entry getEntry(java.lang.String name)
Returns theIoFilterChain.Entrywith the specifiednamein this chain.- Specified by:
getEntryin interfaceIoFilterChain- Parameters:
name- The filter's name we are looking for- Returns:
nullif there's no such name in this chain
-
getEntry
public IoFilterChain.Entry getEntry(IoFilter filter)
Returns theIoFilterChain.Entrywith the specifiedfilterin this chain.- Specified by:
getEntryin interfaceIoFilterChain- Parameters:
filter- The Filter we are looking for- Returns:
nullif there's no such filter in this chain
-
getEntry
public IoFilterChain.Entry getEntry(java.lang.Class<? extends IoFilter> filterType)
Returns theIoFilterChain.Entrywith the specifiedfilterTypein this chain. If there's more than one filter with the specified type, the first match will be chosen.- Specified by:
getEntryin interfaceIoFilterChain- Parameters:
filterType- The filter class we are looking for- Returns:
nullif there's no such name in this chain
-
get
public IoFilter get(java.lang.String name)
Returns theIoFilterwith the specifiednamein this chain.- Specified by:
getin interfaceIoFilterChain- Parameters:
name- the filter's name- Returns:
nullif there's no such name in this chain
-
get
public IoFilter get(java.lang.Class<? extends IoFilter> filterType)
Returns theIoFilterwith the specifiedfilterTypein this chain. If there's more than one filter with the specified type, the first match will be chosen.- Specified by:
getin interfaceIoFilterChain- Parameters:
filterType- The filter class- Returns:
nullif there's no such name in this chain
-
getNextFilter
public IoFilter.NextFilter getNextFilter(java.lang.String name)
- Specified by:
getNextFilterin interfaceIoFilterChain- Parameters:
name- The filter's name we want the next filter- Returns:
nullif there's no such name in this chain
-
getNextFilter
public IoFilter.NextFilter getNextFilter(IoFilter filter)
Returns theIoFilter.NextFilterof the specifiedIoFilterin this chain.- Specified by:
getNextFilterin interfaceIoFilterChain- Parameters:
filter- The filter for which we want the next filter- Returns:
nullif there's no such name in this chain
-
getNextFilter
public IoFilter.NextFilter getNextFilter(java.lang.Class<? extends IoFilter> filterType)
Returns theIoFilter.NextFilterof the specifiedfilterTypein this chain. If there's more than one filter with the specified type, the first match will be chosen.- Specified by:
getNextFilterin interfaceIoFilterChain- Parameters:
filterType- The Filter class for which we want the next filter- Returns:
nullif there's no such name in this chain
-
addFirst
public void addFirst(java.lang.String name, IoFilter filter)Adds the specified filter with the specified name at the beginning of this chain.- Specified by:
addFirstin interfaceIoFilterChain- Parameters:
name- The filter's namefilter- The filter to add
-
addLast
public void addLast(java.lang.String name, IoFilter filter)Adds the specified filter with the specified name at the end of this chain.- Specified by:
addLastin interfaceIoFilterChain- Parameters:
name- The filter's namefilter- The filter to add
-
addBefore
public void addBefore(java.lang.String baseName, java.lang.String name, IoFilter filter)Adds the specified filter with the specified name just before the filter whose name isbaseNamein this chain.- Specified by:
addBeforein interfaceIoFilterChain- Parameters:
baseName- The targeted Filter's namename- The filter's namefilter- The filter to add
-
addAfter
public void addAfter(java.lang.String baseName, java.lang.String name, IoFilter filter)Adds the specified filter with the specified name just after the filter whose name isbaseNamein this chain.- Specified by:
addAfterin interfaceIoFilterChain- Parameters:
baseName- The targeted Filter's namename- The filter's namefilter- The filter to add
-
remove
public IoFilter remove(java.lang.String name)
Removes the filter with the specified name from this chain.- Specified by:
removein interfaceIoFilterChain- Parameters:
name- The name of the filter to remove- Returns:
- The removed filter
-
remove
public void remove(IoFilter filter)
Replace the filter with the specified name with the specified new filter.- Specified by:
removein interfaceIoFilterChain- Parameters:
filter- The filter to remove
-
remove
public IoFilter remove(java.lang.Class<? extends IoFilter> filterType)
Replace the filter of the specified type with the specified new filter. If there's more than one filter with the specified type, the first match will be replaced.- Specified by:
removein interfaceIoFilterChain- Parameters:
filterType- The filter class to remove- Returns:
- The removed filter
-
replace
public IoFilter replace(java.lang.String name, IoFilter newFilter)
Replace the filter with the specified name with the specified new filter.- Specified by:
replacein interfaceIoFilterChain- Parameters:
name- The name of the filter we want to replacenewFilter- The new filter- Returns:
- the old filter
-
replace
public void replace(IoFilter oldFilter, IoFilter newFilter)
Replace the filter with the specified name with the specified new filter.- Specified by:
replacein interfaceIoFilterChain- Parameters:
oldFilter- The filter we want to replacenewFilter- The new filter
-
replace
public IoFilter replace(java.lang.Class<? extends IoFilter> oldFilterType, IoFilter newFilter)
Replace the filter of the specified type with the specified new filter. If there's more than one filter with the specified type, the first match will be replaced.- Specified by:
replacein interfaceIoFilterChain- Parameters:
oldFilterType- The filter class we want to replacenewFilter- The new filter- Returns:
- The replaced IoFilter
-
clear
public void clear() throws java.lang.ExceptionRemoves all filters added to this chain.- Specified by:
clearin interfaceIoFilterChain- Throws:
java.lang.Exception- If we weren't able to clear the filters
-
register
private void register(DefaultIoFilterChain.EntryImpl prevEntry, java.lang.String name, IoFilter filter)
Register the newly added filter, inserting it between the previous and the next filter in the filter's chain. We also call the preAdd and postAdd methods.
-
deregister
private void deregister(DefaultIoFilterChain.EntryImpl entry)
-
deregister0
private void deregister0(DefaultIoFilterChain.EntryImpl entry)
-
checkOldName
private DefaultIoFilterChain.EntryImpl 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.
-
fireSessionCreated
public void fireSessionCreated()
Fires aIoHandler.sessionCreated(IoSession)event. Most users don't need to call this method at all. Please use this method only when you implement a new transport or fire a virtual event.- Specified by:
fireSessionCreatedin interfaceIoFilterChain
-
callNextSessionCreated
private void callNextSessionCreated(IoFilterChain.Entry entry, IoSession session)
-
fireSessionOpened
public void fireSessionOpened()
Fires aIoHandler.sessionOpened(IoSession)event. Most users don't need to call this method at all. Please use this method only when you implement a new transport or fire a virtual event.- Specified by:
fireSessionOpenedin interfaceIoFilterChain
-
fireEvent
public void fireEvent(FilterEvent event)
Fires aIoHandler.event(IoSession, FilterEvent)event. Most users don't need to call this method at all. Please use this method only when you implement a new transport or fire a virtual event.- Specified by:
fireEventin interfaceIoFilterChain- Parameters:
event- The specific event being fired
-
callNextSessionOpened
private void callNextSessionOpened(IoFilterChain.Entry entry, IoSession session)
-
fireSessionClosed
public void fireSessionClosed()
Fires aIoHandler.sessionClosed(IoSession)event. Most users don't need to call this method at all. Please use this method only when you implement a new transport or fire a virtual event.- Specified by:
fireSessionClosedin interfaceIoFilterChain
-
callNextSessionClosed
private void callNextSessionClosed(IoFilterChain.Entry entry, IoSession session)
-
fireSessionIdle
public void fireSessionIdle(IdleStatus status)
Fires aIoHandler.sessionIdle(IoSession, IdleStatus)event. Most users don't need to call this method at all. Please use this method only when you implement a new transport or fire a virtual event.- Specified by:
fireSessionIdlein interfaceIoFilterChain- Parameters:
status- The current status to propagate
-
callNextSessionIdle
private void callNextSessionIdle(IoFilterChain.Entry entry, IoSession session, IdleStatus status)
-
fireMessageReceived
public void fireMessageReceived(java.lang.Object message)
Fires aIoHandler.messageReceived(IoSession, Object)event. Most users don't need to call this method at all. Please use this method only when you implement a new transport or fire a virtual event.- Specified by:
fireMessageReceivedin interfaceIoFilterChain- Parameters:
message- The received message
-
callNextMessageReceived
private void callNextMessageReceived(IoFilterChain.Entry entry, IoSession session, java.lang.Object message)
-
fireMessageSent
public void fireMessageSent(WriteRequest request)
Fires aIoHandler.messageSent(IoSession, Object)event. Most users don't need to call this method at all. Please use this method only when you implement a new transport or fire a virtual event.- Specified by:
fireMessageSentin interfaceIoFilterChain- Parameters:
request- The sent request
-
callNextMessageSent
private void callNextMessageSent(IoFilterChain.Entry entry, IoSession session, WriteRequest writeRequest)
-
fireExceptionCaught
public void fireExceptionCaught(java.lang.Throwable cause)
Fires aIoHandler.exceptionCaught(IoSession, Throwable)event. Most users don't need to call this method at all. Please use this method only when you implement a new transport or fire a virtual event.- Specified by:
fireExceptionCaughtin interfaceIoFilterChain- Parameters:
cause- The exception cause
-
callNextExceptionCaught
private void callNextExceptionCaught(IoFilterChain.Entry entry, IoSession session, java.lang.Throwable cause)
-
fireInputClosed
public void fireInputClosed()
Fires aIoHandler.inputClosed(IoSession)event. Most users don't need to call this method at all. Please use this method only when you implement a new transport or fire a virtual event.- Specified by:
fireInputClosedin interfaceIoFilterChain
-
callNextInputClosed
private void callNextInputClosed(IoFilterChain.Entry entry, IoSession session)
-
fireFilterWrite
public void fireFilterWrite(WriteRequest writeRequest)
Fires aIoSession.write(Object)event. Most users don't need to call this method at all. Please use this method only when you implement a new transport or fire a virtual event.- Specified by:
fireFilterWritein interfaceIoFilterChain- Parameters:
writeRequest- The message to write
-
callPreviousFilterWrite
private void callPreviousFilterWrite(IoFilterChain.Entry entry, IoSession session, WriteRequest writeRequest)
-
fireFilterClose
public void fireFilterClose()
Fires aIoSession.closeNow()or aIoSession.closeOnFlush()event. Most users don't need to call this method at all. Please use this method only when you implement a new transport or fire a virtual event.- Specified by:
fireFilterClosein interfaceIoFilterChain
-
callPreviousFilterClose
private void callPreviousFilterClose(IoFilterChain.Entry entry, IoSession session)
-
callNextFilterEvent
private void callNextFilterEvent(IoFilterChain.Entry entry, IoSession session, FilterEvent event)
-
getAll
public java.util.List<IoFilterChain.Entry> getAll()
- Specified by:
getAllin interfaceIoFilterChain- Returns:
- The list of all
IoFilterChain.Entrys this chain contains.
-
getAllReversed
public java.util.List<IoFilterChain.Entry> getAllReversed()
- Specified by:
getAllReversedin interfaceIoFilterChain- Returns:
- The reversed list of all
IoFilterChain.Entrys this chain contains.
-
contains
public boolean contains(java.lang.String name)
- Specified by:
containsin interfaceIoFilterChain- Parameters:
name- The filter's name we are looking for- Returns:
trueif this chain contains anIoFilterwith the specifiedname.
-
contains
public boolean contains(IoFilter filter)
- Specified by:
containsin interfaceIoFilterChain- Parameters:
filter- The filter we are looking for- Returns:
trueif this chain contains the specifiedfilter.
-
contains
public boolean contains(java.lang.Class<? extends IoFilter> filterType)
- Specified by:
containsin interfaceIoFilterChain- Parameters:
filterType- The filter's class we are looking for- Returns:
trueif this chain contains anIoFilterof the specifiedfilterType.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-