diff options
| author | abranson <andrew.branson@cern.ch> | 2011-08-02 22:10:28 +0200 |
|---|---|---|
| committer | abranson <andrew.branson@cern.ch> | 2011-08-02 22:10:28 +0200 |
| commit | 5664fd4644c78f4571a1a72e6b9f0511fb10720a (patch) | |
| tree | 7be1c346d1d001bf6b079089f995a60c52b955c1 /source/com/c2kernel/persistency/ClusterStorageManager.java | |
| parent | 29bbf451a22916d39017ec1a3f53f4e0f0e65ee0 (diff) | |
Finished move to generics. Enforced 1.6 compliance for now. No errors or
warnings :)
Diffstat (limited to 'source/com/c2kernel/persistency/ClusterStorageManager.java')
| -rw-r--r--[-rwxr-xr-x] | source/com/c2kernel/persistency/ClusterStorageManager.java | 68 |
1 files changed, 32 insertions, 36 deletions
diff --git a/source/com/c2kernel/persistency/ClusterStorageManager.java b/source/com/c2kernel/persistency/ClusterStorageManager.java index 5309f33..560e022 100755..100644 --- 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<String, ClusterStorage> allStores = new HashMap<String, ClusterStorage>();
String[] clusterPriority;
- HashMap clusterWriters = new HashMap();
- HashMap clusterReaders = new HashMap();
+ HashMap<String, ArrayList<ClusterStorage>> clusterWriters = new HashMap<String, ArrayList<ClusterStorage>>();
+ HashMap<String, ArrayList<ClusterStorage>> clusterReaders = new HashMap<String, ArrayList<ClusterStorage>>();
// 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<Integer, SoftCache<String, C2KLocalObject>> memoryCache = new HashMap<Integer, SoftCache<String, C2KLocalObject>>();
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<ClusterStorage> rootStores = new ArrayList<ClusterStorage>();
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<ClusterStorage> 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<ClusterStorage> 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<String, ArrayList<ClusterStorage>> 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<ClusterStorage>)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<ClusterStorage> useableStorages = new ArrayList<ClusterStorage>();
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<String> contents = new ArrayList<String>();
// 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<ClusterStorage> readers = findStorages(ClusterStorage.getClusterType(path), false);
// try each in turn until we get a result
- for (Iterator i = readers.iterator(); i.hasNext();) {
+ for (Iterator<ClusterStorage> 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<String, C2KLocalObject> sysKeyMemCache = null;
if (memoryCache.containsKey(sysKeyIntObj)) {
- sysKeyMemCache = (SoftCache)memoryCache.get(sysKeyIntObj);
+ sysKeyMemCache = (SoftCache<String, C2KLocalObject>)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<ClusterStorage> readers = findStorages(ClusterStorage.getClusterType(path), false);
+ for (Iterator<ClusterStorage> 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<String, C2KLocalObject>(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<ClusterStorage> writers = findStorages(ClusterStorage.getClusterType(path), true);
+ for (Iterator<ClusterStorage> 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<String, C2KLocalObject> sysKeyMemCache;
if (memoryCache.containsKey(sysKeyIntObj))
- sysKeyMemCache = (SoftCache)memoryCache.get(sysKeyIntObj);
+ sysKeyMemCache = (SoftCache<String, C2KLocalObject>)memoryCache.get(sysKeyIntObj);
else {
- sysKeyMemCache = new SoftCache();
+ sysKeyMemCache = new SoftCache<String, C2KLocalObject>();
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<ClusterStorage> writers = findStorages(ClusterStorage.getClusterType(path), true);
+ for (Iterator<ClusterStorage> 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<Integer> 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());
|
