Java Code Examples for io.netty.channel.ChannelHandlerContext#fireChannelActive()

The following examples show how to use io.netty.channel.ChannelHandlerContext#fireChannelActive() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DcpControlHandler.java    From java-dcp-client with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method to walk the iterator and create a new request that defines which control param
 * should be negotiated right now.
 */
private void negotiate(final ChannelHandlerContext ctx) {
  if (controlSettings.hasNext()) {
    Map.Entry<String, String> setting = controlSettings.next();

    LOGGER.debug("Negotiating DCP Control {}: {}", setting.getKey(), setting.getValue());
    ByteBuf request = ctx.alloc().buffer();
    DcpControlRequest.init(request);
    DcpControlRequest.key(setting.getKey(), request);
    DcpControlRequest.value(Unpooled.copiedBuffer(setting.getValue(), UTF_8), request);

    ctx.writeAndFlush(request);
  } else {
    originalPromise().setSuccess();
    ctx.pipeline().remove(this);
    ctx.fireChannelActive();
    LOGGER.debug("Negotiated all DCP Control settings against Node {}", ctx.channel().remoteAddress());
  }
}
 
Example 2
Source File: TestWssServer.java    From util4j with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
	InputStream ins=TestWssClient.class.getResourceAsStream("cloud.jueb.net.pfx");
	String strPassword="xxxxxx";
	SslContext sslc=NettyServerSslUtil.buildSslContext_P12_Pfx(ins, strPassword);
	NettyServerConfig nc=new NettyServerConfig();
	NettyServer ns=new NettyServer(nc, "0.0.0.0", 1191,new WebSocketServerInitializer("/test",sslc) {
		@Override
		protected void webSocketHandComplete(ChannelHandlerContext ctx) {
			ChannelPipeline p=ctx.pipeline();
			p.addLast(new WebSocketTextFrameStringAdapter());//消息解码器
			p.addLast(new DefaultIdleListenerHandler<String>(new Listener()));//心跳适配器
			//为新加的handler手动触发必要事件
			ctx.fireChannelRegistered();
			ctx.fireChannelActive();
		}
	});
	ns.start();
	new Scanner(System.in).nextLine();
}
 
Example 3
Source File: HttpTrafficHandler.java    From reactor-netty with Apache License 2.0 6 votes vote down vote up
@Override
public void channelActive(ChannelHandlerContext ctx) {
	Channel channel = ctx.channel();
	if (channel.isActive()) {
		if (ctx.pipeline().get(NettyPipeline.H2MultiplexHandler) == null) {
			// Proceed with HTTP/1.x as per configuration
			ctx.fireChannelActive();
		}
		else if (ctx.pipeline().get(NettyPipeline.SslHandler) == null) {
			// Proceed with H2C as per configuration
			sendNewState(Connection.from(channel), ConnectionObserver.State.CONNECTED);
			ctx.flush();
			ctx.read();
		}
		else {
			// Proceed with H2 as per configuration
			sendNewState(Connection.from(channel), ConnectionObserver.State.CONNECTED);
		}
	}
}
 
Example 4
Source File: WebSocketClientTextAdapterHandler.java    From util4j with Apache License 2.0 5 votes vote down vote up
@Override
protected void webSocketHandComplete(ChannelHandlerContext ctx) {
	ctx.channel().pipeline().addLast(new WebSocketTextFrameStringAdapter());//适配器
	ctx.channel().pipeline().addLast(handler);
	//为新加的handler手动触发必要事件
	ctx.fireChannelRegistered();
	ctx.fireChannelActive();
}
 
Example 5
Source File: SslServerHandshakeHandler.java    From joyrpc with Apache License 2.0 5 votes vote down vote up
@Override
public void channelActive(ChannelHandlerContext ctx) {
    ctx.pipeline().get(SslHandler.class).handshakeFuture().addListener(
            (GenericFutureListener<Future<Channel>>) future -> {
                if (future.isSuccess()) {
                    logger.info("Ssl handshake is successed, session is protected by " + ctx.pipeline().get(SslHandler.class).engine().getSession().getCipherSuite());
                } else {
                    ctx.channel().close();
                }
            });
    ctx.fireChannelActive();
}
 
Example 6
Source File: XioResponseClassifier.java    From xio with Apache License 2.0 5 votes vote down vote up
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
  if (noOp) {
    ctx.pipeline().remove(this);
    ctx.fireChannelActive();
  }
}
 
Example 7
Source File: HandlerPublisher.java    From netty-reactive-streams with Apache License 2.0 5 votes vote down vote up
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
    // If we subscribed before the channel was active, then our read would have been ignored.
    if (state == DEMANDING) {
        requestDemand();
    }
    ctx.fireChannelActive();
}
 
