All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hmsonline.cassandra.triggers.ProcessingManager Maven / Gradle / Ivy

package com.hmsonline.cassandra.triggers;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @author Isaac Rieksts
 *
 */
public class ProcessingManager {
  private static long TIME_TO_LIVE = 5000;
  private ConcurrentHashMap processing;

  public boolean isAlreadyBeingProcessed(String key) {
    Long histTime = getProcessing().get(key);
    long currTime = System.currentTimeMillis();
    if(histTime == null) {
      return false;
    }
    else {
      if((currTime - histTime) > TIME_TO_LIVE) {
        remove(key);
        return false;
      }
      else {
        return true;
      }
    }
  }
  
  public void add(String key) {
    getProcessing().put(key, System.currentTimeMillis());
  }
  
  public void remove(String key) {
    getProcessing().remove(key);
  }
  
  /**
   * @return the history
   */
  protected ConcurrentHashMap getProcessing() {
    if(processing == null) {
      processing = new ConcurrentHashMap();
    }
    return processing;
  }

  /**
   * @param history the history to set
   */
  protected void setHistory(ConcurrentHashMap history) {
    this.processing = history;
  }
  
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy