io.fluxcapacitor.javaclient.tracking.TransactionManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-client Show documentation
Show all versions of java-client Show documentation
Default Java client library for interfacing with Flux Capacitor.
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();
}
}