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 = 1000*60*10; // Ten minutes.
    private ConcurrentHashMap processing;

    public synchronized boolean isAlreadyBeingProcessed(String key) {
        Long histTime = getProcessing().get(key);
        long currTime = System.currentTimeMillis();
        if (histTime == null) {
        	add(key);
            return false;
        } else {
            if ((currTime - histTime) > TIME_TO_LIVE) {
                remove(key);
                add(key);
                return false;
            } else {
                return true;
            }
        }
    }

    protected 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