コード例 #1
0
  public boolean process(FSMState state) {
    try {
      AspImpl remAsp = (AspImpl) this.fsm.getAttribute(AsImpl.ATTRIBUTE_ASP);

      if (this.asImpl.getTrafficModeType().getMode() == TrafficModeType.Broadcast) {
        // We don't support this
        return false;
      }

      if (this.asImpl.getTrafficModeType().getMode() == TrafficModeType.Loadshare) {
        this.lbCount = 0;

        for (FastList.Node<Asp> n = this.asImpl.appServerProcs.head(),
                end = this.asImpl.appServerProcs.tail();
            (n = n.getNext()) != end; ) {
          AspImpl remAspImpl = (AspImpl) n.getValue();

          FSM aspPeerFSM = remAspImpl.getPeerFSM();
          AspState aspState = AspState.getState(aspPeerFSM.getState().getName());

          if (aspState == AspState.ACTIVE) {
            this.lbCount++;
          }
        } // for

        if (this.lbCount >= this.asImpl.getMinAspActiveForLb()) {
          // we still have more ASP's ACTIVE for lb. Don't change
          // state
          return false;
        }

        // We are below minAspActiveForLb required for LB
        if (this.lbCount > 0) {
          // But In any case if we have at least one ASP that can take
          // care of traffic, don't change state but send the "Ins.
          // ASPs" to INACTIVE ASP's

          if (asImpl.getFunctionality() != Functionality.IPSP) {
            // In any case send Notify only for ASP or SGW

            for (FastList.Node<Asp> n = this.asImpl.appServerProcs.head(),
                    end = this.asImpl.appServerProcs.tail();
                (n = n.getNext()) != end; ) {
              remAsp = (AspImpl) n.getValue();

              FSM aspPeerFSM = remAsp.getPeerFSM();
              AspState aspState = AspState.getState(aspPeerFSM.getState().getName());

              if (aspState == AspState.INACTIVE) {
                Notify notify =
                    this.createNotify(
                        remAsp, Status.STATUS_Other, Status.INFO_Insufficient_ASP_Resources_Active);
                remAsp.getAspFactory().write(notify);
              }
            }
          }

          return false;
        }
      } // If Loadshare

      // We have reached here means AS is transitioning to be PENDING.
      // Send new AS STATUS to all INACTIVE APS's

      if (asImpl.getFunctionality() != Functionality.IPSP) {
        // Send Notify only for ASP or SGW

        for (FastList.Node<Asp> n = this.asImpl.appServerProcs.head(),
                end = this.asImpl.appServerProcs.tail();
            (n = n.getNext()) != end; ) {
          remAsp = (AspImpl) n.getValue();

          FSM aspPeerFSM = remAsp.getPeerFSM();
          AspState aspState = AspState.getState(aspPeerFSM.getState().getName());

          if (aspState == AspState.INACTIVE) {
            Notify notify =
                this.createNotify(remAsp, Status.STATUS_AS_State_Change, Status.INFO_AS_PENDING);
            remAsp.getAspFactory().write(notify);
          }
        }
      }
    } catch (Exception e) {
      logger.error(
          String.format("Error while translating Rem AS to PENDING. %s", this.fsm.toString()), e);
    }
    return true;
  }