當前位置: 首頁>>代碼示例>>Java>>正文


Java DefaultServerIOEventDispatch類代碼示例

本文整理匯總了Java中org.apache.http.impl.nio.DefaultServerIOEventDispatch的典型用法代碼示例。如果您正苦於以下問題:Java DefaultServerIOEventDispatch類的具體用法?Java DefaultServerIOEventDispatch怎麽用?Java DefaultServerIOEventDispatch使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DefaultServerIOEventDispatch類屬於org.apache.http.impl.nio包,在下文中一共展示了DefaultServerIOEventDispatch類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import org.apache.http.impl.nio.DefaultServerIOEventDispatch; //導入依賴的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

示例2: main

import org.apache.http.impl.nio.DefaultServerIOEventDispatch; //導入依賴的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

示例3: start

import org.apache.http.impl.nio.DefaultServerIOEventDispatch; //導入依賴的package包/類
public void start(EPServiceProviderSPI engine) {
    HttpParams parameters = new BasicHttpParams();
    parameters
            .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");

    BasicHttpProcessor httpproc = new BasicHttpProcessor();
    httpproc.addInterceptor(new ResponseDate());
    httpproc.addInterceptor(new ResponseServer());
    httpproc.addInterceptor(new ResponseContent());
    httpproc.addInterceptor(new ResponseConnControl());

    BufferingHttpServiceHandler handler = new BufferingHttpServiceHandler(
            httpproc,
            new DefaultHttpResponseFactory(),
            new DefaultConnectionReuseStrategy(),
            parameters);

    // Set up request handlers
    HttpRequestHandlerRegistry reqistry = setupRegistry(engine);

    handler.setHandlerResolver(reqistry);

    // Provide an event logger
    handler.setEventListener(new EventLogger());

    IOEventDispatch ioEventDispatch = new DefaultServerIOEventDispatch(handler, parameters);
    try {
        ioReactor = new DefaultListeningIOReactor(2, parameters);
        ioReactor.listen(new InetSocketAddress(this.getServiceConfig().getPort()));
    } catch (IOException e) {
        log.error("I/O for service '" + this.getServiceName() + "' error: " + e.getMessage());
        return;
    }

    runnable = new EsperHttpServiceNIORunnable(this.getServiceName(), this.getServiceConfig().getPort(), ioReactor, ioEventDispatch);
    reactorThread = new Thread(runnable);
    reactorThread.setDaemon(true);
    reactorThread.start();
}
 
開發者ID:espertechinc,項目名稱:esper,代碼行數:44,代碼來源:EsperHttpServiceNIO.java


注:本文中的org.apache.http.impl.nio.DefaultServerIOEventDispatch類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。