use std::marker::PhantomData;
use super::{ExecutionLogger, executor_lock_builder::ExecutorLockBuilder};
use crate::lock::Lock;
#[derive(Debug, Default, Clone)]
pub struct ExecutorBuilder {
logger: ExecutionLogger,
catch_panics: bool,
}
impl ExecutorBuilder {
#[inline]
pub fn log_unmet_condition(mut self, level: log::Level, message: impl Into<String>) -> Self {
self.logger.set_unmet_condition(Some(level), message);
self
}
#[inline]
pub fn disable_unmet_condition_logging(mut self) -> Self {
self.logger.disable_unmet_condition();
self
}
#[inline]
pub fn log_prepare_failure(
mut self,
level: log::Level,
message_prefix: impl Into<String>,
) -> Self {
self.logger.set_prepare_failure(Some(level), message_prefix);
self
}
#[inline]
pub fn disable_prepare_failure_logging(mut self) -> Self {
self.logger.disable_prepare_failure();
self
}
#[inline]
pub fn log_prepare_commit_failure(
mut self,
level: log::Level,
message_prefix: impl Into<String>,
) -> Self {
self.logger
.set_prepare_commit_failure(Some(level), message_prefix);
self
}
#[inline]
pub fn disable_prepare_commit_failure_logging(mut self) -> Self {
self.logger.disable_prepare_commit_failure();
self
}
#[inline]
pub fn log_prepare_rollback_failure(
mut self,
level: log::Level,
message_prefix: impl Into<String>,
) -> Self {
self.logger
.set_prepare_rollback_failure(Some(level), message_prefix);
self
}
#[inline]
pub fn disable_prepare_rollback_failure_logging(mut self) -> Self {
self.logger.disable_prepare_rollback_failure();
self
}
#[inline]
pub fn on<L, T>(self, lock: L) -> ExecutorLockBuilder<L, T>
where
L: Lock<T>,
{
ExecutorLockBuilder {
lock,
logger: self.logger,
catch_panics: self.catch_panics,
_phantom: PhantomData,
}
}
#[inline]
pub fn catch_panics(mut self) -> Self {
self.catch_panics = true;
self
}
#[inline]
pub fn set_catch_panics(mut self, catch_panics: bool) -> Self {
self.catch_panics = catch_panics;
self
}
#[inline]
pub fn disable_catch_panics(mut self) -> Self {
self.catch_panics = false;
self
}
}