Java 类io.netty.channel.ChannelException 实例源码

项目:SurvivalMMO    文件:NetworkManager.java   
@Override
        protected void initChannel(SocketChannel ch) throws Exception {
            try {
                ch.config().setOption(ChannelOption.IP_TOS, 0x18);
//                ch.config().setOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 * 1024);
//                ch.config().setOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 1024);
            } catch (ChannelException ex) {
                // IP_TOS not supported by platform, ignore
            }
            ch.config().setAllocator(PooledByteBufAllocator.DEFAULT);

            PacketRegistry r = new PacketRegistry();

            ch.pipeline().addLast(new HttpServerCodec());
            ch.pipeline().addLast(new HttpObjectAggregator(65536));
            ch.pipeline().addLast(new WebSocketHandler());
            ch.pipeline().addLast(new PacketDecoder(r));
            ch.pipeline().addLast(new PacketEncoder(r));
            ch.pipeline().addLast(new ClientHandler(server));
        }
项目:FFS-PubSub    文件:NetworkManager.java   
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    try {
        ch.config().setOption(ChannelOption.TCP_NODELAY, true);
        ch.config().setOption(ChannelOption.IP_TOS, 0x18);
    } catch (ChannelException ex) {
        // IP_TOS not supported by platform, ignore
    }
    ch.config().setAllocator(PooledByteBufAllocator.DEFAULT);

    PacketRegistry r = new PacketRegistry();

    ch.pipeline().addLast("idleStateHandler", new IdleStateHandler(0, 0, 30));
    ch.pipeline().addLast(new HttpServerCodec());
    ch.pipeline().addLast(new HttpObjectAggregator(65536));
    ch.pipeline().addLast(new WebSocketHandler());
    ch.pipeline().addLast(new PacketDecoder(r));
    ch.pipeline().addLast(new PacketEncoder(r));
    ch.pipeline().addLast(mExecutorGroup, "serverHandler", new ClientHandler(mServer));
}
项目:FPAgar    文件:NetworkManager.java   
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    try {
        ch.config().setOption(ChannelOption.IP_TOS, 0x18);
    } catch (ChannelException ex) {
        // IP_TOS not supported by platform, ignore
    }
    ch.config().setAllocator(PooledByteBufAllocator.DEFAULT);

    ch.pipeline().addLast(new HttpServerCodec());
    ch.pipeline().addLast(new HttpObjectAggregator(65536));
    ch.pipeline().addLast(new WebSocketHandler());
    ch.pipeline().addLast(new PacketDecoder());
    ch.pipeline().addLast(new PacketEncoder());
    ch.pipeline().addLast(new ClientHandler(server));
}
项目:Clither-Server    文件:NetworkManager.java   
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    try {
        ch.config().setOption(ChannelOption.IP_TOS, 0x18);
    } catch (ChannelException ex) {
        // IP_TOS not supported by platform, ignore
    }
    ch.config().setAllocator(PooledByteBufAllocator.DEFAULT);

    ch.pipeline().addLast(new HttpServerCodec());
    ch.pipeline().addLast(new HttpObjectAggregator(65536));
    ch.pipeline().addLast(new Handshaker());
    ch.pipeline().addLast(new WebSocketHandler());
    ch.pipeline().addLast(new PacketDecoder());
    ch.pipeline().addLast(new PacketEncoder());
    ch.pipeline().addLast(new ClientHandler(server));
}
项目:Waterfall-Old    文件:PipelineUtils.java   
@Override
public void initChannel(Channel ch) throws Exception
{
    try
    {
        ch.config().setOption( ChannelOption.IP_TOS, 0x18 );
    } catch ( ChannelException ex )
    {
        // IP_TOS is not supported (Windows XP / Windows Server 2003)
    }
    ch.config().setOption( ChannelOption.TCP_NODELAY, true );
    ch.config().setAllocator( PooledByteBufAllocator.DEFAULT );

    ch.pipeline().addLast( TIMEOUT_HANDLER, new ReadTimeoutHandler( BungeeCord.getInstance().config.getTimeout(), TimeUnit.MILLISECONDS ) );
    ch.pipeline().addLast( FRAME_DECODER, new Varint21FrameDecoder() );
    ch.pipeline().addLast( FRAME_PREPENDER, framePrepender );

    ch.pipeline().addLast( BOSS_HANDLER, new HandlerBoss() );
}
项目:UniversalProxy    文件:PipelineUtils.java   
@Override
public void initChannel(Channel ch) throws Exception
{
    try
    {
        ch.config().setOption( ChannelOption.IP_TOS, 0x18 );
    } catch ( ChannelException ex )
    {
        // IP_TOS is not supported (Windows XP / Windows Server 2003)
    }
    ch.config().setOption( ChannelOption.TCP_NODELAY, true );
    ch.config().setAllocator( PooledByteBufAllocator.DEFAULT );

    ch.pipeline().addLast( TIMEOUT_HANDLER, new ReadTimeoutHandler( BungeeCord.getInstance().config.getTimeout(), TimeUnit.MILLISECONDS ) );
    ch.pipeline().addLast( FRAME_DECODER, new Varint21FrameDecoder() );
    ch.pipeline().addLast( FRAME_PREPENDER, framePrepender );

    ch.pipeline().addLast( BOSS_HANDLER, new HandlerBoss() );
}
项目:flashback    文件:ProxyServer.java   
/**
 * Start proxy server
 * */
public void start()
    throws InterruptedException {
  ServerBootstrap serverBootstrap = new ServerBootstrap();
  serverBootstrap.group(_acceptorGroup, _upstreamWorkerGroup);
  serverBootstrap.channelFactory(new ChannelFactory<ServerChannel>() {
    @Override
    public ServerChannel newChannel() {
      return new NioServerSocketChannel();
    }
  });
  serverBootstrap.childHandler(new ProxyInitializer(this));

  //bind
  ChannelFuture future = serverBootstrap.bind(_host, _port);

  //wait for the future
  future.awaitUninterruptibly();
  if (!future.isSuccess()) {
    future.channel().closeFuture().awaitUninterruptibly();
    throw new ChannelException(String.format("Failed to bind to: %s:%d", _host, _port), future.cause());
  } else {
    _allChannels.add(future.channel());
  }
}
项目:netty4.0.27Learn    文件:NioUdtAcceptorChannel.java   
protected NioUdtAcceptorChannel(final ServerSocketChannelUDT channelUDT) {
    super(null, channelUDT, OP_ACCEPT);
    try {
        channelUDT.configureBlocking(false);
        config = new DefaultUdtServerChannelConfig(this, channelUDT, true);
    } catch (final Exception e) {
        try {
            channelUDT.close();
        } catch (final Exception e2) {
            if (logger.isWarnEnabled()) {
                logger.warn("Failed to close channel.", e2);
            }
        }
        throw new ChannelException("Failed to configure channel.", e);
    }
}
项目:netty4.0.27Learn    文件:DefaultDatagramChannelConfig.java   
@Override
public DatagramChannelConfig setBroadcast(boolean broadcast) {
    try {
        // See: https://github.com/netty/netty/issues/576
        if (broadcast &&
            !javaSocket.getLocalAddress().isAnyLocalAddress() &&
            !PlatformDependent.isWindows() && !PlatformDependent.isRoot()) {
            // Warn a user about the fact that a non-root user can't receive a
            // broadcast packet on *nix if the socket is bound on non-wildcard address.
            logger.warn(
                    "A non-root user can't receive a broadcast packet if the socket " +
                    "is not bound to a wildcard address; setting the SO_BROADCAST flag " +
                    "anyway as requested on the socket which is bound to " +
                    javaSocket.getLocalSocketAddress() + '.');
        }

        javaSocket.setBroadcast(broadcast);
    } catch (SocketException e) {
        throw new ChannelException(e);
    }
    return this;
}
项目:netty4.0.27Learn    文件:LocalChannelRegistry.java   
static LocalAddress register(
        Channel channel, LocalAddress oldLocalAddress, SocketAddress localAddress) {
    if (oldLocalAddress != null) {
        throw new ChannelException("already bound");
    }
    if (!(localAddress instanceof LocalAddress)) {
        throw new ChannelException("unsupported address type: " + StringUtil.simpleClassName(localAddress));
    }

    LocalAddress addr = (LocalAddress) localAddress;
    if (LocalAddress.ANY.equals(addr)) {
        addr = new LocalAddress(channel);
    }

    Channel boundChannel = boundChannels.putIfAbsent(addr, channel);
    if (boundChannel != null) {
        throw new ChannelException("address already in use by: " + boundChannel);
    }
    return addr;
}
项目:netty4.0.27Learn    文件:AbstractNioChannel.java   
/**
 * Create a new instance
 *
 * @param parent            the parent {@link Channel} by which this instance was created. May be {@code null}
 * @param ch                the underlying {@link SelectableChannel} on which it operates
 * @param readInterestOp    the ops to set to receive data from the {@link SelectableChannel}
 */
