当前位置: 首页>>代码示例>>Java>>正文


Java SameThreadIOStrategy类代码示例

本文整理汇总了Java中org.glassfish.grizzly.strategies.SameThreadIOStrategy的典型用法代码示例。如果您正苦于以下问题:Java SameThreadIOStrategy类的具体用法?Java SameThreadIOStrategy怎么用?Java SameThreadIOStrategy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SameThreadIOStrategy类属于org.glassfish.grizzly.strategies包,在下文中一共展示了SameThreadIOStrategy类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doOpen

import org.glassfish.grizzly.strategies.SameThreadIOStrategy; //导入依赖的package包/类
@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();
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:21,代码来源:GrizzlyClient.java

示例2: start

import org.glassfish.grizzly.strategies.SameThreadIOStrategy; //导入依赖的package包/类
public void start(int listenPort, ExecutorService threadpool) throws Exception {
  ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) threadpool;
  ThreadPoolConfig config = ThreadPoolConfig.defaultConfig().copy().setCorePoolSize(threadPoolExecutor.getCorePoolSize())
      .setMaxPoolSize(threadPoolExecutor.getMaximumPoolSize()).setPoolName("GRIZZLY-SERVER");
  ExecutorService executorService = GrizzlyExecutorService.createInstance(config);

  FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();
  filterChainBuilder.add(new TransportFilter());
  filterChainBuilder.add(new GrizzlyProtocolFilter());
  filterChainBuilder.add(new GrizzlyServerHandler(executorService));
  TCPNIOTransportBuilder builder = TCPNIOTransportBuilder.newInstance();
  builder.setOptimizedForMultiplexing(true);
  builder.setIOStrategy(SameThreadIOStrategy.getInstance());

  transport = builder.build();

  transport.setProcessor(filterChainBuilder.build());
  transport.bind(listenPort);

  transport.start();
  LOGGER.warn("server started,listen at: " + listenPort);
}
 
开发者ID:leeyazhou,项目名称:nfs-rpc,代码行数:23,代码来源:GrizzlyServer.java

示例3: startServer

import org.glassfish.grizzly.strategies.SameThreadIOStrategy; //导入依赖的package包/类
public static HttpServer startServer() {
    HttpServer server = new HttpServer();
    server.addListener(new NetworkListener("grizzly", "0.0.0.0", 8080));

    final TCPNIOTransportBuilder transportBuilder = TCPNIOTransportBuilder.newInstance();
    //transportBuilder.setIOStrategy(WorkerThreadIOStrategy.getInstance());
    transportBuilder.setIOStrategy(SameThreadIOStrategy.getInstance());
    server.getListener("grizzly").setTransport(transportBuilder.build());
    final ResourceConfig rc = new ResourceConfig().packages("xyz.muetsch.jersey");
    rc.register(JacksonFeature.class);
    final ServerConfiguration config = server.getServerConfiguration();
    config.addHttpHandler(RuntimeDelegate.getInstance().createEndpoint(rc, GrizzlyHttpContainer.class), "/rest/todo/");

    try {
        server.start();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return server;
}
 
开发者ID:n1try,项目名称:http-server-benchmarks,代码行数:22,代码来源:Main.java

示例4: doOpen

import org.glassfish.grizzly.strategies.SameThreadIOStrategy; //导入依赖的package包/类
@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();
}
 
开发者ID:hufeng,项目名称:dubbo2.js,代码行数:21,代码来源:GrizzlyClient.java

示例5: createClient

import org.glassfish.grizzly.strategies.SameThreadIOStrategy; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
protected Client createClient(String targetIP, int targetPort, int connectTimeout, String key) throws Exception {
  Connection connection = null;
  GrizzlyClientHandler handler = new GrizzlyClientHandler();
  FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();
  filterChainBuilder.add(new TransportFilter());
  filterChainBuilder.add(new GrizzlyProtocolFilter());
  filterChainBuilder.add(handler);

  final TCPNIOTransportBuilder transportBuilder = TCPNIOTransportBuilder.newInstance();
  transportBuilder.setOptimizedForMultiplexing(true);

  transportBuilder.setIOStrategy(SameThreadIOStrategy.getInstance());

  final TCPNIOTransport transport = transportBuilder.build();
  transport.setTcpNoDelay(Boolean.parseBoolean(System.getProperty("nfs.rpc.tcp.nodelay", "true")));

  transport.setProcessor(filterChainBuilder.build());

  transport.start();
  Future<Connection> future = transport.connect(targetIP, targetPort);
  if (connectTimeout < 1000) {
    connectTimeout = 1000;
  }
  connection = future.get(connectTimeout, TimeUnit.MILLISECONDS);
  @SuppressWarnings("unchecked")
  GrizzlyClient client = new GrizzlyClient(targetIP, targetPort, connectTimeout, connection, key);
  handler.setClient(client);
  return client;
}
 
开发者ID:leeyazhou,项目名称:nfs-rpc,代码行数:31,代码来源:GrizzlyClientFactory.java


注:本文中的org.glassfish.grizzly.strategies.SameThreadIOStrategy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。