本文整理汇总了Java中org.apache.http.nio.reactor.ListeningIOReactor类的典型用法代码示例。如果您正苦于以下问题:Java ListeningIOReactor类的具体用法?Java ListeningIOReactor怎么用?Java ListeningIOReactor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ListeningIOReactor类属于org.apache.http.nio.reactor包,在下文中一共展示了ListeningIOReactor类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: start
import org.apache.http.nio.reactor.ListeningIOReactor; //导入依赖的package包/类
public void start() throws Exception {
// Create HTTP protocol basic processing chain
HttpProcessor httpProcessor = HttpProcessorBuilder.create()
.add(new ResponseDate()).add(new ResponseContent())
.add(new ResponseConnControl()).build();
// Create server
HttpAsyncService protocolHandler = new HttpAsyncService(httpProcessor,
uriMapper);
NHttpConnectionFactory<DefaultNHttpServerConnection> connFactory = new DefaultNHttpServerConnectionFactory();
IOEventDispatch ioEventDispatch = new DefaultHttpServerIODispatch(
protocolHandler, connFactory);
IOReactorConfig config = IOReactorConfig.custom()
.setIoThreadCount(threads).setSoReuseAddress(true).build();
ListeningIOReactor ioReactor = new DefaultListeningIOReactor(config);
// Start server
ioReactor.listen(new InetSocketAddress(port));
ioReactor.execute(ioEventDispatch);
}
开发者ID:fxbonnet,项目名称:nio-benchmark,代码行数:19,代码来源:AsyncServer.java
示例2: main
import org.apache.http.nio.reactor.ListeningIOReactor; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
HttpParams params = new SyncBasicHttpParams();
IOEventDispatch ioEventDispatch = new DefaultIoEventDispatch();
ListeningIOReactor ioReactor = new DefaultListeningIOReactor(2, params);
ioReactor.listen(new InetSocketAddress(8080));
try {
ioReactor.execute(ioEventDispatch);
} catch (InterruptedIOException ex) {
System.err.println("Interrupted");
} catch (IOException e) {
System.err.println("I/O error: " + e.getMessage());
}
System.out.println("Shutdown");
}
开发者ID:mleoking,项目名称:PhET,代码行数:15,代码来源:ElementalEchoServer.java
示例3: main
import org.apache.http.nio.reactor.ListeningIOReactor; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
if (args.length < 1) {
System.err.println("Please specify document root directory");
System.exit(1);
}
boolean useFileChannels = true;
if (args.length >= 2) {
String s = args[1];
if (s.equalsIgnoreCase("disableFileChannels")) {
useFileChannels = false;
}
}
HttpParams params = new SyncBasicHttpParams();
params
.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 20000)
.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
.setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");
HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[] {
new ResponseDate(),
new ResponseServer(),
new ResponseContent(),
new ResponseConnControl()
});
AsyncNHttpServiceHandler handler = new AsyncNHttpServiceHandler(
httpproc,
new DefaultHttpResponseFactory(),
new DefaultConnectionReuseStrategy(),
params);
final HttpFileHandler filehandler = new HttpFileHandler(args[0], useFileChannels);
NHttpRequestHandlerResolver resolver = new NHttpRequestHandlerResolver() {
public NHttpRequestHandler lookup(String requestURI) {
return filehandler;
}
};
handler.setHandlerResolver(resolver);
// Provide an event logger
handler.setEventListener(new EventLogger());
IOEventDispatch ioEventDispatch = new DefaultServerIOEventDispatch(handler, params);
ListeningIOReactor ioReactor = new DefaultListeningIOReactor(2, params);
try {
ioReactor.listen(new InetSocketAddress(8080));
ioReactor.execute(ioEventDispatch);
} catch (InterruptedIOException ex) {
System.err.println("Interrupted");
} catch (IOException e) {
System.err.println("I/O error: " + e.getMessage());
}
System.out.println("Shutdown");
}
开发者ID:mleoking,项目名称:PhET,代码行数:63,代码来源:NHttpFileServer.java
示例4: main
import org.apache.http.nio.reactor.ListeningIOReactor; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
if (args.length < 1) {
System.err.println("Please specify document root directory");
System.exit(1);
}
HttpParams params = new SyncBasicHttpParams();
params
.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
.setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");
HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[] {
new ResponseDate(),
new ResponseServer(),
new ResponseContent(),
new ResponseConnControl()
});
BufferingHttpServiceHandler handler = new BufferingHttpServiceHandler(
httpproc,
new DefaultHttpResponseFactory(),
new DefaultConnectionReuseStrategy(),
params);
// Set up request handlers
HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
reqistry.register("*", new HttpFileHandler(args[0]));
handler.setHandlerResolver(reqistry);
// Provide an event logger
handler.setEventListener(new EventLogger());
IOEventDispatch ioEventDispatch = new DefaultServerIOEventDispatch(handler, params);
ListeningIOReactor ioReactor = new DefaultListeningIOReactor(2, params);
try {
ioReactor.listen(new InetSocketAddress(8080));
ioReactor.execute(ioEventDispatch);
} catch (InterruptedIOException ex) {
System.err.println("Interrupted");
} catch (IOException e) {
System.err.println("I/O error: " + e.getMessage());
}
System.out.println("Shutdown");
}
开发者ID:mleoking,项目名称:PhET,代码行数:48,代码来源:NHttpServer.java
示例5: main
import org.apache.http.nio.reactor.ListeningIOReactor; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
if (args.length < 1) {
System.err.println("Please specify document root directory");
System.exit(1);
}
ClassLoader cl = NHttpSSLServer.class.getClassLoader();
URL url = cl.getResource("test.keystore");
KeyStore keystore = KeyStore.getInstance("jks");
keystore.load(url.openStream(), "nopassword".toCharArray());
KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(
KeyManagerFactory.getDefaultAlgorithm());
kmfactory.init(keystore, "nopassword".toCharArray());
KeyManager[] keymanagers = kmfactory.getKeyManagers();
SSLContext sslcontext = SSLContext.getInstance("TLS");
sslcontext.init(keymanagers, null, null);
HttpParams params = new SyncBasicHttpParams();
params
.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
.setParameter(CoreProtocolPNames.ORIGIN_SERVER, "Jakarta-HttpComponents-NIO/1.1");
HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[] {
new ResponseDate(),
new ResponseServer(),
new ResponseContent(),
new ResponseConnControl()
});
BufferingHttpServiceHandler handler = new BufferingHttpServiceHandler(
httpproc,
new DefaultHttpResponseFactory(),
new DefaultConnectionReuseStrategy(),
params);
// Set up request handlers
HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
reqistry.register("*", new HttpFileHandler(args[0]));
handler.setHandlerResolver(reqistry);
// Provide an event logger
handler.setEventListener(new EventLogger());
IOEventDispatch ioEventDispatch = new SSLServerIOEventDispatch(
handler,
sslcontext,
params);
ListeningIOReactor ioReactor = new DefaultListeningIOReactor(2, params);
try {
ioReactor.listen(new InetSocketAddress(8080));
ioReactor.execute(ioEventDispatch);
} catch (InterruptedIOException ex) {
System.err.println("Interrupted");
} catch (IOException e) {
System.err.println("I/O error: " + e.getMessage());
}
System.out.println("Shutdown");
}
开发者ID:mleoking,项目名称:PhET,代码行数:64,代码来源:NHttpSSLServer.java
示例6: EsperHttpServiceNIORunnable
import org.apache.http.nio.reactor.ListeningIOReactor; //导入依赖的package包/类
public EsperHttpServiceNIORunnable(String serviceName, int port, ListeningIOReactor ioReactor, IOEventDispatch ioEventDispatch) {
this.serviceName = serviceName;
this.port = port;
this.ioReactor = ioReactor;
this.ioEventDispatch = ioEventDispatch;
}
开发者ID:espertechinc,项目名称:esper,代码行数:7,代码来源:EsperHttpServiceNIORunnable.java
注:本文中的org.apache.http.nio.reactor.ListeningIOReactor类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论