From 5664fd4644c78f4571a1a72e6b9f0511fb10720a Mon Sep 17 00:00:00 2001 From: abranson Date: Tue, 2 Aug 2011 22:10:28 +0200 Subject: Finished move to generics. Enforced 1.6 compliance for now. No errors or warnings :) --- .../persistency/ClusterStorageManager.java | 68 ++++++++++------------ 1 file changed, 32 insertions(+), 36 deletions(-) mode change 100755 => 100644 source/com/c2kernel/persistency/ClusterStorageManager.java (limited to 'source/com/c2kernel/persistency/ClusterStorageManager.java') diff --git a/source/com/c2kernel/persistency/ClusterStorageManager.java b/source/com/c2kernel/persistency/ClusterStorageManager.java old mode 100755 new mode 100644 index 5309f33..560e022 --- a/source/com/c2kernel/persistency/ClusterStorageManager.java +++ b/source/com/c2kernel/persistency/ClusterStorageManager.java @@ -1,10 +1,6 @@ package com.c2kernel.persistency; import java.util.*; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.StringTokenizer; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.entity.C2KLocalObject; @@ -24,12 +20,12 @@ import com.c2kernel.utils.SoftCache; * @author $Author: abranson $ */ public class ClusterStorageManager { - HashMap allStores = new HashMap(); + HashMap allStores = new HashMap(); String[] clusterPriority; - HashMap clusterWriters = new HashMap(); - HashMap clusterReaders = new HashMap(); + HashMap> clusterWriters = new HashMap>(); + HashMap> clusterReaders = new HashMap>(); // we don't need a soft cache for the top level cache - the proxies and entities clear that when reaped - HashMap memoryCache = new HashMap(); + HashMap> memoryCache = new HashMap>(); boolean ready = false; /** @@ -45,7 +41,7 @@ public class ClusterStorageManager { StringTokenizer tok = new StringTokenizer(allClusters, ","); clusterPriority = new String[tok.countTokens()]; int clusterNo = 0; - ArrayList rootStores = new ArrayList(); + ArrayList rootStores = new ArrayList(); while (tok.hasMoreTokens()) { ClusterStorage newStorage = null; String newStorageClass = tok.nextToken(); @@ -82,7 +78,7 @@ public class ClusterStorageManager { } public void close() { - for (Iterator iter = allStores.values().iterator(); iter.hasNext();) { + for (Iterator iter = allStores.values().iterator(); iter.hasNext();) { ClusterStorage thisStorage = (ClusterStorage)iter.next(); try { thisStorage.close(); @@ -97,7 +93,7 @@ public class ClusterStorageManager { * Returns the loaded storage that declare that they can handle writing or reading the specified cluster name (e.g. * Collection, Property) Must specify if the request is a read or a write. */ - private ArrayList findStorages(String clusterType, boolean forWrite) { + private ArrayList findStorages(String clusterType, boolean forWrite) { if (!ready) { Logger.error("ClusterStorageManager.findStorages() - called before init!"); @@ -105,7 +101,7 @@ public class ClusterStorageManager { } // choose the right cache for readers or writers - HashMap cache; + HashMap> cache; if (forWrite) cache = clusterWriters; else @@ -113,11 +109,11 @@ public class ClusterStorageManager { // check to see if we've been asked to do this before if (cache.containsKey(clusterType)) - return (ArrayList)cache.get(clusterType); + return (ArrayList)cache.get(clusterType); // not done yet, we'll have to query them all Logger.msg(7, "ClusterStorageManager.findStorages() - finding storage for "+clusterType+" forWrite:"+forWrite); - ArrayList useableStorages = new ArrayList(); + ArrayList useableStorages = new ArrayList(); for (int i = 0; i < clusterPriority.length; i++) { ClusterStorage thisStorage = (ClusterStorage)allStores.get(clusterPriority[i]); short requiredSupport = forWrite ? ClusterStorage.WRITE : ClusterStorage.READ; @@ -136,13 +132,13 @@ public class ClusterStorageManager { */ public String[] getClusterContents(Integer sysKey, String path) throws ClusterStorageException { //String[] retArr = new String[0]; - ArrayList contents = new ArrayList(); + ArrayList contents = new ArrayList(); // get all readers String type = ClusterStorage.getClusterType(path); Logger.msg(8, "ClusterStorageManager.getClusterContents() - Finding contents of "+path); - ArrayList readers = findStorages(ClusterStorage.getClusterType(path), false); + ArrayList readers = findStorages(ClusterStorage.getClusterType(path), false); // try each in turn until we get a result - for (Iterator i = readers.iterator(); i.hasNext();) { + for (Iterator i = readers.iterator(); i.hasNext();) { ClusterStorage thisReader = (ClusterStorage)i.next(); try { String[] thisArr = thisReader.getClusterContents(sysKey, path); @@ -168,9 +164,9 @@ public class ClusterStorageManager { public C2KLocalObject get(Integer sysKeyIntObj, String path) throws ClusterStorageException, ObjectNotFoundException { C2KLocalObject result; // check cache first - SoftCache sysKeyMemCache = null; + SoftCache sysKeyMemCache = null; if (memoryCache.containsKey(sysKeyIntObj)) { - sysKeyMemCache = (SoftCache)memoryCache.get(sysKeyIntObj); + sysKeyMemCache = (SoftCache)memoryCache.get(sysKeyIntObj); synchronized(sysKeyMemCache) { C2KLocalObject obj = (C2KLocalObject)sysKeyMemCache.get(path); if (obj != null) { @@ -194,8 +190,8 @@ public class ClusterStorageManager { } // else try each reader in turn until we find it - ArrayList readers = findStorages(ClusterStorage.getClusterType(path), false); - for (Iterator i = readers.iterator(); i.hasNext(); ) { + ArrayList readers = findStorages(ClusterStorage.getClusterType(path), false); + for (Iterator i = readers.iterator(); i.hasNext(); ) { ClusterStorage thisReader = (ClusterStorage)i.next(); try { result = thisReader.get(sysKeyIntObj, path); @@ -203,7 +199,7 @@ public class ClusterStorageManager { if (result != null) { // got it! // store it in the cache if (sysKeyMemCache == null) { // create cache if needed - sysKeyMemCache = new SoftCache(0); + sysKeyMemCache = new SoftCache(0); synchronized (memoryCache) { memoryCache.put(sysKeyIntObj, sysKeyMemCache); } @@ -225,8 +221,8 @@ public class ClusterStorageManager { /** Internal put method. Creates or overwrites a cluster in all writers. Used when committing transactions. */ public void put(Integer sysKeyIntObj, C2KLocalObject obj) throws ClusterStorageException { String path = ClusterStorage.getPath(obj); - ArrayList writers = findStorages(ClusterStorage.getClusterType(path), true); - for (Iterator i = writers.iterator(); i.hasNext(); ) { + ArrayList writers = findStorages(ClusterStorage.getClusterType(path), true); + for (Iterator i = writers.iterator(); i.hasNext(); ) { ClusterStorage thisWriter = (ClusterStorage)i.next(); try { Logger.msg(7, "ClusterStorageManager.put() - writing "+path+" to "+thisWriter.getName()); @@ -238,11 +234,11 @@ public class ClusterStorageManager { } } // put in mem cache if that worked - SoftCache sysKeyMemCache; + SoftCache sysKeyMemCache; if (memoryCache.containsKey(sysKeyIntObj)) - sysKeyMemCache = (SoftCache)memoryCache.get(sysKeyIntObj); + sysKeyMemCache = (SoftCache)memoryCache.get(sysKeyIntObj); else { - sysKeyMemCache = new SoftCache(); + sysKeyMemCache = new SoftCache(); synchronized (memoryCache) { memoryCache.put(sysKeyIntObj, sysKeyMemCache); } @@ -260,8 +256,8 @@ public class ClusterStorageManager { /** Deletes a cluster from all writers */ public void remove(Integer sysKeyIntObj, String path) throws ClusterStorageException { - ArrayList writers = findStorages(ClusterStorage.getClusterType(path), true); - for (Iterator i = writers.iterator(); i.hasNext(); ) { + ArrayList writers = findStorages(ClusterStorage.getClusterType(path), true); + for (Iterator i = writers.iterator(); i.hasNext(); ) { ClusterStorage thisWriter = (ClusterStorage)i.next(); try { Logger.msg(7, "ClusterStorageManager.delete() - removing "+path+" from "+thisWriter.getName()); @@ -274,7 +270,7 @@ public class ClusterStorageManager { } if (memoryCache.containsKey(sysKeyIntObj)) { - SoftCache sysKeyMemCache = (SoftCache)memoryCache.get(sysKeyIntObj); + SoftCache sysKeyMemCache = (SoftCache)memoryCache.get(sysKeyIntObj); synchronized (sysKeyMemCache) { sysKeyMemCache.remove(path); } @@ -289,9 +285,9 @@ public class ClusterStorageManager { Logger.msg(7, "CSM.clearCache() - removing "+sysKeyIntObj+"/"+path); if (memoryCache.containsKey(sysKeyIntObj)) { - SoftCache sysKeyMemCache = (SoftCache)memoryCache.get(sysKeyIntObj); + SoftCache sysKeyMemCache = (SoftCache)memoryCache.get(sysKeyIntObj); synchronized(sysKeyMemCache) { - for (Iterator iter = sysKeyMemCache.keySet().iterator(); iter.hasNext();) { + for (Iterator iter = sysKeyMemCache.keySet().iterator(); iter.hasNext();) { String thisPath = (String)iter.next(); if (thisPath.startsWith(path)) { Logger.msg(7, "CSM.clearCache() - removing "+sysKeyIntObj+"/"+thisPath); @@ -309,7 +305,7 @@ public class ClusterStorageManager { if (memoryCache.containsKey(sysKeyIntObj)) { synchronized (memoryCache) { if (Logger.doLog(6)) { - SoftCache sysKeyMemCache = (SoftCache)memoryCache.get(sysKeyIntObj); + SoftCache sysKeyMemCache = (SoftCache)memoryCache.get(sysKeyIntObj); int size = sysKeyMemCache.size(); Logger.msg(6, "CSM.clearCache() - "+size+" objects to remove."); } @@ -330,13 +326,13 @@ public class ClusterStorageManager { public void dumpCacheContents(int logLevel) { if (!Logger.doLog(logLevel)) return; synchronized(memoryCache) { - for (Iterator iter = memoryCache.keySet().iterator(); iter.hasNext();) { + for (Iterator iter = memoryCache.keySet().iterator(); iter.hasNext();) { Integer sysKey = (Integer) iter.next(); Logger.msg(logLevel, "Cached Objects of Entity "+sysKey); - SoftCache sysKeyMemCache = (SoftCache)memoryCache.get(sysKey); + SoftCache sysKeyMemCache = (SoftCache)memoryCache.get(sysKey); try { synchronized(sysKeyMemCache) { - for (Iterator iterator = sysKeyMemCache.keySet().iterator();iterator.hasNext();) { + for (Iterator iterator = sysKeyMemCache.keySet().iterator();iterator.hasNext();) { String path = (String) iterator.next(); try { Logger.msg(logLevel, " Path "+path+": "+sysKeyMemCache.get(path).getClass().getName()); -- cgit v1.2.3