|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.xsocket.stream.HandlerChain
public final class HandlerChain
Implements a handler chain. Each handler of the chain will be called (in the registering order),
until one handler signal by the return value true, that the event has been handled. In
this case the remaing handlers will not be called.
E.g.
... HandlerChain tcpBasedSpamfilter = new HandlerChain(); tcpBasedSpamfilter.addLast(new BlackIPFilter()); tcpBasedSpamfilter.addLast(new FirstConnectRefuseFilter()); HandlerChain mainChain = new HandlerChain(); mainChain.addLast(tcpBasedSpamfilter); mainChain.addLast(new SmtpProtocolHandler()); IMultithreadedServer smtpServer = new MultithreadedServer(port, mainChain); StreamUtils.start(server); ...
Constructor Summary | |
---|---|
HandlerChain()
constructor |
|
HandlerChain(java.util.List<IHandler> handlers)
constructor |
Method Summary | |
---|---|
void |
addLast(IHandler handler)
add a handler to the end og the chain |
java.lang.Object |
clone()
|
boolean |
onConnect(INonBlockingConnection connection)
handles a new incomming connection |
boolean |
onConnectionTimeout(INonBlockingConnection connection)
handles the connection timeout. |
boolean |
onData(INonBlockingConnection connection)
processes the incomming data based on the given connection. |
void |
onDestroy()
signals that the entity will be destroyed |
boolean |
onDisconnect(INonBlockingConnection connection)
handles disconnecting of a connection |
boolean |
onIdleTimeout(INonBlockingConnection connection)
handles the idle timeout. |
void |
onInit()
signals that the entity has been loaded and initialized |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public HandlerChain()
public HandlerChain(java.util.List<IHandler> handlers)
handlers
- the initial handlersMethod Detail |
---|
public void addLast(IHandler handler)
handler
- the handler to addpublic void onInit()
onInit
in interface ILifeCycle
public void onDestroy()
onDestroy
in interface ILifeCycle
public boolean onConnect(INonBlockingConnection connection) throws java.io.IOException
onConnect
in interface IConnectHandler
java.io.IOException
- If some other I/O error occurs. Throwing this exception causes that the underlying connection will be closed.public boolean onDisconnect(INonBlockingConnection connection) throws java.io.IOException
onDisconnect
in interface IDisconnectHandler
connection
- the closed connection
java.io.IOException
- If some I/O error occurs.public boolean onData(INonBlockingConnection connection) throws java.io.IOException
onData
callback method could also be called
for an already closed connection. This occurs when data has been received
(and buffered internally) and the connection has been closed by the peer,
immediately. In this case the onData
Method will return false. Reading of already received data wouldn`t fail.
To detect if a connection has been closed the callback method onDisconnect
should be implemented. The correct callback order will be managed by the xSocket.
onData
in interface IDataHandler
connection
- the underlying connection
HandlerChain
to interrupted
the chaining (if result is true)
java.io.IOException
- If some other I/O error occurs. Throwing this exception causes that the underlying connection will be closed.public boolean onConnectionTimeout(INonBlockingConnection connection) throws java.io.IOException
onConnectionTimeout
in interface ITimeoutHandler
connection
- the underlying connection
java.io.IOException
- if an error occurs. Throwing this exception causes that the underlying connection will be closed.public boolean onIdleTimeout(INonBlockingConnection connection) throws java.io.IOException
onIdleTimeout
in interface ITimeoutHandler
connection
- the underlying connection
java.io.IOException
- if an error occurs. Throwing this exception causes that the underlying connection will be closed.public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in interface IConnectionScoped
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |