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

com.cqrs.read_model.OnlyOnceTracker Maven / Gradle / Ivy

package com.cqrs.read_model;

import java.util.HashMap;

public class OnlyOnceTracker {

    private final HashMap alreadyAppliedEventsByReadModel = new HashMap<>();

    public boolean isEventAlreadyApplied(ReadModel readModel, String eventId)
    {
        return alreadyAppliedEventsByReadModel.get(makeId(readModel, eventId)) != null;
    }

    public void markEventAsApplied(ReadModel readModel, String eventId)
    {
        alreadyAppliedEventsByReadModel.put(makeId(readModel, eventId), true);
    }

    private String makeId(ReadModel readModel, String eventId)
    {
        return readModel.getClass().getCanonicalName() + eventId;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy