• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java OioSocketChannel类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: AHessianJmxClient

import io.netty.channel.socket.oio.OioSocketChannel; //导入依赖的package包/类
public AHessianJmxClient(String discoveryName, int port, boolean debug,
		InternalLogger logger) throws Exception
{
	_discoveryName = discoveryName;
	_port = port;
	_debug = debug;
	_logger = logger;
	Map options = new HashMap();
	options.put("sync", true);
	options.put("timeout", (long) 5000);

	final ChannelPipelineFactoryBuilder<MBeanServerConnection> builder = new ChannelPipelineFactoryBuilder<MBeanServerConnection>()
			.serviceThreads(10).reconnect(10)
			.rpcServiceInterface(MBeanServerConnection.class)
			.serviceOptions(options);

	builder.debug();
	builder.serializerFactory(new JmxSerializerFactory());

	final Set<String> channelOptions = new HashSet();
	channelOptions.add("SO_REUSE");
	channelOptions.add("TCP_NODELAY");
	client = new DefaultClient<MBeanServerConnection>(
			OioSocketChannel.class, builder, channelOptions);

}
 
开发者ID:yajsw,项目名称:yajsw,代码行数:27,代码来源:AHessianJmxClient.java


示例2: clientSocket

import io.netty.channel.socket.oio.OioSocketChannel; //导入依赖的package包/类
public List<BootstrapFactory<Bootstrap>> clientSocket() {
    return Arrays.asList(
            new BootstrapFactory<Bootstrap>() {
                @Override
                public Bootstrap newInstance() {
                    return new Bootstrap().group(nioWorkerGroup).channel(NioSocketChannel.class);
                }
            },
            new BootstrapFactory<Bootstrap>() {
                @Override
                public Bootstrap newInstance() {
                    return new Bootstrap().group(oioWorkerGroup).channel(OioSocketChannel.class)
                            .option(ChannelOption.SO_TIMEOUT, OIO_SO_TIMEOUT);
                }
            }
    );
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:18,代码来源:SocketTestPermutation.java


示例3: clientSocket

import io.netty.channel.socket.oio.OioSocketChannel; //导入依赖的package包/类
static List<Factory<Bootstrap>> clientSocket() {
    List<Factory<Bootstrap>> list = new ArrayList<Factory<Bootstrap>>();
    list.add(new Factory<Bootstrap>() {
        @Override
        public Bootstrap newInstance() {
            return new Bootstrap().group(nioWorkerGroup).channel(NioSocketChannel.class);
        }
    });
    list.add(new Factory<Bootstrap>() {
        @Override
        public Bootstrap newInstance() {
            return new Bootstrap().group(oioWorkerGroup).channel(OioSocketChannel.class);
        }
    });
    return list;
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:17,代码来源:SocketTestPermutation.java


示例4: createBootstrap

import io.netty.channel.socket.oio.OioSocketChannel; //导入依赖的package包/类
public static Bootstrap createBootstrap(final ChannelType channelType) throws UnsupportedOperationException {
    Bootstrap bootstrap = new Bootstrap();

    switch (channelType) {
        case NIO:
        
            bootstrap.group(new NioEventLoopGroup());
            bootstrap.channel(NioSocketChannel.class);
            return bootstrap;

        case OIO:
 
            bootstrap.group(new OioEventLoopGroup());
            bootstrap.channel(OioSocketChannel.class);
            return bootstrap;

        default:
            throw new UnsupportedOperationException("Failed to create Bootstrap,  " + channelType + " not supported!");
    }
}
 
开发者ID:desperado1992,项目名称:distributeTemplate,代码行数:21,代码来源:BootstrapFactory.java


示例5: getSocketChannelClass

import io.netty.channel.socket.oio.OioSocketChannel; //导入依赖的package包/类
/**
 * Returns a socket channel class suitable for specified event loop group.
 *
 * @param eventLoopGroup the event loop group for which to identify an appropriate socket channel class; must not
 * be {@code null}
 *
 * @return a socket channel class suitable for use with the given event loop group
 *
 * @throws IllegalArgumentException in case of null or unrecognized event loop group
 */
static Class<? extends Channel> getSocketChannelClass(final EventLoopGroup eventLoopGroup) {
    Objects.requireNonNull(eventLoopGroup);

    final Class<? extends Channel> socketChannelClass;

    if (eventLoopGroup instanceof NioEventLoopGroup) {
        socketChannelClass = NioSocketChannel.class;
    } else if (eventLoopGroup instanceof OioEventLoopGroup) {
        socketChannelClass = OioSocketChannel.class;
    } else if (EPOLL_EVENT_LOOP_GROUP_CLASS.equals(eventLoopGroup.getClass().getName())) {
        socketChannelClass = loadSocketChannelClass(EPOLL_SOCKET_CHANNEL_CLASS);
    } else if (KQUEUE_EVENT_LOOP_GROUP_CLASS.equals(eventLoopGroup.getClass().getName())) {
        socketChannelClass = loadSocketChannelClass(KQUEUE_SOCKET_CHANNEL_CLASS);
    } else {
        throw new IllegalArgumentException("Could not find socket class for event loop group class: " + eventLoopGroup.getClass().getName());
    }

    return socketChannelClass;
}
 
开发者ID:relayrides,项目名称:pushy,代码行数:30,代码来源:ClientSocketChannelClassUtil.java


示例6: testTooManyClientChannels

import io.netty.channel.socket.oio.OioSocketChannel; //导入依赖的package包/类
@Test
public void testTooManyClientChannels() throws Exception {
    EventLoopGroup g = new OioEventLoopGroup(1);
    ServerBootstrap sb = new ServerBootstrap();
    sb.channel(OioServerSocketChannel.class);
    sb.group(g);
    sb.childHandler(new ChannelInboundHandlerAdapter());
    ChannelFuture f1 = sb.bind(0);
    f1.sync();

    Bootstrap cb = new Bootstrap();
    cb.channel(OioSocketChannel.class);
    cb.group(g);
    cb.handler(new ChannelInboundHandlerAdapter());
    ChannelFuture f2 = cb.connect(NetUtil.LOCALHOST, ((InetSocketAddress) f1.channel().localAddress()).getPort());
    f2.await();

    assertThat(f2.cause(), is(instanceOf(ChannelException.class)));
    assertThat(f2.cause().getMessage().toLowerCase(), containsString("too many channels"));

    final CountDownLatch notified = new CountDownLatch(1);
    f2.addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
            notified.countDown();
        }
    });

    notified.await();
    g.shutdownGracefully();
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:32,代码来源:OioEventLoopTest.java


