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

com.tapstream.sdk.OneTimeOnlyEventTracker Maven / Gradle / Ivy

There is a newer version: 4.0.0
Show newest version
package com.tapstream.sdk;

import java.util.HashSet;
import java.util.Set;

public class OneTimeOnlyEventTracker {

    private final Platform platform;
    private final Set eventsAlreadyFired;
    private final Set eventsInProgress;

    public OneTimeOnlyEventTracker(Platform platform){
        this.platform = platform;
        this.eventsAlreadyFired = platform.loadFiredEvents();
        this.eventsInProgress = new HashSet();
    }

    synchronized public boolean hasBeenAlreadySent(Event event){
        if (!event.isOneTimeOnly())
            return false;
        return eventsAlreadyFired.contains(event.getName()) || eventsInProgress.contains(event.getName());
    }

    synchronized public void sent(Event event){
        if (!event.isOneTimeOnly())
            return;
        eventsInProgress.remove(event.getName());
        eventsAlreadyFired.add(event.getName());
        platform.saveFiredEvents(eventsAlreadyFired);
    }

    synchronized public void failed(Event event){
        sent(event);
    }

    synchronized public void inProgress(Event event){
        if (!event.isOneTimeOnly())
            return;
        eventsInProgress.add(event.getName());
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy