Examples of GatewayRate


Examples of com.alu.e3.rate.model.GatewayRate

      // if the call was failed then it was not counted so no need to decrease the counter
      if (removed && oldestCall.callSuccess) {
        LockCounter lock = this.gdm.getLockForBucket(oldestCall.bucketID);

        synchronized (lock) {
          GatewayRate gr =  gatewayRateValidator.getRateForBucket(oldestCall.bucketID);
          gr.localApiCallsSinceOneMinute--;
          if (!oldestCall.countedInLastPeriodMinute) {
            // if the call was after the last collect and older than 1 minute
            // then we must count it
            GatewayQueueRate gqr = gatewayRateValidator.getQueueRateForBucket(oldestCall.bucketID);
            gqr.localApiCallsInLastPeriodMinute++;
          }
          this.gdm.releaseLockForBucket(oldestCall.bucketID, lock);
        }
      }
    } 

    // update this.apiCallsPerSecondQueue to remove call older than 1s
    removed = true;
    while (removed) { 
      removed = false;
      synchronized(lockUpdateSecondQueues) {
        oldestCall = this.gdm.peekCallFromSecondQueue();
        if  ((oldestCall!=null) && (currentTime - oldestCall.callTime > 1000)) {
          removed = this.gdm.removeCallFromSecondQueue(oldestCall);
        }
      }
      if (removed && oldestCall.callSuccess) {
        LockCounter lock = this.gdm.getLockForBucket(oldestCall.bucketID);

        synchronized (lock) {
          GatewayRate gr =  gatewayRateValidator.getRateForBucket(oldestCall.bucketID);
          gr.localApiCallsSinceOneSecond--;
          if (!oldestCall.countedInLastPeriodSecond) {
            // if the call was after the last collect and older than 1 second
            // then we must count it
            GatewayQueueRate gqr = gatewayRateValidator.getQueueRateForBucket(oldestCall.bucketID);
View Full Code Here

Examples of com.alu.e3.rate.model.GatewayRate

         
          synchronized (lock) {
         
            lockedSet.add(bucketID);

            GatewayRate gr = gatewayRateValidator.getRateForBucket(bucketID, limit, mustResetRateLimit);
           
            gatewayRateValidator.updateRateLimitAndQuotaValues(gr, limit, currentTime);
           
            params.gr = gr;
            params.limit = limit;
            params.callDescriptor = callDescriptor;
           
            gatewayRateValidator.checkRateLimitAndQuota(apiCallStatus, params);
           
            this.gdm.releaseLockForBucket(bucketID, lock);
            lockedSet.remove(bucketID);
          }
        }
      }
     
      // TODO: maybe increment always in previous loop and decrement all gr only if call was failed
      // step2: save data for call success or fail
      it = authIdentity.getCallDescriptors().iterator();
      while (it.hasNext())
      {
        CallDescriptor callDescriptor = it.next();
        Integer bucketID = callDescriptor.getBucketId();
        Integer contextId = callDescriptor.getContextId();
        this.dataManager.fillLimitsById(contextId, limit);

        if ((limit.getQuotaPerDay()!=null) || (limit.getQuotaPerWeek()!=null) || (limit.getQuotaPerMonth()!=null)
            || (limit.getRateLimitPerMinute()!=null) || (limit.getRateLimitPerSecond()!=null))
        { 
          LockCounter lock = this.gdm.getLockForBucket(bucketID);

          synchronized (lock) {
           
            GatewayRate gr = gatewayRateValidator.getRateForBucket(bucketID);
            GatewayQueueRate gqr = gatewayRateValidator.getQueueRateForBucket(bucketID);     
 
            if (apiCallStatus.apiCallIsSuccess)
            {
              gr.localApiCallsSinceOneMinute++;
View Full Code Here

Examples of com.alu.e3.rate.model.GatewayRate

    topologyClient.removeInstanceTypeListener(this);
  }

  @Override
  public GatewayRate getRateForBucket(Integer bucketID) {
    GatewayRate gr = this.gdm.getFromRateMap(bucketID);
   
    if (gr == null) {
      gr = new GatewayRate(bucketID);
      this.gdm.putInRateMap(gr.bucketID, gr);
    }

    return gr;
  }
View Full Code Here

Examples of com.alu.e3.rate.model.GatewayRate

    return gr;
  }

  @Override
  public GatewayRate getRateForBucket(Integer bucketID, Limit limit, boolean mustResetRateLimit) {
    GatewayRate gr = this.gdm.getFromRateMap(bucketID);
   
    if (gr == null) {
      gr = new GatewayRate(bucketID, limit.getCreatedDate());
      this.gdm.putInRateMap(gr.bucketID, gr);
    }
   
    if (mustResetRateLimit) {
      logger.debug("rate limit is reset");
View Full Code Here

Examples of com.alu.e3.rate.model.GatewayRate

    return (limit != -1) && (value >= limit);
  }

  @Override
  public void checkRateLimitAndQuota(ApiCallStatus apiCallStatus, RateLimitParams params) {
    GatewayRate gr = params.gr;
    Limit limit = params.limit;
   
    if (isValueOverLimit(gr.localApiCallsSinceOneSecond, gr.localRateLimitSecond)) {
      apiCallStatus.apiCallIsSuccess = false;
      apiCallStatus.apiCallAction = (limit.getRateLimitPerSecond().getAction() != null) ? limit.getRateLimitPerSecond().getAction() : E3Constant.DEFAULT_ERROR_ACTION;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.