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 | |
| parent | 29bbf451a22916d39017ec1a3f53f4e0f0e65ee0 (diff) | |
Finished move to generics. Enforced 1.6 compliance for now. No errors or
warnings :)
Diffstat (limited to 'source/com/c2kernel/persistency')
| -rw-r--r--[-rwxr-xr-x] | source/com/c2kernel/persistency/ClusterStorageManager.java | 68 | ||||
| -rw-r--r--[-rwxr-xr-x] | source/com/c2kernel/persistency/LDAPClusterStorage.java | 2 | ||||
| -rw-r--r--[-rwxr-xr-x] | source/com/c2kernel/persistency/ProxyLoader.java | 2 | ||||
| -rw-r--r--[-rwxr-xr-x] | source/com/c2kernel/persistency/TransactionManager.java | 22 | ||||
| -rw-r--r--[-rwxr-xr-x] | source/com/c2kernel/persistency/XMLClusterStorage.java | 2 |
5 files changed, 46 insertions, 50 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());
diff --git a/source/com/c2kernel/persistency/LDAPClusterStorage.java b/source/com/c2kernel/persistency/LDAPClusterStorage.java index 8e159e0..fb36d9f 100755..100644 --- a/source/com/c2kernel/persistency/LDAPClusterStorage.java +++ b/source/com/c2kernel/persistency/LDAPClusterStorage.java @@ -146,7 +146,7 @@ public class LDAPClusterStorage extends ClusterStorage { else
if (type.equals("")) { // root query
String[] allClusters = new String[0];
- ArrayList clusterList = new ArrayList();
+ ArrayList<String> clusterList = new ArrayList<String>();
if (ldapStore.hasProperties(thisEntity))
clusterList.add(PROPERTY);
allClusters = (String[])clusterList.toArray(allClusters);
diff --git a/source/com/c2kernel/persistency/ProxyLoader.java b/source/com/c2kernel/persistency/ProxyLoader.java index d20fb2d..687141f 100755..100644 --- a/source/com/c2kernel/persistency/ProxyLoader.java +++ b/source/com/c2kernel/persistency/ProxyLoader.java @@ -18,7 +18,7 @@ import com.c2kernel.utils.Logger; */
public class ProxyLoader extends ClusterStorage {
- HashMap entities = new HashMap();
+ HashMap<Integer, ManageableEntity> entities = new HashMap<Integer, ManageableEntity>();
LDAPLookup lookup;
public void open() throws ClusterStorageException {
diff --git a/source/com/c2kernel/persistency/TransactionManager.java b/source/com/c2kernel/persistency/TransactionManager.java index 252c758..0908051 100755..100644 --- a/source/com/c2kernel/persistency/TransactionManager.java +++ b/source/com/c2kernel/persistency/TransactionManager.java @@ -13,14 +13,14 @@ import com.c2kernel.utils.Logger; public class TransactionManager {
- HashMap locks;
- HashMap pendingTransactions;
+ HashMap<Integer, Object> locks;
+ HashMap<Object, ArrayList<TransactionEntry>> pendingTransactions;
ClusterStorageManager storage;
public TransactionManager() throws ClusterStorageException {
storage = new ClusterStorageManager();
- locks = new HashMap();
- pendingTransactions = new HashMap();
+ locks = new HashMap<Integer, Object>();
+ pendingTransactions = new HashMap<Object, ArrayList<TransactionEntry>>();
}
public boolean hasPendingTransactions()
@@ -92,7 +92,7 @@ public class TransactionManager { */
public void put(int sysKey, C2KLocalObject obj, Object locker) throws ClusterStorageException {
Integer sysKeyIntObj = new Integer(sysKey);
- ArrayList lockerTransaction;
+ ArrayList<TransactionEntry> lockerTransaction;
String path = ClusterStorage.getPath(obj);
synchronized(locks) {
@@ -101,7 +101,7 @@ public class TransactionManager { // if it's this locker, get the transaction list
Object thisLocker = locks.get(sysKeyIntObj);
if (thisLocker.equals(locker)) // retrieve the transaction list
- lockerTransaction = (ArrayList)pendingTransactions.get(locker);
+ lockerTransaction = pendingTransactions.get(locker);
else // locked by someone else
throw new ClusterStorageException("ClusterStorageManager.get() - Access denied: Object " + sysKeyIntObj +
" has been locked for writing by " + thisLocker);
@@ -113,7 +113,7 @@ public class TransactionManager { }
else {// initialise the transaction
locks.put(sysKeyIntObj, locker);
- lockerTransaction = new ArrayList();
+ lockerTransaction = new ArrayList<TransactionEntry>();
pendingTransactions.put(locker, lockerTransaction);
}
}
@@ -134,14 +134,14 @@ public class TransactionManager { */
public void remove(int sysKey, String path, Object locker) throws ClusterStorageException {
Integer sysKeyIntObj = new Integer(sysKey);
- ArrayList lockerTransaction;
+ ArrayList<TransactionEntry> lockerTransaction;
synchronized(locks) {
// look to see if this object is already locked
if (locks.containsKey(sysKeyIntObj)) {
// if it's this locker, get the transaction list
Object thisLocker = locks.get(sysKeyIntObj);
if (thisLocker.equals(locker)) // retrieve the transaction list
- lockerTransaction = (ArrayList)pendingTransactions.get(locker);
+ lockerTransaction = pendingTransactions.get(locker);
else // locked by someone else
throw new ClusterStorageException("ClusterStorageManager.get() - Access denied: Object " + sysKeyIntObj +
" has been locked for writing by " + thisLocker);
@@ -153,7 +153,7 @@ public class TransactionManager { }
else {// initialise the transaction
locks.put(sysKeyIntObj, locker);
- lockerTransaction = new ArrayList();
+ lockerTransaction = new ArrayList<TransactionEntry>();
pendingTransactions.put(locker, lockerTransaction);
}
}
@@ -194,7 +194,7 @@ public class TransactionManager { public void commit(Object locker) {
synchronized(locks) {
ArrayList lockerTransactions = (ArrayList)pendingTransactions.get(locker);
- HashMap exceptions = new HashMap();
+ HashMap<TransactionEntry, Exception> exceptions = new HashMap<TransactionEntry, Exception>();
// quit if no transactions are present;
if (lockerTransactions == null) return;
for (Iterator i = lockerTransactions.iterator();i.hasNext();) {
diff --git a/source/com/c2kernel/persistency/XMLClusterStorage.java b/source/com/c2kernel/persistency/XMLClusterStorage.java index 6e3cd72..24697af 100755..100644 --- a/source/com/c2kernel/persistency/XMLClusterStorage.java +++ b/source/com/c2kernel/persistency/XMLClusterStorage.java @@ -110,7 +110,7 @@ public class XMLClusterStorage extends ClusterStorage { String filePath = getFilePath(sysKey, path);
ArrayList paths = FileStringUtility.listDir( filePath, true, false );
if (paths == null) return result; // dir doesn't exist yet
- ArrayList contents = new ArrayList();
+ ArrayList<String> contents = new ArrayList<String>();
String previous = null;
for (int i=0; i<paths.size(); i++) {
String next = (String)paths.get(i);
|
