org.glassfish.grizzly.threadpool.ThreadPoolConfig Java Examples

The following examples show how to use org.glassfish.grizzly.threadpool.ThreadPoolConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GrizzlyClient.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Override
protected void doOpen() throws Throwable {
    FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();
    filterChainBuilder.add(new TransportFilter());
    filterChainBuilder.add(new GrizzlyCodecAdapter(getCodec(), getUrl(), this));
    filterChainBuilder.add(new GrizzlyHandler(getUrl(), this));
    TCPNIOTransportBuilder builder = TCPNIOTransportBuilder.newInstance();
    ThreadPoolConfig config = builder.getWorkerThreadPoolConfig();
    config.setPoolName(CLIENT_THREAD_POOL_NAME)
            .setQueueLimit(-1)
            .setCorePoolSize(0)
            .setMaxPoolSize(Integer.MAX_VALUE)
            .setKeepAliveTime(60L, TimeUnit.SECONDS);
    builder.setTcpNoDelay(true).setKeepAlive(true)
            .setConnectionTimeout(getConnectTimeout())
            .setIOStrategy(SameThreadIOStrategy.getInstance());
    transport = builder.build();
    transport.setProcessor(filterChainBuilder.build());
    transport.start();
}
 
Example #2
Source File: GrizzlyClient.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Override
protected void doOpen() throws Throwable {
    FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();
    filterChainBuilder.add(new TransportFilter());
    filterChainBuilder.add(new GrizzlyCodecAdapter(getCodec(), getUrl(), this));
    filterChainBuilder.add(new GrizzlyHandler(getUrl(), this));
    TCPNIOTransportBuilder builder = TCPNIOTransportBuilder.newInstance();
    ThreadPoolConfig config = builder.getWorkerThreadPoolConfig(); 
    config.setPoolName(CLIENT_THREAD_POOL_NAME)
            .setQueueLimit(-1)
            .setCorePoolSize(0)
            .setMaxPoolSize(Integer.MAX_VALUE)
            .setKeepAliveTime(60L, TimeUnit.SECONDS);
    builder.setTcpNoDelay(true).setKeepAlive(true)
            .setConnectionTimeout(getTimeout())
            .setIOStrategy(SameThreadIOStrategy.getInstance());
    transport = builder.build();
    transport.setProcessor(filterChainBuilder.build());
    transport.start();
}
 
Example #3
Source File: GrizzlyClient.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
@Override
protected void doOpen() throws Throwable {
    FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();
    filterChainBuilder.add(new TransportFilter());
    filterChainBuilder.add(new GrizzlyCodecAdapter(getCodec(), getUrl(), this));
    filterChainBuilder.add(new GrizzlyHandler(getUrl(), this));
    TCPNIOTransportBuilder builder = TCPNIOTransportBuilder.newInstance();
    ThreadPoolConfig config = builder.getWorkerThreadPoolConfig(); 
    config.setPoolName(CLIENT_THREAD_POOL_NAME)
            .setQueueLimit(-1)
            .setCorePoolSize(0)
            .setMaxPoolSize(Integer.MAX_VALUE)
            .setKeepAliveTime(60L, TimeUnit.SECONDS);
    builder.setTcpNoDelay(true).setKeepAlive(true)
            .setConnectionTimeout(getTimeout())
            .setIOStrategy(SameThreadIOStrategy.getInstance());
    transport = builder.build();
    transport.setProcessor(filterChainBuilder.build());
    transport.start();
}
 
Example #4
Source File: GrizzlyClient.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Override
protected void doOpen() throws Throwable {
    FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();
    filterChainBuilder.add(new TransportFilter());
    filterChainBuilder.add(new GrizzlyCodecAdapter(getCodec(), getUrl(), this));
    filterChainBuilder.add(new GrizzlyHandler(getUrl(), this));
    TCPNIOTransportBuilder builder = TCPNIOTransportBuilder.newInstance();
    ThreadPoolConfig config = builder.getWorkerThreadPoolConfig(); 
    config.setPoolName(CLIENT_THREAD_POOL_NAME)
            .setQueueLimit(-1)
            .setCorePoolSize(0)
            .setMaxPoolSize(Integer.MAX_VALUE)
            .setKeepAliveTime(60L, TimeUnit.SECONDS);
    builder.setTcpNoDelay(true).setKeepAlive(true)
            .setConnectionTimeout(getTimeout())
            .setIOStrategy(SameThreadIOStrategy.getInstance());
    transport = builder.build();
    transport.setProcessor(filterChainBuilder.build());
    transport.start();
}
 
Example #5
Source File: GrizzlyClient.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Override
protected void doOpen() throws Throwable {
    FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();
    filterChainBuilder.add(new TransportFilter());
    filterChainBuilder.add(new GrizzlyCodecAdapter(getCodec(), getUrl(), this));
    filterChainBuilder.add(new GrizzlyHandler(getUrl(), this));
    TCPNIOTransportBuilder builder = TCPNIOTransportBuilder.newInstance();
    ThreadPoolConfig config = builder.getWorkerThreadPoolConfig(); 
    config.setPoolName(CLIENT_THREAD_POOL_NAME)
            .setQueueLimit(-1)
            .setCorePoolSize(0)
            .setMaxPoolSize(Integer.MAX_VALUE)
            .setKeepAliveTime(60L, TimeUnit.SECONDS);
    builder.setTcpNoDelay(true).setKeepAlive(true)
            .setConnectionTimeout(getTimeout())
            .setIOStrategy(SameThreadIOStrategy.getInstance());
    transport = builder.build();
    transport.setProcessor(filterChainBuilder.build());
    transport.start();
}
 
Example #6
Source File: JsonRpcServer.java    From nuls-v2 with MIT License 5 votes vote down vote up
public void startServer(String ip, int port) {
    initRpcMethodHandlers();
    this.httpServer = new HttpServer();
    NetworkListener listener = new NetworkListener("NULS-RPC", ip, port);
    TCPNIOTransport transport = listener.getTransport();
    ThreadPoolConfig workerPool = ThreadPoolConfig.defaultConfig()
            .setCorePoolSize(8)
            .setMaxPoolSize(8)
            .setQueueLimit(2000)
            .setThreadFactory((new ThreadFactoryBuilder()).setNameFormat("grizzly-http-server-%d").build());
    transport.configureBlocking(false);
    transport.setSelectorRunnersCount(2);
    transport.setWorkerThreadPoolConfig(workerPool);
    transport.setIOStrategy(WorkerThreadIOStrategy.getInstance());
    transport.setTcpNoDelay(true);
    listener.setSecure(false);
    httpServer.addListener(listener);

    ServerConfiguration config = httpServer.getServerConfiguration();
    config.addHttpHandler(new JsonRpcHandler());
    config.setDefaultQueryEncoding(Charsets.UTF8_CHARSET);

    try {
        httpServer.start();
    } catch (IOException e) {
        LoggerUtil.commonLog.error(e);
        httpServer.shutdownNow();
    }
}
 
Example #7
Source File: RpcServerManager.java    From nuls-v2 with MIT License 5 votes vote down vote up
public void startServer(String ip, int port) {
    URI serverURI = UriBuilder.fromUri("http://" + ip).port(port).build();
    // Create test web application context.
    WebappContext webappContext = new WebappContext("NULS-V2-SDK-PROVIDER-SERVER", "/");

    ServletRegistration servletRegistration = webappContext.addServlet("jersey-servlet", ServletContainer.class);
    servletRegistration.setInitParameter("javax.ws.rs.Application", "io.nuls.provider.api.config.NulsResourceConfig");
    servletRegistration.addMapping("/*");

    httpServer = new HttpServer();
    NetworkListener listener = new NetworkListener("grizzly2", ip, port);
    TCPNIOTransport transport = listener.getTransport();
    ThreadPoolConfig workerPool = ThreadPoolConfig.defaultConfig()
            .setCorePoolSize(4)
            .setMaxPoolSize(4)
            .setQueueLimit(1000)
            .setThreadFactory((new ThreadFactoryBuilder()).setNameFormat("grizzly-http-server-%d").build());
    transport.configureBlocking(false);
    transport.setSelectorRunnersCount(2);
    transport.setWorkerThreadPoolConfig(workerPool);
    transport.setIOStrategy(WorkerThreadIOStrategy.getInstance());
    transport.setTcpNoDelay(true);
    listener.setSecure(false);
    httpServer.addListener(listener);

    ServerConfiguration config = httpServer.getServerConfiguration();
    config.setDefaultQueryEncoding(Charsets.UTF8_CHARSET);

    webappContext.deploy(httpServer);

    try {
        ClassLoader loader = this.getClass().getClassLoader();
        httpServer.start();
        Log.info("http restFul server is started!url is " + serverURI.toString());
    } catch (IOException e) {
        Log.error(e);
        httpServer.shutdownNow();
    }
}
 
