Java Code Examples for org.jboss.netty.channel.Channel.isOpen()

The following are Jave code examples for showing how to use isOpen() of the org.jboss.netty.channel.Channel class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Elasticsearch   File: NettyTransport.java   View Source Code Vote up 5 votes
public synchronized void close() {
    List<ChannelFuture> futures = new ArrayList<>();
    for (Channel channel : allChannels) {
        try {
            if (channel != null && channel.isOpen()) {
                futures.add(channel.close());
            }
        } catch (Exception e) {
            //ignore
        }
    }
    for (ChannelFuture future : futures) {
        future.awaitUninterruptibly();
    }
}
 
Example 2
Project: athena   File: DefaultIsisInterface.java   View Source Code Vote up 5 votes
/**
 * 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));
    }
}
 
Example 3
Project: athena   File: DefaultIsisInterface.java   View Source Code Vote up 5 votes
/**
 * 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));
    }
}
 
Example 4
Project: athena   File: DefaultIsisInterface.java   View Source Code Vote up 4 votes
/**
 * 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));
        }
    }
}