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

org.codegas.commons.domain.event.DomainEventPublisherManager Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package org.codegas.commons.domain.event;

public class DomainEventPublisherManager {

    private static final ThreadLocal LOCAL_CONTEXT_COUNT = ThreadLocal.withInitial(() -> 0);

    public void enterPublishingContext() {
        int count = LOCAL_CONTEXT_COUNT.get();
        if (count == 0) {
            DomainEventPublisher.instance().reset();
        }
        LOCAL_CONTEXT_COUNT.set(count + 1);
    }

    public void exitPublishingContext() {
        int count = LOCAL_CONTEXT_COUNT.get() - 1;
        if (count == 0) {
            DomainEventPublisher.instance().reset();
        }
        LOCAL_CONTEXT_COUNT.set(count);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy