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. --- .../c2kernel/persistency/TransactionManager.java | 25 +++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src/main/java/com/c2kernel/persistency/TransactionManager.java') 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) -- cgit v1.2.3