Grizzly NiO Framework Theory [2]

Source: Internet
Author: User
Tags types of filters
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
  1. Future<Connection> clientConnectionFuture = tcpNioTransport.connect("grizzly.java.net",80);
  2. Connection clientConnection = clientConnectionFuture.get();
2. You can add closehandler and other events to the connection.
  1. Connection conn;
  2. conn.addCloseListener(newCloseListener<Closeable,ICloseType>(){
  3. @Override
  4. publicvoid onClosed(Closeable closeable,ICloseType type)
  5. throwsIOException{
  6. // TODO Auto-generated method stub
  7. }
  8. });
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:
  1. /**
  2. * Read flow: reads network data or the message after the last filter read
  3. */
  4. publicNextAction handleRead(FilterChainContext ctx)throwsIOException;
  5. /**
  6. * Write process, such as network data, or process the message after the last filter write
  7. */
  8. publicNextAction handleWrite(FilterChainContext ctx)throwsIOException;
  9. /**
  10. * New Connection
  11. */
  12. publicNextAction handleConnect(FilterChainContext ctx)throwsIOException;
  13. /**
  14. * Same as handleconnect
  15. */
  16. publicNextAction handleAccept(FilterChainContext ctx)throwsIOException;
  17. /**
  18. * Called after the connection is disconnected
  19. */
  20. 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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.