/* (non-Javadoc)
  * @see org.ebayopensource.turmeric.rateLimiterCounterProvider.RateLimiterCounterProvider#incrementRLCounter(java.lang.String)
  */
 public void incrementRLCounter(final String key) {
   RateLimiterPolicyModel activeRL = activeRLDao.find(key);
   if (activeRL != null) {
     activeRL.setCount(activeRL.getCount() + 1);
     activeRLDao.save(key, activeRL);
   }
 }
 /**
  * Gets the or create active rl.
  *
  * @param key the key
  * @return the or create active rl
  */
 private RateLimiterPolicyModel getOrCreateActiveRL(String key) {
   RateLimiterPolicyModel activeRL = activeRLDao.find(key);
   if (activeRL == null) {
     activeRL = new RateLimiterPolicyModel();
   }
   return activeRL;
 }
  /**
   * Reset effect.
   *
   * @param currentSubjectOrGroup the current subject or group
   */
  private void resetEffect(String currentSubjectOrGroup) {
    if (currentSubjectOrGroup != null) {
      currentSubjectOrGroup = currentSubjectOrGroup.trim();
    }

    if (activeEffectDao.containsKey(currentSubjectOrGroup)) {
      RateLimiterPolicyModel limiterPolicyModel = activeEffectDao.find(currentSubjectOrGroup);

      // get current date
      java.util.Date date = new java.util.Date();
      if (date.after(new Date(limiterPolicyModel.getEffectDuration()))) {
        // remove it
        activeEffectDao.delete(currentSubjectOrGroup);

        if (activeRLDao.containsKey(currentSubjectOrGroup)) {
          activeRLDao.delete(currentSubjectOrGroup);
          activeRLDao.save(currentSubjectOrGroup, new RateLimiterPolicyModel());
        }
      }
    }
  }
 /* (non-Javadoc)
  * @see org.ebayopensource.turmeric.rateLimiterCounterProvider.RateLimiterCounterProvider#getActiveRL(java.lang.String)
  */
 public RateLimiterPolicyModel getActiveRL(final String key) {
   return activeRLDao.find(key);
 }
 /* (non-Javadoc)
  * @see org.ebayopensource.turmeric.rateLimiterCounterProvider.RateLimiterCounterProvider#setRLEffect(java.lang.String, org.ebayopensource.turmeric.security.v1.services.RateLimiterStatus)
  */
 public void setRLEffect(final String key, final RateLimiterStatus effect) {
   RateLimiterPolicyModel activeRL = getOrCreateActiveRL(key);
   activeRL.setEffect(effect);
   activeRLDao.save(key, activeRL);
 }
 /* (non-Javadoc)
  * @see org.ebayopensource.turmeric.rateLimiterCounterProvider.RateLimiterCounterProvider#setRLRolloverPeriod(java.lang.String, java.lang.Long)
  */
 public void setRLRolloverPeriod(final String key, final Long rollover) {
   RateLimiterPolicyModel activeRL = getOrCreateActiveRL(key);
   activeRL.setRolloverPeriod(rollover);
   activeRLDao.save(key, activeRL);
 }
 /* (non-Javadoc)
  * @see org.ebayopensource.turmeric.rateLimiterCounterProvider.RateLimiterCounterProvider#setRLEffectDuration(java.lang.String, java.lang.Long)
  */
 public void setRLEffectDuration(final String key, final Long duration) {
   RateLimiterPolicyModel activeRL = getOrCreateActiveRL(key);
   activeRL.setEffectDuration(duration);
   activeRLDao.save(key, activeRL);
 }
 /* (non-Javadoc)
  * @see org.ebayopensource.turmeric.rateLimiterCounterProvider.RateLimiterCounterProvider#setRLActive(java.lang.String, boolean)
  */
 public void setRLActive(final String key, boolean b) {
   RateLimiterPolicyModel activeRL = getOrCreateActiveRL(key);
   activeRL.setActive(b);
   activeRLDao.save(key, activeRL);
 }
 /* (non-Javadoc)
  * @see org.ebayopensource.turmeric.rateLimiterCounterProvider.RateLimiterCounterProvider#setRLTimestamp(java.lang.String, java.util.Date)
  */
 public void setRLTimestamp(final String key, final Date date) {
   RateLimiterPolicyModel activeRL = getOrCreateActiveRL(key);
   activeRL.setTimestamp(date);
   activeRLDao.save(key, activeRL);
 }
 /* (non-Javadoc)
  * @see org.ebayopensource.turmeric.rateLimiterCounterProvider.RateLimiterCounterProvider#setRLCounter(java.lang.String, int)
  */
 public void setRLCounter(final String key, int i) {
   RateLimiterPolicyModel activeRL = getOrCreateActiveRL(key);
   activeRL.setCount(i);
   activeRLDao.save(key, activeRL);
 }
 /* (non-Javadoc)
  * @see org.ebayopensource.turmeric.rateLimiterCounterProvider.RateLimiterCounterProvider#cointainKeyInActiveRL(java.lang.String)
  */
 public boolean cointainKeyInActiveRL(final String key) {
   return activeRLDao.containsKey(key);
 }
 /* (non-Javadoc)
  * @see org.ebayopensource.turmeric.rateLimiterCounterProvider.RateLimiterCounterProvider#addActiveRL(java.lang.String, org.ebayopensource.turmeric.rateLimiterCounterProvider.Policy.model.RateLimiterPolicyModel)
  */
 public void addActiveRL(final String key, final RateLimiterPolicyModel RateLimiterPolicyModel) {
   activeRLDao.save(key, (RateLimiterPolicyModel) RateLimiterPolicyModel);
 }
 /* (non-Javadoc)
  * @see org.ebayopensource.turmeric.rateLimiterCounterProvider.RateLimiterCounterProvider#getActiveRLKeys()
  */
 public Set<String> getActiveRLKeys() {
   return activeRLDao.getKeys();
 }