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


Java ChannelHandlerContext.getAttachment方法代碼示例

本文整理匯總了Java中org.jboss.netty.channel.ChannelHandlerContext.getAttachment方法的典型用法代碼示例。如果您正苦於以下問題:Java ChannelHandlerContext.getAttachment方法的具體用法?Java ChannelHandlerContext.getAttachment怎麽用?Java ChannelHandlerContext.getAttachment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jboss.netty.channel.ChannelHandlerContext的用法示例。


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

示例1: messageReceived

import org.jboss.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
    throws Exception
{
    if (LOG.isTraceEnabled()) {
        LOG.trace("message received called " + e.getMessage());
    }
    try {
        if (LOG.isDebugEnabled()) {
            LOG.debug("New message " + e.toString()
                    + " from " + ctx.getChannel());
        }
        NettyServerCnxn cnxn = (NettyServerCnxn)ctx.getAttachment();
        synchronized(cnxn) {
            processMessage(e, cnxn);
        }
    } catch(Exception ex) {
        LOG.error("Unexpected exception in receive", ex);
        throw ex;
    }
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:22,代碼來源:NettyServerCnxnFactory.java

示例2: exceptionCaught

import org.jboss.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
		throws Exception {
	RpcRequest request = (RpcRequest) ctx.getAttachment();
	if (e.getCause() instanceof ReadTimeoutException) {
		// The connection was OK but there was no traffic for last period.
		logger.warn("Disconnecting due to no inbound traffic");
	} else {
		logger.error("", e);
	}
	e.getChannel().close().awaitUninterruptibly();
}
 
開發者ID:zhaoshiling1017,項目名稱:voyage,代碼行數:13,代碼來源:NettyRpcServerHandler.java

示例3: channelDisconnected

import org.jboss.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@Override
public void channelDisconnected(ChannelHandlerContext ctx,
        ChannelStateEvent e) throws Exception
{
    if (LOG.isTraceEnabled()) {
        LOG.trace("Channel disconnected " + e);
    }
    NettyServerCnxn cnxn = (NettyServerCnxn) ctx.getAttachment();
    if (cnxn != null) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Channel disconnect caused close " + e);
        }
        cnxn.close();
    }
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:16,代碼來源:NettyServerCnxnFactory.java

示例4: exceptionCaught

import org.jboss.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
    throws Exception
{
    LOG.warn("Exception caught " + e, e.getCause());
    NettyServerCnxn cnxn = (NettyServerCnxn) ctx.getAttachment();
    if (cnxn != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Closing " + cnxn);
            cnxn.close();
        }
    }
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:14,代碼來源:NettyServerCnxnFactory.java

示例5: exceptionCaught

import org.jboss.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
    throws Exception
{
    LOG.warn("Exception caught " + e, e.getCause());
    NettyServerCnxn cnxn = (NettyServerCnxn) ctx.getAttachment();
    if (cnxn != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Closing " + cnxn);
        }
        cnxn.close();
    }
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:14,代碼來源:NettyServerCnxnFactory.java

示例6: decode

import org.jboss.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel,
        ChannelBuffer buffer) throws Exception {
    log.debug("Message received.");
    if (!channel.isConnected()) {
        log.info("Channel is not connected.");
        // In testing, I see decode being called AFTER decode last.
        // This check avoids that from reading corrupted frames
        return null;
    }

    HexDump.pcepHexDump(buffer);

    // Buffer can contain multiple messages, also may contain out of bound message.
    // Read the message one by one from buffer and parse it. If it encountered out of bound message,
    // then mark the reader index and again take the next chunk of messages from the channel
    // and parse again from the marked reader index.
    PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
    List<PcepMessage> msgList = (List<PcepMessage>) ctx.getAttachment();

    if (msgList == null) {
        msgList = new LinkedList<>();
    }

    try {
        while (buffer.readableBytes() > 0) {
            buffer.markReaderIndex();
            PcepMessage message = reader.readFrom(buffer);
            msgList.add(message);
        }
        ctx.setAttachment(null);
        return msgList;
    } catch (PcepOutOfBoundMessageException e) {
        log.debug("PCEP message decode error");
        buffer.resetReaderIndex();
        buffer.discardReadBytes();
        ctx.setAttachment(msgList);
    }
    return null;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:41,代碼來源:PcepMessageDecoder.java

示例7: decode

import org.jboss.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
    log.debug("MESSAGE IS RECEIVED.");
    if (!channel.isConnected()) {
        log.info("Channel is not connected.");
        return null;
    }

    HexDump.dump(buffer);

    BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
    List<BgpMessage> msgList = (List<BgpMessage>) ctx.getAttachment();

    if (msgList == null) {
        msgList = new LinkedList<>();
    }

    try {
        while (buffer.readableBytes() > 0) {
            buffer.markReaderIndex();
            BgpHeader bgpHeader = new BgpHeader();
            BgpMessage message = reader.readFrom(buffer, bgpHeader);
            msgList.add(message);
        }

        return msgList;
    } catch (Exception e) {
        log.debug("Bgp protocol message decode error");
        buffer.resetReaderIndex();
        buffer.discardReadBytes();
        ctx.setAttachment(msgList);
    }
    return null;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:35,代碼來源:BgpMessageDecoder.java


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