public static void checkDDP(Metadata metadata,String producer,String owner,String application,int count,long maxwait) throws WarpException {
  if (!loaded) {
    return;
  }
  RateLimiter producerLimiter=producerRateLimiters.get(producer);
  RateLimiter applicationLimiter=applicationRateLimiters.get(application);
  long appMaxWait=maxwait;
  long producerMaxWait=maxwait;
  if (null == producerLimiter && null == applicationLimiter && -1.0D == DEFAULT_RATE_PRODUCER) {
    return;
  }
 else   if (null == producerLimiter) {
    producerLimiter=RateLimiter.create(Math.max(MINIMUM_RATE_LIMIT,DEFAULT_RATE_PRODUCER));
    producerRateLimiters.put(producer,producerLimiter);
  }
  if (null != applicationLimiter) {
synchronized (applicationLimiter) {
      if (!applicationLimiter.tryAcquire(count,appMaxWait * count,TimeUnit.MILLISECONDS)) {
        StringBuilder sb=new StringBuilder();
        sb.append("Storing data for ");
        if (null != metadata) {
          GTSHelper.metadataToString(sb,metadata.getName(),metadata.getLabels());
        }
        sb.append(" would incur a wait greater than ");
        sb.append(appMaxWait);
        sb.append(" ms per datapoint due to your Daily Data Points limit being already exceeded for application '" + application + "'. Current max rate is "+ applicationLimiter.getRate()+ " datapoints/s.");
        Map<String,String> labels=new HashMap<String,String>();
        labels.put(SensisionConstants.SENSISION_LABEL_APPLICATION,application);
        Sensision.update(SensisionConstants.SENSISION_CLASS_CONTINUUM_THROTTLING_RATE_PER_APP,labels,1);
        Sensision.update(SensisionConstants.SENSISION_CLASS_CONTINUUM_THROTTLING_RATE_PER_APP_GLOBAL,Sensision.EMPTY_LABELS,1);
        throw new WarpException(sb.toString());
      }
    }
  }
synchronized (producerLimiter) {
    if (!producerLimiter.tryAcquire(count,producerMaxWait * count,TimeUnit.MILLISECONDS)) {
      StringBuilder sb=new StringBuilder();
      sb.append("Storing data for ");
      if (null != metadata) {
        GTSHelper.metadataToString(sb,metadata.getName(),metadata.getLabels());
      }
      sb.append(" would incur a wait greater than ");
      sb.append(producerMaxWait);
      sb.append(" ms per datapoint due to your Daily Data Points limit being already exceeded. Current maximum rate is " + producerLimiter.getRate() + " datapoints/s.");
      Map<String,String> labels=new HashMap<String,String>();
      labels.put(SensisionConstants.SENSISION_LABEL_PRODUCER,producer);
      Sensision.update(SensisionConstants.SENSISION_CLASS_CONTINUUM_THROTTLING_RATE,labels,1);
      Sensision.update(SensisionConstants.SENSISION_CLASS_CONTINUUM_THROTTLING_RATE_GLOBAL,Sensision.EMPTY_LABELS,1);
      throw new WarpException(sb.toString());
    }
  }
}

public static void checkDDP ( Metadata metadata , String producer , String owner , String application , int count , long maxwait ) throws WarpException { if ( ! loaded ) { return ; } RateLimiter producerLimiter = producerRateLimiters . get ( producer ) ; RateLimiter applicationLimiter = applicationRateLimiters . get ( application ) ; long appMaxWait = maxwait ; long producerMaxWait = maxwait ; if ( null == producerLimiter && null == applicationLimiter && - 1.0D == DEFAULT_RATE_PRODUCER ) { return ; } else if ( null == producerLimiter ) { producerLimiter = RateLimiter . create ( Math . max ( MINIMUM_RATE_LIMIT , DEFAULT_RATE_PRODUCER ) ) ; producerRateLimiters . put ( producer , producerLimiter ) ; } if ( null != applicationLimiter ) { synchronized ( applicationLimiter ) { if ( ! applicationLimiter . tryAcquire ( count , appMaxWait * count , TimeUnit . MILLISECONDS ) ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( "Storing data for " ) ; if ( null != metadata ) { GTSHelper . metadataToString ( sb , metadata . getName ( ) , metadata . getLabels ( ) ) ; } sb . append ( " would incur a wait greater than " ) ; sb . append ( appMaxWait ) ; sb . append ( " ms per datapoint due to your Daily Data Points limit being already exceeded for application '" + application + "'. Current max rate is " + applicationLimiter . getRate ( ) + " datapoints/s." ) ; Map < String , String > labels = new HashMap < String , String > ( ) ; labels . put ( SensisionConstants . SENSISION_LABEL_APPLICATION , application ) ; Sensision . update ( SensisionConstants . SENSISION_CLASS_CONTINUUM_THROTTLING_RATE_PER_APP , labels , 1 ) ; Sensision . update ( SensisionConstants . SENSISION_CLASS_CONTINUUM_THROTTLING_RATE_PER_APP_GLOBAL , Sensision . EMPTY_LABELS , 1 ) ; throw new WarpException ( sb . toString ( ) ) ; } } } synchronized ( producerLimiter ) { if ( ! producerLimiter . tryAcquire ( count , producerMaxWait * count , TimeUnit . MILLISECONDS ) ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( "Storing data for " ) ; if ( null != metadata ) { GTSHelper . metadataToString ( sb , metadata . getName ( ) , metadata . getLabels ( ) ) ; } sb . append ( " would incur a wait greater than " ) ; sb . append ( producerMaxWait ) ; sb . append ( " ms per datapoint due to your Daily Data Points limit being already exceeded. Current maximum rate is " + producerLimiter . getRate ( ) + " datapoints/s." ) ; Map < String , String > labels = new HashMap < String , String > ( ) ; labels . put ( SensisionConstants . SENSISION_LABEL_PRODUCER , producer ) ; Sensision . update ( SensisionConstants . SENSISION_CLASS_CONTINUUM_THROTTLING_RATE , labels , 1 ) ; Sensision . update ( SensisionConstants . SENSISION_CLASS_CONTINUUM_THROTTLING_RATE_GLOBAL , Sensision . EMPTY_LABELS , 1 ) ; throw new WarpException ( sb . toString ( ) ) ; } } }
validate the ingestion of datapoints against the ddp limit we tolerate inputs only if they wouldn ' t incur a wait greater than 2 seconds
