當前位置: 首頁>>代碼示例>>Java>>正文


Java Channels類代碼示例

本文整理匯總了Java中org.jboss.netty.channel.Channels的典型用法代碼示例。如果您正苦於以下問題:Java Channels類的具體用法?Java Channels怎麽用?Java Channels使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Channels類屬於org.jboss.netty.channel包,在下文中一共展示了Channels類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getPipeline

import org.jboss.netty.channel.Channels; //導入依賴的package包/類
@Override
public ChannelPipeline getPipeline() throws Exception {
    BootstrapChannelHandler handler = 
            new BootstrapChannelHandler(bootstrap);
    ChannelPipeline pipeline = Channels.pipeline();

    pipeline.addLast("frameDecoder",
                     new ThriftFrameDecoder(maxFrameSize));
    pipeline.addLast("frameEncoder",
                     new ThriftFrameEncoder());
    pipeline.addLast("timeout",
                     new BootstrapTimeoutHandler(timer, 10));

    pipeline.addLast("handler", handler);

    return pipeline;
}
 
開發者ID:JianqingJiang,項目名稱:QoS-floodlight,代碼行數:18,代碼來源:BootstrapPipelineFactory.java

示例2: send

import org.jboss.netty.channel.Channels; //導入依賴的package包/類
/**
 * Sends this response to all the passed channels as a {@link TextWebSocketFrame}
 * @param listener A channel future listener to attach to each channel future. Ignored if null.
 * @param channels The channels to send this response to
 * @return An array of the futures for the write of this response to each channel written to
 */
public ChannelFuture[] send(ChannelFutureListener listener, Channel...channels) {
	if(channels!=null && channels.length>0) {
		Set<ChannelFuture> futures = new HashSet<ChannelFuture>(channels.length);
		if(opCode==null) {
			opCode = "ok";
		}
		TextWebSocketFrame frame = new TextWebSocketFrame(this.toChannelBuffer());
		for(Channel channel: channels) {
			if(channel!=null && channel.isWritable()) {
				ChannelFuture cf = Channels.future(channel);
				if(listener!=null) cf.addListener(listener);
				channel.getPipeline().sendDownstream(new DownstreamMessageEvent(channel, cf, frame, channel.getRemoteAddress()));
				futures.add(cf);
			}
		}
		return futures.toArray(new ChannelFuture[futures.size()]);
	}		
	return EMPTY_CHANNEL_FUTURE_ARR;
}
 
開發者ID:nickman,項目名稱:HeliosStreams,代碼行數:26,代碼來源:Netty3JSONResponse.java

示例3: doOpen

import org.jboss.netty.channel.Channels; //導入依賴的package包/類
@Override
protected void doOpen() throws Throwable {
    NettyHelper.setNettyLoggerFactory();
    bootstrap = new ClientBootstrap(channelFactory);
    // config
    // @see org.jboss.netty.channel.socket.SocketChannelConfig
    bootstrap.setOption("keepAlive", true);
    bootstrap.setOption("tcpNoDelay", true);
    bootstrap.setOption("connectTimeoutMillis", getTimeout());
    final NettyHandler nettyHandler = new NettyHandler(getUrl(), this);
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
        public ChannelPipeline getPipeline() {
            NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyClient.this);
            ChannelPipeline pipeline = Channels.pipeline();
            pipeline.addLast("decoder", adapter.getDecoder());
            pipeline.addLast("encoder", adapter.getEncoder());
            pipeline.addLast("handler", nettyHandler);
            return pipeline;
        }
    });
}
 
開發者ID:dachengxi,項目名稱:EatDubbo,代碼行數:22,代碼來源:NettyClient.java

示例4: NettyServerCnxnFactory