示例7: run

import io.netty.channel.socket.oio.OioSocketChannel; //导入依赖的package包/类
public void run() {
    // Configure the server.
    worker = new OioEventLoopGroup();
    Bootstrap b = new Bootstrap();
    b.group(worker)
            .channel(OioSocketChannel.class)
            .option(ChannelOption.SO_KEEPALIVE, true)
            .option(ChannelOption.SO_REUSEADDR, true)
            .handler(new SocketClientInitializer());
    // Start the client.
    channel = b.connect(host, port).channel();
}
 
开发者ID:LyLuo,项目名称:message-center,代码行数:13,代码来源:SocketClient.java


示例8: testTooManyClientChannels

import io.netty.channel.socket.oio.OioSocketChannel; //导入依赖的package包/类
@Test
public void testTooManyClientChannels() throws Exception {
    EventLoopGroup g = new OioEventLoopGroup(1);
    ServerBootstrap sb = new ServerBootstrap();
    sb.channel(OioServerSocketChannel.class);
    sb.group(g);
    sb.childHandler(new ChannelHandlerAdapter());
    ChannelFuture f1 = sb.bind(0);
    f1.sync();

    Bootstrap cb = new Bootstrap();
    cb.channel(OioSocketChannel.class);
    cb.group(g);
    cb.handler(new ChannelHandlerAdapter());
    ChannelFuture f2 = cb.connect(NetUtil.LOCALHOST, ((InetSocketAddress) f1.channel().localAddress()).getPort());
    f2.await();

    assertThat(f2.cause(), is(instanceOf(ChannelException.class)));
    assertThat(f2.cause().getMessage().toLowerCase(), containsString("too many channels"));

    final CountDownLatch notified = new CountDownLatch(1);
    f2.addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
            notified.countDown();
        }
    });

    notified.await();
    g.shutdownGracefully();
}
 
开发者ID:nathanchen,项目名称:netty-netty-5.0.0.Alpha1,代码行数:32,代码来源:OioEventLoopTest.java


示例9: connnect

import io.netty.channel.socket.oio.OioSocketChannel; //导入依赖的package包/类
private ChannelFuture connnect(RpcRequest request) {
	final Client client = this;
	final RpcRequest frequest = request;
	Bootstrap b = new Bootstrap();
	try {
		b.group(new OioEventLoopGroup()).channel(OioSocketChannel.class)
				.option(ChannelOption.TCP_NODELAY, true)
				.option(ChannelOption.SO_REUSEADDR, true)
				.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000 * 10)
				.remoteAddress(new InetSocketAddress(host, port))
				.handler(new ChannelInitializer<SocketChannel>() {
					@Override
					public void initChannel(SocketChannel ch)
							throws Exception {
						ChannelPipeline pipeline = ch.pipeline();
						pipeline.addLast("encoder", new RpcEncoder(End.CLIENT));
						pipeline.addLast("decoder", new RpcDecoder(End.CLIENT));
						pipeline.addLast("handler", new ClientChannelHandler(client, frequest));
					}
				});

		ChannelFuture future = b.connect().syncUninterruptibly();
		future.awaitUninterruptibly(1000 * 10);
		return future;
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	}
}
 
