[Major] Pass activity locator, not Activity when archiving

This commit is contained in:
Robert von Burg 2021-09-28 16:54:55 +02:00
parent 86a23fa056
commit f88a80ae1c
3 changed files with 9 additions and 8 deletions

View File

@ -147,7 +147,7 @@ public class Controller {
if (this.activity.getState().isExecuted()) { if (this.activity.getState().isExecuted()) {
this.executionHandler.removeFromExecution(this); this.executionHandler.removeFromExecution(this);
logger.info("Archiving executed activity " + this.locator + " with state " + this.activity.getState()); logger.info("Archiving executed activity " + this.locator + " with state " + this.activity.getState());
this.executionHandler.archiveActivity(this.realm, this.activity); this.executionHandler.archiveActivity(this.realm, this.activity.getLocator());
return false; return false;
} }

View File

@ -217,6 +217,7 @@ public class EventBasedExecutionHandler extends ExecutionHandler {
return; return;
} }
//noinspection SynchronizeOnNonFinalField
synchronized (this.controllers) { synchronized (this.controllers) {
Map<Locator, Controller> controllers = this.controllers.getMap(realm); Map<Locator, Controller> controllers = this.controllers.getMap(realm);
if (controllers != null) if (controllers != null)
@ -409,24 +410,24 @@ public class EventBasedExecutionHandler extends ExecutionHandler {
} }
@Override @Override
public void archiveActivity(String realm, Activity activity) { public void archiveActivity(String realm, Locator activityLoc) {
getExecutor().execute(() -> { getExecutor().execute(() -> {
try { try {
runAsAgent(ctx -> { runAsAgent(ctx -> {
try (StrolchTransaction tx = openTx(realm, ctx.getCertificate(), ArchiveActivityCommand.class, try (StrolchTransaction tx = openTx(realm, ctx.getCertificate(), ArchiveActivityCommand.class,
false)) { false)) {
ArchiveActivityCommand command = new ArchiveActivityCommand(tx); ArchiveActivityCommand command = new ArchiveActivityCommand(tx);
command.setActivityLoc(activity.getLocator()); command.setActivityLoc(activityLoc);
tx.addCommand(command); tx.addCommand(command);
tx.commitOnClose(); tx.commitOnClose();
} }
}); });
} catch (Exception e) { } catch (Exception e) {
logger.error("Failed to archive " + activity.getLocator() + " due to " + e.getMessage(), e); logger.error("Failed to archive " + activityLoc + " due to " + e.getMessage(), e);
if (getContainer().hasComponent(OperationsLog.class)) { if (getContainer().hasComponent(OperationsLog.class)) {
getComponent(OperationsLog.class).addMessage( getComponent(OperationsLog.class).addMessage(
new LogMessage(realm, SYSTEM_USER_AGENT, activity.getLocator(), LogSeverity.Exception, new LogMessage(realm, SYSTEM_USER_AGENT, activityLoc, LogSeverity.Exception,
LogMessageState.Information, ResourceBundle.getBundle("strolch-service"), LogMessageState.Information, ResourceBundle.getBundle("strolch-service"),
"execution.handler.failed.archive").withException(e).value("reason", e)); "execution.handler.failed.archive").withException(e).value("reason", e));
} }

View File

@ -188,10 +188,10 @@ public abstract class ExecutionHandler extends StrolchComponent {
* *
* @param realm * @param realm
* the realm where the activity resides * the realm where the activity resides
* @param activity * @param activityLoc
* the {@link Activity} * the {@link Locator} of the {@link Activity} to archive
*/ */
public abstract void archiveActivity(String realm, Activity activity); public abstract void archiveActivity(String realm, Locator activityLoc);
/** /**
* Returns the {@link Set} of {@link Locator Locators} of {@link Activity Activities} which are registered for * Returns the {@link Set} of {@link Locator Locators} of {@link Activity Activities} which are registered for