當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。