当前位置: 首页>>代码示例>>Java>>正文


Java ChannelHandlerContext.channel方法代码示例

本文整理汇总了Java中io.netty.channel.ChannelHandlerContext.channel方法的典型用法代码示例。如果您正苦于以下问题:Java ChannelHandlerContext.channel方法的具体用法?Java ChannelHandlerContext.channel怎么用?Java ChannelHandlerContext.channel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.channel.ChannelHandlerContext的用法示例。


在下文中一共展示了ChannelHandlerContext.channel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fixHandlerBeforeConnect

import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
/**
	 * 适配
	 */
	@Override
	protected ChannelHandler fixHandlerBeforeConnect(final ChannelHandler handler) {
		ChannelHandler result=new ShareableChannelInboundHandler() {
			@Override
			public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
				Channel ch=ctx.channel();
				ch.pipeline().addLast(new HttpClientCodec());
            	ch.pipeline().addLast(new HttpObjectAggregator(64*1024));
            	ch.pipeline().addLast(new WebSocketClientProtocolHandler(WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, null, false, new DefaultHttpHeaders())));
            	ch.pipeline().addLast(new WebSocketConnectedClientHandler(handler));
				ctx.pipeline().remove(this);//移除当前handler
				ctx.pipeline().fireChannelRegistered();//重新从第一个handler抛出事件
			}
		};
//		ChannelInitializer<SocketChannel> result=new ChannelInitializer<SocketChannel>() {
//            @Override
//            protected void initChannel(SocketChannel ch) {
//            	ch.pipeline().addLast(new HttpClientCodec());
//            	ch.pipeline().addLast(new HttpObjectAggregator(64*1024));
//            	ch.pipeline().addLast(new WebSocketClientProtocolHandler(WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, null, false, new DefaultHttpHeaders())));
//            	ch.pipeline().addLast(new WebSocketConnectedClientHandler(handler));
//            }
//        };
        return result;
	}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:29,代码来源:NettyTextWebSocketClient.java

示例2: channelActive

import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void channelActive(final ChannelHandlerContext ctx) throws Exception {
    Channel channel = ctx.channel();
    //logger.info("connected from {}", NetUtils.channelToString(channel.remoteAddress(), channel.localAddress()));
    BaseServerHandler.addChannel(channel);
    if (connectListeners != null) {
        serverHandler.getBizThreadPool().execute(new Runnable() {
            @Override
            public void run() {
                for (ConnectListener connectListener : connectListeners) {
                    try {
                        connectListener.connected(ctx);
                    } catch (Exception e) {
                        logger.warn("Failed to call connect listener when channel active", e);
                    }
                }
            }
        });
    }
}
 
开发者ID:tiglabs,项目名称:jsf-sdk,代码行数:21,代码来源:ServerChannelHandler.java

示例3: channelActive

import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
    super.channelActive(ctx);
    this.channel = ctx.channel();

    UnknownPandaServer.getLogger().info("Channel active: " + this.channel.remoteAddress());
}
 
开发者ID:dzikoysk,项目名称:UnknownPandaServer,代码行数:8,代码来源:NetworkManager.java

示例4: send

import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
/**
 * Send back the result
 * @param ctx channel context
 * @param result rpc result
 */
private void send(ChannelHandlerContext ctx, Object result) {
  int seqId = 0;
  Channel ch = ctx.channel();

  try {
    seqId = ((ByteBuf) result).readInt();
    ((ByteBuf) result).resetReaderIndex();
    AtomicBoolean channelInUse = channelStates.get(ctx);
    if (channelInUse == null) {
      return;
    }
    long startTs = System.currentTimeMillis();
    while (true) {
      if (channelInUse.compareAndSet(false, true)) {
        ctx.writeAndFlush(result);
        channelInUse.set(false);
        LOG.debug(
          "send response buf=" + result + ",channel ctx=" + ctx.channel() + ", seqId=" + seqId
            + " use time=" + (System.currentTimeMillis() - startTs));
        return;
      }
      Thread.sleep(10);
    }
  } catch (Throwable ex) {
    LOG.error("send response of request failed, request seqId=" + seqId + ", channel=" + ch, ex);
  }
}
 
