diff --git a/source/java/org/alfresco/repo/action/ActionServiceImplTransactionalTest.java b/source/java/org/alfresco/repo/action/ActionServiceImplTransactionalTest.java index 1342b0c308..10f90c8e1a 100644 --- a/source/java/org/alfresco/repo/action/ActionServiceImplTransactionalTest.java +++ b/source/java/org/alfresco/repo/action/ActionServiceImplTransactionalTest.java @@ -245,7 +245,7 @@ public class ActionServiceImplTransactionalTest extends TestCase // Wait for the post-rollback update to complete // (The stored one gets updated asynchronously) txn.rollback(); - Thread.sleep(100); + Thread.sleep(150); txn = transactionService.getUserTransaction(); txn.begin(); @@ -283,7 +283,7 @@ public class ActionServiceImplTransactionalTest extends TestCase // End the transaction. Should allow the async action // to be executed txn.commit(); - Thread.sleep(100); + Thread.sleep(150); assertNotNull(action.getExecutionStartDate()); assertNotNull(action.getExecutionEndDate()); @@ -315,7 +315,7 @@ public class ActionServiceImplTransactionalTest extends TestCase // End the transaction. Should allow the async action // to be executed txn.commit(); - Thread.sleep(100); + Thread.sleep(150); assertNotNull(action.getExecutionStartDate()); assertNotNull(action.getExecutionEndDate()); @@ -351,7 +351,7 @@ public class ActionServiceImplTransactionalTest extends TestCase // End the transaction. Should allow the async action // to be executed txn.commit(); - Thread.sleep(100); + Thread.sleep(150); txn = transactionService.getUserTransaction(); txn.begin(); diff --git a/source/java/org/alfresco/repo/action/ActionTrackingServiceImpl.java b/source/java/org/alfresco/repo/action/ActionTrackingServiceImpl.java index 5a84e391bb..20381f7040 100644 --- a/source/java/org/alfresco/repo/action/ActionTrackingServiceImpl.java +++ b/source/java/org/alfresco/repo/action/ActionTrackingServiceImpl.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.List; +import java.util.StringTokenizer; import org.alfresco.repo.cache.EhCacheAdapter; import org.alfresco.repo.security.authentication.AuthenticationUtil; @@ -33,6 +34,8 @@ import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ActionStatus; import org.alfresco.service.cmr.action.ActionTrackingService; import org.alfresco.service.cmr.action.CancellableAction; +import org.alfresco.service.cmr.action.ExecutionDetails; +import org.alfresco.service.cmr.action.ExecutionSummary; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.transaction.TransactionService; import org.apache.commons.logging.Log; @@ -50,8 +53,7 @@ public class ActionTrackingServiceImpl implements ActionTrackingService */ private static Log logger = LogFactory.getLog(ActionTrackingServiceImpl.class); - // TODO - Fix types - private EhCacheAdapter executingActionsCache; + private EhCacheAdapter executingActionsCache; private TransactionService transactionService; private RuntimeActionService runtimeActionService; @@ -86,9 +88,8 @@ public class ActionTrackingServiceImpl implements ActionTrackingService /** * Sets the cache used to store details of * currently executing actions, cluster wide. - * TODO Fix types */ - public void setExecutingActionsCache(EhCacheAdapter executingActionsCache) + public void setExecutingActionsCache(EhCacheAdapter executingActionsCache) { this.executingActionsCache = executingActionsCache; } @@ -110,6 +111,8 @@ public class ActionTrackingServiceImpl implements ActionTrackingService { runtimeActionService.saveActionImpl(action.getNodeRef(), action); } + + // TODO Remove it from the cache } public void recordActionExecuting(Action action) @@ -117,6 +120,8 @@ public class ActionTrackingServiceImpl implements ActionTrackingService // Mark the action as starting ((ActionImpl)action).setExecutionStartDate(new Date()); ((ActionImpl)action).setExecutionStatus(ActionStatus.Running); + + // TODO Put it into the cache } /** @@ -134,6 +139,8 @@ public class ActionTrackingServiceImpl implements ActionTrackingService ((ActionImpl)action).setExecutionStatus(ActionStatus.Failed); ((ActionImpl)action).setExecutionFailureMessage(exception.getMessage()); + // TODO Take it out of the cache + if(action.getNodeRef() != null) { // Take a local copy of the details @@ -206,55 +213,70 @@ public class ActionTrackingServiceImpl implements ActionTrackingService public void requestActionCancellation(CancellableAction action) { - // See if the action is in the cache - // If it isn't, nothing to do - // If it is, update the cancelled flag on it - // TODO + requestActionCancellation( + generateCacheKey(action) + ); } - public List getAllExecutingActions() { + public void requestActionCancellation(ExecutionSummary executionSummary) + { + requestActionCancellation( + generateCacheKey(executionSummary) + ); + } + + private void requestActionCancellation(String actionKey) + { + // See if the action is in the cache + ExecutionDetails details = executingActionsCache.get(actionKey); + + if(details == null) { + // It isn't in the cache, so nothing to do + return; + } + + // Since it is, update the cancelled flag on it + // TODO + executingActionsCache.put(actionKey, details); + } + + + public List getAllExecutingActions() { Collection actions = executingActionsCache.getKeys(); - // TODO fix types - List details = new ArrayList(actions.size()); + List details = new ArrayList(actions.size()); for(String key : actions) { - //details.add( buildExecutionSummary(key) ); + details.add( buildExecutionSummary(key) ); } return details; } - public List getExecutingActions(Action action) { + public List getExecutingActions(Action action) { Collection actions = executingActionsCache.getKeys(); - // TODO fix types - List details = new ArrayList(); + List details = new ArrayList(); String match = action.getActionDefinitionName() + "-" + action.getId(); for(String key : actions) { if(key.startsWith(match)) { - //details.add( buildExecutionSummary(key) ); + details.add( buildExecutionSummary(key) ); } } return details; } - public List getExecutingActions(String type) { + public List getExecutingActions(String type) { Collection actions = executingActionsCache.getKeys(); - // TODO fix types - List details = new ArrayList(); + List details = new ArrayList(); for(String key : actions) { if(key.startsWith(type)) { - //details.add( buildExecutionSummary(key) ); + details.add( buildExecutionSummary(key) ); } } return details; } - public void getExecutionDetails(Void executionSummary) { - // TODO Auto-generated method stub - - } - - public void requestActionCancellation(Void executionSummary) { - // TODO Auto-generated method stub - + public ExecutionDetails getExecutionDetails(ExecutionSummary executionSummary) { + return executingActionsCache.get( + generateCacheKey(executionSummary) + ); } /** @@ -262,18 +284,33 @@ public class ActionTrackingServiceImpl implements ActionTrackingService */ protected String generateCacheKey(Action action) { - // TODO - return null; + return + action.getActionDefinitionName() + "-" + + action.getId() + "-" + + ""//action.getExecutionInstance // TODO + ; + } + protected String generateCacheKey(ExecutionSummary summary) + { + return + summary.getActionType() + "-" + + summary.getActionId() + "-" + + summary.getExecutionInstance() + ; } /** * Turns a cache key back into its constituent * parts, for easier access. - * TODO Fix types */ - protected void buildExecutionSummary(String key) + protected ExecutionSummary buildExecutionSummary(String key) { + StringTokenizer st = new StringTokenizer(key, "-"); + String actionType = st.nextToken(); + String actionId = st.nextToken(); + int executionInstance = Integer.parseInt(st.nextToken()); + return new ExecutionSummary(actionType, actionId, executionInstance); } } diff --git a/source/java/org/alfresco/service/cmr/action/ActionTrackingService.java b/source/java/org/alfresco/service/cmr/action/ActionTrackingService.java index 8d2dfa8a1e..9c88d76dee 100644 --- a/source/java/org/alfresco/service/cmr/action/ActionTrackingService.java +++ b/source/java/org/alfresco/service/cmr/action/ActionTrackingService.java @@ -82,10 +82,9 @@ public interface ActionTrackingService * If the specified action is not a cancellable * action, nothing will happen. * - * TODO Correct param type - is key based data only. * @param action The action to request the cancel of */ - void requestActionCancellation(Void executionSummary); + void requestActionCancellation(ExecutionSummary executionSummary); /** * Has cancellation been requested for the given @@ -104,30 +103,25 @@ public interface ActionTrackingService * Retrieves the execution details on the given * executing action, such as when it started, * and what machine it is executing on. - * TODO Correct param type - is key based data only. - * TODO Correct return type - is all cache data */ - void getExecutionDetails(Void executionSummary); + ExecutionDetails getExecutionDetails(ExecutionSummary executionSummary); /** * Retrieve summary details of all the actions * currently executing. - * TODO Correct return type - is key based data only. */ - List getAllExecutingActions(); + List getAllExecutingActions(); /** * Retrieve summary details of all the actions * of the given type that are currently executing. - * TODO Correct return type - is key based data only. */ - List getExecutingActions(String type);//or is it qname? + List getExecutingActions(String type); /** * Retrieve summary details of all instances of * the specified action that are currently * executing. - * TODO Correct return type - is key based data only. */ - List getExecutingActions(Action action); + List getExecutingActions(Action action); } diff --git a/source/java/org/alfresco/service/cmr/action/ExecutionDetails.java b/source/java/org/alfresco/service/cmr/action/ExecutionDetails.java new file mode 100644 index 0000000000..6964f5c1d8 --- /dev/null +++ b/source/java/org/alfresco/service/cmr/action/ExecutionDetails.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2005-2010 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.service.cmr.action; + +import java.util.Date; + +import org.alfresco.service.cmr.repository.NodeRef; + +/** + * Holds all the details available to the + * {@link ActionTrackingService} on a currently + * executing Action. + * + * @author Nick Burch + */ +public class ExecutionDetails { + /* + * Transient as all the info is held in the key, + * we don't need to also hold a 2nd copy of it + */ + private transient ExecutionSummary executionSummary; + private NodeRef persistedActionRef; + private String runningOn; + private Date startedAt; + private boolean cancelRequested; + } \ No newline at end of file diff --git a/source/java/org/alfresco/service/cmr/action/ExecutionSummary.java b/source/java/org/alfresco/service/cmr/action/ExecutionSummary.java new file mode 100644 index 0000000000..b1a9aa4bc0 --- /dev/null +++ b/source/java/org/alfresco/service/cmr/action/ExecutionSummary.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2005-2010 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.service.cmr.action; + +/** + * Holds core key details of an Action that is + * currently executing. + * This information is normally the limit + * of what the {@link ActionTrackingService} + * can use when filtering lists of actions. + * + * @author Nick Burch + */ +public class ExecutionSummary { + private String actionType; + private String actionId; + private int executionInstance; + + public ExecutionSummary(String actionType, String actionId, + int executionInstance) { + this.actionType = actionType; + this.actionId = actionId; + this.executionInstance = executionInstance; + } + + public String getActionType() { + return actionType; + } + + public String getActionId() { + return actionId; + } + + public int getExecutionInstance() { + return executionInstance; + } + } \ No newline at end of file