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


Java ChannelHandlerContext类代码示例

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


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

示例1: encode

import org.jboss.netty.channel.ChannelHandlerContext; //导入依赖的package包/类
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
    log.debug("Sending message");
    if (!(msg instanceof List)) {
        log.debug("Invalid msg.");
        return msg;
    }

    @SuppressWarnings("unchecked")
    List<PcepMessage> msglist = (List<PcepMessage>) msg;

    ChannelBuffer buf = ChannelBuffers.dynamicBuffer();

    for (PcepMessage pm : msglist) {
        pm.writeTo(buf);
    }

    HexDump.pcepHexDump(buf);

    return buf;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:22,代码来源:PcepMessageEncoder.java

示例2: channelDisconnected

import org.jboss.netty.channel.ChannelHandlerContext; //导入依赖的package包/类
@Override
public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent evt) {
    log.debug("OspfChannelHandler::channelDisconnected...!!!");

    for (Integer interfaceIndex : ospfInterfaceMap.keySet()) {
        OspfInterface anInterface = ospfInterfaceMap.get(interfaceIndex);
        if (anInterface != null) {
            anInterface.interfaceDown();
            anInterface.stopDelayedAckTimer();
        }
    }

    if (controller != null) {
        controller.connectPeer();
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:17,代码来源:OspfInterfaceChannelHandler.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);
    }

    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

示例4: encode

