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


Java TCPNIOTransport类代码示例

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


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

示例1: configureThreadPools

import org.glassfish.grizzly.nio.transport.TCPNIOTransport; //导入依赖的package包/类
private void configureThreadPools(final NetworkListener networkListener, final String poolNamePrefix,
        final int workerThreads, final int kernelThreads) {
    final TCPNIOTransport transport = networkListener.getTransport();

    if (transport.getKernelThreadPoolConfig() == null) {
        transport.setKernelThreadPoolConfig(ThreadPoolConfig.defaultConfig());
    }
    transport.getKernelThreadPoolConfig().setPoolName(poolNamePrefix + "-Kernel").setMaxPoolSize(kernelThreads)
            .setCorePoolSize(kernelThreads);
    transport.setSelectorRunnersCount(kernelThreads);

    if (transport.getWorkerThreadPoolConfig() == null) {
        transport.setWorkerThreadPoolConfig(ThreadPoolConfig.defaultConfig());
    }
    transport.getWorkerThreadPoolConfig().setPoolName(poolNamePrefix + "-Worker").setMaxPoolSize(workerThreads)
            .setCorePoolSize(workerThreads);
}
 
开发者ID:travel-cloud,项目名称:Cheddar,代码行数:18,代码来源:RestServer.java

示例2: createClient

import org.glassfish.grizzly.nio.transport.TCPNIOTransport; //导入依赖的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

示例3: main

import org.glassfish.grizzly.nio.transport.TCPNIOTransport; //导入依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException {
    // Create a FilterChain using FilterChainBuilder
    @NotNull FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();

    // Add TransportFilter, which is responsible
    // for reading and writing data to the connection
    filterChainBuilder.add(new TransportFilter());

    // EchoFilter is responsible for echoing received messages
    filterChainBuilder.add(new BaseFilter() {
        @Override
        public NextAction handleRead(@NotNull FilterChainContext ctx) {
            // Peer address is used for non-connected UDP Connection :)
            final Object peerAddress = ctx.getAddress();
            final Object message = ctx.getMessage();

            ctx.write(peerAddress, message, null);

            return ctx.getStopAction();
        }
    });

    // Create TCP transport
    final TCPNIOTransport transport = newInstance().build();

    transport.setProcessor(filterChainBuilder.build());
    try {
        // binding transport to start listen on certain host and port
        transport.bind(PORT);

        // start the transport
        transport.start();

        countDownLatch.await(50, TimeUnit.SECONDS);
    } finally {
        LOG.info("Stopping transport...");
        // stop the transport
        transport.shutdownNow();

        LOG.info("Stopped transport...");
    }
}
 
开发者ID:OpenHFT,项目名称:Chronicle-Network,代码行数:43,代码来源:GrizzlyEchoServer.java


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