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

io.fluxcapacitor.javaclient.tracking.TransactionManager Maven / Gradle / Ivy

There is a newer version: 0.1015.0
Show newest version
package io.fluxcapacitor.javaclient.tracking;

import io.fluxcapacitor.common.api.tracking.MessageBatch;

import java.util.function.Consumer;

public interface TransactionManager extends BatchInterceptor {

    Transaction startTransaction();

    default void executeInTransaction(Runnable task) {
        Transaction transaction = startTransaction();
        try {
            task.run();
            transaction.commit();
        } catch (Throwable e) {
            transaction.rollback();
            throw e;
        }
    }

    @Override
    default Consumer intercept(Consumer consumer, Tracker tracker) {
        return messageBatch -> executeInTransaction(() -> consumer.accept(messageBatch));
    }

    interface Transaction {
        void commit();
        void rollback();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy