Package org.apache.mina.core.filterchain
Class DefaultIoFilterChain
- java.lang.Object
-
- org.apache.mina.core.filterchain.DefaultIoFilterChain
-
- All Implemented Interfaces:
IoFilterChain
public class DefaultIoFilterChain extends Object implements IoFilterChain
A default implementation ofIoFilterChain
that provides all operations for developers who want to implement their own transport layer once used withAbstractIoSession
.- Author:
- Apache MINA Project
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.mina.core.filterchain.IoFilterChain
IoFilterChain.Entry
-
-
Field Summary
Fields Modifier and Type Field Description static AttributeKey
SESSION_CREATED_FUTURE
-
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 void
addAfter(String baseName, String name, IoFilter filter)
Adds the specified filter with the specified name just after the filter whose name isbaseName
in this chain.void
addBefore(String baseName, String name, IoFilter filter)
Adds the specified filter with the specified name just before the filter whose name isbaseName
in this chain.void
addFirst(String name, IoFilter filter)
Adds the specified filter with the specified name at the beginning of this chain.void
addLast(String name, IoFilter filter)
Adds the specified filter with the specified name at the end of this chain.void
clear()
Removes all filters added to this chain.boolean
contains(Class<? extends IoFilter> filterType)
boolean
contains(String name)
boolean
contains(IoFilter filter)
void
fireEvent(FilterEvent event)
Fires aIoHandler.event(IoSession, FilterEvent)
event.void
fireExceptionCaught(Throwable cause)
Fires aIoHandler.exceptionCaught(IoSession, Throwable)
event.void
fireFilterClose()
Fires aIoSession.closeNow()
or aIoSession.closeOnFlush()
event.void
fireFilterWrite(WriteRequest writeRequest)
Fires aIoSession.write(Object)
event.void
fireInputClosed()
Fires aIoHandler.inputClosed(IoSession)
event.void
fireMessageReceived(Object message)
Fires aIoHandler.messageReceived(IoSession, Object)
event.void
fireMessageSent(WriteRequest request)
Fires aIoHandler.messageSent(IoSession, Object)
event.void
fireSessionClosed()
Fires aIoHandler.sessionClosed(IoSession)
event.void
fireSessionCreated()
Fires aIoHandler.sessionCreated(IoSession)
event.void
fireSessionIdle(IdleStatus status)
Fires aIoHandler.sessionIdle(IoSession, IdleStatus)
event.void
fireSessionOpened()
Fires aIoHandler.sessionOpened(IoSession)
event.IoFilter
get(Class<? extends IoFilter> filterType)
Returns theIoFilter
with the specifiedfilterType
in this chain.IoFilter
get(String name)
Returns theIoFilter
with the specifiedname
in this chain.List<IoFilterChain.Entry>
getAll()
List<IoFilterChain.Entry>
getAllReversed()
IoFilterChain.Entry
getEntry(Class<? extends IoFilter> filterType)
Returns theIoFilterChain.Entry
with the specifiedfilterType
in this chain.IoFilterChain.Entry
getEntry(String name)
Returns theIoFilterChain.Entry
with the specifiedname
in this chain.IoFilterChain.Entry
getEntry(IoFilter filter)
Returns theIoFilterChain.Entry
with the specifiedfilter
in this chain.IoFilter.NextFilter
getNextFilter(Class<? extends IoFilter> filterType)
Returns theIoFilter.NextFilter
of the specifiedfilterType
in this chain.IoFilter.NextFilter
getNextFilter(String name)
IoFilter.NextFilter
getNextFilter(IoFilter filter)
Returns theIoFilter.NextFilter
of the specifiedIoFilter
in this chain.IoSession
getSession()
IoFilter
remove(Class<? extends IoFilter> filterType)
Replace the filter of the specified type with the specified new filter.IoFilter
remove(String name)
Removes the filter with the specified name from this chain.void
remove(IoFilter filter)
Replace the filter with the specified name with the specified new filter.IoFilter
replace(Class<? extends IoFilter> oldFilterType, IoFilter newFilter)
Replace the filter of the specified type with the specified new filter.IoFilter
replace(String name, IoFilter newFilter)
Replace the filter with the specified name with the specified new filter.void
replace(IoFilter oldFilter, IoFilter newFilter)
Replace the filter with the specified name with the specified new filter.String
toString()
-
-
-
Field Detail
-
SESSION_CREATED_FUTURE
public static final AttributeKey SESSION_CREATED_FUTURE
A session attribute that stores anIoFuture
related with theIoSession
.DefaultIoFilterChain
clears this attribute and notifies the future whenfireSessionCreated()
orfireExceptionCaught(Throwable)
is invoked.
-
-
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:
getSession
in interfaceIoFilterChain
- Returns:
- the parent
IoSession
of this chain.
-
getEntry
public IoFilterChain.Entry getEntry(String name)
Returns theIoFilterChain.Entry
with the specifiedname
in this chain.- Specified by:
getEntry
in interfaceIoFilterChain
- Parameters:
name
- The filter's name we are looking for- Returns:
null
if there's no such name in this chain
-
getEntry
public IoFilterChain.Entry getEntry(IoFilter filter)
Returns theIoFilterChain.Entry
with the specifiedfilter
in this chain.- Specified by:
getEntry
in interfaceIoFilterChain
- Parameters:
filter
- The Filter we are looking for- Returns:
null
if there's no such filter in this chain
-
getEntry
public IoFilterChain.Entry getEntry(Class<? extends IoFilter> filterType)
Returns theIoFilterChain.Entry
with the specifiedfilterType
in this chain. If there's more than one filter with the specified type, the first match will be chosen.- Specified by:
getEntry
in interfaceIoFilterChain
- Parameters:
filterType
- The filter class we are looking for- Returns:
null
if there's no such name in this chain
-
get
public IoFilter get(String name)
Returns theIoFilter
with the specifiedname
in this chain.- Specified by:
get
in interfaceIoFilterChain
- Parameters:
name
- the filter's name- Returns:
null
if there's no such name in this chain
-
get
public IoFilter get(Class<? extends IoFilter> filterType)
Returns theIoFilter
with the specifiedfilterType
in this chain. If there's more than one filter with the specified type, the first match will be chosen.- Specified by:
get
in interfaceIoFilterChain
- Parameters:
filterType
- The filter class- Returns:
null
if there's no such name in this chain
-
getNextFilter
public IoFilter.NextFilter getNextFilter(String name)
- Specified by:
getNextFilter
in interfaceIoFilterChain
- Parameters:
name
- The filter's name we want the next filter- Returns:
null
if there's no such name in this chain
-
getNextFilter
public IoFilter.NextFilter getNextFilter(IoFilter filter)
Returns theIoFilter.NextFilter
of the specifiedIoFilter
in this chain.- Specified by:
getNextFilter
in interfaceIoFilterChain
- Parameters:
filter
- The filter for which we want the next filter- Returns:
null
if there's no such name in this chain
-
getNextFilter
public IoFilter.NextFilter getNextFilter(Class<? extends IoFilter> filterType)
Returns theIoFilter.NextFilter
of the specifiedfilterType
in this chain. If there's more than one filter with the specified type, the first match will be chosen.- Specified by:
getNextFilter
in interfaceIoFilterChain
- Parameters:
filterType
- The Filter class for which we want the next filter- Returns:
null
if there's no such name in this chain
-
addFirst
public void addFirst(String name, IoFilter filter)
Adds the specified filter with the specified name at the beginning of this chain.- Specified by:
addFirst
in interfaceIoFilterChain
- Parameters:
name
- The filter's namefilter
- The filter to add
-
addLast
public void addLast(String name, IoFilter filter)
Adds the specified filter with the specified name at the end of this chain.- Specified by:
addLast
in interfaceIoFilterChain
- Parameters:
name
- The filter's namefilter
- The filter to add
-
addBefore
public void addBefore(String baseName, String name, IoFilter filter)
Adds the specified filter with the specified name just before the filter whose name isbaseName
in this chain.- Specified by:
addBefore
in interfaceIoFilterChain
- Parameters:
baseName
- The targeted Filter's namename
- The filter's namefilter
- The filter to add
-
addAfter
public void addAfter(String baseName, String name, IoFilter filter)
Adds the specified filter with the specified name just after the filter whose name isbaseName
in this chain.- Specified by:
addAfter
in interfaceIoFilterChain
- Parameters:
baseName
- The targeted Filter's namename
- The filter's namefilter
- The filter to add
-
remove
public IoFilter remove(String name)
Removes the filter with the specified name from this chain.- Specified by:
remove
in 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:
remove
in interfaceIoFilterChain
- Parameters:
filter
- The filter to remove
-
remove
public IoFilter remove(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:
remove
in interfaceIoFilterChain
- Parameters:
filterType
- The filter class to remove- Returns:
- The removed filter
-
replace
public IoFilter replace(String name, IoFilter newFilter)
Replace the filter with the specified name with the specified new filter.- Specified by:
replace
in 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:
replace
in interfaceIoFilterChain
- Parameters:
oldFilter
- The filter we want to replacenewFilter
- The new filter
-
replace
public IoFilter replace(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:
replace
in interfaceIoFilterChain
- Parameters:
oldFilterType
- The filter class we want to replacenewFilter
- The new filter- Returns:
- The replaced IoFilter
-
clear
public void clear() throws Exception
Removes all filters added to this chain.- Specified by:
clear
in interfaceIoFilterChain
- Throws:
Exception
- If we weren't able to clear the filters
-
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:
fireSessionCreated
in interfaceIoFilterChain
-
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:
fireSessionOpened
in 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:
fireEvent
in interfaceIoFilterChain
- Parameters:
event
- The specific event being fired
-
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:
fireSessionClosed
in interfaceIoFilterChain
-
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:
fireSessionIdle
in interfaceIoFilterChain
- Parameters:
status
- The current status to propagate
-
fireMessageReceived
public void fireMessageReceived(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:
fireMessageReceived
in interfaceIoFilterChain
- Parameters:
message
- The received 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:
fireMessageSent
in interfaceIoFilterChain
- Parameters:
request
- The sent request
-
fireExceptionCaught
public void fireExceptionCaught(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:
fireExceptionCaught
in interfaceIoFilterChain
- Parameters:
cause
- The exception 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:
fireInputClosed
in interfaceIoFilterChain
-
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:
fireFilterWrite
in interfaceIoFilterChain
- Parameters:
writeRequest
- The message to write
-
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:
fireFilterClose
in interfaceIoFilterChain
-
getAll
public List<IoFilterChain.Entry> getAll()
- Specified by:
getAll
in interfaceIoFilterChain
- Returns:
- The list of all
IoFilterChain.Entry
s this chain contains.
-
getAllReversed
public List<IoFilterChain.Entry> getAllReversed()
- Specified by:
getAllReversed
in interfaceIoFilterChain
- Returns:
- The reversed list of all
IoFilterChain.Entry
s this chain contains.
-
contains
public boolean contains(String name)
- Specified by:
contains
in interfaceIoFilterChain
- Parameters:
name
- The filter's name we are looking for- Returns:
true
if this chain contains anIoFilter
with the specifiedname
.
-
contains
public boolean contains(IoFilter filter)
- Specified by:
contains
in interfaceIoFilterChain
- Parameters:
filter
- The filter we are looking for- Returns:
true
if this chain contains the specifiedfilter
.
-
contains
public boolean contains(Class<? extends IoFilter> filterType)
- Specified by:
contains
in interfaceIoFilterChain
- Parameters:
filterType
- The filter's class we are looking for- Returns:
true
if this chain contains anIoFilter
of the specifiedfilterType
.
-
-