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


Java ChannelPipeline類代碼示例

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


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

示例1: initChannel

import io.netty.channel.ChannelPipeline; //導入依賴的package包/類
@Override
protected void initChannel(Channel ch) throws Exception {
    RPCChannelHandler channelHandler = 
            new RPCChannelHandler(syncManager, rpcService);

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

    pipeline.addLast("syncMessageDecoder",
                     new SyncMessageDecoder(maxFrameSize));
    pipeline.addLast("syncMessageEncoder",
                     new SyncMessageEncoder());

    pipeline.addLast("handler", channelHandler);
}
 
開發者ID:xuraylei,項目名稱:fresco_floodlight,代碼行數:24,代碼來源:RPCChannelInitializer.java

示例2: OFChannelHandler

import io.netty.channel.ChannelPipeline; //導入依賴的package包/類
/**
 * Creates a handler for interacting with the switch channel
 *
 * @param controller
 *            the controller
 * @param newConnectionListener
 *            the class that listens for new OF connections (switchManager)
 * @param pipeline
 *            the channel pipeline
 * @param threadPool
 *            the thread pool
 * @param idleTimer
 *            the hash wheeled timer used to send idle messages (echo).
 *            passed to constructor to modify in case of aux connection.
 * @param debugCounters
 */
OFChannelHandler(@Nonnull IOFSwitchManager switchManager,
		@Nonnull INewOFConnectionListener newConnectionListener,
		@Nonnull ChannelPipeline pipeline,
		@Nonnull IDebugCounterService debugCounters,
		@Nonnull Timer timer,
		@Nonnull List<U32> ofBitmaps,
		@Nonnull OFFactory defaultFactory) {

	Preconditions.checkNotNull(switchManager, "switchManager");
	Preconditions.checkNotNull(newConnectionListener, "connectionOpenedListener");
	Preconditions.checkNotNull(pipeline, "pipeline");
	Preconditions.checkNotNull(timer, "timer");
	Preconditions.checkNotNull(debugCounters, "debugCounters");

	this.pipeline = pipeline;
	this.debugCounters = debugCounters;
	this.newConnectionListener = newConnectionListener;
	this.counters = switchManager.getCounters();
	this.state = new InitState();
	this.timer = timer;
	this.ofBitmaps = ofBitmaps;
	this.factory = defaultFactory;

	log.debug("constructor on OFChannelHandler {}", String.format("%08x", System.identityHashCode(this)));
}
 
開發者ID:xuraylei,項目名稱:fresco_floodlight,代碼行數:42,代碼來源:OFChannelHandler.java

示例3: handleMessage

import io.netty.channel.ChannelPipeline; //導入依賴的package包/類
@Override
public void handleMessage(ChannelHandlerContext ctx, WorldLoginRequest msg) {
	ClientMessage message = evaluateLogin(msg);
	if (message != ClientMessage.SUCCESSFUL) {
		ctx.write(new WorldLoginResponse(message));
		return;
	}

	Player player = new Player(ctx.channel());
	ctx.write(new WorldLoginResponse(player, message, msg.getIsaacPair()));

	ChannelPipeline pipeline = ctx.pipeline();
	pipeline.remove("login.encoder");

	// this isnt set automatically.
	pipeline.addAfter("world.decoder", "game.encoder", new GamePacketEncoder(msg.getIsaacPair().getEncoderRandom()));
	pipeline.replace("world.decoder", "game.decoder", new GamePacketDecoder(player, msg.getIsaacPair().getDecoderRandom()));

	player.init(msg.getDisplayInformation());
}
 
開發者ID:jordanabrahambaws,項目名稱:Quavo,代碼行數:21,代碼來源:WorldLoginListener.java

示例4: run

import io.netty.channel.ChannelPipeline; //導入依賴的package包/類
public void run() {
	workerGroup = new NioEventLoopGroup();
	try {
		Bootstrap b = new Bootstrap();
		b.group(workerGroup);
		b.channel(NioSocketChannel.class);
		// b.option(ChannelOption.SO_KEEPALIVE, true);
		b.handler(new ChannelInitializer<SocketChannel>() {
			@Override
			public void initChannel(SocketChannel ch) throws Exception {
				ChannelPipeline pipeline = ch.pipeline();
				pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(65536, 0, 4, 0, 4));
				pipeline.addLast("frameEncoder", new LengthFieldPrepender(4));
				pipeline.addLast("decoder", new MsgPackDecode());
				pipeline.addLast("encoder", new MsgPackEncode());
				pipeline.addLast(new ClientHandler());
			}
		});
		channel = b.connect(clientProperties.getServerHost(), clientProperties.getServerPort()).sync().channel();
		status = Status.START;
		channel.closeFuture().sync();
	} catch (Exception e) {
		e.printStackTrace();
	}
	status = Status.STOP;
}
 
開發者ID:ctodb,項目名稱:push,代碼行數:27,代碼來源:Client.java

示例5: initChannel

