public class DefaultIoFilterChain extends java.lang.Object implements IoFilterChain
IoFilterChain that provides
all operations for developers who want to implement their own
transport layer once used with AbstractIoSession.| Modifier and Type | Class and Description |
|---|---|
private class |
DefaultIoFilterChain.EntryImpl |
private class |
DefaultIoFilterChain.HeadFilter |
private static class |
DefaultIoFilterChain.TailFilter |
IoFilterChain.Entry| Modifier and Type | Field and Description |
|---|---|
private DefaultIoFilterChain.EntryImpl |
head
The chain head
|
private static org.slf4j.Logger |
LOGGER
The logger for this class
|
private java.util.Map<java.lang.String,IoFilterChain.Entry> |
name2entry
The mapping between the filters and their associated name
|
private AbstractIoSession |
session
The associated session
|
static AttributeKey |
SESSION_CREATED_FUTURE
|
private DefaultIoFilterChain.EntryImpl |
tail
The chain tail
|
| Constructor and Description |
|---|
DefaultIoFilterChain(AbstractIoSession session)
Create a new default chain, associated with a session.
|
| Modifier and Type | Method and Description |
|---|---|
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 is
baseName in this chain. |
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 is
baseName in this chain. |
void |
addFirst(java.lang.String name,
IoFilter filter)
Adds the specified filter with the specified name at the beginning of this chain.
|
void |
addLast(java.lang.String name,
IoFilter filter)
Adds the specified filter with the specified name at the end of this chain.
|
private void |
callNextExceptionCaught(IoFilterChain.Entry entry,
IoSession session,
java.lang.Throwable cause) |
private void |
callNextInputClosed(IoFilterChain.Entry entry,
IoSession session) |
private void |
callNextMessageReceived(IoFilterChain.Entry entry,
IoSession session,
java.lang.Object message) |
private void |
callNextMessageSent(IoFilterChain.Entry entry,
IoSession session,
WriteRequest writeRequest) |
private void |
callNextSessionClosed(IoFilterChain.Entry entry,
IoSession session) |
private void |
callNextSessionCreated(IoFilterChain.Entry entry,
IoSession session) |
private void |
callNextSessionIdle(IoFilterChain.Entry entry,
IoSession session,
IdleStatus status) |
private void |
callNextSessionOpened(IoFilterChain.Entry entry,
IoSession session) |
private void |
callPreviousFilterClose(IoFilterChain.Entry entry,
IoSession session) |
private void |
callPreviousFilterWrite(IoFilterChain.Entry entry,
IoSession session,
WriteRequest writeRequest) |
private void |
checkAddable(java.lang.String name)
Checks the specified filter name is already taken and throws an exception if already taken.
|
private DefaultIoFilterChain.EntryImpl |
checkOldName(java.lang.String baseName)
Throws an exception when the specified filter name is not registered in this chain.
|
void |
clear()
Removes all filters added to this chain.
|
boolean |
contains(java.lang.Class<? extends IoFilter> filterType) |
boolean |
contains(IoFilter filter) |
boolean |
contains(java.lang.String name) |
private void |
deregister(DefaultIoFilterChain.EntryImpl entry) |
private void |
deregister0(DefaultIoFilterChain.EntryImpl entry) |
void |
fireExceptionCaught(java.lang.Throwable cause)
Fires a
IoHandler.exceptionCaught(IoSession, Throwable) event. |
void |
fireFilterClose()
Fires a
IoSession.close() event. |
void |
fireFilterWrite(WriteRequest writeRequest)
Fires a
IoSession.write(Object) event. |
void |
fireInputClosed()
Fires a
IoHandler.inputClosed(IoSession) event. |
void |
fireMessageReceived(java.lang.Object message)
Fires a
IoHandler.messageReceived(IoSession, Object) event. |
void |
fireMessageSent(WriteRequest request)
Fires a
IoHandler.messageSent(IoSession, Object) event. |
void |
fireSessionClosed()
Fires a
IoHandler.sessionClosed(IoSession) event. |
void |
fireSessionCreated()
Fires a
IoHandler.sessionCreated(IoSession) event. |
void |
fireSessionIdle(IdleStatus status)
Fires a
IoHandler.sessionIdle(IoSession, IdleStatus) event. |
void |
fireSessionOpened()
Fires a
IoHandler.sessionOpened(IoSession) event. |
IoFilter |
get(java.lang.Class<? extends IoFilter> filterType)
Returns the
IoFilter with the specified filterType
in this chain. |
IoFilter |
get(java.lang.String name)
Returns the
IoFilter with the specified name in this chain. |
java.util.List<IoFilterChain.Entry> |
getAll() |
java.util.List<IoFilterChain.Entry> |
getAllReversed() |
IoFilterChain.Entry |
getEntry(java.lang.Class<? extends IoFilter> filterType)
Returns the
IoFilterChain.Entry with the specified filterType
in this chain. |
IoFilterChain.Entry |
getEntry(IoFilter filter)
Returns the
IoFilterChain.Entry with the specified filter in this chain. |
IoFilterChain.Entry |
getEntry(java.lang.String name)
Returns the
IoFilterChain.Entry with the specified name in this chain. |
IoFilter.NextFilter |
getNextFilter(java.lang.Class<? extends IoFilter> filterType)
Returns the
IoFilter.NextFilter of the specified filterType
in this chain. |
IoFilter.NextFilter |
getNextFilter(IoFilter filter)
Returns the
IoFilter.NextFilter of the specified IoFilter
in this chain. |
IoFilter.NextFilter |
getNextFilter(java.lang.String name)
Returns the
IoFilter.NextFilter of the IoFilter with the
specified name in this chain. |
IoSession |
getSession()
Returns the parent
IoSession of this chain. |
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.
|
IoFilter |
remove(java.lang.Class<? extends IoFilter> filterType)
Replace the filter of the specified type with the specified new filter.
|
void |
remove(IoFilter filter)
Replace the filter with the specified name with the specified new filter.
|
IoFilter |
remove(java.lang.String name)
Removes the filter with the specified name from this chain.
|
IoFilter |
replace(java.lang.Class<? extends IoFilter> oldFilterType,
IoFilter newFilter)
Replace the filter of the specified type with the specified new
filter.
|
void |
replace(IoFilter oldFilter,
IoFilter newFilter)
Replace the filter with the specified name with the specified new
filter.
|
IoFilter |
replace(java.lang.String name,
IoFilter newFilter)
Replace the filter with the specified name with the specified new
filter.
|
java.lang.String |
toString() |
public static final AttributeKey SESSION_CREATED_FUTURE
IoFuture related with
the IoSession. DefaultIoFilterChain clears this
attribute and notifies the future when fireSessionCreated()
or fireExceptionCaught(Throwable) is invoked.private final AbstractIoSession session
private final java.util.Map<java.lang.String,IoFilterChain.Entry> name2entry
private final DefaultIoFilterChain.EntryImpl head
private final DefaultIoFilterChain.EntryImpl tail
private static final org.slf4j.Logger LOGGER
public DefaultIoFilterChain(AbstractIoSession session)
session - The session associated with the created filter chainpublic IoSession getSession()
IoFilterChainIoSession of this chain.getSession in interface IoFilterChainIoSessionpublic IoFilterChain.Entry getEntry(java.lang.String name)
IoFilterChainIoFilterChain.Entry with the specified name in this chain.getEntry in interface IoFilterChainname - The filter's name we are looking forpublic IoFilterChain.Entry getEntry(IoFilter filter)
IoFilterChainIoFilterChain.Entry with the specified filter in this chain.getEntry in interface IoFilterChainfilter - The Filter we are looking forpublic IoFilterChain.Entry getEntry(java.lang.Class<? extends IoFilter> filterType)
IoFilterChainIoFilterChain.Entry with the specified filterType
in this chain. If there's more than one filter with the specified
type, the first match will be chosen.getEntry in interface IoFilterChainfilterType - The filter class we are looking forpublic IoFilter get(java.lang.String name)
IoFilterChainIoFilter with the specified name in this chain.get in interface IoFilterChainname - the filter's namepublic IoFilter get(java.lang.Class<? extends IoFilter> filterType)
IoFilterChainIoFilter with the specified filterType
in this chain. If there's more than one filter with the specified
type, the first match will be chosen.get in interface IoFilterChainfilterType - The filter classpublic IoFilter.NextFilter getNextFilter(java.lang.String name)
IoFilterChainIoFilter.NextFilter of the IoFilter with the
specified name in this chain.getNextFilter in interface IoFilterChainname - The filter's name we want the next filterpublic IoFilter.NextFilter getNextFilter(IoFilter filter)
IoFilterChainIoFilter.NextFilter of the specified IoFilter
in this chain.getNextFilter in interface IoFilterChainfilter - The filter for which we want the next filterpublic IoFilter.NextFilter getNextFilter(java.lang.Class<? extends IoFilter> filterType)
IoFilterChainIoFilter.NextFilter of the specified filterType
in this chain. If there's more than one filter with the specified
type, the first match will be chosen.getNextFilter in interface IoFilterChainfilterType - The Filter class for which we want the next filterpublic void addFirst(java.lang.String name,
IoFilter filter)
IoFilterChainaddFirst in interface IoFilterChainname - The filter's namefilter - The filter to addpublic void addLast(java.lang.String name,
IoFilter filter)
IoFilterChainaddLast in interface IoFilterChainname - The filter's namefilter - The filter to addpublic void addBefore(java.lang.String baseName,
java.lang.String name,
IoFilter filter)
IoFilterChainbaseName in this chain.addBefore in interface IoFilterChainbaseName - The targeted Filter's namename - The filter's namefilter - The filter to addpublic void addAfter(java.lang.String baseName,
java.lang.String name,
IoFilter filter)
IoFilterChainbaseName in this chain.addAfter in interface IoFilterChainbaseName - The targeted Filter's namename - The filter's namefilter - The filter to addpublic IoFilter remove(java.lang.String name)
IoFilterChainremove in interface IoFilterChainname - The name of the filter to removepublic void remove(IoFilter filter)
IoFilterChainremove in interface IoFilterChainfilter - The filter to removepublic IoFilter remove(java.lang.Class<? extends IoFilter> filterType)
IoFilterChainremove in interface IoFilterChainfilterType - The filter class to removepublic IoFilter replace(java.lang.String name, IoFilter newFilter)
IoFilterChainreplace in interface IoFilterChainname - The name of the filter we want to replacenewFilter - The new filterpublic void replace(IoFilter oldFilter, IoFilter newFilter)
IoFilterChainreplace in interface IoFilterChainoldFilter - The filter we want to replacenewFilter - The new filterpublic IoFilter replace(java.lang.Class<? extends IoFilter> oldFilterType, IoFilter newFilter)
IoFilterChainreplace in interface IoFilterChainoldFilterType - The filter class we want to replacenewFilter - The new filterpublic void clear()
throws java.lang.Exception
IoFilterChainclear in interface IoFilterChainjava.lang.Exceptionprivate void register(DefaultIoFilterChain.EntryImpl prevEntry, java.lang.String name, IoFilter filter)
private void deregister(DefaultIoFilterChain.EntryImpl entry)
private void deregister0(DefaultIoFilterChain.EntryImpl entry)
private DefaultIoFilterChain.EntryImpl checkOldName(java.lang.String baseName)
private void checkAddable(java.lang.String name)
public void fireSessionCreated()
IoFilterChainIoHandler.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.fireSessionCreated in interface IoFilterChainprivate void callNextSessionCreated(IoFilterChain.Entry entry, IoSession session)
public void fireSessionOpened()
IoFilterChainIoHandler.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.fireSessionOpened in interface IoFilterChainprivate void callNextSessionOpened(IoFilterChain.Entry entry, IoSession session)
public void fireSessionClosed()
IoFilterChainIoHandler.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.fireSessionClosed in interface IoFilterChainprivate void callNextSessionClosed(IoFilterChain.Entry entry, IoSession session)
public void fireSessionIdle(IdleStatus status)
IoFilterChainIoHandler.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.fireSessionIdle in interface IoFilterChainstatus - The current status to propagateprivate void callNextSessionIdle(IoFilterChain.Entry entry, IoSession session, IdleStatus status)
public void fireMessageReceived(java.lang.Object message)
IoFilterChainIoHandler.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.fireMessageReceived in interface IoFilterChainmessage - The received messageprivate void callNextMessageReceived(IoFilterChain.Entry entry, IoSession session, java.lang.Object message)
public void fireMessageSent(WriteRequest request)
IoFilterChainIoHandler.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.fireMessageSent in interface IoFilterChainrequest - The sent requestprivate void callNextMessageSent(IoFilterChain.Entry entry, IoSession session, WriteRequest writeRequest)
public void fireExceptionCaught(java.lang.Throwable cause)
IoFilterChainIoHandler.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.fireExceptionCaught in interface IoFilterChaincause - The exception causeprivate void callNextExceptionCaught(IoFilterChain.Entry entry, IoSession session, java.lang.Throwable cause)
public void fireInputClosed()
IoFilterChainIoHandler.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.fireInputClosed in interface IoFilterChainprivate void callNextInputClosed(IoFilterChain.Entry entry, IoSession session)
public void fireFilterWrite(WriteRequest writeRequest)
IoFilterChainIoSession.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.fireFilterWrite in interface IoFilterChainwriteRequest - The message to writeprivate void callPreviousFilterWrite(IoFilterChain.Entry entry, IoSession session, WriteRequest writeRequest)
public void fireFilterClose()
IoFilterChainIoSession.close() 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.fireFilterClose in interface IoFilterChainprivate void callPreviousFilterClose(IoFilterChain.Entry entry, IoSession session)
public java.util.List<IoFilterChain.Entry> getAll()
getAll in interface IoFilterChainIoFilterChain.Entrys this chain contains.public java.util.List<IoFilterChain.Entry> getAllReversed()
getAllReversed in interface IoFilterChainIoFilterChain.Entrys this chain contains.public boolean contains(java.lang.String name)
contains in interface IoFilterChainname - The filter's name we are looking forIoFilter with the
specified name.public boolean contains(IoFilter filter)
contains in interface IoFilterChainfilter - The filter we are looking forpublic boolean contains(java.lang.Class<? extends IoFilter> filterType)
contains in interface IoFilterChainfilterType - The filter's class we are looking forIoFilter of the
specified filterType.public java.lang.String toString()
toString in class java.lang.Object