com.tapstream.sdk.OneTimeOnlyEventTracker Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tapstream-core Show documentation
Show all versions of tapstream-core Show documentation
This library contains the building blocks for a Tapstream Java SDK
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