Package com.alu.e3.rate.model

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


  private static final Validation fromDataModel(com.alu.e3.data.model.sub.Validation val) {
    if (val == null)
      return null;

    Validation rVal = new Validation();

    if (val.getXml() != null) {
      rVal.setXml(new Validation.Xml());
    }
    if (val.getSchema() != null) {
      rVal.setSchema(fromDataModel(val.getSchema()));
    }

    if (val.getSoap() != null) {
      rVal.setSoap(new Validation.Soap(com.alu.e3.prov.restapi.model.SoapVersionEnum.fromValue(val.getSoap().getVersion().value())));
    }

    return rVal;
  }
View Full Code Here


      // 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

         
          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

    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

    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

    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

   
    return perfWatch;
  }
 
  public TdrStreamWriter(File dir) throws TransformerConfigurationException {
    this(new RotatableFileWriterProvider(dir, TDR_FILE_SIZE, TDR_FILE_AGE) {
      @Override
      protected String getFileName() {
        return "tdrs." + System.currentTimeMillis() + ".xml";   // TDR file name
      }
View Full Code Here

   
    topologyWatcher.setPollingInterval(POLLING_INTERVAL);
   
    topologyClient = new DummyTopologyClient();
   
    healthCheckFactory = new DummyHealthCheckFactory();
   
    setHealthCheckGateways(gatewayList);
    setHealthCheckGatewaysActive(gatewayActiveList);
    setHealthCheckSpeakers(activeSpeakerList);
   
View Full Code Here

  private void createTestResources(String[] gatewayList, String[] gatewayActiveList, String[] activeSpeakerList) {
    topologyWatcher = new TopologyWatcher();
   
    topologyWatcher.setPollingInterval(POLLING_INTERVAL);
   
    topologyClient = new DummyTopologyClient();
   
    healthCheckFactory = new DummyHealthCheckFactory();
   
    setHealthCheckGateways(gatewayList);
    setHealthCheckGatewaysActive(gatewayActiveList);
View Full Code Here

   
    return instance;
  }
 
  private void createTestResources(String[] gatewayList, String[] gatewayActiveList, String[] activeSpeakerList) {
    topologyWatcher = new TopologyWatcher();
   
    topologyWatcher.setPollingInterval(POLLING_INTERVAL);
   
    topologyClient = new DummyTopologyClient();
   
View Full Code Here

TOP

Related Classes of com.alu.e3.rate.model.GatewayRate

Copyright © 2018 www.massapicom. 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.