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/persistency/ClusterStorage.java | 27 +++++++------ .../persistency/ClusterStorageException.java | 47 ---------------------- .../persistency/ClusterStorageManager.java | 43 ++++++++++---------- .../persistency/MemoryOnlyClusterStorage.java | 13 +++--- .../java/com/c2kernel/persistency/ProxyLoader.java | 31 +++++++------- .../java/com/c2kernel/persistency/RemoteMap.java | 13 +++--- .../c2kernel/persistency/TransactionManager.java | 25 ++++++------ .../c2kernel/persistency/XMLClusterStorage.java | 23 ++++++----- .../com/c2kernel/persistency/outcome/Outcome.java | 32 +++++++-------- .../persistency/outcome/OutcomeInitiator.java | 4 +- .../persistency/outcome/OutcomeValidator.java | 12 +++--- .../c2kernel/persistency/outcome/Viewpoint.java | 14 +++---- 12 files changed, 122 insertions(+), 162 deletions(-) delete mode 100644 src/main/java/com/c2kernel/persistency/ClusterStorageException.java (limited to 'src/main/java/com/c2kernel/persistency') diff --git a/src/main/java/com/c2kernel/persistency/ClusterStorage.java b/src/main/java/com/c2kernel/persistency/ClusterStorage.java index e4aa81c..a2a33fe 100644 --- a/src/main/java/com/c2kernel/persistency/ClusterStorage.java +++ b/src/main/java/com/c2kernel/persistency/ClusterStorage.java @@ -21,6 +21,7 @@ package com.c2kernel.persistency; import com.c2kernel.collection.Collection; +import com.c2kernel.common.PersistencyException; import com.c2kernel.common.SystemKey; import com.c2kernel.entity.C2KLocalObject; import com.c2kernel.lookup.ItemPath; @@ -48,7 +49,7 @@ import com.c2kernel.utils.Logger; * {@link #put(ItemPath, C2KLocalObject)} and {@link #delete(ItemPath, String)} * for clusters they return {@link #WRITE} and {@link #READWRITE} from * {@link #getClusterContents(ItemPath, String)}. Operations that have not been - * declared as not supported should throw a ClusterStorageException. If a + * declared as not supported should throw a PersistencyException. If a * cluster does not exist, get should return null, and delete should return with * no action. */ @@ -145,21 +146,21 @@ public abstract class ClusterStorage { * @param auth * The Authenticator instance that the user or server logged in * with. - * @throws ClusterStorageException + * @throws PersistencyException * If storage initialization failed */ public abstract void open(Authenticator auth) - throws ClusterStorageException; + throws PersistencyException; /** * Shuts down the storage. Data must be completely written to disk before * this method returns, so the process can exit. No further gets or puts * should follow. * - * @throws ClusterStorageException + * @throws PersistencyException * If closing failed */ - public abstract void close() throws ClusterStorageException; + public abstract void close() throws PersistencyException; /** * Declares whether or not this ClusterStorage can read or write a @@ -240,11 +241,11 @@ public abstract class ClusterStorage { * @param path * The path of the local object * @return The C2KLocalObject, or null if the object was not found - * @throws ClusterStorageException + * @throws PersistencyException * when retrieval failed */ public abstract C2KLocalObject get(ItemPath itemPath, String path) - throws ClusterStorageException; + throws PersistencyException; /** * Stores a CRISTAL local object. The path is automatically generated. @@ -253,11 +254,11 @@ public abstract class ClusterStorage { * The Item that the object will be stored under * @param obj * The C2KLocalObject to store - * @throws ClusterStorageException + * @throws PersistencyException * When storage fails */ public abstract void put(ItemPath itemPath, C2KLocalObject obj) - throws ClusterStorageException; + throws PersistencyException; /** * Remove a CRISTAL local object from storage. This should be used sparingly @@ -268,11 +269,11 @@ public abstract class ClusterStorage { * The containing Item * @param path * The path of the object to be removed - * @throws ClusterStorageException + * @throws PersistencyException * When deletion fails or is not allowed */ public abstract void delete(ItemPath itemPath, String path) - throws ClusterStorageException; + throws PersistencyException; // directory listing /** @@ -285,10 +286,10 @@ public abstract class ClusterStorage { * The path within that Item to query. May be ClusterStorage.ROOT * (empty String) * @return A String array of the possible next path elements - * @throws ClusterStorageException + * @throws PersistencyException * When an error occurred during the query */ public abstract String[] getClusterContents(ItemPath itemPath, String path) - throws ClusterStorageException; + throws PersistencyException; } diff --git a/src/main/java/com/c2kernel/persistency/ClusterStorageException.java b/src/main/java/com/c2kernel/persistency/ClusterStorageException.java deleted file mode 100644 index dc83446..0000000 --- a/src/main/java/com/c2kernel/persistency/ClusterStorageException.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * This file is part of the CRISTAL-iSE kernel. - * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. - * - * This library 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. - * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; with out 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 this library; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - * - * http://www.fsf.org/licensing/licenses/lgpl.html - */ -package com.c2kernel.persistency; - -/** - * - * @version $Revision: 1.2 $ $Date: 2003/07/14 07:57:06 $ - * @author $Author: abranson $ - */ - -public class ClusterStorageException extends Exception { - public ClusterStorageException() { - super(); - } - - public ClusterStorageException(String s) { - super(s); - } - - /** - * @param aMessage - * the detail message. - * @param aCause - * the cause - */ - public ClusterStorageException(String aMessage, Throwable aCause) { - super(aMessage, aCause); - } -} diff --git a/src/main/java/com/c2kernel/persistency/ClusterStorageManager.java b/src/main/java/com/c2kernel/persistency/ClusterStorageManager.java index 61e04a7..baabb19 100644 --- a/src/main/java/com/c2kernel/persistency/ClusterStorageManager.java +++ b/src/main/java/com/c2kernel/persistency/ClusterStorageManager.java @@ -27,7 +27,8 @@ import java.util.Iterator; import java.util.Map; import java.util.StringTokenizer; -import com.c2kernel.common.ObjectNotFoundException; +import com.c2kernel.common.ObjectNotFound; +import com.c2kernel.common.PersistencyException; import com.c2kernel.entity.C2KLocalObject; import com.c2kernel.entity.agent.JobList; import com.c2kernel.entity.proxy.ProxyMessage; @@ -60,10 +61,10 @@ public class ClusterStorageManager { * Initialises all ClusterStorage handlers listed by class name in the property "ClusterStorages" * This property is usually process specific, and so should be in the server/client.conf and not the connect file. */ - public ClusterStorageManager(Authenticator auth) throws ClusterStorageException { + public ClusterStorageManager(Authenticator auth) throws PersistencyException { Object clusterStorageProp = Gateway.getProperties().getObject("ClusterStorage"); if (clusterStorageProp == null || clusterStorageProp.equals("")) { - throw new ClusterStorageException("ClusterStorageManager.init() - no ClusterStorages defined. No persistency!"); + throw new PersistencyException("ClusterStorageManager.init() - no ClusterStorages defined. No persistency!"); } ArrayList rootStores; @@ -77,20 +78,20 @@ public class ClusterStorageManager { if (thisStore instanceof ClusterStorage) rootStores.add((ClusterStorage)thisStore); else - throw new ClusterStorageException("Supplied ClusterStorage "+thisStore.toString()+" was not an instance of ClusterStorage"); + throw new PersistencyException("Supplied ClusterStorage "+thisStore.toString()+" was not an instance of ClusterStorage"); } } else { - throw new ClusterStorageException("Unknown class of ClusterStorage property: "+clusterStorageProp.getClass().getName()); + throw new PersistencyException("Unknown class of ClusterStorage property: "+clusterStorageProp.getClass().getName()); } int clusterNo = 0; for (ClusterStorage newStorage : rootStores) { try { newStorage.open(auth); - } catch (ClusterStorageException ex) { + } catch (PersistencyException ex) { Logger.error(ex); - throw new ClusterStorageException("ClusterStorageManager.init() - Error initialising storage handler " + newStorage.getClass().getName() + + throw new PersistencyException("ClusterStorageManager.init() - Error initialising storage handler " + newStorage.getClass().getName() + ": " + ex.getMessage()); } Logger.msg(5, "ClusterStorageManager.init() - Cluster storage " + newStorage.getClass().getName() + @@ -102,7 +103,7 @@ public class ClusterStorageManager { } - public ArrayList instantiateStores(String allClusters) throws ClusterStorageException { + public ArrayList instantiateStores(String allClusters) throws PersistencyException { ArrayList rootStores = new ArrayList(); StringTokenizer tok = new StringTokenizer(allClusters, ","); clusterPriority = new String[tok.countTokens()]; @@ -117,13 +118,13 @@ public class ClusterStorageManager { newStorage = (ClusterStorage)(Class.forName("com.c2kernel.persistency."+newStorageClass).newInstance()); } } catch (ClassNotFoundException ex) { - throw new ClusterStorageException("ClusterStorageManager.init() - The cluster storage handler class " + newStorageClass + + throw new PersistencyException("ClusterStorageManager.init() - The cluster storage handler class " + newStorageClass + " could not be found."); } catch (InstantiationException ex) { - throw new ClusterStorageException("ClusterStorageManager.init() - The cluster storage handler class " + newStorageClass + + throw new PersistencyException("ClusterStorageManager.init() - The cluster storage handler class " + newStorageClass + " could not be instantiated."); } catch (IllegalAccessException ex) { - throw new ClusterStorageException("ClusterStorageManager.init() - The cluster storage handler class " + newStorageClass + + throw new PersistencyException("ClusterStorageManager.init() - The cluster storage handler class " + newStorageClass + " was not allowed to be instantiated."); } rootStores.add(newStorage); @@ -135,7 +136,7 @@ public class ClusterStorageManager { for (ClusterStorage thisStorage : allStores.values()) { try { thisStorage.close(); - } catch (ClusterStorageException ex) { + } catch (PersistencyException ex) { Logger.error(ex); } } @@ -177,7 +178,7 @@ public class ClusterStorageManager { * Retrieves the ids of the next level of a cluster * Does not look in any currently open transactions. */ - public String[] getClusterContents(ItemPath itemPath, String path) throws ClusterStorageException { + public String[] getClusterContents(ItemPath itemPath, String path) throws PersistencyException { ArrayList contents = new ArrayList(); // get all readers @@ -194,7 +195,7 @@ public class ClusterStorageManager { contents.add(thisArr[j]); } } - } catch (ClusterStorageException e) { + } catch (PersistencyException e) { Logger.msg(5, "ClusterStorageManager.getClusterContents() - reader " + thisReader.getName() + " could not retrieve contents of " + itemPath + "/" + path + ": " + e.getMessage()); } @@ -206,7 +207,7 @@ public class ClusterStorageManager { } /** Internal get method. Retrieves clusters from ClusterStorages & maintains the memory cache */ - public C2KLocalObject get(ItemPath itemPath, String path) throws ClusterStorageException, ObjectNotFoundException { + public C2KLocalObject get(ItemPath itemPath, String path) throws PersistencyException, ObjectNotFound { C2KLocalObject result = null; // check cache first Map sysKeyMemCache = null; @@ -271,23 +272,23 @@ public class ClusterStorageManager { // then return it return result; } - } catch (ClusterStorageException e) { + } catch (PersistencyException e) { Logger.msg(7, "ClusterStorageManager.get() - reader " + thisReader.getName() + " could not retrieve " + itemPath + "/" + path + ": " + e.getMessage()); } } - throw new ObjectNotFoundException("ClusterStorageManager.get() - Path " + path + " not found in " + itemPath, ""); + throw new ObjectNotFound("ClusterStorageManager.get() - Path " + path + " not found in " + itemPath); } /** Internal put method. Creates or overwrites a cluster in all writers. Used when committing transactions. */ - public void put(ItemPath itemPath, C2KLocalObject obj) throws ClusterStorageException { + public void put(ItemPath itemPath, C2KLocalObject obj) throws PersistencyException { String path = ClusterStorage.getPath(obj); ArrayList writers = findStorages(ClusterStorage.getClusterType(path), true); for (ClusterStorage thisWriter : writers) { try { Logger.msg(7, "ClusterStorageManager.put() - writing "+path+" to "+thisWriter.getName()); thisWriter.put(itemPath, obj); - } catch (ClusterStorageException e) { + } catch (PersistencyException e) { Logger.error("ClusterStorageManager.put() - writer " + thisWriter.getName() + " could not store " + itemPath + "/" + path + ": " + e.getMessage()); throw e; @@ -317,13 +318,13 @@ public class ClusterStorageManager { } /** Deletes a cluster from all writers */ - public void remove(ItemPath itemPath, String path) throws ClusterStorageException { + public void remove(ItemPath itemPath, String path) throws PersistencyException { ArrayList writers = findStorages(ClusterStorage.getClusterType(path), true); for (ClusterStorage thisWriter : writers) { try { Logger.msg(7, "ClusterStorageManager.delete() - removing "+path+" from "+thisWriter.getName()); thisWriter.delete(itemPath, path); - } catch (ClusterStorageException e) { + } catch (PersistencyException e) { Logger.error("ClusterStorageManager.delete() - writer " + thisWriter.getName() + " could not delete " + itemPath + "/" + path + ": " + e.getMessage()); throw e; diff --git a/src/main/java/com/c2kernel/persistency/MemoryOnlyClusterStorage.java b/src/main/java/com/c2kernel/persistency/MemoryOnlyClusterStorage.java index 5717d85..7408da3 100644 --- a/src/main/java/com/c2kernel/persistency/MemoryOnlyClusterStorage.java +++ b/src/main/java/com/c2kernel/persistency/MemoryOnlyClusterStorage.java @@ -25,6 +25,7 @@ import java.util.ConcurrentModificationException; import java.util.HashMap; import java.util.Map; +import com.c2kernel.common.PersistencyException; import com.c2kernel.entity.C2KLocalObject; import com.c2kernel.lookup.ItemPath; import com.c2kernel.process.auth.Authenticator; @@ -41,12 +42,12 @@ public class MemoryOnlyClusterStorage extends ClusterStorage { } @Override - public void open(Authenticator auth) throws ClusterStorageException { + public void open(Authenticator auth) throws PersistencyException { } @Override - public void close() throws ClusterStorageException { + public void close() throws PersistencyException { } @Override @@ -66,7 +67,7 @@ public class MemoryOnlyClusterStorage extends ClusterStorage { @Override public C2KLocalObject get(ItemPath thisItem, String path) - throws ClusterStorageException { + throws PersistencyException { Map sysKeyMemCache = memoryCache.get(thisItem); if (sysKeyMemCache != null) return sysKeyMemCache.get(path); @@ -75,7 +76,7 @@ public class MemoryOnlyClusterStorage extends ClusterStorage { @Override public void put(ItemPath thisItem, C2KLocalObject obj) - throws ClusterStorageException { + throws PersistencyException { // create item cache if not present Map sysKeyMemCache; @@ -98,7 +99,7 @@ public class MemoryOnlyClusterStorage extends ClusterStorage { @Override public void delete(ItemPath thisItem, String path) - throws ClusterStorageException { + throws PersistencyException { Map sysKeyMemCache = memoryCache.get(thisItem); if (sysKeyMemCache != null) { synchronized (sysKeyMemCache) { @@ -116,7 +117,7 @@ public class MemoryOnlyClusterStorage extends ClusterStorage { @Override public String[] getClusterContents(ItemPath thisItem, String path) - throws ClusterStorageException { + throws PersistencyException { Map sysKeyMemCache = memoryCache.get(thisItem); ArrayList result = new ArrayList(); if (sysKeyMemCache != null) { diff --git a/src/main/java/com/c2kernel/persistency/ProxyLoader.java b/src/main/java/com/c2kernel/persistency/ProxyLoader.java index 26e43d7..f8704e3 100644 --- a/src/main/java/com/c2kernel/persistency/ProxyLoader.java +++ b/src/main/java/com/c2kernel/persistency/ProxyLoader.java @@ -22,7 +22,8 @@ package com.c2kernel.persistency; import java.util.HashMap; import java.util.StringTokenizer; -import com.c2kernel.common.ObjectNotFoundException; +import com.c2kernel.common.ObjectNotFound; +import com.c2kernel.common.PersistencyException; import com.c2kernel.entity.AgentHelper; import com.c2kernel.entity.C2KLocalObject; import com.c2kernel.entity.Item; @@ -43,12 +44,12 @@ public class ProxyLoader extends ClusterStorage { Lookup lookup; @Override - public void open(Authenticator auth) throws ClusterStorageException { + public void open(Authenticator auth) throws PersistencyException { lookup = Gateway.getLookup(); } @Override - public void close() throws ClusterStorageException { + public void close() throws PersistencyException { } // introspection @Override @@ -68,7 +69,7 @@ public class ProxyLoader extends ClusterStorage { // retrieve object by path @Override - public C2KLocalObject get(ItemPath thisItem, String path) throws ClusterStorageException { + public C2KLocalObject get(ItemPath thisItem, String path) throws PersistencyException { try { Item thisEntity = getIOR(thisItem); String type = getClusterType(path); @@ -83,33 +84,33 @@ public class ProxyLoader extends ClusterStorage { else return (C2KLocalObject)Gateway.getMarshaller().unmarshall(queryData); } - } catch (ObjectNotFoundException e) { + } catch (ObjectNotFound e) { return null; } catch (Exception e) { Logger.error(e); - throw new ClusterStorageException(e.getMessage()); + throw new PersistencyException(e.getMessage()); } return null; } // store object by path @Override - public void put(ItemPath thisItem, C2KLocalObject obj) throws ClusterStorageException { + public void put(ItemPath thisItem, C2KLocalObject obj) throws PersistencyException { // not supported - throw new ClusterStorageException("Cannot write to items through the ProxyLoader"); + throw new PersistencyException("Cannot write to items through the ProxyLoader"); } // delete cluster @Override - public void delete(ItemPath thisItem, String path) throws ClusterStorageException { + public void delete(ItemPath thisItem, String path) throws PersistencyException { // not supported - throw new ClusterStorageException("Cannot write to items through the ProxyLoader"); + throw new PersistencyException("Cannot write to items through the ProxyLoader"); } /* navigation */ // directory listing @Override - public String[] getClusterContents(ItemPath thisItem, String path) throws ClusterStorageException { + public String[] getClusterContents(ItemPath thisItem, String path) throws PersistencyException { try { Item thisEntity = getIOR(thisItem); String contents = thisEntity.queryData(path+"/all"); @@ -121,11 +122,11 @@ public class ProxyLoader extends ClusterStorage { return result; } catch (Exception e) { Logger.error(e); - throw new ClusterStorageException(e.getMessage()); + throw new PersistencyException(e.getMessage()); } } - private Item getIOR(ItemPath thisPath) throws ClusterStorageException { + private Item getIOR(ItemPath thisPath) throws PersistencyException { if (entities.containsKey(thisPath)) { // check the cache Logger.msg(7, "ProxyLoader.getIOR() - "+thisPath+" cached."); @@ -143,7 +144,7 @@ public class ProxyLoader extends ClusterStorage { try { thisItem = AgentHelper.narrow(ior); } catch (org.omg.CORBA.BAD_PARAM ex2) { - throw new ClusterStorageException ("Could not narrow "+thisItem+" as a known Entity type"); + throw new PersistencyException ("Could not narrow "+thisItem+" as a known Entity type"); } } @@ -151,7 +152,7 @@ public class ProxyLoader extends ClusterStorage { entities.put(thisPath, thisItem); return thisItem; } catch (Exception e) { - throw new ClusterStorageException("Error narrowing "+thisPath+": "+e.getMessage()); + throw new PersistencyException("Error narrowing "+thisPath+": "+e.getMessage()); } } } diff --git a/src/main/java/com/c2kernel/persistency/RemoteMap.java b/src/main/java/com/c2kernel/persistency/RemoteMap.java index c11ceab..b1a1e51 100644 --- a/src/main/java/com/c2kernel/persistency/RemoteMap.java +++ b/src/main/java/com/c2kernel/persistency/RemoteMap.java @@ -27,7 +27,8 @@ import java.util.Iterator; import java.util.Set; import java.util.TreeMap; -import com.c2kernel.common.ObjectNotFoundException; +import com.c2kernel.common.ObjectNotFound; +import com.c2kernel.common.PersistencyException; import com.c2kernel.entity.C2KLocalObject; import com.c2kernel.entity.proxy.ItemProxy; import com.c2kernel.entity.proxy.MemberSubscription; @@ -125,7 +126,7 @@ public class RemoteMap extends TreeMap impl try { keys = storage.getClusterContents(mItemPath, mPath+mName); for (String key : keys) super.put(key, null); - } catch (ClusterStorageException e) { + } catch (PersistencyException e) { Logger.error(e); } @@ -222,9 +223,9 @@ public class RemoteMap extends TreeMap impl super.put(key, value); } return value; - } catch (ClusterStorageException e) { + } catch (PersistencyException e) { Logger.error(e); - } catch (ObjectNotFoundException e) { + } catch (ObjectNotFound e) { Logger.error(e); } } @@ -261,7 +262,7 @@ public class RemoteMap extends TreeMap impl storage.put(mItemPath, value, mLocker); return putLocal(key, value); } - } catch (ClusterStorageException e) { + } catch (PersistencyException e) { Logger.error(e); return null; } @@ -282,7 +283,7 @@ public class RemoteMap extends TreeMap impl storage.remove(mItemPath, mPath+mName+"/"+key, mLocker); return super.remove(key); } - } catch (ClusterStorageException e) { + } catch (PersistencyException e) { Logger.error(e); } return null; diff --git a/src/main/java/com/c2kernel/persistency/TransactionManager.java b/src/main/java/com/c2kernel/persistency/TransactionManager.java index 9f2dac4..792709a 100644 --- a/src/main/java/com/c2kernel/persistency/TransactionManager.java +++ b/src/main/java/com/c2kernel/persistency/TransactionManager.java @@ -23,7 +23,8 @@ package com.c2kernel.persistency; import java.util.ArrayList; import java.util.HashMap; -import com.c2kernel.common.ObjectNotFoundException; +import com.c2kernel.common.ObjectNotFound; +import com.c2kernel.common.PersistencyException; import com.c2kernel.entity.C2KLocalObject; import com.c2kernel.entity.agent.JobList; import com.c2kernel.events.History; @@ -37,7 +38,7 @@ public class TransactionManager { HashMap> pendingTransactions; ClusterStorageManager storage; - public TransactionManager(Authenticator auth) throws ClusterStorageException { + public TransactionManager(Authenticator auth) throws PersistencyException { storage = new ClusterStorageManager(auth); locks = new HashMap(); pendingTransactions = new HashMap>(); @@ -61,7 +62,7 @@ public class TransactionManager { storage.close(); } - public String[] getClusterContents(ItemPath itemPath, String path) throws ClusterStorageException { + public String[] getClusterContents(ItemPath itemPath, String path) throws PersistencyException { if (path.startsWith("/") && path.length() > 1) path = path.substring(1); return storage.getClusterContents(itemPath, path); } @@ -71,8 +72,8 @@ public class TransactionManager { * Checks the transaction table first to see if the caller has uncommitted changes */ public C2KLocalObject get(ItemPath itemPath, String path, Object locker) - throws ClusterStorageException, - ObjectNotFoundException { + throws PersistencyException, + ObjectNotFound { if (path.startsWith("/") && path.length() > 1) path = path.substring(1); // deal out top level remote maps, if transactions aren't needed @@ -89,7 +90,7 @@ public class TransactionManager { for (TransactionEntry thisEntry : lockerTransaction) { if (itemPath.equals(thisEntry.itemPath) && path.equals(thisEntry.path)) { if (thisEntry.obj == null) - throw new ClusterStorageException("ClusterStorageManager.get() - Cluster " + path + " has been deleted in " + itemPath + + throw new PersistencyException("ClusterStorageManager.get() - Cluster " + path + " has been deleted in " + itemPath + " but not yet committed"); return thisEntry.obj; } @@ -102,7 +103,7 @@ public class TransactionManager { * Public put method. Manages the transaction table keyed by the object 'locker'. * If this object is null, transaction support is bypassed (so long as no lock exists on that object). */ - public void put(ItemPath itemPath, C2KLocalObject obj, Object locker) throws ClusterStorageException { + public void put(ItemPath itemPath, C2KLocalObject obj, Object locker) throws PersistencyException { Object tempLocker = null; ArrayList lockerTransaction; @@ -114,7 +115,7 @@ public class TransactionManager { if (thisLocker.equals(locker)) // retrieve the transaction list lockerTransaction = pendingTransactions.get(locker); else // locked by someone else - throw new ClusterStorageException("ClusterStorageManager.get() - Access denied: Object " + itemPath + + throw new PersistencyException("ClusterStorageManager.get() - Access denied: Object " + itemPath + " has been locked for writing by " + thisLocker); } else { // no locks for this item @@ -150,7 +151,7 @@ public class TransactionManager { /** Public delete method. Uses the put method, with null as the object value. */ - public void remove(ItemPath itemPath, String path, Object locker) throws ClusterStorageException { + public void remove(ItemPath itemPath, String path, Object locker) throws PersistencyException { ArrayList lockerTransaction; Object tempLocker = null; synchronized(locks) { @@ -161,7 +162,7 @@ public class TransactionManager { if (thisLocker.equals(locker)) // retrieve the transaction list lockerTransaction = pendingTransactions.get(locker); else // locked by someone else - throw new ClusterStorageException("ClusterStorageManager.get() - Access denied: Object " + itemPath + + throw new PersistencyException("ClusterStorageManager.get() - Access denied: Object " + itemPath + " has been locked for writing by " + thisLocker); } else { // either we are the locker, or there is no locker @@ -203,9 +204,9 @@ public class TransactionManager { * @param path - root path to delete * @param locker - locking object * - * @throws ClusterStorageException - when deleting fails + * @throws PersistencyException - when deleting fails */ - public void removeCluster(ItemPath itemPath, String path, Object locker) throws ClusterStorageException { + public void removeCluster(ItemPath itemPath, String path, Object locker) throws PersistencyException { String[] children = getClusterContents(itemPath, path); for (String element : children) diff --git a/src/main/java/com/c2kernel/persistency/XMLClusterStorage.java b/src/main/java/com/c2kernel/persistency/XMLClusterStorage.java index 8f1ed02..4a250e5 100644 --- a/src/main/java/com/c2kernel/persistency/XMLClusterStorage.java +++ b/src/main/java/com/c2kernel/persistency/XMLClusterStorage.java @@ -22,6 +22,7 @@ package com.c2kernel.persistency; import java.io.File; import java.util.ArrayList; +import com.c2kernel.common.PersistencyException; import com.c2kernel.entity.C2KLocalObject; import com.c2kernel.lookup.InvalidItemPathException; import com.c2kernel.lookup.ItemPath; @@ -38,17 +39,17 @@ public class XMLClusterStorage extends ClusterStorage { } @Override - public void open(Authenticator auth) throws ClusterStorageException { + public void open(Authenticator auth) throws PersistencyException { String rootProp = Gateway.getProperties().getString("XMLStorage.root"); if (rootProp == null) - throw new ClusterStorageException("XMLClusterStorage.open() - Root path not given in config file."); + throw new PersistencyException("XMLClusterStorage.open() - Root path not given in config file."); rootDir = new File(rootProp).getAbsolutePath(); if( !FileStringUtility.checkDir( rootDir ) ) { Logger.error("XMLClusterStorage.open() - Path " + rootDir + "' does not exist. Attempting to create."); boolean success = FileStringUtility.createNewDir(rootDir); - if (!success) throw new ClusterStorageException("XMLClusterStorage.open() - Could not create dir "+ rootDir +". Cannot continue."); + if (!success) throw new PersistencyException("XMLClusterStorage.open() - Could not create dir "+ rootDir +". Cannot continue."); } } @@ -77,7 +78,7 @@ public class XMLClusterStorage extends ClusterStorage { // retrieve object by path @Override - public C2KLocalObject get(ItemPath itemPath, String path) throws ClusterStorageException { + public C2KLocalObject get(ItemPath itemPath, String path) throws PersistencyException { try { String type = ClusterStorage.getClusterType(path); String filePath = getFilePath(itemPath, path)+".xml"; @@ -99,7 +100,7 @@ public class XMLClusterStorage extends ClusterStorage { // store object by path @Override - public void put(ItemPath itemPath, C2KLocalObject obj) throws ClusterStorageException { + public void put(ItemPath itemPath, C2KLocalObject obj) throws PersistencyException { try { String filePath = getFilePath(itemPath, getPath(obj)+".xml"); Logger.msg(7, "Writing "+filePath); @@ -108,18 +109,18 @@ public class XMLClusterStorage extends ClusterStorage { String dir = filePath.substring(0, filePath.lastIndexOf('/')); if( !FileStringUtility.checkDir( dir ) ) { boolean success = FileStringUtility.createNewDir(dir); - if (!success) throw new ClusterStorageException("XMLClusterStorage.put() - Could not create dir "+ dir +". Cannot continue."); + if (!success) throw new PersistencyException("XMLClusterStorage.put() - Could not create dir "+ dir +". Cannot continue."); } FileStringUtility.string2File(filePath, data); } catch (Exception e) { Logger.error(e); - throw new ClusterStorageException("XMLClusterStorage.put() - Could not write "+getPath(obj)+" to "+itemPath); + throw new PersistencyException("XMLClusterStorage.put() - Could not write "+getPath(obj)+" to "+itemPath); } } // delete cluster @Override - public void delete(ItemPath itemPath, String path) throws ClusterStorageException { + public void delete(ItemPath itemPath, String path) throws PersistencyException { try { String filePath = getFilePath(itemPath, path+".xml"); boolean success = FileStringUtility.deleteDir(filePath, true, true); @@ -128,14 +129,14 @@ public class XMLClusterStorage extends ClusterStorage { success = FileStringUtility.deleteDir(filePath, true, true); if (success) return; } catch(Exception e) { } - throw new ClusterStorageException("XMLClusterStorage.delete() - Failure deleting path "+path+" in "+itemPath); + throw new PersistencyException("XMLClusterStorage.delete() - Failure deleting path "+path+" in "+itemPath); } /* navigation */ // directory listing @Override - public String[] getClusterContents(ItemPath itemPath, String path) throws ClusterStorageException { + public String[] getClusterContents(ItemPath itemPath, String path) throws PersistencyException { String[] result = new String[0]; try { String filePath = getFilePath(itemPath, path); @@ -162,7 +163,7 @@ public class XMLClusterStorage extends ClusterStorage { return result; } catch (Exception e) { Logger.error(e); - throw new ClusterStorageException("XMLClusterStorage.getClusterContents() - Could not get contents of "+path+" from "+itemPath+": "+e.getMessage()); + throw new PersistencyException("XMLClusterStorage.getClusterContents() - Could not get contents of "+path+" from "+itemPath+": "+e.getMessage()); } } diff --git a/src/main/java/com/c2kernel/persistency/outcome/Outcome.java b/src/main/java/com/c2kernel/persistency/outcome/Outcome.java index 8dbe94e..ac2d970 100644 --- a/src/main/java/com/c2kernel/persistency/outcome/Outcome.java +++ b/src/main/java/com/c2kernel/persistency/outcome/Outcome.java @@ -40,8 +40,8 @@ import org.w3c.dom.ls.DOMImplementationLS; import org.w3c.dom.ls.LSSerializer; import org.xml.sax.InputSource; -import com.c2kernel.common.InvalidDataException; -import com.c2kernel.common.ObjectNotFoundException; +import com.c2kernel.common.InvalidData; +import com.c2kernel.common.ObjectNotFound; import com.c2kernel.common.PersistencyException; import com.c2kernel.entity.C2KLocalObject; import com.c2kernel.persistency.ClusterStorage; @@ -95,14 +95,14 @@ public class Outcome implements C2KLocalObject { // derive all the meta data from the path StringTokenizer tok = new StringTokenizer(path,"/"); if (tok.countTokens() != 3 && !(tok.nextToken().equals(ClusterStorage.OUTCOME))) - throw new PersistencyException("Outcome() - Outcome path must have three components: "+path, null); + throw new PersistencyException("Outcome() - Outcome path must have three components: "+path); mSchemaType = tok.nextToken(); String verstring = tok.nextToken(); String objId = tok.nextToken(); try { mSchemaVersion = Integer.parseInt(verstring); } catch (NumberFormatException ex) { - throw new PersistencyException("Outcome() - Outcome version was an invalid number: "+verstring, null); + throw new PersistencyException("Outcome() - Outcome version was an invalid number: "+verstring); } try { mID = new Integer(objId); @@ -144,10 +144,10 @@ public class Outcome implements C2KLocalObject { mData = null; } - public String getFieldByXPath(String xpath) throws XPathExpressionException, InvalidDataException { + public String getFieldByXPath(String xpath) throws XPathExpressionException, InvalidData { Node field = getNodeByXPath(xpath); if (field == null) - throw new InvalidDataException(xpath, ""); + throw new InvalidData(xpath); else if (field.getNodeType()==Node.TEXT_NODE || field.getNodeType()==Node.CDATA_SECTION_NODE) return field.getNodeValue(); @@ -155,28 +155,28 @@ public class Outcome implements C2KLocalObject { else if (field.getNodeType()==Node.ELEMENT_NODE) { NodeList fieldChildren = field.getChildNodes(); if (fieldChildren.getLength() == 0) - throw new InvalidDataException("No child node for element", ""); + throw new InvalidData("No child node for element"); else if (fieldChildren.getLength() == 1) { Node child = fieldChildren.item(0); if (child.getNodeType()==Node.TEXT_NODE || child.getNodeType()==Node.CDATA_SECTION_NODE) return child.getNodeValue(); else - throw new InvalidDataException("Can't get data from child node of type "+child.getNodeName(), ""); + throw new InvalidData("Can't get data from child node of type "+child.getNodeName()); } else - throw new InvalidDataException("Element "+xpath+" has too many children", ""); + throw new InvalidData("Element "+xpath+" has too many children"); } else if (field.getNodeType()==Node.ATTRIBUTE_NODE) return field.getNodeValue(); else - throw new InvalidDataException("Don't know what to do with node "+field.getNodeName(), ""); + throw new InvalidData("Don't know what to do with node "+field.getNodeName()); } - public void setFieldByXPath(String xpath, String data) throws XPathExpressionException, InvalidDataException { + public void setFieldByXPath(String xpath, String data) throws XPathExpressionException, InvalidData { Node field = getNodeByXPath(xpath); if (field == null) - throw new InvalidDataException(xpath, ""); + throw new InvalidData(xpath); else if (field.getNodeType()==Node.ELEMENT_NODE) { NodeList fieldChildren = field.getChildNodes(); @@ -191,16 +191,16 @@ public class Outcome implements C2KLocalObject { child.setNodeValue(data); break; default: - throw new InvalidDataException("Can't set child node of type "+child.getNodeName(), ""); + throw new InvalidData("Can't set child node of type "+child.getNodeName()); } } else - throw new InvalidDataException("Element "+xpath+" has too many children", ""); + throw new InvalidData("Element "+xpath+" has too many children"); } else if (field.getNodeType()==Node.ATTRIBUTE_NODE) field.setNodeValue(data); else - throw new InvalidDataException("Don't know what to do with node "+field.getNodeName(), ""); + throw new InvalidData("Don't know what to do with node "+field.getNodeName()); } @@ -211,7 +211,7 @@ public class Outcome implements C2KLocalObject { return mData; } - public Schema getSchema() throws ObjectNotFoundException { + public Schema getSchema() throws ObjectNotFound { return LocalObjectLoader.getSchema(mSchemaType, mSchemaVersion); } diff --git a/src/main/java/com/c2kernel/persistency/outcome/OutcomeInitiator.java b/src/main/java/com/c2kernel/persistency/outcome/OutcomeInitiator.java index e152df9..2c4427e 100644 --- a/src/main/java/com/c2kernel/persistency/outcome/OutcomeInitiator.java +++ b/src/main/java/com/c2kernel/persistency/outcome/OutcomeInitiator.java @@ -20,11 +20,11 @@ */ package com.c2kernel.persistency.outcome; -import com.c2kernel.common.InvalidDataException; +import com.c2kernel.common.InvalidData; import com.c2kernel.entity.agent.Job; public interface OutcomeInitiator { - public String initOutcome(Job job) throws InvalidDataException; + public String initOutcome(Job job) throws InvalidData; } diff --git a/src/main/java/com/c2kernel/persistency/outcome/OutcomeValidator.java b/src/main/java/com/c2kernel/persistency/outcome/OutcomeValidator.java index defac3a..d89f7e7 100644 --- a/src/main/java/com/c2kernel/persistency/outcome/OutcomeValidator.java +++ b/src/main/java/com/c2kernel/persistency/outcome/OutcomeValidator.java @@ -38,7 +38,7 @@ import org.xml.sax.ErrorHandler; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; -import com.c2kernel.common.InvalidDataException; +import com.c2kernel.common.InvalidData; import com.c2kernel.utils.Logger; /************************************************************************** @@ -69,7 +69,7 @@ public class OutcomeValidator implements ErrorHandler, XMLErrorHandler { XMLGrammarPoolImpl schemaGrammarPool = new XMLGrammarPoolImpl(1); SymbolTable sym = new SymbolTable(); - public static OutcomeValidator getValidator(Schema schema) throws InvalidDataException { + public static OutcomeValidator getValidator(Schema schema) throws InvalidData { if (schema.docType.equals("Schema") && schema.docVersion==0) @@ -82,11 +82,11 @@ public class OutcomeValidator implements ErrorHandler, XMLErrorHandler { errors = new StringBuffer(); } - public OutcomeValidator(Schema schema) throws InvalidDataException { + public OutcomeValidator(Schema schema) throws InvalidData { this.schema = schema; if (schema.docType.equals("Schema")) - throw new InvalidDataException("Use SchemaValidator to validate schema", ""); + throw new InvalidData("Use SchemaValidator to validate schema"); errors = new StringBuffer(); Logger.msg(5, "Parsing "+schema.docType+" version "+schema.docVersion+". "+schema.schema.length()+" chars"); @@ -103,11 +103,11 @@ public class OutcomeValidator implements ErrorHandler, XMLErrorHandler { try { preparser.preparseGrammar(XMLGrammarDescription.XML_SCHEMA, new XMLInputSource(null, null, null, new StringReader(schema.schema), null)); } catch (IOException ex) { - throw new InvalidDataException("Error parsing schema: "+ex.getMessage(), ""); + throw new InvalidData("Error parsing schema: "+ex.getMessage()); } if (errors.length() > 0) { - throw new InvalidDataException("Schema error: \n"+errors.toString(), ""); + throw new InvalidData("Schema error: \n"+errors.toString()); } } diff --git a/src/main/java/com/c2kernel/persistency/outcome/Viewpoint.java b/src/main/java/com/c2kernel/persistency/outcome/Viewpoint.java index 2a5118f..151bf65 100644 --- a/src/main/java/com/c2kernel/persistency/outcome/Viewpoint.java +++ b/src/main/java/com/c2kernel/persistency/outcome/Viewpoint.java @@ -20,14 +20,14 @@ */ package com.c2kernel.persistency.outcome; -import com.c2kernel.common.InvalidDataException; -import com.c2kernel.common.ObjectNotFoundException; +import com.c2kernel.common.InvalidData; +import com.c2kernel.common.ObjectNotFound; +import com.c2kernel.common.PersistencyException; import com.c2kernel.entity.C2KLocalObject; import com.c2kernel.events.Event; import com.c2kernel.lookup.InvalidItemPathException; import com.c2kernel.lookup.ItemPath; import com.c2kernel.persistency.ClusterStorage; -import com.c2kernel.persistency.ClusterStorageException; import com.c2kernel.process.Gateway; /** @@ -70,8 +70,8 @@ public class Viewpoint implements C2KLocalObject { this.eventId = eventId; } - public Outcome getOutcome() throws ObjectNotFoundException, ClusterStorageException { - if (eventId == NONE) throw new ObjectNotFoundException("No last eventId defined", ""); + public Outcome getOutcome() throws ObjectNotFound, PersistencyException { + if (eventId == NONE) throw new ObjectNotFound("No last eventId defined"); Outcome retVal = (Outcome)Gateway.getStorage().get(itemPath, ClusterStorage.OUTCOME+"/"+schemaName+"/"+schemaVersion+"/"+eventId, null); return retVal; } @@ -194,10 +194,10 @@ public class Viewpoint implements C2KLocalObject { * @return GDataRecord */ public Event getEvent() - throws InvalidDataException, ClusterStorageException, ObjectNotFoundException + throws InvalidData, PersistencyException, ObjectNotFound { if (eventId == NONE) - throw new InvalidDataException("No last eventId defined", ""); + throw new InvalidData("No last eventId defined"); return (Event)Gateway.getStorage().get(itemPath, ClusterStorage.HISTORY+"/"+eventId, null); } -- cgit v1.2.3