From 275d0bbf555c8917be82ce4cc21eb4cabb00f4c5 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Fri, 3 Oct 2014 17:30:41 +0200 Subject: Huge exception overhaul: Merged ClusterStorageException with PersistencyException. Replaced MembershipException with InvalidCollectionModification CORBA Exception. Made all predef steps throw more accurate exceptions when they go wrong, and let more exceptions bubble through from underneath. --- .../com/c2kernel/lifecycle/instance/Activity.java | 103 ++++++++++++--------- 1 file changed, 61 insertions(+), 42 deletions(-) (limited to 'src/main/java/com/c2kernel/lifecycle/instance/Activity.java') diff --git a/src/main/java/com/c2kernel/lifecycle/instance/Activity.java b/src/main/java/com/c2kernel/lifecycle/instance/Activity.java index a0fe6a0..70b991d 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/Activity.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/Activity.java @@ -26,11 +26,14 @@ import java.util.Map; import java.util.Vector; import com.c2kernel.common.AccessRightsException; +import com.c2kernel.common.CannotManage; import com.c2kernel.common.GTimeStamp; -import com.c2kernel.common.InvalidDataException; -import com.c2kernel.common.InvalidTransitionException; -import com.c2kernel.common.ObjectAlreadyExistsException; -import com.c2kernel.common.ObjectNotFoundException; +import com.c2kernel.common.InvalidCollectionModification; +import com.c2kernel.common.InvalidData; +import com.c2kernel.common.InvalidTransition; +import com.c2kernel.common.ObjectAlreadyExists; +import com.c2kernel.common.ObjectCannotBeUpdated; +import com.c2kernel.common.ObjectNotFound; import com.c2kernel.common.PersistencyException; import com.c2kernel.entity.agent.Job; import com.c2kernel.events.Event; @@ -45,7 +48,6 @@ import com.c2kernel.lookup.InvalidAgentPathException; import com.c2kernel.lookup.ItemPath; import com.c2kernel.lookup.Path; import com.c2kernel.lookup.RolePath; -import com.c2kernel.persistency.ClusterStorageException; import com.c2kernel.persistency.outcome.Outcome; import com.c2kernel.persistency.outcome.Schema; import com.c2kernel.persistency.outcome.Viewpoint; @@ -101,13 +103,13 @@ public class Activity extends WfVertex return new Next(this, vertex); } - public StateMachine getStateMachine() throws InvalidDataException { + public StateMachine getStateMachine() throws InvalidData { if (machine == null) { String name = (String)getProperties().get("StateMachineName"); int version = getVersionNumberProperty("StateMachineVersion"); try { machine = LocalObjectLoader.getStateMachine(name, version); - } catch (ObjectNotFoundException ex) { + } catch (ObjectNotFound ex) { if (name.equals(getDefaultSMName()) && version == 0) { // default state machine not imported yet. Fake it. try { String marshalledSM = Gateway.getResource().getTextResource(null, "boot/SM/"+getDefaultSMName()+".xml"); @@ -117,24 +119,24 @@ public class Activity extends WfVertex return bootstrap; } catch (Exception ex2) { Logger.error(ex2); - throw new InvalidDataException("Could not bootstrap default state machine from resources.", ""); + throw new InvalidData("Could not bootstrap default state machine from resources."); } } Logger.error(ex); - throw new InvalidDataException("Error loading state machine '"+name+"' v"+version, ""); + throw new InvalidData("Error loading state machine '"+name+"' v"+version); } } return machine; } /** return the current State of the State machine (Used in Serialisation) */ - public int getState() throws InvalidDataException + public int getState() throws InvalidData { if (state == -1) state = getStateMachine().getInitialStateCode(); return state; } - public String getStateName() throws InvalidDataException + public String getStateName() throws InvalidData { return getStateMachine().getState(getState()).getName(); } @@ -145,15 +147,19 @@ public class Activity extends WfVertex this.state = state; } - public boolean isFinished() throws InvalidDataException { + public boolean isFinished() throws InvalidData { return getStateMachine().getState(getState()).isFinished(); } /** cf Item request - * @throws ObjectNotFoundException - * @throws PersistencyException */ - public String request(AgentPath agent, ItemPath itemPath, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectNotFoundException, PersistencyException + * @throws ObjectNotFound + * @throws PersistencyException + * @throws ObjectAlreadyExists + * @throws ObjectCannotBeUpdated + * @throws CannotManage + * @throws InvalidCollectionModification */ + public String request(AgentPath agent, ItemPath itemPath, int transitionID, String requestData) throws AccessRightsException, InvalidTransition, InvalidData, ObjectNotFound, PersistencyException, ObjectAlreadyExists, ObjectCannotBeUpdated, CannotManage, InvalidCollectionModification { // Find requested transition @@ -172,7 +178,7 @@ public class Activity extends WfVertex if (requestData != null && requestData.length()>0) storeOutcome = true; else if (transition.getOutcome().isRequired()) - throw new InvalidDataException("Transition requires outcome data, but none was given", ""); + throw new InvalidData("Transition requires outcome data, but none was given"); } // Get new state @@ -212,10 +218,10 @@ public class Activity extends WfVertex Gateway.getStorage().put(itemPath, currentView, getWf()); } Gateway.getStorage().commit(getWf()); - } catch (ClusterStorageException ex) { + } catch (PersistencyException ex) { Logger.error(ex); Gateway.getStorage().abort(getWf()); - throw new PersistencyException("Exception storing event data"); + throw ex; } if (newState.isFinished()) { @@ -231,7 +237,7 @@ public class Activity extends WfVertex try { RolePath myRole = Gateway.getLookup().getRolePath(agentRole); pushJobsToAgents(itemPath, myRole); - } catch (ObjectNotFoundException ex) { // non-existent role + } catch (ObjectNotFound ex) { // non-existent role Logger.msg(7, "Activity.pushJobsToAgents() - Activity role '"+agentRole+" not found."); } } @@ -241,7 +247,15 @@ public class Activity extends WfVertex } protected String runActivityLogic(AgentPath agent, ItemPath itemPath, - int transitionID, String requestData) throws InvalidDataException { + int transitionID, String requestData) throws + InvalidData, + InvalidCollectionModification, + ObjectAlreadyExists, + ObjectCannotBeUpdated, + ObjectNotFound, + PersistencyException, + CannotManage + { // Overriden in predefined steps return requestData; } @@ -309,13 +323,14 @@ public class Activity extends WfVertex return loop2; } /** sets the next activity available if possible - * @throws ObjectNotFoundException + * @throws ObjectNotFound * @throws AccessRightsException - * @throws InvalidTransitionException + * @throws InvalidTransition * @throws PersistencyException - * @throws ObjectAlreadyExistsException */ + * @throws ObjectAlreadyExists + * @throws ObjectCannotBeUpdated */ @Override - public void runNext(AgentPath agent, ItemPath itemPath) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException + public void runNext(AgentPath agent, ItemPath itemPath) throws InvalidData { setActive(false); try @@ -353,7 +368,7 @@ public class Activity extends WfVertex } } } - catch (InvalidDataException s) + catch (InvalidData s) { setActive(true); throw s; @@ -368,10 +383,10 @@ public class Activity extends WfVertex return null; } /** reinitialises the Activity and propagate (for Loop) - * @throws InvalidDataException - * @throws ObjectNotFoundException */ + * @throws InvalidData + * @throws ObjectNotFound */ @Override - public void reinit(int idLoop) throws InvalidDataException + public void reinit(int idLoop) throws InvalidData { Vertex[] outVertices = getOutGraphables(); setState(getStateMachine().getInitialState().getId()); @@ -391,15 +406,16 @@ public class Activity extends WfVertex } /** * called by precedent Activity runNext() for setting the activity able to be executed - * @throws InvalidDataException - * @throws ObjectAlreadyExistsException + * @throws InvalidData + * @throws ObjectAlreadyExists * @throws AccessRightsException - * @throws InvalidTransitionException - * @throws ObjectNotFoundException + * @throws InvalidTransition + * @throws ObjectNotFound * @throws PersistencyException + * @throws ObjectCannotBeUpdated */ @Override - public void run(AgentPath agent, ItemPath itemPath) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException + public void run(AgentPath agent, ItemPath itemPath) throws InvalidData { Logger.debug(8, getPath() + " run " + getState()); @@ -417,15 +433,16 @@ public class Activity extends WfVertex } /** * sets the activity available to be executed on start of Workflow or composite activity (when it is the first one of the (sub)process - * @throws InvalidDataException - * @throws ObjectAlreadyExistsException - * @throws ObjectNotFoundException + * @throws InvalidData + * @throws ObjectAlreadyExists + * @throws ObjectNotFound * @throws AccessRightsException - * @throws InvalidTransitionException + * @throws InvalidTransition * @throws PersistencyException + * @throws ObjectCannotBeUpdated */ @Override - public void runFirst(AgentPath agent, ItemPath itemPath) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException + public void runFirst(AgentPath agent, ItemPath itemPath) throws InvalidData { Logger.debug(8, getPath() + " runfirst"); run(agent, itemPath); @@ -458,17 +475,19 @@ public class Activity extends WfVertex /** * returns the lists of jobs for the activity and children (cf com.c2kernel.entity.Job) + * @throws InvalidData + * @throws ObjectNotFound * @throws InvalidAgentPathException */ - public ArrayList calculateJobs(AgentPath agent, ItemPath itemPath, boolean recurse) throws ObjectNotFoundException, InvalidDataException, InvalidAgentPathException + public ArrayList calculateJobs(AgentPath agent, ItemPath itemPath, boolean recurse) throws InvalidAgentPathException, ObjectNotFound, InvalidData { return calculateJobsBase(agent, itemPath, false); } // - public ArrayList calculateAllJobs(AgentPath agent, ItemPath itemPath, boolean recurse) throws ObjectNotFoundException, InvalidDataException, InvalidAgentPathException + public ArrayList calculateAllJobs(AgentPath agent, ItemPath itemPath, boolean recurse) throws InvalidAgentPathException, ObjectNotFound, InvalidData { return calculateJobsBase(agent, itemPath, true); } - private ArrayList calculateJobsBase(AgentPath agent, ItemPath itemPath, boolean includeInactive) throws ObjectNotFoundException, InvalidDataException, InvalidAgentPathException + private ArrayList calculateJobsBase(AgentPath agent, ItemPath itemPath, boolean includeInactive) throws ObjectNotFound, InvalidData, InvalidAgentPathException { Logger.msg(7, "calculateJobs - " + getPath()); ArrayList jobs = new ArrayList(); @@ -491,7 +510,7 @@ public class Activity extends WfVertex try { RolePath myRole = Gateway.getLookup().getRolePath(agentRole); pushJobsToAgents(itemPath, myRole); - } catch (ObjectNotFoundException ex) { // non-existent role + } catch (ObjectNotFound ex) { // non-existent role Logger.msg(7, "Activity.pushJobsToAgents() - Activity role '"+agentRole+" not found."); } } -- cgit v1.2.3