import org.jboss.netty.channel.Channels; //導入依賴的package包/類
NettyServerCnxnFactory() {
    bootstrap = new ServerBootstrap(
            new NioServerSocketChannelFactory(
                    Executors.newCachedThreadPool(),
                    Executors.newCachedThreadPool()));
    // parent channel
    bootstrap.setOption("reuseAddress", true);
    // child channels
    bootstrap.setOption("child.tcpNoDelay", true);
    /* set socket linger to off, so that socket close does not block */
    bootstrap.setOption("child.soLinger", -1);
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline p = Channels.pipeline();
            if (secure) {
                initSSL(p);
            }
            p.addLast("servercnxnfactory", channelHandler);

            return p;
        }
    });
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:25,代碼來源:NettyServerCnxnFactory.java

示例5: getPipeline

import org.jboss.netty.channel.Channels; //導入依賴的package包/類
@Override
public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline channelPipeline = Channels.pipeline();
    SizeHeaderFrameDecoder sizeHeader = new SizeHeaderFrameDecoder();
    if (nettyTransport.maxCumulationBufferCapacity != null) {
        if (nettyTransport.maxCumulationBufferCapacity.bytes() > Integer.MAX_VALUE) {
            sizeHeader.setMaxCumulationBufferCapacity(Integer.MAX_VALUE);
        } else {
            sizeHeader.setMaxCumulationBufferCapacity((int) nettyTransport.maxCumulationBufferCapacity.bytes());
        }
    }
    if (nettyTransport.maxCompositeBufferComponents != -1) {
        sizeHeader.setMaxCumulationBufferComponents(nettyTransport.maxCompositeBufferComponents);
    }
    channelPipeline.addLast("size", sizeHeader);
    // using a dot as a prefix means, this cannot come from any settings parsed
    channelPipeline.addLast("dispatcher", new MessageChannelHandler(nettyTransport, nettyTransport.logger, ".client"));
    return channelPipeline;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:20,代碼來源:NettyTransport.java

示例6: getPipeline

import org.jboss.netty.channel.Channels; //導入依賴的package包/類
@Override
public ChannelPipeline getPipeline() throws Exception {
  ChannelPipeline pipeline = Channels.pipeline();
  if (sslFactory != null) {
    pipeline.addLast("ssl", new SslHandler(sslFactory.createSSLEngine()));
  }
  pipeline.addLast("decoder", new HttpRequestDecoder());
  pipeline.addLast("aggregator", new HttpChunkAggregator(1 << 16));
  pipeline.addLast("encoder", new HttpResponseEncoder());
  pipeline.addLast("chunking", new ChunkedWriteHandler());
  pipeline.addLast("shuffle", SHUFFLE);
  return pipeline;
  // TODO factor security manager into pipeline
  // TODO factor out encode/decode to permit binary shuffle
  // TODO factor out decode of index to permit alt. models
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:17,代碼來源:ShuffleHandler.java

示例7: startHttpServer

import org.jboss.netty.channel.Channels; //導入依賴的package包/類
private ServerBootstrap startHttpServer(int port,
    final Token<DelegationTokenIdentifier> token, final URI url) {
  ServerBootstrap bootstrap = new ServerBootstrap(
      new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),
          Executors.newCachedThreadPool()));

  bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
    @Override
    public ChannelPipeline getPipeline() throws Exception {
      return Channels.pipeline(new HttpRequestDecoder(),
          new HttpChunkAggregator(65536), new HttpResponseEncoder(),
          new CredentialsLogicHandler(token, url.toString()));
    }
  });
  bootstrap.bind(new InetSocketAddress("localhost", port));
  return bootstrap;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:18,代碼來源:TestDelegationTokenRemoteFetcher.java

示例8: run