开发者ID:ReliefZk,项目名称:minor-rpc,代码行数:30,代码来源:NettyClient.java


示例10: initializeConnectionManager

import io.netty.channel.socket.oio.OioSocketChannel; //导入依赖的package包/类
/**
 * Initializes a new TCPConnectionManager.
 * 
 * @param serverConfig
 *            a configuration to use for initializing
 * @return the new ConnectionManager
 */
private ConnectionManager initializeConnectionManager(final AddressBasedServerConfig serverConfig) {
	LOGGER.entry();
	final EventLoopGroup applicationEventLoopGroup = new OioEventLoopGroup();
	final EventLoopGroup networkEventLoopGroup = new OioEventLoopGroup();
	eventExecutorGroups.add(applicationEventLoopGroup);
	eventExecutorGroups.add(networkEventLoopGroup);

	final ServerBootstrap serverBootstrap = new ServerBootstrap();
	serverBootstrap.group(networkEventLoopGroup, applicationEventLoopGroup);
	serverBootstrap.channel(OioServerSocketChannel.class);
	final ServerBootstrapChannelFactory serverChannelFactory = new ServerBootstrapChannelFactory(serverBootstrap);

	final Bootstrap clientBootstrap = new Bootstrap();
	clientBootstrap.group(applicationEventLoopGroup);
	clientBootstrap.channel(OioSocketChannel.class);
	final ClientBootstrapChannelFactory clientChannelFactory = new ClientBootstrapChannelFactory(clientBootstrap);

	final TCPConnectionManager connectionManager =
			new TCPConnectionManager(serverChannelFactory, clientChannelFactory, scheduledExecutorService,
					serverConfig.getModuleID());

	new TCPProtocol().initialize(connectionManager);

	for (final InetSocketAddress address : serverConfig.getListenAddresses()) {
		connectionManager.startListening(address);
	}

	return LOGGER.exit(connectionManager);
}
 
开发者ID:DesignAndDeploy,项目名称:dnd,代码行数:37,代码来源:TCPUDPServerManager.java


示例11: RpcClient

import io.netty.channel.socket.oio.OioSocketChannel; //导入依赖的package包/类
public RpcClient(OioEventLoopGroup eventLoopGroup, EventExecutorGroup eventExecutor) {
    this(eventLoopGroup, eventExecutor, OioSocketChannel.class);
}
 
开发者ID:lemonJun,项目名称:TakinRPC,代码行数:4,代码来源:RpcClient.java


示例12: worksWithOioEventLoopGroup

