当前位置: 首页>>代码示例>>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;未经允许,请勿转载。