本文整理汇总了Java中org.jboss.netty.channel.Channel.isConnected方法的典型用法代码示例。如果您正苦于以下问题:Java Channel.isConnected方法的具体用法?Java Channel.isConnected怎么用?Java Channel.isConnected使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jboss.netty.channel.Channel
的用法示例。
在下文中一共展示了Channel.isConnected方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exceptionCaught
import org.jboss.netty.channel.Channel; //导入方法依赖的package包/类
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
throws Exception {
Channel ch = e.getChannel();
Throwable cause = e.getCause();
if (cause instanceof TooLongFrameException) {
sendError(ctx, BAD_REQUEST);
return;
} else if (cause instanceof IOException) {
if (cause instanceof ClosedChannelException) {
LOG.debug("Ignoring closed channel error", cause);
return;
}
String message = String.valueOf(cause.getMessage());
if (IGNORABLE_ERROR_MESSAGE.matcher(message).matches()) {
LOG.debug("Ignoring client socket close", cause);
return;
}
}
LOG.error("Shuffle error: ", cause);
if (ch.isConnected()) {
LOG.error("Shuffle error " + e);
sendError(ctx, INTERNAL_SERVER_ERROR);
}
}
示例2: decode
import org.jboss.netty.channel.Channel; //导入方法依赖的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;
}
// Note that a single call to decode results in reading a single
// OFMessage from the channel buffer, which is passed on to, and processed
// by, the controller (in OFChannelHandler).
// This is different from earlier behavior (with the original openflowj),
// where we parsed all the messages in the buffer, before passing on
// a list of the parsed messages to the controller.
// The performance *may or may not* not be as good as before.
OFMessageReader<OFMessage> reader = OFFactories.getGenericReader();
OFMessage message = reader.readFrom(buffer);
return message;
}
示例3: processRefreshLsp
import org.jboss.netty.channel.Channel; //导入方法依赖的package包/类
/**
* Process refresh LSP.
*
* @param wrapper LSP wrapper instance
*/
private void processRefreshLsp(LspWrapper wrapper) throws Exception {
if (wrapper.isSelfOriginated()) { //self originated
DefaultIsisInterface isisInterface = (DefaultIsisInterface) wrapper.isisInterface();
Channel channel = isisInterface.channel();
if (channel != null && channel.isConnected()) {
LsPdu lsPdu = (LsPdu) wrapper.lsPdu();
lsPdu.setSequenceNumber(isisInterface.isisLsdb().lsSequenceNumber(
IsisPduType.get(lsPdu.pduType())));
lsPdu.setRemainingLifeTime(IsisConstants.LSPMAXAGE);
byte[] lspBytes = lsPdu.asBytes();
lspBytes = IsisUtil.addLengthAndMarkItInReserved(lspBytes, IsisConstants.LENGTHPOSITION,
IsisConstants.LENGTHPOSITION + 1,
IsisConstants.RESERVEDPOSITION);
lspBytes = IsisUtil.addChecksum(lspBytes, IsisConstants.CHECKSUMPOSITION,
IsisConstants.CHECKSUMPOSITION + 1);
//write to the channel
channel.write(IsisUtil.framePacket(lspBytes, isisInterface.interfaceIndex()));
// Updating the database with resetting remaining life time to default.
IsisLsdb isisDb = isisInterface.isisLsdb();
isisDb.addLsp(lsPdu, true, isisInterface);
log.debug("LSPQueueConsumer: processRefreshLsp - Flooded SelfOriginated LSP {}",
wrapper.lsPdu());
}
}
}
示例4: decode
import org.jboss.netty.channel.Channel; //导入方法依赖的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;
}
示例5: getChannel
import org.jboss.netty.channel.Channel; //导入方法依赖的package包/类
@Override
protected com.alibaba.dubbo.remoting.Channel getChannel() {
Channel c = channel;
if (c == null || ! c.isConnected())
return null;
return NettyChannel.getOrAddChannel(c, getUrl(), this);
}
示例6: decode
import org.jboss.netty.channel.Channel; //导入方法依赖的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: sendLsp
import org.jboss.netty.channel.Channel; //导入方法依赖的package包/类
/**
* Sends LS PDU message to channel.
*
* @param lsp LS PDU message instance
* @param channel channel instance
*/
private void sendLsp(LsPdu lsp, Channel channel) {
byte[] lspBytes = lsp.asBytes();
lspBytes = IsisUtil.addLengthAndMarkItInReserved(lspBytes, IsisConstants.LENGTHPOSITION,
IsisConstants.LENGTHPOSITION + 1,
IsisConstants.RESERVEDPOSITION);
lspBytes = IsisUtil.addChecksum(lspBytes, IsisConstants.CHECKSUMPOSITION,
IsisConstants.CHECKSUMPOSITION + 1);
//write to the channel
if (channel != null && channel.isConnected() && channel.isOpen()) {
channel.write(IsisUtil.framePacket(lspBytes, interfaceIndex));
}
}
示例8: sendPsnPduMessage
import org.jboss.netty.channel.Channel; //导入方法依赖的package包/类
/**
* Sends the partial sequence number PDU.
*
* @param lspEntryRequestList list of lsp entry request
* @param isisPduType intermediate system PDU type
* @param channel netty channel instance
*/
private void sendPsnPduMessage(List<LspEntry> lspEntryRequestList, IsisPduType isisPduType, Channel channel) {
IsisHeader isisHeader = new LspGenerator().getHeader(isisPduType);
Psnp psnp = new Psnp(isisHeader);
psnp.setSourceId(lspKeyP2P(this.systemId));
TlvHeader tlvHeader = new TlvHeader();
tlvHeader.setTlvType(TlvType.LSPENTRY.value());
tlvHeader.setTlvLength(0);
LspEntriesTlv lspEntriesTlv = new LspEntriesTlv(tlvHeader);
for (LspEntry lspEntry : lspEntryRequestList) {
lspEntry.setLspChecksum(0);
lspEntry.setLspSequenceNumber(0);
lspEntry.setRemainingTime(0);
lspEntriesTlv.addLspEntry(lspEntry);
}
psnp.addTlv(lspEntriesTlv);
//write it to channel buffer.
byte[] psnpBytes = psnp.asBytes();
psnpBytes = IsisUtil.addLengthAndMarkItInReserved(psnpBytes, IsisConstants.LENGTHPOSITION,
IsisConstants.LENGTHPOSITION + 1,
IsisConstants.RESERVEDPOSITION);
flagValue = false;
//write to the channel
if (channel != null && channel.isConnected() && channel.isOpen()) {
channel.write(IsisUtil.framePacket(psnpBytes, interfaceIndex));
}
}
示例9: decode
import org.jboss.netty.channel.Channel; //导入方法依赖的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;
}
示例10: decode
import org.jboss.netty.channel.Channel; //导入方法依赖的package包/类
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer)
throws Exception {
if (!channel.isConnected()) {
return null;
}
if (buffer.readableBytes() < FpmHeader.FPM_HEADER_LENGTH) {
return null;
}
buffer.markReaderIndex();
short version = buffer.readUnsignedByte();
short type = buffer.readUnsignedByte();
int length = buffer.readUnsignedShort();
buffer.resetReaderIndex();
if (buffer.readableBytes() < length) {
// Not enough bytes to read a whole message
return null;
}
byte[] fpmMessage = new byte[length];
buffer.readBytes(fpmMessage);
return FpmHeader.decode(fpmMessage, 0, fpmMessage.length);
}
示例11: execute
import org.jboss.netty.channel.Channel; //导入方法依赖的package包/类
@Override
public void execute(Channel chan, String[] command) throws DatastoreException
{
m_counter.incrementAndGet();
if (chan.isConnected())
{
Package thisPackage = getClass().getPackage();
String versionString = thisPackage.getImplementationTitle()+" "+thisPackage.getImplementationVersion();
chan.write(versionString+"\n");
}
}
示例12: processLsPduMessage
import org.jboss.netty.channel.Channel; //导入方法依赖的package包/类
/**
* Processes LS PDU message.
*
* @param isisMessage LS pdu message instance
* @param channel channel instance
*/
public void processLsPduMessage(IsisMessage isisMessage, Channel channel) {
log.debug("Enters processLsPduMessage ...!!!");
IsisNeighbor neighbor = neighbouringRouter(isisMessage.sourceMac());
if (networkType == IsisNetworkType.BROADCAST && neighbor == null) {
return;
}
LsPdu lsPdu = (LsPdu) isisMessage;
LspWrapper wrapper = isisLsdb.findLsp(lsPdu.isisPduType(), lsPdu.lspId());
if (wrapper == null || isisLsdb.isNewerOrSameLsp(lsPdu, wrapper.lsPdu()).equalsIgnoreCase("latest")) {
if (wrapper != null) { // verify if the LSA - is your own LSA - get system ID and compare LSP
String lspKey = isisLsdb.lspKey(systemId);
if (lsPdu.lspId().equals(lspKey)) {
lsPdu.setSequenceNumber(lsPdu.sequenceNumber() + 1);
if (lsPdu.pduType() == IsisPduType.L1LSPDU.value()) {
// setting the ls sequence number
isisLsdb.setL1LspSeqNo(lsPdu.sequenceNumber());
} else if (lsPdu.pduType() == IsisPduType.L2LSPDU.value()) {
// setting the ls sequence number
isisLsdb.setL2LspSeqNo(lsPdu.sequenceNumber());
}
isisLsdb.addLsp(lsPdu, true, this);
sendLsp(lsPdu, channel);
} else {
isisLsdb.addLsp(lsPdu, false, this);
}
} else {
//not exist in the database or latest, then add it in database
isisLsdb.addLsp(lsPdu, false, this);
}
}
//If network type is P2P, acknowledge with a PSNP
if (networkType() == IsisNetworkType.P2P) {
IsisPduType psnpType = null;
if (IsisPduType.get(lsPdu.pduType()) == IsisPduType.L1LSPDU) {
psnpType = IsisPduType.L1PSNP;
} else if (IsisPduType.get(lsPdu.pduType()) == IsisPduType.L2LSPDU) {
psnpType = IsisPduType.L2PSNP;
}
IsisHeader isisHeader = new LspGenerator().getHeader(psnpType);
Psnp psnp = new Psnp(isisHeader);
psnp.setSourceId(lspKeyP2P(this.systemId));
TlvHeader tlvHeader = new TlvHeader();
tlvHeader.setTlvType(TlvType.LSPENTRY.value());
tlvHeader.setTlvLength(0);
LspEntriesTlv lspEntriesTlv = new LspEntriesTlv(tlvHeader);
LspEntry lspEntry = new LspEntry();
lspEntry.setLspChecksum(lsPdu.checkSum());
lspEntry.setLspId(lsPdu.lspId());
lspEntry.setLspSequenceNumber(lsPdu.sequenceNumber());
lspEntry.setRemainingTime(lsPdu.remainingLifeTime());
lspEntriesTlv.addLspEntry(lspEntry);
psnp.addTlv(lspEntriesTlv);
//write it to channel buffer.
byte[] psnpBytes = psnp.asBytes();
psnpBytes = IsisUtil.addLengthAndMarkItInReserved(psnpBytes, IsisConstants.LENGTHPOSITION,
IsisConstants.LENGTHPOSITION + 1,
IsisConstants.RESERVEDPOSITION);
flagValue = false;
//write to the channel
if (channel != null && channel.isConnected() && channel.isOpen()) {
channel.write(IsisUtil.framePacket(psnpBytes, interfaceIndex));
}
}
}