public static void checkMADS(Metadata metadata,String producer,String owner,String application,long classId,long labelsId) throws WarpException {
  if (!loaded) {
    return;
  }
  Long oProducerLimit=producerMADSLimits.get(producer);
  Long oApplicationLimit=applicationMADSLimits.get(application);
  if (null == oProducerLimit) {
    oProducerLimit=DEFAULT_MADS_PRODUCER;
    if (-1 == oProducerLimit && null == oApplicationLimit) {
      return;
    }
 else     if (0 == oProducerLimit) {
      Map<String,String> labels=new HashMap<String,String>();
      labels.put(SensisionConstants.SENSISION_LABEL_PRODUCER,producer);
      StringBuilder sb=new StringBuilder();
      sb.append("Geo Time Series ");
      GTSHelper.metadataToString(sb,metadata.getName(),metadata.getLabels());
      sb.append(" would exceed your Monthly Active Data Streams limit (");
      sb.append(oProducerLimit);
      sb.append(").");
      Sensision.update(SensisionConstants.SENSISION_CLASS_CONTINUUM_THROTTLING_GTS,labels,1);
      Sensision.update(SensisionConstants.SENSISION_CLASS_CONTINUUM_THROTTLING_GTS_GLOBAL,Sensision.EMPTY_LABELS,1);
      throw new WarpException(sb.toString());
    }
    oProducerLimit=(long)Math.ceil(oProducerLimit * toleranceRatio);
  }
  long producerLimit=oProducerLimit;
  HyperLogLogPlus producerHLLP;
synchronized (producerHLLPEstimators) {
    producerHLLP=producerHLLPEstimators.get(producer);
    if (null == producerHLLP || producerHLLP.hasExpired()) {
      producerHLLP=new HyperLogLogPlus(DEFAULT_P,DEFAULT_PPRIME);
      try {
        producerHLLP.toNormal();
      }
 catch (      IOException ioe) {
        throw new WarpException(ioe);
      }
      producerHLLP.setKey(producer);
      producerHLLPEstimators.put(producer,producerHLLP);
    }
  }
  long hash=GTSHelper.gtsId(SIP_KEYS,classId,labelsId);
  boolean newForProducer=producerHLLP.isNew(hash);
  if (!newForProducer && null == oApplicationLimit) {
    return;
  }
  HyperLogLogPlus applicationHLLP=null;
  long applicationLimit=Long.MIN_VALUE;
  if (null != oApplicationLimit) {
    applicationLimit=oApplicationLimit;
synchronized (applicationHLLPEstimators) {
      applicationHLLP=applicationHLLPEstimators.get(application);
      if (null == applicationHLLP || applicationHLLP.hasExpired()) {
        applicationHLLP=new HyperLogLogPlus(DEFAULT_P,DEFAULT_PPRIME);
        try {
          applicationHLLP.toNormal();
        }
 catch (        IOException ioe) {
          throw new WarpException(ioe);
        }
        applicationHLLP.setKey(APPLICATION_PREFIX_CHAR + application);
        applicationHLLPEstimators.put(application,applicationHLLP);
      }
    }
  }
  if (null != applicationHLLP) {
    if (!applicationHLLP.isNew(hash)) {
      return;
    }
    try {
      long cardinality=applicationHLLP.cardinality();
      Map<String,String> labels=new HashMap<String,String>();
      labels.put(SensisionConstants.SENSISION_LABEL_APPLICATION,application);
      if (cardinality > applicationLimit) {
        StringBuilder sb=new StringBuilder();
        sb.append("Geo Time Series ");
        GTSHelper.metadataToString(sb,metadata.getName(),metadata.getLabels());
        sb.append(" would exceed your Monthly Active Data Streams limit for application '" + application + "' (");
        sb.append((long)Math.floor(applicationLimit / toleranceRatio));
        sb.append(").");
        Sensision.update(SensisionConstants.SENSISION_CLASS_CONTINUUM_THROTTLING_GTS_PER_APP,labels,1);
        Sensision.update(SensisionConstants.SENSISION_CLASS_CONTINUUM_THROTTLING_GTS_PER_APP_GLOBAL,Sensision.EMPTY_LABELS,1);
        throw new WarpException(sb.toString());
      }
      applicationHLLP.aggregate(hash);
      Sensision.set(SensisionConstants.SENSISION_CLASS_CONTINUUM_GTS_DISTINCT_PER_APP,labels,applicationHLLP.cardinality());
    }
 catch (    IOException ioe) {
    }
  }
  try {
    long cardinality=producerHLLP.cardinality();
    Map<String,String> labels=new HashMap<String,String>();
    labels.put(SensisionConstants.SENSISION_LABEL_PRODUCER,producer);
    if (cardinality > producerLimit) {
      StringBuilder sb=new StringBuilder();
      sb.append("Geo Time Series ");
      GTSHelper.metadataToString(sb,metadata.getName(),metadata.getLabels());
      sb.append(" would exceed your Monthly Active Data Streams limit (");
      sb.append((long)Math.floor(producerLimit / toleranceRatio));
      sb.append(").");
      Sensision.update(SensisionConstants.SENSISION_CLASS_CONTINUUM_THROTTLING_GTS,labels,1);
      Sensision.update(SensisionConstants.SENSISION_CLASS_CONTINUUM_THROTTLING_GTS_GLOBAL,Sensision.EMPTY_LABELS,1);
      throw new WarpException(sb.toString());
    }
    producerHLLP.aggregate(hash);
    Sensision.set(SensisionConstants.SENSISION_CLASS_CONTINUUM_GTS_DISTINCT,labels,producerHLLP.cardinality());
  }
 catch (  IOException ioe) {
  }
}