protected AbstractNioChannel(Channel parent, SelectableChannel ch, int readInterestOp) {
    super(parent);
    this.ch = ch;
    this.readInterestOp = readInterestOp;
    try {
        ch.configureBlocking(false);
    } catch (IOException e) {
        try {
            ch.close();
        } catch (IOException e2) {
            if (logger.isWarnEnabled()) {
                logger.warn(
                        "Failed to close a partially initialized socket.", e2);
            }
        }

        throw new ChannelException("Failed to enter non-blocking mode.", e);
    }
}
项目:netty4.0.27Learn    文件:NioSctpChannel.java   
/**
 * Create a new instance
 *
 * @param parent        the {@link Channel} which is the parent of this {@link NioSctpChannel}
 *                      or {@code null}.
 * @param sctpChannel   the underlying {@link SctpChannel}
 */
public NioSctpChannel(Channel parent, SctpChannel sctpChannel) {
    super(parent, sctpChannel, SelectionKey.OP_READ);
    try {
        sctpChannel.configureBlocking(false);
        config = new NioSctpChannelConfig(this, sctpChannel);
        notificationHandler = new SctpNotificationHandler(this);
    } catch (IOException e) {
        try {
            sctpChannel.close();
        } catch (IOException e2) {
            if (logger.isWarnEnabled()) {
                logger.warn(
                        "Failed to close a partially initialized sctp channel.", e2);
            }
        }

        throw new ChannelException("Failed to enter non-blocking mode.", e);
    }
}
项目:Ogar2-Server    文件:NetworkManager.java   
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    try {
        ch.config().setOption(ChannelOption.IP_TOS, 0x18);
    } catch (ChannelException ex) {
        // IP_TOS not supported by platform, ignore
    }
    ch.config().setAllocator(PooledByteBufAllocator.DEFAULT);

    ch.pipeline().addLast(new HttpServerCodec());
    ch.pipeline().addLast(new HttpObjectAggregator(65536));
    ch.pipeline().addLast(new WebSocketHandler());
    ch.pipeline().addLast(new PacketDecoder());
    ch.pipeline().addLast(new PacketEncoder());
    ch.pipeline().addLast(new ClientHandler(server));
}
项目:netty4study    文件:NioUdtAcceptorChannel.java   
protected NioUdtAcceptorChannel(final ServerSocketChannelUDT channelUDT) {
    super(null, channelUDT, OP_ACCEPT);
    try {
        channelUDT.configureBlocking(false);
        config = new DefaultUdtServerChannelConfig(this, channelUDT, true);
    } catch (final Exception e) {
        try {
            channelUDT.close();
        } catch (final Exception e2) {
            if (logger.isWarnEnabled()) {
                logger.warn("Failed to close channel.", e2);
            }
        }
        throw new ChannelException("Failed to configure channel.", e);
    }
}
项目:netty-netty-5.0.0.Alpha1    文件:NioUdtAcceptorChannel.java   
protected NioUdtAcceptorChannel(EventLoop eventLoop, EventLoopGroup childGroup,
        ServerSocketChannelUDT channelUDT) {
    super(null, eventLoop, childGroup, channelUDT, OP_ACCEPT);
    try {
        channelUDT.configureBlocking(false);
        config = new DefaultUdtServerChannelConfig(this, channelUDT, true);
    } catch (final Exception e) {
        try {
            channelUDT.close();
        } catch (final Exception e2) {
            if (logger.isWarnEnabled()) {
                logger.warn("Failed to close channel.", e2);
            }
        }
        throw new ChannelException("Failed to configure channel.", e);
    }
}
项目:netty-netty-5.0.0.Alpha1    文件:LocalChannelRegistry.java   
static LocalAddress register(
        Channel channel, LocalAddress oldLocalAddress, SocketAddress localAddress) {
    if (oldLocalAddress != null) {
        throw new ChannelException("already bound");
    }
    if (!(localAddress instanceof LocalAddress)) {
        throw new ChannelException("unsupported address type: " + StringUtil.simpleClassName(localAddress));
    }

    LocalAddress addr = (LocalAddress) localAddress;
    if (LocalAddress.ANY.equals(addr)) {
        addr = new LocalAddress(channel);
    }

    Channel boundChannel = boundChannels.putIfAbsent(addr, channel);
    if (boundChannel != null) {
        throw new ChannelException("address already in use by: " + boundChannel);
    }
    return addr;
}
项目:netty4study    文件:AbstractNioChannel.java   
/**
 * Create a new instance
 *
 * @param parent         the parent {@link Channel} by which this instance was created. May be {@code null}
 * @param ch             the underlying {@link SelectableChannel} on which it operates
 * @param readInterestOp the ops to set to receive data from the {@link SelectableChannel}
 */
protected AbstractNioChannel(Channel parent, SelectableChannel ch, int readInterestOp) {
    super(parent);
    this.ch = ch;
    this.readInterestOp = readInterestOp;
    try {
        ch.configureBlocking(false);
    } catch (IOException e) {
        try {
            ch.close();
        } catch (IOException e2) {
            if (logger.isWarnEnabled()) {
                logger.warn(
                        "Failed to close a partially initialized socket.", e2);
            }
        }

        throw new ChannelException("Failed to enter non-blocking mode.", e);
    }
}
项目:netty-netty-5.0.0.Alpha1    文件:OioDatagramChannel.java   
/**
 * Create a new instance from the given {@link MulticastSocket}.
 *
 * @param socket    the {@link MulticastSocket} which is used by this instance
 */
public OioDatagramChannel(EventLoop eventLoop, MulticastSocket socket) {
    super(null, eventLoop);

    boolean success = false;
    try {
        socket.setSoTimeout(SO_TIMEOUT);
        socket.setBroadcast(false);
        success = true;
    } catch (SocketException e) {
        throw new ChannelException(
                "Failed to configure the datagram socket timeout.", e);
    } finally {
        if (!success) {
            socket.close();
        }
    }

    this.socket = socket;
    config = new DefaultDatagramChannelConfig(this, socket);
}
项目:netty-netty-5.0.0.Alpha1    文件:NioSctpChannel.java   
/**
 * Create a new instance
 *
 * @param parent        the {@link Channel} which is the parent of this {@link NioSctpChannel}
 *                      or {@code null}.
 * @param sctpChannel   the underlying {@link SctpChannel}
 */