import io.netty.channel.ChannelPipeline; //導入依賴的package包/類
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline p = ch.pipeline();

    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(ch.alloc()));
    }

    p.addLast(new HttpRequestDecoder());
    // Uncomment the following line if you don't want to handle HttpChunks.
    //p.addLast(new HttpObjectAggregator(1048576));
    p.addLast(new HttpResponseEncoder());
    // Remove the following line if you don't want automatic content compression.
    //p.addLast(new HttpContentCompressor());
    p.addLast(new MockingFCMServerHandler());
}
 
開發者ID:aerogear,項目名稱:push-network-proxies,代碼行數:17,代碼來源:MockingFCMServerInitializer.java

示例6: initChannel

import io.netty.channel.ChannelPipeline; //導入依賴的package包/類
@Override
public void initChannel(final SocketChannel ch) throws Exception {
    final ChannelPipeline p = ch.pipeline();

    // removes idle connections after READER_IDLE_SECONDS seconds
    p.addLast("idleStateHandler",
            new IdleStateHandler(READER_IDLE_SECONDS, 0, 0));

    // handle new connections and idle timeouts
    p.addLast("auth", authHandler);

    // break each data chunk by newlines and split out metrics
    p.addLast("line", new GraphiteMetricDecoder(maxLength));

    // batch up metrics and store
    p.addLast("metrics", new MetricHandler(store));
}
 
開發者ID:smoketurner,項目名稱:graphiak,代碼行數:18,代碼來源:GraphiakInitializer.java

示例7: unregisterChannelHandler

import io.netty.channel.ChannelPipeline; //導入依賴的package包/類
private void unregisterChannelHandler() {
    if (serverChannelHandler == null)
        return;

    for (Channel serverChannel : serverChannels) {
        final ChannelPipeline pipeline = serverChannel.pipeline();

        // Remove channel handler
        serverChannel.eventLoop().execute(new Runnable() {

            @Override
            public void run() {
                try {
                    pipeline.remove(serverChannelHandler);
                } catch (NoSuchElementException e) {
                    // That's fine
                }
            }

        });
    }
}
 
開發者ID:edasaki,項目名稱:ZentrelaRPG,代碼行數:23,代碼來源:TinyProtocol.java

示例8: encode

import io.netty.channel.ChannelPipeline; //導入依賴的package包/類
@Override
protected void encode(ChannelHandlerContext ctx, ConnectionResponse msg, ByteBuf out) throws Exception {
	ChannelPipeline pipeline = ctx.pipeline();

	switch (msg.getType()) {
	case HANDSHAKE_CONNECTION:
		pipeline.addAfter("decoder", "handshake.encoder", new HandshakeEncoder());
		pipeline.replace("decoder", "handshake.decoder", new HandshakeDecoder());
		break;
	case LOGIN_CONNECTION:
		out.writeByte(ClientMessage.SUCCESSFUL_CONNECTION.getId());
		pipeline.addAfter("decoder", "login.encoder", new LoginEncoder());
		pipeline.replace("decoder", "login.decoder", new LoginDecoder());
		break;
	}

	pipeline.remove(this);
}
 
開發者ID:jordanabrahambaws,項目名稱:Quavo,代碼行數:19,代碼來源:ConnectionEncoder.java

示例9: initChannel

import io.netty.channel.ChannelPipeline; //導入依賴的package包/類
@Override
  public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();
    SslHandler sslHandler = null;
    if (sslHandlerProvider != null) {
      sslHandler = sslHandlerProvider.getSslHandler();
      pipeline.addLast(sslHandler);
    }
    pipeline.addLast("decoder", new MqttDecoder(MAX_PAYLOAD_SIZE));
    pipeline.addLast("encoder", MqttEncoder.INSTANCE);

    MqttTransportHandler handler = new MqttTransportHandler(msgProducer, deviceService, authService, assetService,
        assetAuthService, relationService, sslHandler);
    pipeline.addLast(handler);

//    ch.closeFuture().addListener(handler);

  }
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:19,代碼來源:MqttTransportServerInitializer.java

示例10: appendHttpPipeline

import io.netty.channel.ChannelPipeline; //導入依賴的package包/類
public final ChannelPipeline appendHttpPipeline(ChannelPipeline channelPipeline) {
    // 服務端,對響應編碼。屬於ChannelOutboundHandler,逆序執行
    channelPipeline.addLast("encoder", new HttpResponseEncoder());

    // 服務端,對請求解碼。屬於ChannelIntboundHandler,按照順序執行
    channelPipeline.addLast("decoder", new HttpRequestDecoder());
    //即通過它可以把 HttpMessage 和 HttpContent 聚合成一個 FullHttpRequest,並定義可以接受的數據大小,在文件上傳時,可以支持params+multipart
    channelPipeline.addLast("aggregator", new HttpObjectAggregator(maxConentLength));
    //塊寫入寫出Handler
    channelPipeline.addLast("chunkedWriter", new ChunkedWriteHandler());

    // 對傳輸數據進行壓縮,這裏在客戶端需要解壓縮處理
    // channelPipeline.addLast("deflater", new HttpContentCompressor());

    HttpServletHandler servletHandler = new HttpServletHandler();
    servletHandler.addInterceptor(new ChannelInterceptor());
    //servletHandler.addInterceptor(new HttpSessionInterceptor(getHttpSessionStore()));
    // 自定義Handler
    channelPipeline.addLast("handler", servletHandler);
    // 異步
    // channelPipeline.addLast(businessExecutor, new AsyncHttpServletHandler());
    return channelPipeline;
}
 