import org.jboss.netty.channel.Channels; //導入依賴的package包/類
public void run() {
  // Configure the client.
  DatagramChannelFactory f = new NioDatagramChannelFactory(
      Executors.newCachedThreadPool(), workerCount);

  server = new ConnectionlessBootstrap(f);
  server.setPipeline(Channels.pipeline(RpcUtil.STAGE_RPC_MESSAGE_PARSER,
      rpcProgram, RpcUtil.STAGE_RPC_UDP_RESPONSE));

  server.setOption("broadcast", "false");
  server.setOption("sendBufferSize", SEND_BUFFER_SIZE);
  server.setOption("receiveBufferSize", RECEIVE_BUFFER_SIZE);

  // Listen to the UDP port
  ch = server.bind(new InetSocketAddress(port));
  InetSocketAddress socketAddr = (InetSocketAddress) ch.getLocalAddress();
  boundPort = socketAddr.getPort();

  LOG.info("Started listening to UDP requests at port " + boundPort + " for "
      + rpcProgram + " with workerCount " + workerCount);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:22,代碼來源:SimpleUdpServer.java

示例9: messageReceived

import org.jboss.netty.channel.Channels; //導入依賴的package包/類
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
    throws Exception {
  ChannelBuffer buf = (ChannelBuffer) e.getMessage();
  ByteBuffer b = buf.toByteBuffer().asReadOnlyBuffer();
  XDR in = new XDR(b, XDR.State.READING);

  RpcInfo info = null;
  try {
    RpcCall callHeader = RpcCall.read(in);
    ChannelBuffer dataBuffer = ChannelBuffers.wrappedBuffer(in.buffer()
        .slice());
    info = new RpcInfo(callHeader, dataBuffer, ctx, e.getChannel(),
        e.getRemoteAddress());
  } catch (Exception exc) {
    LOG.info("Malformed RPC request from " + e.getRemoteAddress());
  }

  if (info != null) {
    Channels.fireMessageReceived(ctx, info);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:23,代碼來源:RpcUtil.java

示例10: getPipeline

import org.jboss.netty.channel.Channels; //導入依賴的package包/類
@Override
public ChannelPipeline getPipeline() throws Exception {
    BgpChannelHandler handler = new BgpChannelHandler(bgpController);

    ChannelPipeline pipeline = Channels.pipeline();
    pipeline.addLast("bgpmessagedecoder", new BgpMessageDecoder());
    pipeline.addLast("bgpmessageencoder", new BgpMessageEncoder());
    pipeline.addLast("holdTime", readTimeoutHandler);
    if (isBgpServ) {
        pipeline.addLast("PassiveHandler", handler);
    } else {
        pipeline.addLast("ActiveHandler", handler);
    }

    return pipeline;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:17,代碼來源:BgpPipelineFactory.java

示例11: connect

import org.jboss.netty.channel.Channels; //導入依賴的package包/類
/**
  * Starts the BGP peer.
  *
  * @param connectToSocket the socket to connect to
  */
 private void connect(InetSocketAddress connectToSocket)
     throws InterruptedException {

     ChannelFactory channelFactory =
         new NioClientSocketChannelFactory(
                 Executors.newCachedThreadPool(),
                 Executors.newCachedThreadPool());
     ChannelPipelineFactory pipelineFactory = () -> {
         ChannelPipeline pipeline = Channels.pipeline();
         pipeline.addLast("BgpPeerFrameDecoderTest",
                 peerFrameDecoder);
         pipeline.addLast("BgpPeerChannelHandlerTest",
                 peerChannelHandler);
         return pipeline;
     };

     peerBootstrap = new ClientBootstrap(channelFactory);
     peerBootstrap.setOption("child.keepAlive", true);
     peerBootstrap.setOption("child.tcpNoDelay", true);
     peerBootstrap.setPipelineFactory(pipelineFactory);
     peerBootstrap.connect(connectToSocket);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:28,代碼來源:BgpControllerImplTest.java

示例12: connectFrom

import org.jboss.netty.channel.Channels; //導入依賴的package包/類
private Channel connectFrom(InetSocketAddress connectToSocket, SocketAddress localAddress)
     throws InterruptedException {

     ChannelFactory channelFactory =
         new NioClientSocketChannelFactory(
                 Executors.newCachedThreadPool(),
                 Executors.newCachedThreadPool());
     ChannelPipelineFactory pipelineFactory = () -> {
         ChannelPipeline pipeline = Channels.pipeline();
         pipeline.addLast("BgpPeerFrameDecoderTest",
                 peerFrameDecoder);
         pipeline.addLast("BgpPeerChannelHandlerTest",
                 peerChannelHandler);
         return pipeline;
     };

     peerBootstrap = new ClientBootstrap(channelFactory);
     peerBootstrap.setOption("child.keepAlive", true);
     peerBootstrap.setOption("child.tcpNoDelay", true);
     peerBootstrap.setPipelineFactory(pipelineFactory);
     Channel channel = peerBootstrap.connect(connectToSocket, localAddress).getChannel();
     return channel;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:24,代碼來源:BgpControllerImplTest.java

示例13: messageReceived

import org.jboss.netty.channel.Channels; //導入依賴的package包/類
@Override
public void messageReceived(ChannelHandlerContext ctx,
                            MessageEvent e) throws Exception {
    Object message = e.getMessage();
    if (message instanceof SyncMessage) {
        handleSyncMessage((SyncMessage)message, ctx.getChannel());
    } else if (message instanceof List) {
        for (Object i : (List<?>)message) {
            if (i instanceof SyncMessage) {
                try {
                    handleSyncMessage((SyncMessage)i,
                                         ctx.getChannel());
                } catch (Exception ex) {
                    Channels.fireExceptionCaught(ctx, ex);
                }
            }
        }
    } else {
        handleUnknownMessage(ctx, message);
    }
}
 
開發者ID:nsg-ethz,項目名稱:iTAP-controller,代碼行數:22,代碼來源:AbstractRPCChannelHandler.java

示例14: getPipeline

import org.jboss.netty.channel.Channels; //導入依賴的package包/類
@Override
public ChannelPipeline getPipeline() throws Exception {
    RPCChannelHandler channelHandler = 
            new RPCChannelHandler(syncManager, rpcService);

    IdleStateHandler idleHandler = 
            new IdleStateHandler(timer, 5, 10, 0);
    ReadTimeoutHandler readTimeoutHandler = 
            new ReadTimeoutHandler(timer, 30);
    
    ChannelPipeline pipeline = Channels.pipeline();
    pipeline.addLast("idle", idleHandler);
    pipeline.addLast("timeout", readTimeoutHandler);
    pipeline.addLast("handshaketimeout",
                     new HandshakeTimeoutHandler(channelHandler, timer, 10));

    pipeline.addLast("frameDecoder",
                     new ThriftFrameDecoder(maxFrameSize));
    pipeline.addLast("frameEncoder",
                     new ThriftFrameEncoder());

    pipeline.addLast("handler", channelHandler);
    return pipeline;
}
 
開發者ID:nsg-ethz,項目名稱:iTAP-controller,代碼行數:25,代碼來源:RPCPipelineFactory.java

示例15: getPipeline

import org.jboss.netty.channel.Channels; //導入依賴的package包/類
@Override
public ChannelPipeline getPipeline() throws Exception {
    RemoteSyncChannelHandler channelHandler = 
            new RemoteSyncChannelHandler(syncManager);
    ChannelPipeline pipeline = Channels.pipeline();

    pipeline.addLast("frameDecoder",
                     new ThriftFrameDecoder(maxFrameSize));
    pipeline.addLast("frameEncoder",
                     new ThriftFrameEncoder());
    pipeline.addLast("timeout",
                     new RSHandshakeTimeoutHandler(channelHandler,
                                                   timer, 3));

    pipeline.addLast("handler", channelHandler);
    return pipeline;
}
 
開發者ID:nsg-ethz,項目名稱:iTAP-controller,代碼行數:18,代碼來源:RemoteSyncPipelineFactory.java


注:本文中的org.jboss.netty.channel.Channels類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。