Transports and connections are the core structure of the grizzly frame ~ The transports toolkit contains TCP or UDP protocols, and incorporates various component resources (thread-pool thread pool, Memory Manager, and so on. In terms of structure, there is nothing to do, mainly using the above 1. Using the future mode to establish a connection
Future<Connection> clientConnectionFuture = tcpNioTransport.connect("grizzly.java.net",80);
Connection clientConnection = clientConnectionFuture.get();
2. You can add closehandler and other events to the connection.
Connection conn;
conn.addCloseListener(newCloseListener<Closeable,ICloseType>(){
@Override
publicvoid onClosed(Closeable closeable,ICloseType type)
throwsIOException{
// TODO Auto-generated method stub
}
});
The filterchains and Filters provide infinite scalability for Grizzly. Filterchains are the process encapsulation of filters and can be used to process filters step by step. For example, to expand to HTTP and filter combinations: for example, to change HTTP to https, you only need to add sslfilter: Where, transport filter is the basis for all processing, it is used to interact with the selector of grizzly. In addition, I need to know the basefilter. All filters inherit from it:
- /**
- * Read flow: reads network data or the message after the last filter read
- */
publicNextAction handleRead(FilterChainContext ctx)throwsIOException;
- /**
- * Write process, such as network data, or process the message after the last filter write
- */
publicNextAction handleWrite(FilterChainContext ctx)throwsIOException;
- /**
- * New Connection
- */
publicNextAction handleConnect(FilterChainContext ctx)throwsIOException;
- /**
- * Same as handleconnect
- */
publicNextAction handleAccept(FilterChainContext ctx)throwsIOException;
- /**
- * Called after the connection is disconnected
- */
publicNextAction handleClose(FilterChainContext ctx)throwsIOException;
How to link two filters, we need to know how nextaction works and what types of filters are available:
StopactionIf you want to stop the current workflow of filter, return CTX. getstopaction () directly. If you want to interrupt the work and put the data stream that is not processed into the next call, you can add the following parameter:
Return CTX. getstopaction (incompletechunk );
Invokeaction
If the next filter process is continued, invokeaction is returned.
Return CTX. getinvokeaction ();
If there is a sticky packet in the data stream (two packets are sent together, we need to process them one by one), you can also add parameters:
Return CTX. getinvokeaction (incompletechunk );
Rerunfilteraction
Return CTX. getrerunfilteraction ()
This means that the action of the current filter is executed once more.
Suspendaction
Return CTX. getsuspendaction ();
This is paused .... Interrupt the thread and call it through another thread
CTX. Resume ():
Forkaction (was suspendstopaction)
Return CTX. getforkaction ();
Similar to the previous one.
From Weizhi note (wiz)
Grizzly NiO Framework Theory [2]