public static void checkMADS ( Metadata metadata , String producer , String owner , String application , long classId , long labelsId ) throws WarpException { if ( ! loaded ) { return ; } Long oProducerLimit = producerMADSLimits . get ( producer ) ; Long oApplicationLimit = applicationMADSLimits . get ( application ) ; if ( null == oProducerLimit ) { oProducerLimit = DEFAULT_MADS_PRODUCER ; if ( - 1 == oProducerLimit && null == oApplicationLimit ) { return ; } else if ( 0 == oProducerLimit ) { Map < String , String > labels = new HashMap < String , String > ( ) ; labels . put ( SensisionConstants . SENSISION_LABEL_PRODUCER , producer ) ; StringBuilder sb = new StringBuilder ( ) ; sb . append ( "Geo Time Series " ) ; GTSHelper . metadataToString ( sb , metadata . getName ( ) , metadata . getLabels ( ) ) ; sb . append ( " would exceed your Monthly Active Data Streams limit (" ) ; sb . append ( oProducerLimit ) ; sb . append ( ")." ) ; Sensision . update ( SensisionConstants . SENSISION_CLASS_CONTINUUM_THROTTLING_GTS , labels , 1 ) ; Sensision . update ( SensisionConstants . SENSISION_CLASS_CONTINUUM_THROTTLING_GTS_GLOBAL , Sensision . EMPTY_LABELS , 1 ) ; throw new WarpException ( sb . toString ( ) ) ; } oProducerLimit = ( long ) Math . ceil ( oProducerLimit * toleranceRatio ) ; } long producerLimit = oProducerLimit ; HyperLogLogPlus producerHLLP ; synchronized ( producerHLLPEstimators ) { producerHLLP = producerHLLPEstimators . get ( producer ) ; if ( null == producerHLLP || producerHLLP . hasExpired ( ) ) { producerHLLP = new HyperLogLogPlus ( DEFAULT_P , DEFAULT_PPRIME ) ; try { producerHLLP . toNormal ( ) ; } catch ( IOException ioe ) { throw new WarpException ( ioe ) ; } producerHLLP . setKey ( producer ) ; producerHLLPEstimators . put ( producer , producerHLLP ) ; } } long hash = GTSHelper . gtsId ( SIP_KEYS , classId , labelsId ) ; boolean newForProducer = producerHLLP . isNew ( hash ) ; if ( ! newForProducer && null == oApplicationLimit ) { return ; } HyperLogLogPlus applicationHLLP = null ; long applicationLimit = Long . MIN_VALUE ; if ( null != oApplicationLimit ) { applicationLimit = oApplicationLimit ; synchronized ( applicationHLLPEstimators ) { applicationHLLP = applicationHLLPEstimators . get ( application ) ; if ( null == applicationHLLP || applicationHLLP . hasExpired ( ) ) { applicationHLLP = new HyperLogLogPlus ( DEFAULT_P , DEFAULT_PPRIME ) ; try { applicationHLLP . toNormal ( ) ; } catch ( IOException ioe ) { throw new WarpException ( ioe ) ; } applicationHLLP . setKey ( APPLICATION_PREFIX_CHAR + application ) ; applicationHLLPEstimators . put ( application , applicationHLLP ) ; } } } if ( null != applicationHLLP ) { if ( ! applicationHLLP . isNew ( hash ) ) { return ; } try { long cardinality = applicationHLLP . cardinality ( ) ; Map < String , String > labels = new HashMap < String , String > ( ) ; labels . put ( SensisionConstants . SENSISION_LABEL_APPLICATION , application ) ; if ( cardinality > applicationLimit ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( "Geo Time Series " ) ; GTSHelper . metadataToString ( sb , metadata . getName ( ) , metadata . getLabels ( ) ) ; sb . append ( " would exceed your Monthly Active Data Streams limit for application '" + application + "' (" ) ; sb . append ( ( long ) Math . floor ( applicationLimit / toleranceRatio ) ) ; sb . append ( ")." ) ; Sensision . update ( SensisionConstants . SENSISION_CLASS_CONTINUUM_THROTTLING_GTS_PER_APP , labels , 1 ) ; Sensision . update ( SensisionConstants . SENSISION_CLASS_CONTINUUM_THROTTLING_GTS_PER_APP_GLOBAL , Sensision . EMPTY_LABELS , 1 ) ; throw new WarpException ( sb . toString ( ) ) ; } applicationHLLP . aggregate ( hash ) ; Sensision . set ( SensisionConstants . SENSISION_CLASS_CONTINUUM_GTS_DISTINCT_PER_APP , labels , applicationHLLP . cardinality ( ) ) ; } catch ( IOException ioe ) { } } try { long cardinality = producerHLLP . cardinality ( ) ; Map < String , String > labels = new HashMap < String , String > ( ) ; labels . put ( SensisionConstants . SENSISION_LABEL_PRODUCER , producer ) ; if ( cardinality > producerLimit ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( "Geo Time Series " ) ; GTSHelper . metadataToString ( sb , metadata . getName ( ) , metadata . getLabels ( ) ) ; sb . append ( " would exceed your Monthly Active Data Streams limit (" ) ; sb . append ( ( long ) Math . floor ( producerLimit / toleranceRatio ) ) ; sb . append ( ")." ) ; Sensision . update ( SensisionConstants . SENSISION_CLASS_CONTINUUM_THROTTLING_GTS , labels , 1 ) ; Sensision . update ( SensisionConstants . SENSISION_CLASS_CONTINUUM_THROTTLING_GTS_GLOBAL , Sensision . EMPTY_LABELS , 1 ) ; throw new WarpException ( sb . toString ( ) ) ; } producerHLLP . aggregate ( hash ) ; Sensision . set ( SensisionConstants . SENSISION_CLASS_CONTINUUM_GTS_DISTINCT , labels , producerHLLP . cardinality ( ) ) ; } catch ( IOException ioe ) { } }
check compatibility of a gts with the current mads limit