开发者ID:Tencent,项目名称:angel,代码行数:33,代码来源:WorkerPool.java

示例5: channelInactive

import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public final void channelInactive(ChannelHandlerContext ctx)throws Exception 
{
	Channel channel=ctx.channel();
	JConnection connection = findConnection(channel);
	if (connection != null) 
	{
		listener.connectionClosed(connection);
	} else 
	{
		log.error(ctx.channel() + ":not found NettyConnection Created.");
	}
	super.channelInactive(ctx);
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:15,代码来源:AbstractListenerHandler.java

示例6: disconnected

import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
public void disconnected(ChannelHandlerContext ctx)
{
    JSON.ClientDisconnectMessage dmsg = new JSON.ClientDisconnectMessage( ctx.channel( ));
    try {
        outQ.put( dmsg);
    }
    catch (InterruptedException e) {
        logr.info( "StockTickerMessageHandler.disconnected: outQ.put( ) failed for "
                                                            + ctx + "\n" + e.toString( ));
    }
}
 
开发者ID:SpreadServe,项目名称:TFWebSock,代码行数:12,代码来源:SubscriptionHandler.java

示例7: call

import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void call(ChannelHandlerContext ctx, MultiMessageToDeviceReq message) {
    //找寻到对应设备的channel 将消息全部推送给这个设备
    if (message != null) {
        pushSender.send(message.getDevice(), PushReq.builder().msgs(message.getMessages()).build());
        Channel channel = ctx.channel();
        channel.writeAndFlush(MultiMessageToDeviceResp.builder().result(NodeMessageEnum.OK.getCode()).build().encode());
    }
}
 
开发者ID:lee123lee123,项目名称:GoPush,代码行数:10,代码来源:MultiMessageToDeviceHandler.java

示例8: channelActive

import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception
{
	super.channelActive(ctx);

	this.channel = ctx.channel();
	this.address = this.channel.remoteAddress();

	//Try to handshake?
}
 
开发者ID:andykuo1,项目名称:candlelight,代码行数:11,代码来源:NetworkDispatcher.java

示例9: channelActive

import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
    if(initMessage != null){
        ctx.writeAndFlush(initMessage);
    } else {
        logger.info("build connection success.");
        channel[0] = ctx.channel();
        ProcessData.Builder builder = ProcessData.newBuilder();
        builder.setType(MessageType.HEART_BEAT_REQ.getValue());
        ctx.fireChannelRead(builder.build());
    }
}
 
开发者ID:xiongbeer,项目名称:Cobweb,代码行数:13,代码来源:LoginAuthReqHandler.java

示例10: channelInactive

import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
    Channel channel = ctx.channel();
    LOGGER.info("Disconnected telnet from {}", NetUtils.channelToString(channel.remoteAddress(), channel.localAddress()));
    BaseServerHandler.removeChannel(channel);
    charsetMap.remove(channel);
    ALLOW_INVOKE_CHANNELS.remove(channel);
}
 
开发者ID:tiglabs,项目名称:jsf-sdk,代码行数:9,代码来源:TelnetChannelHandler.java

示例11: processSubscribe

import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
private void processSubscribe(ChannelHandlerContext ctx, MqttSubscribeMessage mqttMsg) {
  if (!checkConnected(ctx)) {
    return;
  }
  log.trace("[{}] Processing subscription [{}]!", sessionId, mqttMsg.variableHeader().messageId());
  List<Integer> grantedQoSList = new ArrayList<>();
  for (MqttTopicSubscription subscription : mqttMsg.payload().topicSubscriptions()) {
    String topicName = subscription.topicName();
    // TODO: handle this qos level.
    MqttQoS reqQoS = subscription.qualityOfService();
    try {
      if (topicName.equals(DEVICE_ATTRIBUTES_TOPIC)) {
        // AdaptorToSessionActorMsg msg =
        // adaptor.convertToActorMsg(deviceSessionCtx,
        // SUBSCRIBE_ATTRIBUTES_REQUEST,
        // mqttMsg);
        // BasicToDeviceActorSessionMsg basicToDeviceActorSessionMsg = new
        // BasicToDeviceActorSessionMsg(
        // deviceSessionCtx.getDevice(), msg);
        // processor.process(basicToDeviceActorSessionMsg);
        grantedQoSList.add(getMinSupportedQos(reqQoS));
      } else if (topicName.equals(DEVICE_RPC_REQUESTS_SUB_TOPIC)) {
        // AdaptorToSessionActorMsg msg =
        // adaptor.convertToActorMsg(deviceSessionCtx,
        // SUBSCRIBE_RPC_COMMANDS_REQUEST,
        // mqttMsg);
        // processor.process(new
        // BasicToDeviceActorSessionMsg(deviceSessionCtx.getDevice(), msg));
        grantedQoSList.add(getMinSupportedQos(reqQoS));
      } else if (topicName.equals(DEVICE_RPC_RESPONSE_SUB_TOPIC)) {
        grantedQoSList.add(getMinSupportedQos(reqQoS));
      } else if (topicName.equals(DEVICE_ATTRIBUTES_RESPONSES_TOPIC)) {
        deviceSessionCtx.setAllowAttributeResponses();
        grantedQoSList.add(getMinSupportedQos(reqQoS));
      } else if (topicName.equals(DEVICE_TELEMETRY_TOPIC)) {
        grantedQoSList.add(getMinSupportedQos(reqQoS));
      } else {
        log.warn("[{}] Failed to subscribe to [{}][{}]", sessionId, topicName, reqQoS);
        grantedQoSList.add(FAILURE.value());
      }
      ChannelEntity channelEntity = new TcpChannelEntity(ctx.channel());
      MemoryMetaPool.registerTopic(channelEntity, topicName);
    } catch (Exception e) {
      e.printStackTrace();
      log.warn("[{}] Failed to subscribe to [{}][{}]", sessionId, topicName, reqQoS);
      grantedQoSList.add(FAILURE.value());
    }
  }

  ctx.writeAndFlush(createSubAckMessage(mqttMsg.variableHeader().messageId(), grantedQoSList));
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:52,代码来源:MqttTransportHandler.java

示例12: openSession

import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
public CLSession openSession(String identifier, ChannelHandlerContext ctx) {
    CLSession session = new CLSession(this, identifier, (SocketChannel) ctx.channel());
    this.players.put(identifier, session);
    return session;
}
 
开发者ID:CloudLandGame,项目名称:CloudLand-Server,代码行数:6,代码来源:NetworkServer.java

示例13: NettyConnection

import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
public NettyConnection(ChannelHandlerContext ctx) {
	this.ctx=ctx;
	this.channel=ctx.channel();
	this.id=getChannelId(channel);
	channel.attr(CHANNEL_KEY).set(this);
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:7,代码来源:NettyConnection.java

示例14: handlerAdded

import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void handlerAdded(final ChannelHandlerContext ctx) {
    final Channel incoming = ctx.channel();
    LOGGER.info("Handling connection");
    channels.add(incoming);
}
 
开发者ID:dethi,项目名称:guereza,代码行数:7,代码来源:ServerHandler.java

示例15: channelActive

import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
    UkcpChannel kcpCh = (UkcpChannel) ctx.channel();
    kcpCh.conv(EchoServer.CONV);
}
 
开发者ID:szhnet,项目名称:kcp-netty,代码行数:6,代码来源:EchoServerHandler.java


注:本文中的io.netty.channel.ChannelHandlerContext.channel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。