public NioSctpChannel(Channel parent, EventLoop eventLoop, SctpChannel sctpChannel) {
    super(parent, eventLoop, sctpChannel, SelectionKey.OP_READ);
    try {
        sctpChannel.configureBlocking(false);
        config = new DefaultSctpChannelConfig(this, sctpChannel);
        notificationHandler = new SctpNotificationHandler(this);
    } catch (IOException e) {
        try {
            sctpChannel.close();
        } catch (IOException e2) {
            if (logger.isWarnEnabled()) {
                logger.warn(
                        "Failed to close a partially initialized sctp channel.", e2);
            }
        }

        throw new ChannelException("Failed to enter non-blocking mode.", e);
    }
}
项目:DecompiledMinecraft    文件:NetworkManager.java   
public static NetworkManager func_181124_a(InetAddress p_181124_0_, int p_181124_1_, boolean p_181124_2_)
{
    final NetworkManager networkmanager = new NetworkManager(EnumPacketDirection.CLIENTBOUND);
    Class <? extends SocketChannel > oclass;
    LazyLoadBase <? extends EventLoopGroup > lazyloadbase;

    if (Epoll.isAvailable() && p_181124_2_)
    {
        oclass = EpollSocketChannel.class;
        lazyloadbase = field_181125_e;
    }
    else
    {
        oclass = NioSocketChannel.class;
        lazyloadbase = CLIENT_NIO_EVENTLOOP;
    }

    ((Bootstrap)((Bootstrap)((Bootstrap)(new Bootstrap()).group((EventLoopGroup)lazyloadbase.getValue())).handler(new ChannelInitializer<Channel>()
    {
        protected void initChannel(Channel p_initChannel_1_) throws Exception
        {
            try
            {
                p_initChannel_1_.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(true));
            }
            catch (ChannelException var3)
            {
                ;
            }

            p_initChannel_1_.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(30))).addLast((String)"splitter", (ChannelHandler)(new MessageDeserializer2())).addLast((String)"decoder", (ChannelHandler)(new MessageDeserializer(EnumPacketDirection.CLIENTBOUND))).addLast((String)"prepender", (ChannelHandler)(new MessageSerializer2())).addLast((String)"encoder", (ChannelHandler)(new MessageSerializer(EnumPacketDirection.SERVERBOUND))).addLast((String)"packet_handler", (ChannelHandler)networkmanager);
        }
    })).channel(oclass)).connect(p_181124_0_, p_181124_1_).syncUninterruptibly();
    return networkmanager;
}
项目:BaseClient    文件:NetworkManager.java   
public static NetworkManager func_181124_a(InetAddress p_181124_0_, int p_181124_1_, boolean p_181124_2_)
{
    final NetworkManager networkmanager = new NetworkManager(EnumPacketDirection.CLIENTBOUND);
    Class <? extends SocketChannel > oclass;
    LazyLoadBase <? extends EventLoopGroup > lazyloadbase;

    if (Epoll.isAvailable() && p_181124_2_)
    {
        oclass = EpollSocketChannel.class;
        lazyloadbase = field_181125_e;
    }
    else
    {
        oclass = NioSocketChannel.class;
        lazyloadbase = CLIENT_NIO_EVENTLOOP;
    }

    ((Bootstrap)((Bootstrap)((Bootstrap)(new Bootstrap()).group((EventLoopGroup)lazyloadbase.getValue())).handler(new ChannelInitializer<Channel>()
    {
        protected void initChannel(Channel p_initChannel_1_) throws Exception
        {
            try
            {
                p_initChannel_1_.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(true));
            }
            catch (ChannelException var3)
            {
                ;
            }

            p_initChannel_1_.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(30))).addLast((String)"splitter", (ChannelHandler)(new MessageDeserializer2())).addLast((String)"decoder", (ChannelHandler)(new MessageDeserializer(EnumPacketDirection.CLIENTBOUND))).addLast((String)"prepender", (ChannelHandler)(new MessageSerializer2())).addLast((String)"encoder", (ChannelHandler)(new MessageSerializer(EnumPacketDirection.SERVERBOUND))).addLast((String)"packet_handler", (ChannelHandler)networkmanager);
        }
    })).channel(oclass)).connect(p_181124_0_, p_181124_1_).syncUninterruptibly();
    return networkmanager;
}
项目:BaseClient    文件:NetworkManager.java   
public static NetworkManager func_181124_a(InetAddress p_181124_0_, int p_181124_1_, boolean p_181124_2_)
{
    final NetworkManager networkmanager = new NetworkManager(EnumPacketDirection.CLIENTBOUND);
    Class <? extends SocketChannel > oclass;
    LazyLoadBase <? extends EventLoopGroup > lazyloadbase;

    if (Epoll.isAvailable() && p_181124_2_)
    {
        oclass = EpollSocketChannel.class;
        lazyloadbase = field_181125_e;
    }
    else
    {
        oclass = NioSocketChannel.class;
        lazyloadbase = CLIENT_NIO_EVENTLOOP;
    }

    ((Bootstrap)((Bootstrap)((Bootstrap)(new Bootstrap()).group((EventLoopGroup)lazyloadbase.getValue())).handler(new ChannelInitializer<Channel>()
    {
        protected void initChannel(Channel p_initChannel_1_) throws Exception
        {
            try
            {
                p_initChannel_1_.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(true));
            }
            catch (ChannelException var3)
            {
                ;
            }

            p_initChannel_1_.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(30))).addLast((String)"splitter", (ChannelHandler)(new MessageDeserializer2())).addLast((String)"decoder", (ChannelHandler)(new MessageDeserializer(EnumPacketDirection.CLIENTBOUND))).addLast((String)"prepender", (ChannelHandler)(new MessageSerializer2())).addLast((String)"encoder", (ChannelHandler)(new MessageSerializer(EnumPacketDirection.SERVERBOUND))).addLast((String)"packet_handler", (ChannelHandler)networkmanager);
        }
    })).channel(oclass)).connect(p_181124_0_, p_181124_1_).syncUninterruptibly();
    return networkmanager;
}
项目:EMC    文件:OAuthNetworkManager.java   
public static OAuthNetworkManager createNetworkManagerAndConnect(InetAddress address, int serverPort,
        boolean useNativeTransport, OAuthCallback callback) {
    final OAuthNetworkManager networkmanager = new OAuthNetworkManager(EnumPacketDirection.CLIENTBOUND, callback);
    Class<? extends SocketChannel> oclass;
    LazyLoadBase<? extends EventLoopGroup> lazyloadbase;

    if (Epoll.isAvailable() && useNativeTransport) {
        oclass = EpollSocketChannel.class;
        lazyloadbase = CLIENT_EPOLL_EVENTLOOP;
    } else {
        oclass = NioSocketChannel.class;
        lazyloadbase = CLIENT_NIO_EVENTLOOP;
    }

    (new Bootstrap()).group(lazyloadbase.getValue()).handler(new ChannelInitializer<Channel>() {
        @Override
        protected void initChannel(Channel p_initChannel_1_) throws Exception {
            try {
                p_initChannel_1_.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(true));
            } catch (ChannelException var3) {
                ;
            }

            p_initChannel_1_.pipeline().addLast("timeout", new ReadTimeoutHandler(30))
                    .addLast("splitter", new NettyVarint21FrameDecoder())
                    .addLast("decoder", new NettyPacketDecoder(EnumPacketDirection.CLIENTBOUND))
                    .addLast("prepender", new NettyVarint21FrameEncoder())
                    .addLast("encoder", new NettyPacketEncoder(EnumPacketDirection.SERVERBOUND))
                    .addLast("packet_handler", networkmanager);
        }
    }).channel(oclass).connect(address, serverPort).syncUninterruptibly();
    return networkmanager;
}
项目:Backmemed    文件:NetworkManager.java   
/**
 * Create a new NetworkManager from the server host and connect it to the server
 */
