| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||

java.lang.Objectorg.xsocket.connection.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 remaining handlers will not be called.  
 
 Nested chains is not supported yet
   
 
 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); ...
| Field Summary | 
|---|
| Fields inherited from interface org.xsocket.connection.IHandler | 
|---|
| DEFAULT_EXECUTION_MODE | 
| Constructor Summary | |
|---|---|
| HandlerChain()constructor | |
| HandlerChain(List<IHandler> handlers)constructor | |
| Method Summary | |
|---|---|
|  void | addLast(IHandler handler)add a handler to the end og the chain | 
|  boolean | onConnect(INonBlockingConnection connection)handles a new incoming connection | 
|  boolean | onConnectionTimeout(INonBlockingConnection connection)handles the connection timeout. | 
|  boolean | onData(INonBlockingConnection connection)processes the incoming data based on the given connection. | 
|  void | onDestroy()notifies 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()notifies that the entity has been loaded and initialized | 
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Constructor Detail | 
|---|
public HandlerChain()
public HandlerChain(List<IHandler> handlers)
handlers - the initial handlers| Method Detail | 
|---|
public void onInit()
ILifeCycle
onInit in interface ILifeCycle
public void onDestroy()
               throws IOException
ILifeCycle
onDestroy in interface ILifeCycleIOException - if an exception occurs. The exception will be (logged and) swallowedpublic void addLast(IHandler handler)
handler - the handler to add
public boolean onConnect(INonBlockingConnection connection)
                  throws IOException,
                         BufferUnderflowException,
                         MaxReadSizeExceededException
onConnect in interface IConnectHandlerIOException - if some other I/O error occurs. Throwing this exception causes that the underlying connection will be closed.
MaxReadSizeExceededException - if the max read size has been reached (e.g. by calling method IDataSource.readStringByDelimiter(String, int)).
                                      Throwing this exception causes that the underlying connection will be closed.
BufferUnderflowException - if more incoming data is required to process (e.g. delimiter hasn't yet received -> readByDelimiter methods or size of the available, received data is smaller than the required size -> readByLength). The BufferUnderflowException will be swallowed by the framework
public boolean onData(INonBlockingConnection connection)
               throws IOException
onData call back method can also be called
 for if an connection will be closed. In this case the isOpen call 
 within the onData Method will return false. Reading of already 
 received data will not fail. 
 To detect if a connection has been closed the callback method onDisconnect
 should be implemented. The correct call back order will be managed by the xSocket.
onData in interface IDataHandlerconnection - the underlying connection
HandlerChain to interrupted
              the chaining (if result is true)
IOException - If some other I/O error occurs. Throwing this exception causes that the underlying connection will be closed.
ClosedChannelException - if the connection is closed
MaxReadSizeExceededException - if the max read size has been reached (e.g. by calling method IDataSource.readStringByDelimiter(String, int)).
                                      Throwing this exception causes that the underlying connection will be closed.
public boolean onDisconnect(INonBlockingConnection connection)
                     throws IOException,
                            BufferUnderflowException,
                            MaxReadSizeExceededException
onDisconnect in interface IDisconnectHandlerconnection - the closed connection
IOException - If some I/O error occurs.
BufferUnderflowException
MaxReadSizeExceededException
public boolean onIdleTimeout(INonBlockingConnection connection)
                      throws IOException,
                             BufferUnderflowException,
                             MaxReadSizeExceededException
onIdleTimeout in interface IIdleTimeoutHandlerconnection - the underlying connection
IOException - if an error occurs. Throwing this exception causes that the underlying connection will be closed.
BufferUnderflowException
MaxReadSizeExceededException
public boolean onConnectionTimeout(INonBlockingConnection connection)
                            throws IOException,
                                   BufferUnderflowException,
                                   MaxReadSizeExceededException
onConnectionTimeout in interface IConnectionTimeoutHandlerconnection - the underlying connection
IOException - if an error occurs. Throwing this exception causes that the underlying connection will be closed.
BufferUnderflowException
MaxReadSizeExceededException| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||