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