public static NetworkManager createNetworkManagerAndConnect(InetAddress address, int serverPort, boolean useNativeTransport)
{
    final NetworkManager networkmanager = new NetworkManager(EnumPacketDirection.CLIENTBOUND);
    Class <? extends SocketChannel > oclass;
    LazyLoadBase <? extends EventLoopGroup > lazyloadbase;

    if (Epoll.isAvailable() && useNativeTransport)
    {
        oclass = EpollSocketChannel.class;
        lazyloadbase = CLIENT_EPOLL_EVENTLOOP;
    }
    else
    {
        oclass = NioSocketChannel.class;
        lazyloadbase = CLIENT_NIO_EVENTLOOP;
    }

    ((Bootstrap)((Bootstrap)((Bootstrap)(new Bootstrap()).group((EventLoopGroup)lazyloadbase.getValue())).handler(new ChannelInitializer<Channel>()
    {
        protected void initChannel(Channel p_initChannel_1_) throws Exception
        {
            try
            {
                p_initChannel_1_.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(true));
            }
            catch (ChannelException var3)
            {
                ;
            }

            p_initChannel_1_.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(30))).addLast((String)"splitter", (ChannelHandler)(new NettyVarint21FrameDecoder())).addLast((String)"decoder", (ChannelHandler)(new NettyPacketDecoder(EnumPacketDirection.CLIENTBOUND))).addLast((String)"prepender", (ChannelHandler)(new NettyVarint21FrameEncoder())).addLast((String)"encoder", (ChannelHandler)(new NettyPacketEncoder(EnumPacketDirection.SERVERBOUND))).addLast((String)"packet_handler", (ChannelHandler)networkmanager);
        }
    })).channel(oclass)).connect(address, serverPort).syncUninterruptibly();
    return networkmanager;
}
项目:CustomWorldGen    文件:NetworkManager.java   
/**
 * Create a new NetworkManager from the server host and connect it to the server
 */