Example #8
Source File: RestServer.java    From Cheddar with Apache License 2.0 5 votes vote down vote up
private void configureWorkerThreadPool(final NetworkListener networkListener, final int workerThreads) {
    final TCPNIOTransport transport = networkListener.getTransport();

    if (transport.getWorkerThreadPoolConfig() == null) {
        transport.setWorkerThreadPoolConfig(ThreadPoolConfig.defaultConfig());
    }
    transport.getWorkerThreadPoolConfig().setMaxPoolSize(workerThreads).setCorePoolSize(workerThreads);
}
 
Example #9
Source File: RpcServerManager.java    From nuls-v2 with MIT License 4 votes vote down vote up
public void startServer(String ip, int port) {
    URI serverURI = UriBuilder.fromUri("http://" + ip).port(port).build();
    // Create test web application context.
    WebappContext webappContext = new WebappContext("NULS-RPC-SERVER", "/api");

    ServletRegistration servletRegistration = webappContext.addServlet("jersey-servlet", ServletContainer.class);
    servletRegistration.setInitParameter("javax.ws.rs.Application", "io.nuls.test.controller.NulsResourceConfig");
    servletRegistration.addMapping("/api/*");

    httpServer = new HttpServer();
    NetworkListener listener = new NetworkListener("grizzly2", ip, port);
    TCPNIOTransport transport = listener.getTransport();
    ThreadPoolConfig workerPool = ThreadPoolConfig.defaultConfig()
            .setCorePoolSize(4)
            .setMaxPoolSize(4)
            .setQueueLimit(1000)
            .setThreadFactory((new ThreadFactoryBuilder()).setNameFormat("grizzly-http-server-%d").build());
    transport.configureBlocking(false);
    transport.setSelectorRunnersCount(2);
    transport.setWorkerThreadPoolConfig(workerPool);
    transport.setIOStrategy(WorkerThreadIOStrategy.getInstance());
    transport.setTcpNoDelay(true);
    listener.setSecure(false);
    httpServer.addListener(listener);

    ServerConfiguration config = httpServer.getServerConfiguration();
    config.setDefaultQueryEncoding(Charsets.UTF8_CHARSET);

    webappContext.deploy(httpServer);

    try {
        ClassLoader loader = this.getClass().getClassLoader();

        addSwagerUi(loader);
        addClientUi(loader);

        httpServer.start();
        log.info("http restFul server is started!url is " + serverURI.toString());
    } catch (IOException e) {
        log.error("",e);
        httpServer.shutdownNow();
    }
}
 
Example #10
Source File: RpcServerManager.java    From nuls with MIT License 4 votes vote down vote up
public void startServer(String ip, int port) {
    URI serverURI = UriBuilder.fromUri("http://" + ip).port(port).build();
    // Create test web application context.
    WebappContext webappContext = new WebappContext("NULS-RPC-SERVER", "/api");

    ServletRegistration servletRegistration = webappContext.addServlet("jersey-servlet", ServletContainer.class);
    servletRegistration.setInitParameter("javax.ws.rs.Application", "io.nuls.client.rpc.config.NulsResourceConfig");
    servletRegistration.addMapping("/api/*");

    httpServer = new HttpServer();
    NetworkListener listener = new NetworkListener("grizzly2", ip, port);
    TCPNIOTransport transport = listener.getTransport();
    ThreadPoolConfig workerPool = ThreadPoolConfig.defaultConfig()
            .setCorePoolSize(4)
            .setMaxPoolSize(4)
            .setQueueLimit(1000)
            .setThreadFactory((new ThreadFactoryBuilder()).setNameFormat("grizzly-http-server-%d").build());
    transport.configureBlocking(false);
    transport.setSelectorRunnersCount(2);
    transport.setWorkerThreadPoolConfig(workerPool);
    transport.setIOStrategy(WorkerThreadIOStrategy.getInstance());
    transport.setTcpNoDelay(true);
    listener.setSecure(false);
    httpServer.addListener(listener);

    ServerConfiguration config = httpServer.getServerConfiguration();
    config.setDefaultQueryEncoding(Charsets.UTF8_CHARSET);

    webappContext.deploy(httpServer);

    try {
        ClassLoader loader = this.getClass().getClassLoader();

        addSwagerUi(loader);
        addClientUi(loader);

        httpServer.start();
        Log.info("http restFul server is started!url is " + serverURI.toString());
    } catch (IOException e) {
        Log.error(e);
        httpServer.shutdownNow();
    }
}