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