Thomescai http://blog.csdn.net/thomescai (reprinted please keep)
Introduction:
Asyncweb is a high-performance, non-blocking (non-blocking) Java HTTP engine embedded in applications. It is always designed to support asynchronous request processing. Asyncweb can also be integrated with the Spring framework.
Usage:
Asyncweb is very simple to use, as long as an interface is implemented. This is also his convenience.
Public interfaceHttpservice{
Void handlerequest (httpservicecontext context) throws exception;
Void start ();
Void stop ();
}
Start:
In combination with spring, to start a service, you only need to load two configuration files: asyncweb. XML and the configuration files of all services under the httpservicedefinitions folder. Configure asyncweb. XML as follows:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"><beans><bean id="mina-transport"class="org.apache.asyncweb.server.transport.mina.MinaTransport"><property name="port"><value>9013</value></property><property name="ioThreads"><value>4</value></property><property name="eventThreads"><value>16</value></property><property name="ioHandler"><beanclass="org.apache.asyncweb.server.transport.mina.DefaultHttpIoHandler" /></property></bean><!-- The service container --><bean id="container"class="org.apache.asyncweb.server.BasicServiceContainer"><property name="serviceFilters"><list><ref bean="httpServiceHandler" /></list></property><property name="transports"><list><ref bean="mina-transport" /></list></property><property name="sessionAccessor"><beanclass="org.apache.asyncweb.server.session.DefaultSessionAccessor"><property name="sessionStore"><beanclass="org.apache.asyncweb.server.session.BasicSessionStore"><constructor-arg type="long"><value>900000</value></constructor-arg><property name="sessionListeners"><list><beanclass="org.apache.asyncweb.server.session.LoggingSessionListener" /></list></property></bean></property></bean></property><property name="maxKeepAlives" value="1024" /></bean><!-- The HTTP Service Resolver --><bean id="httpServiceHandler"class="org.apache.asyncweb.server.HttpServiceHandler"><property name="serviceResolver"><beanclass="org.apache.asyncweb.server.resolver.CompositeResolver"><property name="resolvers"><list><beanclass="org.apache.asyncweb.server.resolver.SimplePrefixResolver"><property name="uriPrefix"><value>/service/</value></property></bean><beanclass="org.apache.asyncweb.server.resolver.PassThruResolver" /></list></property></bean></property></bean><bean id="httpServiceAutoload"class="org.apache.asyncweb.spring.HttpServiceLoader"><property name="handler"><ref bean="httpServiceHandler" /></property></bean></beans>
Several important classes of asyncweb. xml:
1.org. Apache. asyncweb. Spring. httpserviceloader
Load the configuration files of all httpservice servicesHttpservicehandler
2.org. Apache. asyncweb. server. httpservicehandler
The processor of the httpservice Service implementsHttpservicefilterTo process the request and response.
Void handlerequest (nextfilter next, httpservicecontext context)
Void handleresponse (nextfilternext, httpservicecontext context)
3.org. Apache. asyncweb. server. resolver. compositeresolver
Resolve the service name, for example, http: // localhost: 9013/actionservice. The actionservice matches the com. Cai. server. actionservice class.
4.org. Apache. asyncweb. server. session. defaultsessionaccessor
Session accessors, which includeHttpsessionkeyfactoryAndHttpsessionstoreGenerate and store sessions separately
5.org. Apache. asyncweb. server. Transport. Mina. minatransport
Using MinaOrderedthreadpoolexecutorThe thread pool to process the request and response. For requests from the same session, it can be executed according to the time sequence of the Request arrival.OrderedthreadpoolexecutorFor detailed analysis, see references.
6.org. Apache. asyncweb. server. basicservicecontainer
The main container is responsible for starting sessions, handlers, and transports.
Startup sequence diagram:
References:
Java threadpoolexecutor: http://blog.csdn.net/historyasamirror/article/details/5961368
Implementation Analysis of Mina thread pool (1): http://yanxuxin.iteye.com/blog/592903
Implementation Analysis of Mina thread pool (2): http://yanxuxin.iteye.com/blog/592908