當前位置: 首頁>>代碼示例>>Java>>正文


Java ChannelHandlerContext.getChannel方法代碼示例

本文整理匯總了Java中org.jboss.netty.channel.ChannelHandlerContext.getChannel方法的典型用法代碼示例。如果您正苦於以下問題:Java ChannelHandlerContext.getChannel方法的具體用法?Java ChannelHandlerContext.getChannel怎麽用?Java ChannelHandlerContext.getChannel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jboss.netty.channel.ChannelHandlerContext的用法示例。


在下文中一共展示了ChannelHandlerContext.getChannel方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: 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);
    }
    allChannels.add(ctx.getChannel());
    NettyServerCnxn cnxn = new NettyServerCnxn(ctx.getChannel(),
            zkServer, NettyServerCnxnFactory.this);
    ctx.setAttachment(cnxn);
    addCnxn(cnxn);
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:14,代碼來源:NettyServerCnxnFactory.java

示例3: channelOpen

import org.jboss.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@Override
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e)
        throws Exception {
    if (!fpmListener.peerConnected(ctx.getChannel().getRemoteAddress())) {
        log.error("Received new FPM connection while already connected");
        ctx.getChannel().close();
        return;
    }

    channel = ctx.getChannel();
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:12,代碼來源:FpmSessionHandler.java

示例4: processLsRequestMessage

import org.jboss.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
/**
 * Process the Ls Request message.
 *
 * @param ospfMessage OSPF message instance.
 * @param ctx         channel handler context instance.
 * @throws Exception might throws exception
 */
void processLsRequestMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception {
    log.debug("OspfChannelHandler::processLsRequestMessage...!!!");
    Channel channel = ctx.getChannel();
    LsRequest lsrPacket = (LsRequest) ospfMessage;
    OspfNbr nbr = neighbouringRouter(lsrPacket.routerId().toString());

    if (nbr.getState() == OspfNeighborState.EXCHANGE || nbr.getState() == OspfNeighborState.LOADING ||
            nbr.getState() == OspfNeighborState.FULL) {

        LsRequest reqMsg = (LsRequest) ospfMessage;
        if (reqMsg.getLinkStateRequests().isEmpty()) {
            log.debug("Received Link State Request Vector is Empty ");
            return;
        } else {
            //Send the LsUpdate back
            ListIterator<LsRequestPacket> listItr = reqMsg.getLinkStateRequests().listIterator();
            while (listItr.hasNext()) {
                LsUpdate lsupdate = new LsUpdate();
                lsupdate.setOspfVer(OspfUtil.OSPF_VERSION);
                lsupdate.setOspftype(OspfPacketType.LSUPDATE.value());
                lsupdate.setRouterId(ospfArea.routerId());
                lsupdate.setAreaId(ospfArea.areaId());
                lsupdate.setAuthType(OspfUtil.NOT_ASSIGNED);
                lsupdate.setAuthentication(OspfUtil.NOT_ASSIGNED);
                lsupdate.setOspfPacLength(OspfUtil.NOT_ASSIGNED); // to calculate packet length
                lsupdate.setChecksum(OspfUtil.NOT_ASSIGNED);

                //limit to mtu
                int currentLength = OspfUtil.OSPF_HEADER_LENGTH + OspfUtil.FOUR_BYTES;
                int maxSize = mtu() -
                        OspfUtil.LSA_HEADER_LENGTH; // subtract a normal IP header.
                int noLsa = 0;
                while (listItr.hasNext()) {
                    LsRequestPacket lsRequest = (LsRequestPacket) listItr.next();
                    // to verify length of the LSA
                    LsaWrapper wrapper = ospfArea.getLsa(lsRequest.lsType(), lsRequest.linkStateId(),
                                                         lsRequest.ownRouterId());
                    OspfLsa ospflsa = wrapper.ospfLsa();
                    if ((currentLength + ((LsaWrapperImpl) wrapper).lsaHeader().lsPacketLen()) >= maxSize) {
                        listItr.previous();
                        break;
                    }
                    if (ospflsa != null) {
                        lsupdate.addLsa(ospflsa);
                        noLsa++;

                        currentLength = currentLength + ((LsaWrapperImpl) wrapper).lsaHeader().lsPacketLen();
                    } else {
                        nbr.badLSReq(channel);
                    }
                }
                lsupdate.setNumberOfLsa(noLsa);
                //set the destination
                if (state() == OspfInterfaceState.DR ||
                        state() == OspfInterfaceState.BDR ||
                        state() == OspfInterfaceState.POINT2POINT) {
                    lsupdate.setDestinationIp(OspfUtil.ALL_SPF_ROUTERS);
                } else if (state() == OspfInterfaceState.DROTHER) {
                    lsupdate.setDestinationIp(OspfUtil.ALL_DROUTERS);
                }
                byte[] messageToWrite = getMessage(lsupdate);
                ctx.getChannel().write(messageToWrite);
            }
        }
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:74,代碼來源:OspfInterfaceImpl.java


注:本文中的org.jboss.netty.channel.ChannelHandlerContext.getChannel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。