mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Further ActionTrackingService work
Documentation on DTOs, and flesh out more of the logic. Existing unit tests still happy despite the new features, new unit tests to follow git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@21294 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -112,7 +112,9 @@ public class ActionTrackingServiceImpl implements ActionTrackingService
|
||||
runtimeActionService.saveActionImpl(action.getNodeRef(), action);
|
||||
}
|
||||
|
||||
// TODO Remove it from the cache
|
||||
// Remove it from the cache, as it's finished
|
||||
String key = generateCacheKey(action);
|
||||
executingActionsCache.remove(key);
|
||||
}
|
||||
|
||||
public void recordActionExecuting(Action action)
|
||||
@@ -121,6 +123,8 @@ public class ActionTrackingServiceImpl implements ActionTrackingService
|
||||
((ActionImpl)action).setExecutionStartDate(new Date());
|
||||
((ActionImpl)action).setExecutionStatus(ActionStatus.Running);
|
||||
|
||||
// TODO assign it a (unique) execution ID
|
||||
|
||||
// TODO Put it into the cache
|
||||
}
|
||||
|
||||
@@ -139,8 +143,11 @@ public class ActionTrackingServiceImpl implements ActionTrackingService
|
||||
((ActionImpl)action).setExecutionStatus(ActionStatus.Failed);
|
||||
((ActionImpl)action).setExecutionFailureMessage(exception.getMessage());
|
||||
|
||||
// TODO Take it out of the cache
|
||||
// Remove it from the cache, as it's no longer running
|
||||
String key = generateCacheKey(action);
|
||||
executingActionsCache.remove(key);
|
||||
|
||||
// Do we need to update the persisted details?
|
||||
if(action.getNodeRef() != null)
|
||||
{
|
||||
// Take a local copy of the details
|
||||
@@ -203,12 +210,25 @@ public class ActionTrackingServiceImpl implements ActionTrackingService
|
||||
// status executing, then put it back into the
|
||||
// cache and warn
|
||||
// (Probably means the cache is too small)
|
||||
String key = generateCacheKey(action);
|
||||
ExecutionDetails details = getExecutionDetails(buildExecutionSummary(key));
|
||||
if(details == null) {
|
||||
logger.warn(
|
||||
"Unable to check cancellation status for running action " +
|
||||
action + " as it wasn't in the running actions cache! " +
|
||||
"Your running actions cache is probably too small"
|
||||
);
|
||||
|
||||
// Retrieve from the cache, and see if cancellation
|
||||
// TODO Re-generate
|
||||
|
||||
// Re-save into the cache, so it's there for
|
||||
// next time
|
||||
executingActionsCache.put(key, details);
|
||||
}
|
||||
|
||||
// Check the cached details, and see if cancellation
|
||||
// has been requested
|
||||
|
||||
// TODO
|
||||
return false;
|
||||
return details.isCancelRequested();
|
||||
}
|
||||
|
||||
public void requestActionCancellation(CancellableAction action)
|
||||
@@ -236,7 +256,9 @@ public class ActionTrackingServiceImpl implements ActionTrackingService
|
||||
}
|
||||
|
||||
// Since it is, update the cancelled flag on it
|
||||
// TODO
|
||||
details.requestCancel();
|
||||
|
||||
// Save the flag to the cache
|
||||
executingActionsCache.put(actionKey, details);
|
||||
}
|
||||
|
||||
@@ -274,9 +296,13 @@ public class ActionTrackingServiceImpl implements ActionTrackingService
|
||||
}
|
||||
|
||||
public ExecutionDetails getExecutionDetails(ExecutionSummary executionSummary) {
|
||||
return executingActionsCache.get(
|
||||
ExecutionDetails details = executingActionsCache.get(
|
||||
generateCacheKey(executionSummary)
|
||||
);
|
||||
if(details != null) {
|
||||
details.setExecutionSummary(executionSummary);
|
||||
}
|
||||
return details;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -312,5 +338,4 @@ public class ActionTrackingServiceImpl implements ActionTrackingService
|
||||
|
||||
return new ExecutionSummary(actionType, actionId, executionInstance);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package org.alfresco.service.cmr.action;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
@@ -29,7 +30,9 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
*
|
||||
* @author Nick Burch
|
||||
*/
|
||||
public class ExecutionDetails {
|
||||
public class ExecutionDetails implements Serializable {
|
||||
private static final long serialVersionUID = 8002491363996364589L;
|
||||
|
||||
/*
|
||||
* Transient as all the info is held in the key,
|
||||
* we don't need to also hold a 2nd copy of it
|
||||
@@ -39,4 +42,70 @@ public class ExecutionDetails {
|
||||
private String runningOn;
|
||||
private Date startedAt;
|
||||
private boolean cancelRequested;
|
||||
|
||||
public ExecutionDetails() {}
|
||||
|
||||
public ExecutionDetails(ExecutionSummary executionSummary,
|
||||
NodeRef persistedActionRef, String runningOn, Date startedAt,
|
||||
boolean cancelRequested) {
|
||||
this.executionSummary = executionSummary;
|
||||
this.persistedActionRef = persistedActionRef;
|
||||
this.runningOn = runningOn;
|
||||
this.startedAt = startedAt;
|
||||
this.cancelRequested = cancelRequested;
|
||||
}
|
||||
|
||||
public ExecutionSummary getExecutionSummary() {
|
||||
return executionSummary;
|
||||
}
|
||||
public void setExecutionSummary(ExecutionSummary executionSummary) {
|
||||
this.executionSummary = executionSummary;
|
||||
}
|
||||
|
||||
/**
|
||||
* What kind of action is this?
|
||||
* @return The action type, typically an executor bean name
|
||||
*/
|
||||
public String getActionType() {
|
||||
return executionSummary.getActionType();
|
||||
}
|
||||
|
||||
/**
|
||||
* What is the id of the action?
|
||||
* @return The action ID
|
||||
*/
|
||||
public String getActionId() {
|
||||
return executionSummary.getActionId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Which instance of the action is this?
|
||||
* Every time you start an action, it gets
|
||||
* a new instance ID, and this lets you
|
||||
* tell the difference between two copies
|
||||
* running in parallel.
|
||||
* @return The instance ID
|
||||
*/
|
||||
public int getExecutionInstance() {
|
||||
return executionSummary.getExecutionInstance();
|
||||
}
|
||||
|
||||
public NodeRef getPersistedActionRef() {
|
||||
return persistedActionRef;
|
||||
}
|
||||
|
||||
public String getRunningOn() {
|
||||
return runningOn;
|
||||
}
|
||||
|
||||
public Date getStartedAt() {
|
||||
return startedAt;
|
||||
}
|
||||
|
||||
public boolean isCancelRequested() {
|
||||
return cancelRequested;
|
||||
}
|
||||
public void requestCancel() {
|
||||
cancelRequested = true;
|
||||
}
|
||||
}
|
@@ -39,14 +39,30 @@ public class ExecutionSummary {
|
||||
this.executionInstance = executionInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* What kind of action is this?
|
||||
* @return The action type, typically an executor bean name
|
||||
*/
|
||||
public String getActionType() {
|
||||
return actionType;
|
||||
}
|
||||
|
||||
/**
|
||||
* What is the id of the action?
|
||||
* @return The action ID
|
||||
*/
|
||||
public String getActionId() {
|
||||
return actionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Which instance of the action is this?
|
||||
* Every time you start an action, it gets
|
||||
* a new instance ID, and this lets you
|
||||
* tell the difference between two copies
|
||||
* running in parallel.
|
||||
* @return The instance ID
|
||||
*/
|
||||
public int getExecutionInstance() {
|
||||
return executionInstance;
|
||||
}
|
||||
|
Reference in New Issue
Block a user