@SideOnly(Side.CLIENT)
public static NetworkManager createNetworkManagerAndConnect(InetAddress address, int serverPort, boolean useNativeTransport)
{
    final NetworkManager networkmanager = new NetworkManager(EnumPacketDirection.CLIENTBOUND);
    Class <? extends SocketChannel > oclass;
    LazyLoadBase <? extends EventLoopGroup > lazyloadbase;

    if (Epoll.isAvailable() && useNativeTransport)
    {
        oclass = EpollSocketChannel.class;
        lazyloadbase = CLIENT_EPOLL_EVENTLOOP;
    }
    else
    {
        oclass = NioSocketChannel.class;
        lazyloadbase = CLIENT_NIO_EVENTLOOP;
    }

    ((Bootstrap)((Bootstrap)((Bootstrap)(new Bootstrap()).group((EventLoopGroup)lazyloadbase.getValue())).handler(new ChannelInitializer<Channel>()
    {
        protected void initChannel(Channel p_initChannel_1_) throws Exception
        {
            try
            {
                p_initChannel_1_.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(true));
            }
            catch (ChannelException var3)
            {
                ;
            }

            p_initChannel_1_.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(30))).addLast((String)"splitter", (ChannelHandler)(new NettyVarint21FrameDecoder())).addLast((String)"decoder", (ChannelHandler)(new NettyPacketDecoder(EnumPacketDirection.CLIENTBOUND))).addLast((String)"prepender", (ChannelHandler)(new NettyVarint21FrameEncoder())).addLast((String)"encoder", (ChannelHandler)(new NettyPacketEncoder(EnumPacketDirection.SERVERBOUND))).addLast((String)"packet_handler", (ChannelHandler)networkmanager);
        }
    })).channel(oclass)).connect(address, serverPort).syncUninterruptibly();
    return networkmanager;
}
项目:ditb    文件:ClusterStatusPublisher.java   
@Override
public T newChannel() {
    try {
      return ReflectionUtils.instantiateWithCustomCtor(clazz.getName(),
        new Class[] { InternetProtocolFamily.class }, new Object[] { family });

    } catch (Throwable t) {
        throw new ChannelException("Unable to create Channel from class " + clazz, t);
    }
}
项目:Waterfall-Old    文件:BungeeCord.java   
public void stopListeners()
{
    for ( Channel listener : listeners )
    {
        getLogger().log( Level.INFO, "Closing listener {0}", listener );
        try
        {
            listener.close().syncUninterruptibly();
        } catch ( ChannelException ex )
        {
            getLogger().severe( "Could not close listen thread" );
        }
    }
    listeners.clear();
}
项目:JaPS    文件:ClientChannelInitializer.java   
@Override
protected void initChannel(Channel channel) throws Exception {
    try {
        channel.config().setOption(ChannelOption.IP_TOS, 0x18);
    } catch (ChannelException e) {
        // Not supported
    }
    channel.config().setAllocator(PooledByteBufAllocator.DEFAULT);

    channel.pipeline().addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4));
    channel.pipeline().addLast(new JSONObjectDecoder());
    channel.pipeline().addLast(new LengthFieldPrepender(4));
    channel.pipeline().addLast(new JSONObjectEncoder());
    channel.pipeline().addLast(nioSocketClient);
}
项目:JaPS    文件:ServerChannelInitializer.java   
@Override
protected void initChannel(Channel channel) throws Exception {
    try {
        channel.config().setOption(ChannelOption.IP_TOS, 0x18);
    } catch (ChannelException e) {
        // Not supported
    }
    channel.config().setAllocator(PooledByteBufAllocator.DEFAULT);

    channel.pipeline().addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4));
    channel.pipeline().addLast(new JSONObjectDecoder());
    channel.pipeline().addLast(new LengthFieldPrepender(4));
    channel.pipeline().addLast(new JSONObjectEncoder());
    channel.pipeline().addLast(new Connection(jaPSServer, channel));
}
项目:JaPS    文件:ClusterPublisherChannelInitializer.java   
@Override
protected void initChannel(Channel channel) throws Exception {
    try {
        channel.config().setOption(ChannelOption.IP_TOS, 0x18);
    } catch (ChannelException e) {
        // Not supported
    }
    channel.config().setAllocator(PooledByteBufAllocator.DEFAULT);

    channel.pipeline().addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4));
    channel.pipeline().addLast(new JSONObjectDecoder());
    channel.pipeline().addLast(new LengthFieldPrepender(4));
    channel.pipeline().addLast(new JSONObjectEncoder());
    channel.pipeline().addLast(clusterPublisher);
}
项目:UdpServerSocketChannel    文件:UdpServerChannelConfig.java   
@Override
public int getReceiveBufferSize() {
    try {
        return dchannel.socket().getReceiveBufferSize();
    } catch (SocketException ex) {
        throw new ChannelException(ex);
    }
}
项目:UdpServerSocketChannel    文件:UdpServerChannelConfig.java   
@Override
public ServerSocketChannelConfig setReceiveBufferSize(int size) {
    try {
        dchannel.socket().setReceiveBufferSize(size);
    } catch (SocketException ex) {
        throw new ChannelException(ex);
    }
    return this;
}
项目:UdpServerSocketChannel    文件:UdpServerChannelConfig.java   
@Override
public boolean isReuseAddress() {
    try {
        return dchannel.socket().getReuseAddress();
    } catch (SocketException ex) {
        throw new ChannelException(ex);
    }
}
项目:UdpServerSocketChannel    文件:UdpServerChannelConfig.java   
@Override
public ServerSocketChannelConfig setReuseAddress(boolean reuseaddr) {
    try {
        dchannel.socket().setReuseAddress(true);
    } catch (SocketException ex) {
        throw new ChannelException(ex);
    }
    return this;
}
项目:UniversalProxy    文件:BungeeCord.java   
public void stopListeners()
{
    for ( Channel listener : listeners )
    {
        getLogger().log( Level.INFO, "Closing listener {0}", listener );
        try
        {
            listener.close().syncUninterruptibly();
        } catch ( ChannelException ex )
        {
            getLogger().severe( "Could not close listen thread" );
        }
    }
    listeners.clear();
}
项目:netty4.0.27Learn    文件:DiskAttribute.java   
@Override
public Attribute copy() {
    DiskAttribute attr = new DiskAttribute(getName());
    attr.setCharset(getCharset());
    ByteBuf content = content();
    if (content != null) {
        try {
            attr.setContent(content.copy());
        } catch (IOException e) {
            throw new ChannelException(e);
        }
    }
    return attr;
}
项目:netty4.0.27Learn    文件:DiskAttribute.java   
@Override
public Attribute duplicate() {
    DiskAttribute attr = new DiskAttribute(getName());
    attr.setCharset(getCharset());
    ByteBuf content = content();
    if (content != null) {
        try {
            attr.setContent(content.duplicate());
        } catch (IOException e) {
            throw new ChannelException(e);
        }
    }
    return attr;
}
项目:netty4.0.27Learn    文件:DiskFileUpload.java   
@Override
public FileUpload copy() {
    DiskFileUpload upload = new DiskFileUpload(getName(),
            getFilename(), getContentType(), getContentTransferEncoding(), getCharset(), size);
    ByteBuf buf = content();
    if (buf != null) {
        try {
            upload.setContent(buf.copy());
        } catch (IOException e) {
            throw new ChannelException(e);
        }
    }
    return upload;
}
项目:netty4.0.27Learn    文件:DiskFileUpload.java   
@Override
public FileUpload duplicate() {
    DiskFileUpload upload = new DiskFileUpload(getName(),
            getFilename(), getContentType(), getContentTransferEncoding(), getCharset(), size);
    ByteBuf buf = content();
    if (buf != null) {
        try {
            upload.setContent(buf.duplicate());
        } catch (IOException e) {
            throw new ChannelException(e);
        }
    }
    return upload;
}
项目:netty4.0.27Learn    文件:MemoryFileUpload.java   
@Override
public FileUpload copy() {
    MemoryFileUpload upload = new MemoryFileUpload(getName(), getFilename(), getContentType(),
            getContentTransferEncoding(), getCharset(), size);
    ByteBuf buf = content();
    if (buf != null) {
        try {
            upload.setContent(buf.copy());
            return upload;
        } catch (IOException e) {
            throw new ChannelException(e);
        }
    }
    return upload;
}