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:
Nick Burch
2010-07-20 11:24:09 +00:00
parent 0844595d01
commit 44f1aa459b
3 changed files with 122 additions and 12 deletions

View File

@@ -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"
);
// TODO Re-generate
// Re-save into the cache, so it's there for
// next time
executingActionsCache.put(key, details);
}
// Retrieve from the cache, and see if cancellation
// 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);
}
}

View File

@@ -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,8 +30,10 @@ 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;
}
}

View File

@@ -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;
}