Example #1
0
  public void transactionFinished(AbstractServerProxy proxy, String jobId) {
    if (proxy instanceof JsonDimProxy) {
      JsonDimProxy dimProxy = (JsonDimProxy) proxy;
      int status = dimProxy.getStatus();
      String action = dimProxy.getRequestAction();

      if (action.equals(IServerProxyConstants.ACT_GET_DIM_TOKEN)) {
        if (status == IServerProxyConstants.SUCCESS) {
          this.token = dimProxy.getToken();
          this.destination = dimProxy.getDestination();
          this.port = dimProxy.getPort();
          retryIntervals = dimProxy.getRetryIntervals();
          if (retryIntervals == null) {
            // retryIntervals unit is ms, we retry ptn 3 times and every time use 15s
            retryIntervals = new int[] {8000, 5000, 5000};
          }

          int serverDrivenTimeout = dimProxy.getTimeout();

          if (serverDrivenTimeout > MIN_TIMEOUT) {
            this.timeout = serverDrivenTimeout;
          } else {
            this.timeout = DEFAULT_TIMEOUT;
          }

          isAllowFallback = dimProxy.isAllowFallback();
          isPtnEncrypted = dimProxy.isPtnEncrypted();

          synchronized (mutex_overall) {
            mutex_overall.notifyAll();
          }
        } else {
          this.ptn = "";
          notifyDimFinish();
        }

        writeLog(
            "DimProvider - action: "
                + action
                + " status:"
                + status
                + " token:"
                + token
                + " destination:"
                + destination
                + " port:"
                + port
                + " timeout:"
                + timeout
                + " isAllowFallback:"
                + isAllowFallback
                + " isPtnEncrypted:"
                + isPtnEncrypted);

      } else if (action.equals(IServerProxyConstants.ACT_GET_DIM_PTN)) {
        if (status == IServerProxyConstants.SUCCESS) {
          this.errorMessage = null;
          this.ptn = dimProxy.getPTN();
          this.carrier = dimProxy.getCarrier();
          // FIX ME: Remove this hardcode after dim server support retrieving carrier.
          if (AppConfigHelper.BRAND_BELL.equals(AppConfigHelper.brandName)) {
            this.carrier = "70";
          }
          if (this.ptn == null || this.ptn.trim().equalsIgnoreCase(NULL_RESPONSE)) this.ptn = "";

          if (this.carrier == null || this.carrier.trim().equalsIgnoreCase(NULL_RESPONSE))
            this.carrier = "";

          if (ptn != null
              && ptn.trim().length() > 0
              && carrier != null
              && carrier.trim().length() > 0) {
            notifyDimFinish();
          } else {
            notifyGetPtnMutex();
          }
        } else {
          this.ptn = "";
          this.carrier = "";

          notifyGetPtnMutex();
        }

        writeLog(
            "DimProvider - action: "
                + action
                + " status:"
                + status
                + " ptn:"
                + ptn
                + " carrier:"
                + carrier);
      }
    }
  }