[New] Added SimpleExecution.to*(Action, LogMessage) actions

This commit is contained in:
Robert von Burg 2023-08-03 09:58:26 +02:00
parent de5c2fe7e6
commit 7fc6c2d8c8
Signed by: eitch
GPG Key ID: 75DB9C85C74331F7
1 changed files with 42 additions and 30 deletions

View File

@ -1,10 +1,5 @@
package li.strolch.execution.policy;
import java.util.Locale;
import java.util.concurrent.ScheduledFuture;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
import li.strolch.exception.StrolchException;
import li.strolch.handler.operationslog.OperationsLog;
import li.strolch.model.State;
@ -17,6 +12,11 @@ import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.privilege.model.PrivilegeContext;
import li.strolch.utils.time.PeriodDuration;
import java.util.Locale;
import java.util.concurrent.ScheduledFuture;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
/**
* <p>
* Simple Execution Policy which sets the state of the action depending on the method called.
@ -71,11 +71,36 @@ public class SimpleExecution extends ExecutionPolicy {
setActionStateWithValueChange(action, State.EXECUTION, 1.0D);
}
@Override
public void toStopped(Action action) {
cancelWarningTask();
stop();
setActionStateWithValueChange(action, State.STOPPED, 0.0D);
}
protected void toWarning(Action action, LogMessage message) {
addMessage(message);
toWarning(action);
}
@Override
public void toWarning(Action action) {
cancelWarningTask();
setActionState(action, State.WARNING);
}
protected void toWarning(LogMessage message) {
cancelWarningTask();
addMessage(message);
getExecutionHandler().toWarning(this.realm, message.getLocator());
}
protected void toExecuted() throws Exception {
cancelWarningTask();
stop();
getExecutionHandler().toExecuted(this.realm, this.actionLoc);
}
@Override
public void toExecuted(Action action) {
cancelWarningTask();
@ -83,11 +108,10 @@ public class SimpleExecution extends ExecutionPolicy {
setActionStateWithValueChange(action, State.EXECUTED, 0.0D);
}
@Override
public void toStopped(Action action) {
cancelWarningTask();
stop();
setActionStateWithValueChange(action, State.STOPPED, 0.0D);
protected void toError(Action action, LogMessage message) {
logger.error("Action " + message.getLocator() + " failed because of: " + message.formatMessage());
addMessage(message);
toError(action);
}
@Override
@ -97,6 +121,14 @@ public class SimpleExecution extends ExecutionPolicy {
setActionStateWithValueChange(action, State.ERROR, 0.0D);
}
protected void toError(LogMessage message) {
cancelWarningTask();
stop();
logger.error("Action " + message.getLocator() + " failed because of: " + message.formatMessage());
addMessage(message);
getExecutionHandler().toError(this.realm, message.getLocator());
}
protected void setActionStateWithValueChange(Action action, State execution, double value) {
setActionState(action, execution);
action.addChange(new ValueChange<>(System.currentTimeMillis(), new FloatValue(value), ""));
@ -114,26 +146,6 @@ public class SimpleExecution extends ExecutionPolicy {
}
}
protected void toExecuted() throws Exception {
cancelWarningTask();
stop();
getExecutionHandler().toExecuted(this.realm, this.actionLoc);
}
protected void toError(LogMessage message) {
cancelWarningTask();
stop();
logger.error("Action " + message.getLocator() + " failed because of: " + message.formatMessage());
addMessage(message);
getExecutionHandler().toError(this.realm, message.getLocator());
}
protected void toWarning(LogMessage message) {
cancelWarningTask();
addMessage(message);
getExecutionHandler().toWarning(this.realm, message.getLocator());
}
protected StrolchTransaction openLocalTx(PrivilegeContext ctx, boolean readOnly) throws StrolchException {
return getContainer().getRealm(ctx.getCertificate()).openTx(ctx.getCertificate(), getClass(), readOnly);
}