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/entity/ItemImplementation.java | 73 ++++++++++------------ 1 file changed, 32 insertions(+), 41 deletions(-) (limited to 'src/main/java/com/c2kernel/entity/ItemImplementation.java') diff --git a/src/main/java/com/c2kernel/entity/ItemImplementation.java b/src/main/java/com/c2kernel/entity/ItemImplementation.java index 23080f1..a33607b 100644 --- a/src/main/java/com/c2kernel/entity/ItemImplementation.java +++ b/src/main/java/com/c2kernel/entity/ItemImplementation.java @@ -25,10 +25,11 @@ import java.util.UUID; import com.c2kernel.collection.Collection; import com.c2kernel.collection.CollectionArrayList; import com.c2kernel.common.AccessRightsException; -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.ObjectNotFound; import com.c2kernel.common.PersistencyException; import com.c2kernel.common.SystemKey; import com.c2kernel.entity.agent.JobArrayList; @@ -43,7 +44,6 @@ import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.InvalidItemPathException; import com.c2kernel.lookup.ItemPath; import com.c2kernel.persistency.ClusterStorage; -import com.c2kernel.persistency.ClusterStorageException; import com.c2kernel.persistency.TransactionManager; import com.c2kernel.persistency.outcome.Outcome; import com.c2kernel.persistency.outcome.Viewpoint; @@ -74,7 +74,7 @@ public class ItemImplementation implements ItemOperations { @Override public void initialise(SystemKey agentId, String propString, String initWfString, String initCollsString) throws AccessRightsException, - InvalidDataException, PersistencyException + InvalidData, PersistencyException { Logger.msg(5, "Item::initialise("+mItemPath+") - agent:"+agentId); Object locker = new Object(); @@ -88,7 +88,7 @@ public class ItemImplementation implements ItemOperations { // must supply properties if (propString == null || propString.length() == 0) { - throw new InvalidDataException("No properties supplied", ""); + throw new InvalidData("No properties supplied"); } // store properties @@ -102,7 +102,7 @@ public class ItemImplementation implements ItemOperations { + ") - Properties were invalid: " + propString); Logger.error(ex); mStorage.abort(locker); - throw new InvalidDataException("Properties were invalid", ""); + throw new InvalidData("Properties were invalid"); } // Store an event and the initial properties @@ -120,7 +120,7 @@ public class ItemImplementation implements ItemOperations { + ") - Could not store event and outcome."); Logger.error(ex); mStorage.abort(locker); - throw new PersistencyException("Error storing event and outcome", ""); + throw new PersistencyException("Error storing event and outcome"); } // create wf @@ -138,7 +138,7 @@ public class ItemImplementation implements ItemOperations { + ") - Workflow was invalid: " + initWfString); Logger.error(ex); mStorage.abort(locker); - throw new InvalidDataException("Workflow was invalid", ""); + throw new InvalidData("Workflow was invalid"); } // init collections @@ -155,7 +155,7 @@ public class ItemImplementation implements ItemOperations { + initCollsString); Logger.error(ex); mStorage.abort(locker); - throw new InvalidDataException("Collections were invalid"); + throw new InvalidData("Collections were invalid"); } } @@ -173,9 +173,9 @@ public class ItemImplementation implements ItemOperations { @Override public String requestAction(SystemKey agentId, String stepPath, int transitionID, String requestData) throws AccessRightsException, - InvalidTransitionException, ObjectNotFoundException, - InvalidDataException, PersistencyException, - ObjectAlreadyExistsException { + InvalidTransition, ObjectNotFound, + InvalidData, PersistencyException, + ObjectAlreadyExists, InvalidCollectionModification { try { @@ -200,44 +200,42 @@ public class ItemImplementation implements ItemOperations { } catch (AccessRightsException ex) { Logger.msg("Propagating AccessRightsException back to the calling agent"); throw ex; - } catch (InvalidTransitionException ex) { + } catch (InvalidTransition ex) { Logger.msg("Propagating InvalidTransitionException back to the calling agent"); throw ex; - } catch (ObjectNotFoundException ex) { + } catch (ObjectNotFound ex) { Logger.msg("Propagating ObjectNotFoundException back to the calling agent"); throw ex; // errors - } catch (ClusterStorageException ex) { - Logger.error(ex); - throw new PersistencyException("Error on storage: " - + ex.getMessage(), ""); } catch (InvalidItemPathException ex) { Logger.error(ex); - throw new AccessRightsException("Invalid Agent Id: " + agentId, - ""); - } catch (InvalidDataException ex) { + throw new AccessRightsException("Invalid Agent Id: " + agentId); + } catch (InvalidData ex) { Logger.error(ex); Logger.msg("Propagating InvalidDataException back to the calling agent"); throw ex; - } catch (ObjectAlreadyExistsException ex) { + } catch (ObjectAlreadyExists ex) { Logger.error(ex); Logger.msg("Propagating ObjectAlreadyExistsException back to the calling agent"); throw ex; - // non-CORBA exception hasn't been caught! - } catch (Throwable ex) { + } catch (InvalidCollectionModification ex) { + Logger.error(ex); + Logger.msg("Propagating InvalidCollectionModification back to the calling agent"); + throw ex; + } catch (Throwable ex) { // non-CORBA exception hasn't been caught! Logger.error("Unknown Error: requestAction on " + mItemPath + " by " + agentId + " executing " + stepPath); Logger.error(ex); - throw new InvalidDataException( + throw new InvalidData( "Extraordinary Exception during execution:" + ex.getClass().getName() + " - " - + ex.getMessage(), ""); + + ex.getMessage()); } } @Override public String queryLifeCycle(SystemKey agentId, boolean filter) - throws AccessRightsException, ObjectNotFoundException, + throws AccessRightsException, ObjectNotFound, PersistencyException { Logger.msg(1, "TraceableEntity::queryLifeCycle(" + mItemPath + ") - agent: " + agentId); @@ -250,15 +248,8 @@ public class ItemImplementation implements ItemOperations { + " doesn't exist"); } Workflow wf; - try { - wf = (Workflow) mStorage.get(mItemPath, - ClusterStorage.LIFECYCLE + "/workflow", null); - } catch (ClusterStorageException e) { - Logger.error("TraceableEntity::queryLifeCycle(" - + mItemPath + ") - Error loading workflow"); - Logger.error(e); - throw new PersistencyException("Error loading workflow"); - } + wf = (Workflow) mStorage.get(mItemPath, + ClusterStorage.LIFECYCLE + "/workflow", null); JobArrayList jobBag = new JobArrayList(); CompositeActivity domainWf = (CompositeActivity) wf .search("workflow/domain"); @@ -284,7 +275,7 @@ public class ItemImplementation implements ItemOperations { @Override public String queryData(String path) throws AccessRightsException, - ObjectNotFoundException, PersistencyException { + ObjectNotFound, PersistencyException { String result = ""; @@ -312,13 +303,13 @@ public class ItemImplementation implements ItemOperations { // marshall it, or in the case of an outcome get the data. result = Gateway.getMarshaller().marshall(obj); } - } catch (ObjectNotFoundException ex) { + } catch (ObjectNotFound ex) { throw ex; } catch (Throwable ex) { Logger.warning("TraceableEntity::queryData(" + mItemPath + ") - " + path + " Failed: " + ex.getClass().getName()); throw new PersistencyException("Server exception: " - + ex.getClass().getName(), ""); + + ex.getClass().getName()); } if (Logger.doLog(9)) -- cgit v1.2.3