Example 8
Source File: SslHandlerTest.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
public void test(final boolean dropChannelActive) throws Exception {
     SSLEngine engine = SSLContext.getDefault().createSSLEngine();
     engine.setUseClientMode(true);

     EmbeddedChannel ch = new EmbeddedChannel(false, false,
             this,
             new SslHandler(engine),
             new ChannelInboundHandlerAdapter() {
                 @Override
                 public void channelActive(ChannelHandlerContext ctx) throws Exception {
                     if (!dropChannelActive) {
                         ctx.fireChannelActive();
                     }
                 }
             }
     );
     ch.config().setAutoRead(false);
     assertFalse(ch.config().isAutoRead());

     ch.register();

     assertTrue(readIssued);
     readIssued = false;

     assertTrue(ch.writeOutbound(Unpooled.EMPTY_BUFFER));
     assertTrue(readIssued);
     assertTrue(ch.finishAndReleaseAll());
}
 
Example 9
Source File: BlackListFilter.java    From xrpc with Apache License 2.0 5 votes vote down vote up
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
  String remoteAddress =
      ((InetSocketAddress) ctx.channel().remoteAddress()).getAddress().getHostAddress();

  if (blackList.contains(remoteAddress)) {
    ctx.channel().attr(XrpcConstants.IP_BLACK_LIST).set(Boolean.TRUE);
  }

  ctx.fireChannelActive();
}
 
Example 10
Source File: NegotiateChannelHandler.java    From sailfish with Apache License 2.0 5 votes vote down vote up
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
	if (ChannelUtil.clientSide(ctx)) {
		negotiate(ctx);
	}
	ctx.fireChannelActive();
}
 
Example 11
Source File: ClientMessageClientHandler.java    From sctalk with Apache License 2.0 5 votes vote down vote up
/**
 * 服务端监听到客户端活动
 * 
 * @param ctx 连接context
 * @throws Exception
 */
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
    // 服务端接收到客户端上线通知
    Channel incoming = ctx.channel();
    logger.debug("MessageServerHandler:" + incoming.remoteAddress() + "在线");
    login(ctx);
    ctx.fireChannelActive();
}
 
Example 12
Source File: OcspClientExample.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
    FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
    request.headers().set(HttpHeaderNames.HOST, host);
    request.headers().set(HttpHeaderNames.USER_AGENT, "netty-ocsp-example/1.0");

    ctx.writeAndFlush(request).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);

    ctx.fireChannelActive();
}
 
Example 13
Source File: HandlerSubscriber.java    From netty-reactive-streams with Apache License 2.0 5 votes vote down vote up
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
    if (state == INACTIVE) {
        state = RUNNING;
        maybeRequestMore();
    }
    ctx.fireChannelActive();
}
 
Example 14
Source File: Http2ClientInitializer.java    From product-microgateway with Apache License 2.0 5 votes vote down vote up
@Override
public void channelActive(ChannelHandlerContext ctx) {
    DefaultFullHttpRequest upgradeRequest =
            new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
    ctx.writeAndFlush(upgradeRequest);

    ctx.fireChannelActive();

    // Done with this handler, remove it from the pipeline.
    ctx.pipeline().remove(this);

    configureEndOfPipeline(ctx.pipeline());
}
 
Example 15
Source File: RntbdRequestManager.java    From azure-cosmosdb-java with MIT License 4 votes vote down vote up
/**
 * The {@link Channel} of the {@link ChannelHandlerContext} is now active
 *
 * @param context {@link ChannelHandlerContext} to which this {@link RntbdRequestManager} belongs
 */
@Override
public void channelActive(final ChannelHandlerContext context) {
    this.traceOperation(context, "channelActive");
    context.fireChannelActive();
}
 
Example 16
Source File: Http2MultiplexCodecBuilderTest.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
    ctx.fireChannelActive();
}
 
Example 17
Source File: EndpointedChannelHandler.java    From riiablo with Apache License 2.0 4 votes vote down vote up
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
  if (DEBUG_CALLS) Gdx.app.debug(TAG, "channelActive");
  ctx.fireChannelActive();
}
 
Example 18
Source File: XioNoOpHandler.java    From xio with Apache License 2.0 4 votes vote down vote up
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
  ctx.pipeline().remove(this);
  ctx.fireChannelActive();
}
 
Example 19
Source File: ConnectionChannelHandler.java    From joyrpc with Apache License 2.0 4 votes vote down vote up
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
    eventPublisher.offer(new ActiveEvent(channel));
    ctx.fireChannelActive();
}
 
Example 20
Source File: NettyClientHandlerDemo5.java    From java-study with Apache License 2.0 4 votes vote down vote up
/**
 * 建立连接时
 */
@Override  
public void channelActive(ChannelHandlerContext ctx) throws Exception {  
    System.out.println("激活时间是:"+MyTools.getNowTime(""));  
    ctx.fireChannelActive();  
}