開發者ID:geeker-lait,項目名稱:tasfe-framework,代碼行數:24,代碼來源:HttpChannelInitializer.java

示例11: channelActive

import io.netty.channel.ChannelPipeline; //導入依賴的package包/類
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
    super.channelActive(ctx);
    logger.info("通道重置");
    List<ChannelPipeline> channelPipelines = tcpMediator.getSendingMsgRepo().getChannelPipelines();
    channelPipelines.add(ctx.pipeline());
    channelPipelines.removeIf(channel -> {
        i++;
        if (channel == null || !channel.channel().isActive()) {
            logger.info("「" + i + "」" + "通道失效");
            return true;
        } else {
            logger.info("「" + i + "」" + "通道有效");
            return false;
        }
    });
    i = 0;
    logger.info("通道數量:" + channelPipelines.size());
}
 
開發者ID:bitkylin,項目名稱:ClusterDeviceControlPlatform,代碼行數:20,代碼來源:ConfigHandler.java

示例12: initChannel

import io.netty.channel.ChannelPipeline; //導入依賴的package包/類
@Override
	protected void initChannel(SocketChannel ch) throws Exception {
		ChannelPipeline p = ch.pipeline();
		if(sslCtx!=null)
		{
			p.addLast(new SslHandler(sslCtx.newEngine(ch.alloc())));
		}
		p.addLast(new HttpResponseEncoder());//必須放在最前麵,如果decoder途中需要回複消息,則decoder前麵需要encoder
		p.addLast(new HttpRequestDecoder());
		p.addLast(new HttpObjectAggregator(65536));//限製contentLength
		//大文件傳輸處理
//		p.addLast(new ChunkedWriteHandler());
//		p.addLast(new HttpContentCompressor());
		//跨域配置
		CorsConfig corsConfig = CorsConfigBuilder.forAnyOrigin().allowNullOrigin().allowCredentials().build();
		p.addLast(new CorsHandler(corsConfig));
		p.addLast(new DefaultListenerHandler<HttpRequest>(listener));
	}
 
開發者ID:juebanlin,項目名稱:util4j,代碼行數:19,代碼來源:HttpServerInitHandler.java

示例13: initChannel

import io.netty.channel.ChannelPipeline; //導入依賴的package包/類
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    // 根據服務端協議,選擇解碼器
    Constants.ProtocolType type = transportConfig.getProvider().getProtocolType();
    switch (type) {
        case jsf:
            pipeline.addLast(new JSFEncoder());
            pipeline.addLast(new JSFDecoder(transportConfig.getPayload()));
            break;
        case dubbo:
            pipeline.addLast(new DubboEncoder());
            pipeline.addLast(new DubboDecoder(transportConfig.getPayload()));
            break;
        default:
            throw new InitErrorException("Unsupported client protocol type : " + type.name());
    }
    pipeline.addLast(Constants.CLIENT_CHANNELHANDLE_NAME, clientChannelHandler);
}
 
開發者ID:tiglabs,項目名稱:jsf-sdk,代碼行數:20,代碼來源:ClientChannelInitializer.java

示例14: initiateProtocolOrSsl

import io.netty.channel.ChannelPipeline; //導入依賴的package包/類
void initiateProtocolOrSsl(String username, String password, String database, Handler<? super CommandResponse<Connection>> completionHandler) {
  ChannelPipeline pipeline = socket.channelHandlerContext().pipeline();
  if (ssl) {
    Future<Void> upgradeFuture = Future.future();
    upgradeFuture.setHandler(ar -> {
      if (ar.succeeded()) {
        initiateProtocol(username, password, database, completionHandler);
      } else {
        Throwable cause = ar.cause();
        if (cause instanceof DecoderException) {
          DecoderException err = (DecoderException) cause;
          cause = err.getCause();
        }
        completionHandler.handle(CommandResponse.failure(cause));
      }
    });
    pipeline.addBefore("handler", "initiate-ssl-handler", new InitiateSslHandler(this, upgradeFuture));
  } else {
    initiateProtocol(username, password, database, completionHandler);
  }
}
 
開發者ID:vietj,項目名稱:reactive-pg-client,代碼行數:22,代碼來源:SocketConnection.java

示例15: initChannel

import io.netty.channel.ChannelPipeline; //導入依賴的package包/類
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    final ChannelPipeline pipeline = ch.pipeline();
    NettyPipelineInit.serializePipeline(serializeProtocolEnum, pipeline);
    pipeline.addLast("timeout",
            new IdleStateHandler(nettyConfig.getHeartTime(), nettyConfig.getHeartTime(), nettyConfig.getHeartTime(), TimeUnit.SECONDS));
    pipeline.addLast(nettyServerMessageHandler);
}
 
開發者ID:yu199195,項目名稱:happylifeplat-transaction,代碼行數:9,代碼來源:NettyServerHandlerInitializer.java


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