import org.jboss.netty.channel.ChannelHandlerContext; //导入依赖的package包/类
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {

    if (msg instanceof Command) {
        Command command = (Command) msg;
        Object encodedCommand = encodeCommand(command);

        // Log command
        StringBuilder s = new StringBuilder();
        s.append(String.format("[%08X] ", channel.getId()));
        s.append("id: ").append(getUniqueId(command.getDeviceId())).append(", ");
        s.append("command type: ").append(command.getType()).append(" ");
        if (encodedCommand != null) {
            s.append("sent");
        } else {
            s.append("not sent");
        }
        Log.info(s.toString());

        return encodedCommand;
    }

    return msg;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:25,代码来源:BaseProtocolEncoder.java

示例5: decode

import org.jboss.netty.channel.ChannelHandlerContext; //导入依赖的package包/类
@Override
protected Object decode(
        ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {

    ChannelBuffer result = (ChannelBuffer) super.decode(ctx, channel, buf);

    if (result != null) {

        int index = result.indexOf(result.readerIndex(), result.writerIndex(), (byte) '$');
        if (index == -1) {
            return result;
        } else {
            result.skipBytes(index);
            return result.readBytes(result.readableBytes());
        }

    }

    return null;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:21,代码来源:Stl060FrameDecoder.java

示例6: decode

import org.jboss.netty.channel.ChannelHandlerContext; //导入依赖的package包/类
@Override
protected Object decode(
        ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {

    if (buf.readableBytes() < 80) {
        return null;
    }

    int spaceIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ' ');
    if (spaceIndex == -1) {
        return null;
    }

    int endIndex = buf.indexOf(spaceIndex, buf.writerIndex(), (byte) ',');
    if (endIndex == -1) {
        return null;
    }

    return buf.readBytes(endIndex + 1);
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:21,代码来源:JpKorjarFrameDecoder.java

示例7: messageReceived

import org.jboss.netty.channel.ChannelHandlerContext; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
  if (e.getMessage() instanceof ChannelBuffer) {
    ChannelBuffer buffer = (ChannelBuffer) e.getMessage();

    int bytesToRead = Math.min(currentChunkSize - bytesRead, buffer.readableBytes());
    buffer.readBytes(getMailEnvelope().getMessageOutputStream(), bytesToRead);
    bytesRead += bytesToRead;

    if (bytesRead == currentChunkSize) {
      stopCapturingData();
    }

    return;
  }

  super.messageReceived(ctx, e);
}
 
开发者ID:HubSpot,项目名称:NioSmtpClient,代码行数:19,代码来源:ChunkingExtension.java

示例8: encode

import org.jboss.netty.channel.ChannelHandlerContext; //导入依赖的package包/类
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
    log.debug("BGPMessageEncoder::encode");
    if (!(msg instanceof List)) {
        log.debug("Invalid msg.");
        return msg;
    }

    @SuppressWarnings("unchecked")
    List<BgpMessage> msglist = (List<BgpMessage>) msg;

    ChannelBuffer buf = ChannelBuffers.dynamicBuffer();

    log.debug("SENDING MESSAGE");
    for (BgpMessage pm : msglist) {
        pm.writeTo(buf);
    }

    HexDump.dump(buf);

    return buf;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:23,代码来源:BgpMessageEncoder.java

示例9: messageReceived

import org.jboss.netty.channel.ChannelHandlerContext; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx,
                            MessageEvent e) throws Exception {
    Object message = e.getMessage();
    if (message instanceof SyncMessage) {
        handleSyncMessage((SyncMessage)message, ctx.getChannel());
    } else if (message instanceof List) {
        for (Object i : (List<?>)message) {
            if (i instanceof SyncMessage) {
                try {
                    handleSyncMessage((SyncMessage)i,
                                         ctx.getChannel());
                } catch (Exception ex) {
                    Channels.fireExceptionCaught(ctx, ex);
                }
            }
        }
    } else {
        handleUnknownMessage(ctx, message);
    }
}
 
开发者ID:nsg-ethz,项目名称:iTAP-controller,代码行数:22,代码来源:AbstractRPCChannelHandler.java

示例10: decode

import org.jboss.netty.channel.ChannelHandlerContext; //导入依赖的package包/类
@Override
protected Object decode(
        ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {

    if (buf.readableBytes() < BINARY_HEADER) {
        return null;
    }

    if (buf.getUnsignedByte(buf.readerIndex()) == 0xbf) {
        buf.skipBytes(BINARY_HEADER);
    }

    int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '\r');
    if (index != -1 && index + 1 < buf.writerIndex()) {
        ChannelBuffer result = buf.readBytes(index - buf.readerIndex());
        buf.skipBytes(2);
        return result;
    }

    return null;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:22,代码来源:Pt502FrameDecoder.java

示例11: decode

import org.jboss.netty.channel.ChannelHandlerContext; //导入依赖的package包/类
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {

    // Check minimum length
    if (buf.readableBytes() < MESSAGE_MINIMUM_LENGTH) {
        return null;
    }

    // Check for sync packet
    if (buf.getUnsignedShort(buf.readerIndex()) == 0xFAF8) {
        ChannelBuffer syncMessage = buf.readBytes(8);
        if (channel != null) {
            channel.write(syncMessage);
        }
    }

    return super.decode(ctx, channel, buf);
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:19,代码来源:IntellitracFrameDecoder.java

示例12: decode

import org.jboss.netty.channel.ChannelHandlerContext; //导入依赖的package包/类
@Override
protected Object decode(
        ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {

    if (buf.readableBytes() >= MESSAGE_HEADER) {
        int length = Integer.parseInt(buf.toString(2, 2, StandardCharsets.US_ASCII)) + 5;
        if (buf.readableBytes() >= length) {
            ChannelBuffer frame = buf.readBytes(length);
            while (buf.readable() && buf.getUnsignedByte(buf.readerIndex()) != '$') {
                buf.readByte();
            }
            return frame;
        }
    }

    return null;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:18,代码来源:Gps056FrameDecoder.java

示例13: messageReceived

import org.jboss.netty.channel.ChannelHandlerContext; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
        throws Exception {
    if (e.getMessage() instanceof List) {
        @SuppressWarnings("unchecked")
        List<OFMessage> msglist = (List<OFMessage>) e.getMessage();


        for (OFMessage ofm : msglist) {
            // Do the actual packet processing
            state.processOFMessage(this, ofm);
        }
    } else {
        state.processOFMessage(this, (OFMessage) e.getMessage());
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:17,代码来源:OFChannelHandler.java

示例14: parseAttributeTypeAtomicAggregate

import org.jboss.netty.channel.ChannelHandlerContext; //导入依赖的package包/类
/**
 * Parses BGP UPDATE Attribute Type ATOMIC_AGGREGATE.
 *
 * @param bgpSession the BGP Session to use
 * @param ctx the Channel Handler Context
 * @param attrTypeCode the attribute type code
 * @param attrLen the attribute length (in octets)
 * @param attrFlags the attribute flags
 * @param message the message to parse
 * @throws BgpMessage.BgpParseException
 */
private static void parseAttributeTypeAtomicAggregate(
                            BgpSession bgpSession,
                            ChannelHandlerContext ctx,
                            int attrTypeCode,
                            int attrLen,
                            int attrFlags,
                            ChannelBuffer message)
    throws BgpMessage.BgpParseException {

    // Check the Attribute Length
    if (attrLen != BgpConstants.Update.AtomicAggregate.LENGTH) {
        // ERROR: Attribute Length Error
        actionsBgpUpdateAttributeLengthError(
            bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message);
        String errorMsg = "Attribute Length Error";
        throw new BgpMessage.BgpParseException(errorMsg);
    }

    // Nothing to do: this attribute is primarily informational
}
 
开发者ID:shlee89,项目名称:athena,代码行数:32,代码来源:BgpUpdate.java

示例15: decode

import org.jboss.netty.channel.ChannelHandlerContext; //导入依赖的package包/类
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel,
                        ChannelBuffer buffer) throws Exception {
    if (!channel.isConnected()) {
        // In testing, I see decode being called AFTER decode last.
        // This check avoids that from reading corrupted frames
        return null;
    }

    List<OFMessage> messageList = new ArrayList<OFMessage>();
    for (;;) {
        OFMessage message = reader.readFrom(buffer);
        if (message == null)
            break;
        messageList.add(message);
    }
    return messageList.isEmpty() ? null : messageList;
}
 
开发者ID:nsg-ethz,项目名称:iTAP-controller,代码行数:19,代码来源:OFMessageDecoder.java


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