本文整理汇总了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;
}
}
示例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();
}
示例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();
}
}
示例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();
}
}
}
示例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();
}
}
示例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;
}
示例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;
}