import io.netty.channel.socket.oio.OioSocketChannel; //导入依赖的package包/类
@Test
public void worksWithOioEventLoopGroup() {
    assertThat(resolveSocketChannelClass(new OioEventLoopGroup())).isEqualTo(OioSocketChannel.class);
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:5,代码来源:SocketChannelResolverTest.java


示例13: oioClientBootstrap

import io.netty.channel.socket.oio.OioSocketChannel; //导入依赖的package包/类
@NotNull
public static Bootstrap oioClientBootstrap() {
  Bootstrap bootstrap = new Bootstrap().group(new OioEventLoopGroup(1, PooledThreadExecutor.INSTANCE)).channel(OioSocketChannel.class);
  bootstrap.option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.SO_KEEPALIVE, true);
  return bootstrap;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:NettyUtil.java


示例14: AbstractEndpoint

import io.netty.channel.socket.oio.OioSocketChannel; //导入依赖的package包/类
/**
 * Create a new {@link AbstractEndpoint}.
 *
 * @param hostname the hostname/ipaddr of the remote channel.
 * @param bucket the name of the bucket.
 * @param username the user authorized for bucket access.
 * @param password the password of the user.
 * @param port the port of the remote channel.
 * @param environment the environment of the core.
 * @param responseBuffer the response buffer for passing responses up the stack.
 */
protected AbstractEndpoint(final String hostname, final String bucket, final String username, final String password, final int port,
    final CoreEnvironment environment, final RingBuffer<ResponseEvent> responseBuffer, boolean isTransient,
    final EventLoopGroup ioPool, final boolean pipeline) {
    super(LifecycleState.DISCONNECTED);
    this.bucket = bucket;
    this.username = username;
    this.password = password;
    this.responseBuffer = responseBuffer;
    this.env = environment;
    this.isTransient = isTransient;
    this.ioPool = ioPool;
    this.pipeline = pipeline;
    this.free = true;
    this.hostname = hostname;
    this.connectCallbackGracePeriod = Integer.parseInt(
        System.getProperty("com.couchbase.connectCallbackGracePeriod", DEFAULT_CONNECT_CALLBACK_GRACE_PERIOD)
    );
    LOGGER.debug("Using a connectCallbackGracePeriod of {} on Endpoint {}:{}", connectCallbackGracePeriod,
        hostname, port);
    if (environment.sslEnabled()) {
        this.sslEngineFactory = new SSLEngineFactory(environment);
    }

    Class<? extends Channel> channelClass = NioSocketChannel.class;
    if (ioPool instanceof EpollEventLoopGroup) {
        channelClass = EpollSocketChannel.class;
    } else if (ioPool instanceof OioEventLoopGroup) {
        channelClass = OioSocketChannel.class;
    }

    ByteBufAllocator allocator = env.bufferPoolingEnabled()
            ? PooledByteBufAllocator.DEFAULT : UnpooledByteBufAllocator.DEFAULT;

    boolean tcpNodelay = environment().tcpNodelayEnabled();
    bootstrap = new BootstrapAdapter(new Bootstrap()
        .remoteAddress(hostname, port)
        .group(ioPool)
        .channel(channelClass)
        .option(ChannelOption.ALLOCATOR, allocator)
        .option(ChannelOption.TCP_NODELAY, tcpNodelay)
        .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, env.socketConnectTimeout())
        .handler(new ChannelInitializer<Channel>() {
            @Override
            protected void initChannel(Channel channel) throws Exception {
                ChannelPipeline pipeline = channel.pipeline();
                if (environment.sslEnabled()) {
                    pipeline.addLast(new SslHandler(sslEngineFactory.get()));
                }
                if (LOGGER.isTraceEnabled()) {
                    pipeline.addLast(LOGGING_HANDLER_INSTANCE);
                }
                customEndpointHandlers(pipeline);
            }
        }));
}
 
开发者ID:couchbase,项目名称:couchbase-jvm-core,代码行数:67,代码来源:AbstractEndpoint.java


示例15: newChannel

import io.netty.channel.socket.oio.OioSocketChannel; //导入依赖的package包/类
@Override
public OioSocketChannel newChannel() {
    return new OioSocketChannel(new Socket(this.proxy));
}
 
开发者ID:Steveice10,项目名称:PacketLib,代码行数:5,代码来源:ProxyOioChannelFactory.java


示例16: oioClientBootstrap

import io.netty.channel.socket.oio.OioSocketChannel; //导入依赖的package包/类
public static Bootstrap oioClientBootstrap() {
  Bootstrap bootstrap = new Bootstrap().group(new OioEventLoopGroup(1, PooledThreadExecutor.INSTANCE)).channel(OioSocketChannel.class);
  bootstrap.option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.SO_KEEPALIVE, true);
  return bootstrap;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:6,代码来源:NettyKt.java


示例17: doConnect

import io.netty.channel.socket.oio.OioSocketChannel; //导入依赖的package包/类
private static Channel doConnect(Bootstrap bootstrap,
                                 InetSocketAddress remoteAddress,
                                 AsyncResult<?> asyncResult,
                                 int maxAttemptCount,
                                 @Nullable Condition<Void> stopCondition) throws Throwable {
  int attemptCount = 0;
  if (bootstrap.config().group() instanceof NioEventLoopGroup) {
    return connectNio(bootstrap, remoteAddress, asyncResult, maxAttemptCount, stopCondition, attemptCount);
  }

  bootstrap.validate();

  while (true) {
    try {
      OioSocketChannel channel = new OioSocketChannel(new Socket(remoteAddress.getAddress(), remoteAddress.getPort()));
      BootstrapUtil.initAndRegister(channel, bootstrap).sync();
      return channel;
    }
    catch (IOException e) {
      if (stopCondition != null && stopCondition.value(null) || asyncResult != null && !asyncResult.isProcessed()) {
        return null;
      }
      else if (maxAttemptCount == -1) {
        if (sleep(asyncResult, 300)) {
          return null;
        }
        attemptCount++;
      }
      else if (++attemptCount < maxAttemptCount) {
        if (sleep(asyncResult, attemptCount * NettyUtil.MIN_START_TIME)) {
          return null;
        }
      }
      else {
        if (asyncResult != null) {
          asyncResult.rejectWithThrowable(e);
        }
        return null;
      }
    }
  }
}
 
开发者ID:consulo,项目名称:consulo,代码行数:43,代码来源:NettyKt.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ValueFactory类代码示例发布时间:2022-05-21
下一篇:
Java TypeMirror类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap