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


Java ChannelHandlerContext.setAttachment方法代码示例

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


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

示例1: messageReceived

import org.jboss.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
	Object msg = e.getMessage();
	if (!(msg instanceof RpcRequest)) {
		logger.error("not RpcRequest received!");
		return;
	}
	RpcRequest request = (RpcRequest) msg;
	ctx.setAttachment(request);

	RpcResponse response = new RpcResponse(request.getRequestID());
	try {
		Object result = handle(request);
		response.setResult(result);
	} catch (Throwable t) {
		logger.error("handle rpc request fail! request:"+request, t);
		response.setException(t);
	}
	e.getChannel().write(response);
}
 
开发者ID:zhaoshiling1017,项目名称:voyage,代码行数:21,代码来源:NettyRpcServerHandler.java

示例2: channelConnected

import org.jboss.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void channelConnected(ChannelHandlerContext ctx,
        ChannelStateEvent e) throws Exception
{
    if (LOG.isTraceEnabled()) {
        LOG.trace("Channel connected " + e);
    }

    NettyServerCnxn cnxn = new NettyServerCnxn(ctx.getChannel(),
            zkServer, NettyServerCnxnFactory.this);
    ctx.setAttachment(cnxn);

    if (secure) {
        SslHandler sslHandler = ctx.getPipeline().get(SslHandler.class);
        ChannelFuture handshakeFuture = sslHandler.handshake();
        handshakeFuture.addListener(new CertificateVerifier(sslHandler, cnxn));
    } else {
        allChannels.add(ctx.getChannel());
        addCnxn(cnxn);
    }
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:22,代码来源:NettyServerCnxnFactory.java

示例3: channelConnected

import org.jboss.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void channelConnected(ChannelHandlerContext ctx,
        ChannelStateEvent e) throws Exception
{
    if (LOG.isTraceEnabled()) {
        LOG.trace("Channel connected " + e);
    }
    allChannels.add(ctx.getChannel());
    NettyServerCnxn cnxn = new NettyServerCnxn(ctx.getChannel(),
            zkServer, NettyServerCnxnFactory.this);
    ctx.setAttachment(cnxn);
    addCnxn(cnxn);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:14,代码来源:NettyServerCnxnFactory.java

示例4: 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

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