[jbosscache-commits] JBoss Cache SVN: r7711 - in core/branches/flat/src: main/java/org/horizon/loader/decorators and 10 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Tue Feb 17 13:39:52 EST 2009


Author: manik.surtani at jboss.com
Date: 2009-02-17 13:39:52 -0500 (Tue, 17 Feb 2009)
New Revision: 7711

Added:
   core/branches/flat/src/main/java/org/horizon/loader/decorators/ChainingCacheStore.java
   core/branches/flat/src/main/java/org/horizon/loader/file/
   core/branches/flat/src/main/java/org/horizon/loader/file/FileCacheStore.java
   core/branches/flat/src/main/java/org/horizon/loader/file/FileCacheStoreConfig.java
   core/branches/flat/src/main/java/org/horizon/loader/jdbc/JDBCCacheStore.java
   core/branches/flat/src/main/java/org/horizon/loader/jdbc/JDBCCacheStoreConfig.java
   core/branches/flat/src/test/java/org/horizon/loader/BaseCacheStoreTest.java
   core/branches/flat/src/test/java/org/horizon/loader/dummy/DummyInMemoryCacheStore.java
   core/branches/flat/src/test/java/org/horizon/loader/dummy/DummyInMemoryCacheStoreTest.java
   core/branches/flat/src/test/java/org/horizon/loader/file/
   core/branches/flat/src/test/java/org/horizon/loader/file/FileCacheStoreTest.java
Removed:
   core/branches/flat/src/main/java/org/horizon/loader/decorators/ChainingCacheLoader.java
   core/branches/flat/src/main/java/org/horizon/loader/jdbc/JDBCCacheLoader.java
   core/branches/flat/src/main/java/org/horizon/loader/jdbc/JDBCCacheLoaderConfig.java
   core/branches/flat/src/test/java/org/horizon/loader/BaseCacheLoaderTest.java
   core/branches/flat/src/test/java/org/horizon/loader/dummy/DummyInMemoryCacheLoader.java
   core/branches/flat/src/test/java/org/horizon/loader/dummy/DummyInMemoryCacheLoaderTest.java
Modified:
   core/branches/flat/src/main/java/org/horizon/loader/AbstractCacheStore.java
   core/branches/flat/src/main/java/org/horizon/loader/CacheLoaderManagerImpl.java
   core/branches/flat/src/main/java/org/horizon/marshall/HorizonMarshaller.java
   core/branches/flat/src/main/java/org/horizon/marshall/Marshaller.java
   core/branches/flat/src/main/java/org/horizon/marshall/VersionAwareMarshaller.java
   core/branches/flat/src/test/java/org/horizon/config/parsing/ConfigurationParserTest.java
   core/branches/flat/src/test/java/org/horizon/loader/CacheLoaderFunctionalTest.java
   core/branches/flat/src/test/java/org/horizon/loader/PassivationFunctionalTest.java
   core/branches/flat/src/test/java/org/horizon/loader/decorators/AsyncTest.java
   core/branches/flat/src/test/java/org/horizon/loader/decorators/ChainingCacheLoaderTest.java
   core/branches/flat/src/test/java/org/horizon/loader/decorators/SingletonStoreTest.java
   core/branches/flat/src/test/java/org/horizon/marshall/MarshalledValueTest.java
   core/branches/flat/src/test/java/org/horizon/notifications/CacheListenerCacheLoaderTest.java
Log:
FIxed some stuff, FCL is work in progress

Modified: core/branches/flat/src/main/java/org/horizon/loader/AbstractCacheStore.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/AbstractCacheStore.java	2009-02-17 18:37:38 UTC (rev 7710)
+++ core/branches/flat/src/main/java/org/horizon/loader/AbstractCacheStore.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -62,4 +62,8 @@
          for (Object key : keys) remove(key);
       }
    }
+
+   public boolean containsKey(Object key) {
+      return load(key) != null;
+   }
 }

Modified: core/branches/flat/src/main/java/org/horizon/loader/CacheLoaderManagerImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/CacheLoaderManagerImpl.java	2009-02-17 18:37:38 UTC (rev 7710)
+++ core/branches/flat/src/main/java/org/horizon/loader/CacheLoaderManagerImpl.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -10,7 +10,7 @@
 import org.horizon.factories.annotations.Stop;
 import org.horizon.invocation.Options;
 import org.horizon.loader.decorators.AsyncStore;
-import org.horizon.loader.decorators.ChainingCacheLoader;
+import org.horizon.loader.decorators.ChainingCacheStore;
 import org.horizon.loader.decorators.ReadOnlyStore;
 import org.horizon.loader.decorators.SingletonStore;
 import org.horizon.loader.decorators.SingletonStoreConfig;
@@ -59,8 +59,8 @@
    private void purgeLoaders(boolean force) throws Exception {
       CacheStore cs = getCacheStore();
       if (cs != null) {
-         if ((cs instanceof ChainingCacheLoader) && !force) {
-            ((ChainingCacheLoader) loader).purgeIfNecessary();
+         if ((cs instanceof ChainingCacheStore) && !force) {
+            ((ChainingCacheStore) loader).purgeIfNecessary();
          } else {
             CacheLoaderConfig first = clmConfig.getFirstCacheLoaderConfig();
             if (force || (first != null && first.isPurgeOnStartup())) {
@@ -132,7 +132,7 @@
       // also if we are using passivation then just directly use the first cache loader.
       if (clmConfig.useChainingCacheLoader()) {
          // create chaining cache loader.
-         ChainingCacheLoader ccl = new ChainingCacheLoader();
+         ChainingCacheStore ccl = new ChainingCacheStore();
          tmpLoader = ccl;
 
          // only one cache loader may have fetchPersistentState to true.

Deleted: core/branches/flat/src/main/java/org/horizon/loader/decorators/ChainingCacheLoader.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/decorators/ChainingCacheLoader.java	2009-02-17 18:37:38 UTC (rev 7710)
+++ core/branches/flat/src/main/java/org/horizon/loader/decorators/ChainingCacheLoader.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -1,144 +0,0 @@
-package org.horizon.loader.decorators;
-
-import org.horizon.Cache;
-import org.horizon.loader.CacheLoader;
-import org.horizon.loader.CacheLoaderConfig;
-import org.horizon.loader.CacheStore;
-import org.horizon.loader.StoredEntry;
-import org.horizon.loader.modifications.Modification;
-import org.horizon.marshall.Marshaller;
-
-import javax.transaction.Transaction;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * A chaining cache loader that allows us to configure > 1 cache loader.
- * <p/>
- * READ operations are directed to each of the cache loaders (in the order which they were configured) until a non-null
- * (or non-empty in the case of retrieving collection objects) result is achieved.
- * <p/>
- * WRITE operations are propagated to ALL registered cache stores specified, that set ignoreModifications to false.
- *
- * @author Manik Surtani
- * @since 1.0
- */
-public class ChainingCacheLoader implements CacheStore {
-
-   // linked hash sets used since it provides fast (O(1)) iteration, maintains order and provides O(1) lookups to values as well.
-   LinkedHashMap<CacheLoader, CacheLoaderConfig> loaders = new LinkedHashMap<CacheLoader, CacheLoaderConfig>();
-   LinkedHashMap<CacheStore, CacheLoaderConfig> stores = new LinkedHashMap<CacheStore, CacheLoaderConfig>();
-
-   public void store(StoredEntry ed) {
-      for (CacheStore s : stores.keySet()) s.store(ed);
-   }
-
-   public void store(InputStream inputStream) throws IOException, ClassNotFoundException {
-      // loading and storing state via streams is *only* supported on the *first* store that has fetchPersistentState set.
-      for (Map.Entry<CacheStore, CacheLoaderConfig> e : stores.entrySet()) {
-         if (e.getValue().isFetchPersistentState()) {
-            e.getKey().store(inputStream);
-            // do NOT continue this for other stores, since the stream will not be in an appropriate state anymore
-            break;
-         }
-      }
-   }
-
-   public void load(OutputStream outputStream) throws IOException {
-      // loading and storing state via streams is *only* supported on the *first* store that has fetchPersistentState set.
-      for (Map.Entry<CacheStore, CacheLoaderConfig> e : stores.entrySet()) {
-         if (e.getValue().isFetchPersistentState()) {
-            e.getKey().load(outputStream);
-            // do NOT continue this for other stores, since the stream will not be in an appropriate state anymore
-            break;
-         }
-      }
-   }
-
-   public void clear() {
-      for (CacheStore s : stores.keySet()) s.clear();
-   }
-
-   public boolean remove(Object key) {
-      boolean r = false;
-      for (CacheStore s : stores.keySet()) r = s.remove(key) || r;
-      return r;
-   }
-
-   public void removeAll(Set<Object> keys) {
-      for (CacheStore s : stores.keySet()) s.removeAll(keys);
-   }
-
-   public void purgeExpired() {
-      for (CacheStore s : stores.keySet()) s.purgeExpired();
-   }
-
-   public void commit(Transaction tx) {
-      for (CacheStore s : stores.keySet()) s.commit(tx);
-   }
-
-   public void rollback(Transaction tx) {
-      for (CacheStore s : stores.keySet()) s.rollback(tx);
-   }
-
-   public void prepare(List<? extends Modification> list, Transaction tx, boolean isOnePhase) {
-      for (CacheStore s : stores.keySet()) s.prepare(list, tx, isOnePhase);
-   }
-
-   public void init(CacheLoaderConfig config, Cache cache, Marshaller m) {
-      for (Map.Entry<CacheLoader, CacheLoaderConfig> e : loaders.entrySet()) {
-         e.getKey().init(e.getValue(), cache, m);
-      }
-   }
-
-   public StoredEntry load(Object key) {
-      StoredEntry se = null;
-      for (CacheLoader l : loaders.keySet()) {
-         se = l.load(key);
-         if (se != null) break;
-      }
-      return se;
-   }
-
-   public Set<StoredEntry> loadAll() {
-      Set<StoredEntry> set = new HashSet<StoredEntry>();
-      for (CacheStore s : stores.keySet()) set.addAll(s.loadAll());
-      return set;
-   }
-
-   public boolean containsKey(Object key) {
-      for (CacheLoader l : loaders.keySet()) {
-         if (l.containsKey(key)) return true;
-      }
-      return false;
-   }
-
-   public Class<? extends CacheLoaderConfig> getConfigurationClass() {
-      return null;
-   }
-
-   public void start() {
-      for (CacheLoader l : loaders.keySet()) l.start();
-   }
-
-   public void stop() {
-      for (CacheLoader l : loaders.keySet()) l.stop();
-   }
-
-   public void addCacheLoader(CacheLoader loader, CacheLoaderConfig config) {
-      loaders.put(loader, config);
-      if (loader instanceof CacheStore) stores.put((CacheStore) loader, config);
-   }
-
-   public void purgeIfNecessary() {
-      for (Map.Entry<CacheStore, CacheLoaderConfig> e : stores.entrySet()) {
-         if (e.getValue().isPurgeOnStartup()) e.getKey().clear();
-      }
-   }
-}

Copied: core/branches/flat/src/main/java/org/horizon/loader/decorators/ChainingCacheStore.java (from rev 7701, core/branches/flat/src/main/java/org/horizon/loader/decorators/ChainingCacheLoader.java)
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/decorators/ChainingCacheStore.java	                        (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/loader/decorators/ChainingCacheStore.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -0,0 +1,144 @@
+package org.horizon.loader.decorators;
+
+import org.horizon.Cache;
+import org.horizon.loader.CacheLoader;
+import org.horizon.loader.CacheLoaderConfig;
+import org.horizon.loader.CacheStore;
+import org.horizon.loader.StoredEntry;
+import org.horizon.loader.modifications.Modification;
+import org.horizon.marshall.Marshaller;
+
+import javax.transaction.Transaction;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A chaining cache loader that allows us to configure > 1 cache loader.
+ * <p/>
+ * READ operations are directed to each of the cache loaders (in the order which they were configured) until a non-null
+ * (or non-empty in the case of retrieving collection objects) result is achieved.
+ * <p/>
+ * WRITE operations are propagated to ALL registered cache stores specified, that set ignoreModifications to false.
+ *
+ * @author Manik Surtani
+ * @since 1.0
+ */
+public class ChainingCacheStore implements CacheStore {
+
+   // linked hash sets used since it provides fast (O(1)) iteration, maintains order and provides O(1) lookups to values as well.
+   LinkedHashMap<CacheLoader, CacheLoaderConfig> loaders = new LinkedHashMap<CacheLoader, CacheLoaderConfig>();
+   LinkedHashMap<CacheStore, CacheLoaderConfig> stores = new LinkedHashMap<CacheStore, CacheLoaderConfig>();
+
+   public void store(StoredEntry ed) {
+      for (CacheStore s : stores.keySet()) s.store(ed);
+   }
+
+   public void store(InputStream inputStream) throws IOException, ClassNotFoundException {
+      // loading and storing state via streams is *only* supported on the *first* store that has fetchPersistentState set.
+      for (Map.Entry<CacheStore, CacheLoaderConfig> e : stores.entrySet()) {
+         if (e.getValue().isFetchPersistentState()) {
+            e.getKey().store(inputStream);
+            // do NOT continue this for other stores, since the stream will not be in an appropriate state anymore
+            break;
+         }
+      }
+   }
+
+   public void load(OutputStream outputStream) throws IOException {
+      // loading and storing state via streams is *only* supported on the *first* store that has fetchPersistentState set.
+      for (Map.Entry<CacheStore, CacheLoaderConfig> e : stores.entrySet()) {
+         if (e.getValue().isFetchPersistentState()) {
+            e.getKey().load(outputStream);
+            // do NOT continue this for other stores, since the stream will not be in an appropriate state anymore
+            break;
+         }
+      }
+   }
+
+   public void clear() {
+      for (CacheStore s : stores.keySet()) s.clear();
+   }
+
+   public boolean remove(Object key) {
+      boolean r = false;
+      for (CacheStore s : stores.keySet()) r = s.remove(key) || r;
+      return r;
+   }
+
+   public void removeAll(Set<Object> keys) {
+      for (CacheStore s : stores.keySet()) s.removeAll(keys);
+   }
+
+   public void purgeExpired() {
+      for (CacheStore s : stores.keySet()) s.purgeExpired();
+   }
+
+   public void commit(Transaction tx) {
+      for (CacheStore s : stores.keySet()) s.commit(tx);
+   }
+
+   public void rollback(Transaction tx) {
+      for (CacheStore s : stores.keySet()) s.rollback(tx);
+   }
+
+   public void prepare(List<? extends Modification> list, Transaction tx, boolean isOnePhase) {
+      for (CacheStore s : stores.keySet()) s.prepare(list, tx, isOnePhase);
+   }
+
+   public void init(CacheLoaderConfig config, Cache cache, Marshaller m) {
+      for (Map.Entry<CacheLoader, CacheLoaderConfig> e : loaders.entrySet()) {
+         e.getKey().init(e.getValue(), cache, m);
+      }
+   }
+
+   public StoredEntry load(Object key) {
+      StoredEntry se = null;
+      for (CacheLoader l : loaders.keySet()) {
+         se = l.load(key);
+         if (se != null) break;
+      }
+      return se;
+   }
+
+   public Set<StoredEntry> loadAll() {
+      Set<StoredEntry> set = new HashSet<StoredEntry>();
+      for (CacheStore s : stores.keySet()) set.addAll(s.loadAll());
+      return set;
+   }
+
+   public boolean containsKey(Object key) {
+      for (CacheLoader l : loaders.keySet()) {
+         if (l.containsKey(key)) return true;
+      }
+      return false;
+   }
+
+   public Class<? extends CacheLoaderConfig> getConfigurationClass() {
+      return null;
+   }
+
+   public void start() {
+      for (CacheLoader l : loaders.keySet()) l.start();
+   }
+
+   public void stop() {
+      for (CacheLoader l : loaders.keySet()) l.stop();
+   }
+
+   public void addCacheLoader(CacheLoader loader, CacheLoaderConfig config) {
+      loaders.put(loader, config);
+      if (loader instanceof CacheStore) stores.put((CacheStore) loader, config);
+   }
+
+   public void purgeIfNecessary() {
+      for (Map.Entry<CacheStore, CacheLoaderConfig> e : stores.entrySet()) {
+         if (e.getValue().isPurgeOnStartup()) e.getKey().clear();
+      }
+   }
+}

Added: core/branches/flat/src/main/java/org/horizon/loader/file/FileCacheStore.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/file/FileCacheStore.java	                        (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/loader/file/FileCacheStore.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -0,0 +1,171 @@
+package org.horizon.loader.file;
+
+import org.horizon.Cache;
+import org.horizon.CacheException;
+import org.horizon.loader.AbstractCacheStore;
+import org.horizon.loader.CacheLoaderConfig;
+import org.horizon.loader.StoredEntry;
+import org.horizon.logging.Log;
+import org.horizon.logging.LogFactory;
+import org.horizon.marshall.Marshaller;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A filesystem-based implementation of a {@link org.horizon.loader.CacheStore}.  This file store stores stuff in the
+ * following format: <tt>/location/cache name/bucket.dat</tt>
+ * <p/>
+ * A hashing algorithm is used to map keys to buckets, and a bucket consists of a collection of key/value pairs.
+ * <p/>
+ * This approach, while adding an overhead of having to search buckets for keys, means that we can use any serializable
+ * object we like as keys and not just Strings or objects that translate to something meaningful on a file system.
+ *
+ * @author Manik Surtani
+ * @since 1.0
+ */
+public class FileCacheStore extends AbstractCacheStore {
+   private static final Log log = LogFactory.getLog(FileCacheStore.class);
+   // TODO: make bucket size fixed rather than number of buckets, and support resizes
+   private static final int NUM_BUCKETS = Integer.MAX_VALUE;
+
+   FileCacheStoreConfig cfg;
+   Cache cache;
+   Marshaller m;
+   File root;
+
+   public void init(CacheLoaderConfig config, Cache cache, Marshaller m) {
+      this.cfg = (FileCacheStoreConfig) config;
+      this.cache = cache;
+      this.m = m;
+   }
+
+   public StoredEntry load(Object key) {
+      String bucketName = getBucketName(key);
+      File f = new File(root, bucketName);
+      if (f.exists()) {
+         FileInputStream is = null;
+         ObjectInputStream ois = null;
+         try {
+            is = new FileInputStream(f);
+            ois = new ObjectInputStream(is);
+            Map data = (Map) ois.readObject();
+            if (data.containsKey(key)) return (StoredEntry) data.get(key);
+         } catch (FileNotFoundException e) {
+            e.printStackTrace();  // TODO: Manik: Customise this generated block
+         } catch (IOException e) {
+            e.printStackTrace();  // TODO: Manik: Customise this generated block
+         } catch (ClassNotFoundException e) {
+            e.printStackTrace();  // TODO: Manik: Customise this generated block
+         } finally {
+            if (ois != null) try {
+               ois.close();
+            } catch (IOException e) {
+               e.printStackTrace();  // TODO: Manik: Customise this generated block
+            }
+            if (is != null) try {
+               is.close();
+            } catch (IOException e) {
+               e.printStackTrace();  // TODO: Manik: Customise this generated block
+            }
+         }
+      }
+      return null;
+   }
+
+   public Set<StoredEntry> loadAll() {
+      return null;  // TODO: Manik: Customise this generated block
+   }
+
+   public Class<? extends CacheLoaderConfig> getConfigurationClass() {
+      return null;  // TODO: Manik: Customise this generated block
+   }
+
+   public void start() {
+      String location = cfg.getLocation();
+      if (location == null || location.trim().length() == 0) location = "Horizon-FileCacheStore"; // use relative path!
+      location += File.separator + cache.getName();
+      root = new File(location);
+      if (!root.exists()) {
+         if (!root.mkdirs())
+            throw new CacheException("Directory " + root.getAbsolutePath() + " does not exist and cannot be created!");
+      }
+   }
+
+   public void stop() {
+   }
+
+   public void store(StoredEntry ed) {
+      // TODO: Manik: Customise this generated block
+   }
+
+   public void store(InputStream inputStream) throws IOException, ClassNotFoundException {
+      clear();
+      // TODO: buffer streams!
+      // TODO: close streams in a finally block, and close Object stream if an object stream was created
+      ObjectInputStream ois =
+            (inputStream instanceof ObjectInputStream) ? (ObjectInputStream) inputStream :
+                  new ObjectInputStream(inputStream);
+      int numFiles = ois.readInt();
+      for (int i = 0; i < numFiles; i++) {
+         String fName = (String) ois.readObject();
+         int numBytes = ois.readInt();
+         FileOutputStream fos = new FileOutputStream(root.getAbsolutePath() + File.separator + fName);
+         for (int bytes = 0; bytes < numBytes; bytes++) fos.write(ois.read());
+         fos.close();
+      }
+   }
+
+   public void load(OutputStream outputStream) throws IOException {
+      // TODO: buffer streams!
+      // TODO: close streams in a finally block, and close Object stream if an object stream was created
+      ObjectOutputStream oos = (outputStream instanceof ObjectOutputStream) ? (ObjectOutputStream) outputStream :
+            new ObjectOutputStream(outputStream);
+      File[] files = root.listFiles();
+      oos.writeInt(files.length);
+      for (int i = 0; i < files.length; i++) {
+         FileInputStream is = new FileInputStream(files[i]);
+         int sz = is.available();
+         oos.writeObject(files[i].getName());
+         oos.writeInt(sz);
+         for (int bytes = 0; bytes < sz; bytes++) oos.write(is.read());
+         is.close();
+      }
+   }
+
+   public void clear() {
+      for (File f : root.listFiles()) f.delete();
+   }
+
+   public boolean remove(Object key) {
+      return false;  // TODO: Manik: Customise this generated block
+   }
+
+   public void purgeExpired() {
+      // TODO: Manik: Customise this generated block
+   }
+
+   private String getBucketName(Object key) {
+      int bucketNumber = index(hash(key));
+      return bucketNumber + ".dat";
+   }
+
+   private int hash(Object key) {
+      int h = key.hashCode();
+      h ^= (h >>> 20) ^ (h >>> 12);
+      return h ^ (h >>> 7) ^ (h >>> 4);
+   }
+
+   private int index(int h) {
+      return h & (NUM_BUCKETS - 1);
+   }
+}

Added: core/branches/flat/src/main/java/org/horizon/loader/file/FileCacheStoreConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/file/FileCacheStoreConfig.java	                        (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/loader/file/FileCacheStoreConfig.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -0,0 +1,26 @@
+package org.horizon.loader.file;
+
+import org.horizon.loader.AbstractCacheLoaderConfig;
+
+/**
+ * Configures {@link org.horizon.loader.file.FileCacheStore}
+ *
+ * @author Manik Surtani
+ * @since 1.0
+ */
+public class FileCacheStoreConfig extends AbstractCacheLoaderConfig {
+   String location;
+
+   public FileCacheStoreConfig() {
+      setClassName(FileCacheStore.class.getName());
+   }
+
+   public String getLocation() {
+      return location;
+   }
+
+   public void setLocation(String location) {
+      testImmutability("location");
+      this.location = location;
+   }
+}

Deleted: core/branches/flat/src/main/java/org/horizon/loader/jdbc/JDBCCacheLoader.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/JDBCCacheLoader.java	2009-02-17 18:37:38 UTC (rev 7710)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/JDBCCacheLoader.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -1,98 +0,0 @@
-package org.horizon.loader.jdbc;
-
-import org.horizon.Cache;
-import org.horizon.loader.CacheLoaderConfig;
-import org.horizon.loader.CacheStore;
-import org.horizon.loader.StoredEntry;
-import org.horizon.marshall.Marshaller;
-
-import javax.transaction.Transaction;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-
-/**
- * // TODO: Manik: Document this!
- *
- * @author Manik Surtani
- */
-public class JDBCCacheLoader implements CacheStore {
-   public void store(StoredEntry ed) {
-      // TODO: Manik: Customise this generated block
-   }
-
-   public void storeAll(Collection ed) {
-      // TODO: Manik: Customise this generated block
-   }
-
-   public void store(InputStream inputStream) {
-      // TODO: Manik: Customise this generated block
-   }
-
-   public void load(OutputStream outputStream) throws IOException {
-      // TODO: Manik: Customise this generated block
-   }
-
-   public void clear() {
-      // TODO: Manik: Customise this generated block
-   }
-
-   public boolean remove(Object key) {
-      return false;  // TODO: Manik: Customise this generated block
-   }
-
-   public void removeAll(Set<Object> keys) {
-      // TODO: Manik: Customise this generated block
-   }
-
-   public void purgeExpired() {
-      // TODO: Manik: Customise this generated block
-   }
-
-   public void commit(Transaction tx) {
-      // TODO: Manik: Customise this generated block
-   }
-
-   public void rollback(Transaction tx) {
-      // TODO: Manik: Customise this generated block
-   }
-
-   public void prepare(List list, Transaction tx, boolean isOnePhase) {
-      // TODO: Manik: Customise this generated block
-   }
-
-   public void init(CacheLoaderConfig config, Cache cache, Marshaller m) {
-      // TODO: Manik: Customise this generated block
-   }
-
-   public StoredEntry load(Object key) {
-      return null;  // TODO: Manik: Customise this generated block
-   }
-
-   public Set loadAll(Collection keys) {
-      return null;  // TODO: Manik: Customise this generated block
-   }
-
-   public Set loadAll() {
-      return null;  // TODO: Manik: Customise this generated block
-   }
-
-   public boolean containsKey(Object key) {
-      return false;  // TODO: Manik: Customise this generated block
-   }
-
-   public Class<? extends CacheLoaderConfig> getConfigurationClass() {
-      return JDBCCacheLoaderConfig.class;
-   }
-
-   public void start() {
-      // TODO: Manik: Customise this generated block
-   }
-
-   public void stop() {
-      // TODO: Manik: Customise this generated block
-   }
-}

Deleted: core/branches/flat/src/main/java/org/horizon/loader/jdbc/JDBCCacheLoaderConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/JDBCCacheLoaderConfig.java	2009-02-17 18:37:38 UTC (rev 7710)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/JDBCCacheLoaderConfig.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -1,51 +0,0 @@
-package org.horizon.loader.jdbc;
-
-import org.horizon.loader.AbstractCacheLoaderConfig;
-
-/**
- * // TODO: Manik: Document this!
- *
- * @author Manik Surtani
- */
-public class JDBCCacheLoaderConfig extends AbstractCacheLoaderConfig {
-   String dataSource;
-   String tableNamePrefix = "horizon";
-   boolean createTable = true;
-   boolean dropTable = false;
-
-   public JDBCCacheLoaderConfig() {
-      className = JDBCCacheLoader.class.getName();
-   }
-
-   public String getDataSource() {
-      return dataSource;
-   }
-
-   public void setDataSource(String dataSource) {
-      this.dataSource = dataSource;
-   }
-
-   public String getTableNamePrefix() {
-      return tableNamePrefix;
-   }
-
-   public void setTableNamePrefix(String tableNamePrefix) {
-      this.tableNamePrefix = tableNamePrefix;
-   }
-
-   public boolean isCreateTable() {
-      return createTable;
-   }
-
-   public void setCreateTable(boolean createTable) {
-      this.createTable = createTable;
-   }
-
-   public boolean isDropTable() {
-      return dropTable;
-   }
-
-   public void setDropTable(boolean dropTable) {
-      this.dropTable = dropTable;
-   }
-}

Copied: core/branches/flat/src/main/java/org/horizon/loader/jdbc/JDBCCacheStore.java (from rev 7701, core/branches/flat/src/main/java/org/horizon/loader/jdbc/JDBCCacheLoader.java)
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/JDBCCacheStore.java	                        (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/JDBCCacheStore.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -0,0 +1,98 @@
+package org.horizon.loader.jdbc;
+
+import org.horizon.Cache;
+import org.horizon.loader.CacheLoaderConfig;
+import org.horizon.loader.CacheStore;
+import org.horizon.loader.StoredEntry;
+import org.horizon.marshall.Marshaller;
+
+import javax.transaction.Transaction;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * // TODO: Manik: Document this!
+ *
+ * @author Manik Surtani
+ */
+public class JDBCCacheStore implements CacheStore {
+   public void store(StoredEntry ed) {
+      // TODO: Manik: Customise this generated block
+   }
+
+   public void storeAll(Collection ed) {
+      // TODO: Manik: Customise this generated block
+   }
+
+   public void store(InputStream inputStream) {
+      // TODO: Manik: Customise this generated block
+   }
+
+   public void load(OutputStream outputStream) throws IOException {
+      // TODO: Manik: Customise this generated block
+   }
+
+   public void clear() {
+      // TODO: Manik: Customise this generated block
+   }
+
+   public boolean remove(Object key) {
+      return false;  // TODO: Manik: Customise this generated block
+   }
+
+   public void removeAll(Set<Object> keys) {
+      // TODO: Manik: Customise this generated block
+   }
+
+   public void purgeExpired() {
+      // TODO: Manik: Customise this generated block
+   }
+
+   public void commit(Transaction tx) {
+      // TODO: Manik: Customise this generated block
+   }
+
+   public void rollback(Transaction tx) {
+      // TODO: Manik: Customise this generated block
+   }
+
+   public void prepare(List list, Transaction tx, boolean isOnePhase) {
+      // TODO: Manik: Customise this generated block
+   }
+
+   public void init(CacheLoaderConfig config, Cache cache, Marshaller m) {
+      // TODO: Manik: Customise this generated block
+   }
+
+   public StoredEntry load(Object key) {
+      return null;  // TODO: Manik: Customise this generated block
+   }
+
+   public Set loadAll(Collection keys) {
+      return null;  // TODO: Manik: Customise this generated block
+   }
+
+   public Set loadAll() {
+      return null;  // TODO: Manik: Customise this generated block
+   }
+
+   public boolean containsKey(Object key) {
+      return false;  // TODO: Manik: Customise this generated block
+   }
+
+   public Class<? extends CacheLoaderConfig> getConfigurationClass() {
+      return JDBCCacheStoreConfig.class;
+   }
+
+   public void start() {
+      // TODO: Manik: Customise this generated block
+   }
+
+   public void stop() {
+      // TODO: Manik: Customise this generated block
+   }
+}

Copied: core/branches/flat/src/main/java/org/horizon/loader/jdbc/JDBCCacheStoreConfig.java (from rev 7700, core/branches/flat/src/main/java/org/horizon/loader/jdbc/JDBCCacheLoaderConfig.java)
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/JDBCCacheStoreConfig.java	                        (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/JDBCCacheStoreConfig.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -0,0 +1,51 @@
+package org.horizon.loader.jdbc;
+
+import org.horizon.loader.AbstractCacheLoaderConfig;
+
+/**
+ * // TODO: Manik: Document this!
+ *
+ * @author Manik Surtani
+ */
+public class JDBCCacheStoreConfig extends AbstractCacheLoaderConfig {
+   String dataSource;
+   String tableNamePrefix = "horizon";
+   boolean createTable = true;
+   boolean dropTable = false;
+
+   public JDBCCacheStoreConfig() {
+      className = JDBCCacheStore.class.getName();
+   }
+
+   public String getDataSource() {
+      return dataSource;
+   }
+
+   public void setDataSource(String dataSource) {
+      this.dataSource = dataSource;
+   }
+
+   public String getTableNamePrefix() {
+      return tableNamePrefix;
+   }
+
+   public void setTableNamePrefix(String tableNamePrefix) {
+      this.tableNamePrefix = tableNamePrefix;
+   }
+
+   public boolean isCreateTable() {
+      return createTable;
+   }
+
+   public void setCreateTable(boolean createTable) {
+      this.createTable = createTable;
+   }
+
+   public boolean isDropTable() {
+      return dropTable;
+   }
+
+   public void setDropTable(boolean dropTable) {
+      this.dropTable = dropTable;
+   }
+}

Modified: core/branches/flat/src/main/java/org/horizon/marshall/HorizonMarshaller.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/marshall/HorizonMarshaller.java	2009-02-17 18:37:38 UTC (rev 7710)
+++ core/branches/flat/src/main/java/org/horizon/marshall/HorizonMarshaller.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -104,15 +104,14 @@
       trace = log.isTraceEnabled();
    }
 
-   // implement the basic contract set in RPCDispatcher.AbstractMarshaller
-   public byte[] objectToByteBuffer(Object obj) throws Exception {
+   public byte[] objectToByteBuffer(Object obj) throws IOException {
       ByteBuffer b = objectToBuffer(obj);
       byte[] bytes = new byte[b.getLength()];
       System.arraycopy(b.getBuf(), b.getOffset(), bytes, 0, b.getLength());
       return bytes;
    }
 
-   protected void marshallObject(Object o, ObjectOutputStream out, Map<Object, Integer> refMap) throws Exception {
+   protected void marshallObject(Object o, ObjectOutputStream out, Map<Object, Integer> refMap) throws IOException {
       if (o != null && o.getClass().isArray() && isKnownType(o.getClass().getComponentType())) {
          marshallArray(o, out, refMap);
       } else {
@@ -197,18 +196,18 @@
             if (useRefs) writeReference(out, createReference(o, refMap));
             out.writeObject(o);
          } else {
-            throw new Exception("Don't know how to marshall object of type " + o.getClass());
+            throw new IOException("Don't know how to marshall object of type " + o.getClass());
          }
       }
    }
 
 
-   protected void marshallString(String s, ObjectOutputStream out) throws Exception {
+   protected void marshallString(String s, ObjectOutputStream out) throws IOException {
       //StringUtil.saveString(out, s);
       out.writeObject(s);
    }
 
-   private void marshallCommand(ReplicableCommand command, ObjectOutputStream out, Map<Object, Integer> refMap) throws Exception {
+   private void marshallCommand(ReplicableCommand command, ObjectOutputStream out, Map<Object, Integer> refMap) throws IOException {
       out.writeShort(command.getCommandId());
       Object[] args = command.getParameters();
       byte numArgs = (byte) (args == null ? 0 : args.length);
@@ -225,17 +224,17 @@
       return reference;
    }
 
-   private void marshallGlobalTransaction(GlobalTransaction globalTransaction, ObjectOutputStream out, Map<Object, Integer> refMap) throws Exception {
+   private void marshallGlobalTransaction(GlobalTransaction globalTransaction, ObjectOutputStream out, Map<Object, Integer> refMap) throws IOException {
       out.writeLong(globalTransaction.getId());
       marshallObject(globalTransaction.getAddress(), out, refMap);
    }
 
-   private void marshallJGroupsAddress(JGroupsAddress address, ObjectOutputStream out) throws Exception {
+   private void marshallJGroupsAddress(JGroupsAddress address, ObjectOutputStream out) throws IOException {
       address.writeExternal(out);
    }
 
    @SuppressWarnings("unchecked")
-   private void marshallCollection(Collection c, ObjectOutputStream out, Map refMap) throws Exception {
+   private void marshallCollection(Collection c, ObjectOutputStream out, Map refMap) throws IOException {
       writeUnsignedInt(out, c.size());
       for (Object o : c) {
          marshallObject(o, out, refMap);
@@ -243,7 +242,7 @@
    }
 
    @SuppressWarnings("unchecked")
-   private void marshallMap(Map map, ObjectOutputStream out, Map<Object, Integer> refMap) throws Exception {
+   private void marshallMap(Map map, ObjectOutputStream out, Map<Object, Integer> refMap) throws IOException {
       int mapSize = map.size();
       writeUnsignedInt(out, mapSize);
       if (mapSize == 0) return;
@@ -256,7 +255,7 @@
 
    // --------- Unmarshalling methods
 
-   protected Object unmarshallObject(ObjectInputStream in, ClassLoader loader, UnmarshalledReferences refMap, boolean overrideContextClassloaderOnThread) throws Exception {
+   protected Object unmarshallObject(ObjectInputStream in, ClassLoader loader, UnmarshalledReferences refMap, boolean overrideContextClassloaderOnThread) throws IOException, ClassNotFoundException {
       if (loader == null) {
          return unmarshallObject(in, refMap);
       } else {
@@ -273,7 +272,7 @@
       }
    }
 
-   protected Object unmarshallObject(ObjectInputStream in, UnmarshalledReferences refMap) throws Exception {
+   protected Object unmarshallObject(ObjectInputStream in, UnmarshalledReferences refMap) throws IOException, ClassNotFoundException {
       byte magicNumber = in.readByte();
       int reference = 0;
       Object retVal;
@@ -342,22 +341,22 @@
             if (log.isErrorEnabled()) {
                log.error("Unknown Magic Number " + magicNumber);
             }
-            throw new Exception("Unknown magic number " + magicNumber);
+            throw new IOException("Unknown magic number " + magicNumber);
       }
-      throw new Exception("Unknown magic number " + magicNumber);
+      throw new IOException("Unknown magic number " + magicNumber);
    }
 
-   private FastCopyHashMap unmarshallFastCopyHashMap(ObjectInputStream in, UnmarshalledReferences refMap) throws Exception {
+   private FastCopyHashMap unmarshallFastCopyHashMap(ObjectInputStream in, UnmarshalledReferences refMap) throws IOException, ClassNotFoundException {
       FastCopyHashMap map = new FastCopyHashMap();
       populateFromStream(in, refMap, map);
       return map;
    }
 
-   protected String unmarshallString(ObjectInputStream in) throws Exception {
+   protected String unmarshallString(ObjectInputStream in) throws IOException, ClassNotFoundException {
       return (String) in.readObject();
    }
 
-   private ReplicableCommand unmarshallCommand(ObjectInputStream in, UnmarshalledReferences refMap) throws Exception {
+   private ReplicableCommand unmarshallCommand(ObjectInputStream in, UnmarshalledReferences refMap) throws IOException, ClassNotFoundException {
       short methodId = in.readShort();
       byte numArgs = in.readByte();
       Object[] args = null;
@@ -371,7 +370,7 @@
    }
 
 
-   private GlobalTransaction unmarshallGlobalTransaction(ObjectInputStream in, UnmarshalledReferences refMap) throws Exception {
+   private GlobalTransaction unmarshallGlobalTransaction(ObjectInputStream in, UnmarshalledReferences refMap) throws IOException, ClassNotFoundException {
       GlobalTransaction gtx = new GlobalTransaction();
       long id = in.readLong();
       Object address = unmarshallObject(in, refMap);
@@ -380,74 +379,74 @@
       return gtx;
    }
 
-   private JGroupsAddress unmarshallJGroupsAddress(ObjectInputStream in) throws Exception {
+   private JGroupsAddress unmarshallJGroupsAddress(ObjectInputStream in) throws IOException, ClassNotFoundException {
       JGroupsAddress address = new JGroupsAddress();
       address.readExternal(in);
       return address;
    }
 
-   private List unmarshallArrayList(ObjectInputStream in, UnmarshalledReferences refMap) throws Exception {
+   private List unmarshallArrayList(ObjectInputStream in, UnmarshalledReferences refMap) throws IOException, ClassNotFoundException {
       int listSize = readUnsignedInt(in);
       List list = new ArrayList(listSize);
       populateFromStream(in, refMap, list, listSize);
       return list;
    }
 
-   private List unmarshallLinkedList(ObjectInputStream in, UnmarshalledReferences refMap) throws Exception {
+   private List unmarshallLinkedList(ObjectInputStream in, UnmarshalledReferences refMap) throws IOException, ClassNotFoundException {
       List list = new LinkedList();
       populateFromStream(in, refMap, list, readUnsignedInt(in));
       return list;
    }
 
-   private List unmarshallSingletonList(ObjectInputStream in, UnmarshalledReferences refMap) throws Exception {
+   private List unmarshallSingletonList(ObjectInputStream in, UnmarshalledReferences refMap) throws IOException, ClassNotFoundException {
       return Collections.singletonList(unmarshallObject(in, refMap));
    }
 
-   private Map unmarshallHashMap(ObjectInputStream in, UnmarshalledReferences refMap) throws Exception {
+   private Map unmarshallHashMap(ObjectInputStream in, UnmarshalledReferences refMap) throws IOException, ClassNotFoundException {
       Map map = new HashMap();
       populateFromStream(in, refMap, map);
       return map;
    }
 
    @SuppressWarnings("unchecked")
-   private Map unmarshallMapCopy(ObjectInputStream in, UnmarshalledReferences refMap) throws Exception {
+   private Map unmarshallMapCopy(ObjectInputStream in, UnmarshalledReferences refMap) throws IOException, ClassNotFoundException {
       // read in as a HashMap first
       Map m = unmarshallHashMap(in, refMap);
       return Immutables.immutableMapWrap(m);
    }
 
-   private Map unmarshallTreeMap(ObjectInputStream in, UnmarshalledReferences refMap) throws Exception {
+   private Map unmarshallTreeMap(ObjectInputStream in, UnmarshalledReferences refMap) throws IOException, ClassNotFoundException {
       Map map = new TreeMap();
       populateFromStream(in, refMap, map);
       return map;
    }
 
-   private Set unmarshallHashSet(ObjectInputStream in, UnmarshalledReferences refMap) throws Exception {
+   private Set unmarshallHashSet(ObjectInputStream in, UnmarshalledReferences refMap) throws IOException, ClassNotFoundException {
       Set set = new HashSet();
       populateFromStream(in, refMap, set);
       return set;
    }
 
-   private Set unmarshallTreeSet(ObjectInputStream in, UnmarshalledReferences refMap) throws Exception {
+   private Set unmarshallTreeSet(ObjectInputStream in, UnmarshalledReferences refMap) throws IOException, ClassNotFoundException {
       Set set = new TreeSet();
       populateFromStream(in, refMap, set);
       return set;
    }
 
    @SuppressWarnings("unchecked")
-   private void populateFromStream(ObjectInputStream in, UnmarshalledReferences refMap, Map mapToPopulate) throws Exception {
+   private void populateFromStream(ObjectInputStream in, UnmarshalledReferences refMap, Map mapToPopulate) throws IOException, ClassNotFoundException {
       int size = readUnsignedInt(in);
       for (int i = 0; i < size; i++) mapToPopulate.put(unmarshallObject(in, refMap), unmarshallObject(in, refMap));
    }
 
    @SuppressWarnings("unchecked")
-   private void populateFromStream(ObjectInputStream in, UnmarshalledReferences refMap, Set setToPopulate) throws Exception {
+   private void populateFromStream(ObjectInputStream in, UnmarshalledReferences refMap, Set setToPopulate) throws IOException, ClassNotFoundException {
       int size = readUnsignedInt(in);
       for (int i = 0; i < size; i++) setToPopulate.add(unmarshallObject(in, refMap));
    }
 
    @SuppressWarnings("unchecked")
-   private void populateFromStream(ObjectInputStream in, UnmarshalledReferences refMap, List listToPopulate, int listSize) throws Exception {
+   private void populateFromStream(ObjectInputStream in, UnmarshalledReferences refMap, List listToPopulate, int listSize) throws IOException, ClassNotFoundException {
       for (int i = 0; i < listSize; i++) listToPopulate.add(unmarshallObject(in, refMap));
    }
 
@@ -534,7 +533,7 @@
       out.writeByte((byte) i);
    }
 
-   protected Object unmarshallArray(ObjectInputStream in, UnmarshalledReferences refs) throws Exception {
+   protected Object unmarshallArray(ObjectInputStream in, UnmarshalledReferences refs) throws IOException, ClassNotFoundException {
       int sz = readUnsignedInt(in);
       byte type = in.readByte();
       switch (type) {
@@ -651,7 +650,7 @@
       }
    }
 
-   protected void marshallArray(Object o, ObjectOutputStream out, Map<Object, Integer> refMap) throws Exception {
+   protected void marshallArray(Object o, ObjectOutputStream out, Map<Object, Integer> refMap) throws IOException {
       out.writeByte(MAGICNUMBER_ARRAY);
       Class arrayTypeClass = o.getClass().getComponentType();
       int sz = Array.getLength(o);
@@ -727,7 +726,7 @@
             c.equals(Double.class));
    }
 
-   public void objectToObjectStream(Object o, ObjectOutputStream out) throws Exception {
+   public void objectToObjectStream(Object o, ObjectOutputStream out) throws IOException {
       Map<Object, Integer> refMap = useRefs ? new IdentityHashMap<Object, Integer>() : null;
       ClassLoader toUse = defaultClassLoader;
       Thread current = Thread.currentThread();
@@ -743,18 +742,18 @@
       }
    }
 
-   public Object objectFromObjectStream(ObjectInputStream in) throws Exception {
+   public Object objectFromObjectStream(ObjectInputStream in) throws IOException, ClassNotFoundException {
       UnmarshalledReferences refMap = useRefs ? new UnmarshalledReferences() : null;
       Object retValue = unmarshallObject(in, defaultClassLoader, refMap, false);
       if (trace) log.trace("Unmarshalled object " + retValue);
       return retValue;
    }
 
-   public Object objectFromStream(InputStream is) throws Exception {
+   public Object objectFromStream(InputStream is) throws IOException {
       throw new NotImplementedException("not implemented");
    }
 
-   public ByteBuffer objectToBuffer(Object o) throws Exception {
+   public ByteBuffer objectToBuffer(Object o) throws IOException {
       ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream(128);
       ObjectOutputStream out = new ObjectOutputStream(baos);
 
@@ -765,12 +764,12 @@
       return new ByteBuffer(baos.getRawBuffer(), 0, baos.size());
    }
 
-   public Object objectFromByteBuffer(byte[] buf, int offset, int length) throws Exception {
+   public Object objectFromByteBuffer(byte[] buf, int offset, int length) throws IOException, ClassNotFoundException {
       ObjectInputStream in = new MarshalledValueInputStream(new ByteArrayInputStream(buf, offset, length));
       return objectFromObjectStream(in);
    }
 
-   public Object objectFromByteBuffer(byte[] bytes) throws Exception {
+   public Object objectFromByteBuffer(byte[] bytes) throws IOException, ClassNotFoundException {
       return objectFromByteBuffer(bytes, 0, bytes.length);
    }
 }
\ No newline at end of file

Modified: core/branches/flat/src/main/java/org/horizon/marshall/Marshaller.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/marshall/Marshaller.java	2009-02-17 18:37:38 UTC (rev 7710)
+++ core/branches/flat/src/main/java/org/horizon/marshall/Marshaller.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -25,6 +25,7 @@
 import org.horizon.factories.scopes.Scopes;
 import org.horizon.io.ByteBuffer;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
@@ -47,8 +48,8 @@
  * This interface is used to marshall {@link org.horizon.commands.ReplicableCommand}s, their parameters and their
  * response values.
  * <p/>
- * The interface is also used by the {@link org.horizon.loader.CacheLoaderOld} framework to efficiently serialize data
- * to be persisted, as well as the {@link org.horizon.statetransfer.StateTransferManager} when serializing the cache for
+ * The interface is also used by the {@link org.horizon.loader.CacheStore} framework to efficiently serialize data to be
+ * persisted, as well as the {@link org.horizon.statetransfer.StateTransferManager} when serializing the cache for
  * transferring state en-masse.
  *
  * @author <a href="mailto://manik@jboss.org">Manik Surtani</a>
@@ -62,14 +63,14 @@
     * @param obj object to marshall
     * @param out stream to marshall to
     */
-   void objectToObjectStream(Object obj, ObjectOutputStream out) throws Exception;
+   void objectToObjectStream(Object obj, ObjectOutputStream out) throws IOException;
 
    /**
     * Unmarshalls an object from an {@link java.io.ObjectInputStream}
     *
     * @param in stream to unmarshall from
     */
-   Object objectFromObjectStream(ObjectInputStream in) throws Exception;
+   Object objectFromObjectStream(ObjectInputStream in) throws IOException, ClassNotFoundException;
 
    /**
     * Unmarshalls an object from an {@link java.io.InputStream}
@@ -77,7 +78,7 @@
     * @param is stream to unmarshall from
     * @return Object from stream passed in.
     */
-   Object objectFromStream(InputStream is) throws Exception;
+   Object objectFromStream(InputStream is) throws IOException, ClassNotFoundException;
 
    /**
     * A method that returns an instance of {@link org.horizon.io.ByteBuffer}, which allows direct access to the byte
@@ -87,11 +88,11 @@
     * @return a ByteBuffer
     * @throws Exception
     */
-   ByteBuffer objectToBuffer(Object o) throws Exception;
+   ByteBuffer objectToBuffer(Object o) throws IOException;
 
-   Object objectFromByteBuffer(byte[] buf, int offset, int length) throws Exception;
+   Object objectFromByteBuffer(byte[] buf, int offset, int length) throws IOException, ClassNotFoundException;
 
-   byte[] objectToByteBuffer(Object obj) throws Exception;
+   byte[] objectToByteBuffer(Object obj) throws IOException;
 
-   Object objectFromByteBuffer(byte[] buf) throws Exception;
+   Object objectFromByteBuffer(byte[] buf) throws IOException, ClassNotFoundException;
 }
\ No newline at end of file

Modified: core/branches/flat/src/main/java/org/horizon/marshall/VersionAwareMarshaller.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/marshall/VersionAwareMarshaller.java	2009-02-17 18:37:38 UTC (rev 7710)
+++ core/branches/flat/src/main/java/org/horizon/marshall/VersionAwareMarshaller.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -30,6 +30,7 @@
 import org.jboss.util.stream.MarshalledValueInputStream;
 
 import java.io.ByteArrayInputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
@@ -47,7 +48,7 @@
    private static final Log log = LogFactory.getLog(VersionAwareMarshaller.class);
    private boolean trace = log.isTraceEnabled();
 
-   private static final int VERSION_400 = 40;
+   private static final int VERSION_100 = 100;
    private static final int CUSTOM_MARSHALLER = 999;
 
    private HorizonMarshaller defaultMarshaller;
@@ -64,12 +65,12 @@
       return CUSTOM_MARSHALLER;
    }
 
-   public ByteBuffer objectToBuffer(Object obj) throws Exception {
+   public ByteBuffer objectToBuffer(Object obj) throws IOException {
       ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream(128);
       ObjectOutputStream out = new ObjectOutputStream(baos);
 
-      out.writeShort(VERSION_400);
-      if (trace) log.trace("Wrote version " + VERSION_400);
+      out.writeShort(VERSION_100);
+      log.trace("Wrote version {0}", VERSION_100);
 
       //now marshall the contents of the object
       defaultMarshaller.objectToObjectStream(obj, out);
@@ -79,21 +80,21 @@
       return new ByteBuffer(baos.getRawBuffer(), 0, baos.size());
    }
 
-   public Object objectFromByteBuffer(byte[] bytes, int offset, int len) throws Exception {
+   public Object objectFromByteBuffer(byte[] bytes, int offset, int len) throws IOException, ClassNotFoundException {
       int versionId;
       ObjectInputStream in = new MarshalledValueInputStream(new ByteArrayInputStream(bytes, offset, len));
       try {
          versionId = in.readShort();
-         if (trace) log.trace("Read version " + versionId);
+         log.trace("Read version {0}", versionId);
       }
       catch (Exception e) {
          log.error("Unable to read version id from first two bytes of stream, barfing.");
-         throw e;
+         throw new IOException("Unable to read version id from first two bytes of stream.");
       }
       return defaultMarshaller.objectFromObjectStream(in);
    }
 
-   public Object objectFromStream(InputStream is) throws Exception {
+   public Object objectFromStream(InputStream is) throws IOException, ClassNotFoundException {
       short versionId;
       ObjectInputStream in = new MarshalledValueInputStream(is);
       try {
@@ -102,35 +103,35 @@
       }
       catch (Exception e) {
          log.error("Unable to read version id from first two bytes of stream, barfing.");
-         throw e;
+         throw new IOException("Unable to read version id from first two bytes of stream.");
       }
       return defaultMarshaller.objectFromObjectStream(in);
    }
 
-   public void objectToObjectStream(Object obj, ObjectOutputStream out) throws Exception {
-      out.writeShort(VERSION_400);
-      if (trace) log.trace("Wrote version " + VERSION_400);
+   public void objectToObjectStream(Object obj, ObjectOutputStream out) throws IOException {
+      out.writeShort(VERSION_100);
+      log.trace("Wrote version {0}", VERSION_100);
       defaultMarshaller.objectToObjectStream(obj, out);
    }
 
-   public Object objectFromObjectStream(ObjectInputStream in) throws Exception {
+   public Object objectFromObjectStream(ObjectInputStream in) throws IOException, ClassNotFoundException {
       int versionId;
       try {
          versionId = in.readShort();
-         if (trace) log.trace("Read version " + versionId);
+         log.trace("Read version {0}", versionId);
       }
       catch (Exception e) {
          log.error("Unable to read version id from first two bytes of stream, barfing.");
-         throw e;
+         throw new IOException("Unable to read version id from first two bytes of stream.");
       }
       return defaultMarshaller.objectFromObjectStream(in);
    }
 
-   public byte[] objectToByteBuffer(Object obj) throws Exception {
+   public byte[] objectToByteBuffer(Object obj) throws IOException {
       return defaultMarshaller.objectToByteBuffer(obj);
    }
 
-   public Object objectFromByteBuffer(byte[] buf) throws Exception {
+   public Object objectFromByteBuffer(byte[] buf) throws IOException, ClassNotFoundException {
       return defaultMarshaller.objectFromByteBuffer(buf);
    }
 }
\ No newline at end of file

Modified: core/branches/flat/src/test/java/org/horizon/config/parsing/ConfigurationParserTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/config/parsing/ConfigurationParserTest.java	2009-02-17 18:37:38 UTC (rev 7710)
+++ core/branches/flat/src/test/java/org/horizon/config/parsing/ConfigurationParserTest.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -8,7 +8,7 @@
 import org.horizon.eviction.algorithms.fifo.FIFOAlgorithmConfig;
 import org.horizon.loader.CacheLoaderConfig;
 import org.horizon.loader.decorators.SingletonStoreConfig;
-import org.horizon.loader.jdbc.JDBCCacheLoaderConfig;
+import org.horizon.loader.jdbc.JDBCCacheStoreConfig;
 import org.horizon.lock.IsolationLevel;
 import org.horizon.transaction.GenericTransactionManagerLookup;
 import org.testng.annotations.Test;
@@ -155,7 +155,7 @@
    public void testCacheLoaders() throws Exception {
       XmlConfigurationParserImpl parser = new XmlConfigurationParserImpl();
       String xml = "<loaders passivation=\"true\" shared=\"true\" preload=\"true\">\n" +
-            "         <loader class=\"org.horizon.loader.jdbc.JDBCCacheLoader\" fetchPersistentState=\"true\"\n" +
+            "         <loader class=\"org.horizon.loader.jdbc.JDBCCacheStore\" fetchPersistentState=\"true\"\n" +
             "                 ignoreModifications=\"false\" purgeOnStartup=\"false\">\n" +
             "            <properties>\n" +
             "               dataSource=HorizonDS\n" +
@@ -180,7 +180,7 @@
       assert clc.isPreload();
 
       CacheLoaderConfig iclc = clc.getFirstCacheLoaderConfig();
-      assert iclc.getClassName().equals("org.horizon.loader.jdbc.JDBCCacheLoader");
+      assert iclc.getClassName().equals("org.horizon.loader.jdbc.JDBCCacheStore");
       assert iclc.getAsyncStoreConfig().isEnabled();
       assert iclc.getAsyncStoreConfig().getBatchSize() == 15;
       assert iclc.getAsyncStoreConfig().getPollWait() == 100;
@@ -190,7 +190,7 @@
       assert !iclc.isIgnoreModifications();
       assert !iclc.isPurgeOnStartup();
 
-      JDBCCacheLoaderConfig jdbcclc = (JDBCCacheLoaderConfig) iclc;
+      JDBCCacheStoreConfig jdbcclc = (JDBCCacheStoreConfig) iclc;
       assert jdbcclc.getDataSource().equals("HorizonDS");
       assert jdbcclc.getTableNamePrefix().equals("horizon");
       assert jdbcclc.isCreateTable();
@@ -205,7 +205,7 @@
    public void testCacheLoadersDefaults() throws Exception {
       XmlConfigurationParserImpl parser = new XmlConfigurationParserImpl();
       String xml = "<loaders>\n" +
-            "         <loader class=\"org.horizon.loader.jdbc.JDBCCacheLoader\">\n" +
+            "         <loader class=\"org.horizon.loader.jdbc.JDBCCacheStore\">\n" +
             "            <properties />\n" +
             "         </loader>\n" +
             "      </loaders>";
@@ -222,7 +222,7 @@
       assert !clc.isPreload();
 
       CacheLoaderConfig iclc = clc.getFirstCacheLoaderConfig();
-      assert iclc.getClassName().equals("org.horizon.loader.jdbc.JDBCCacheLoader");
+      assert iclc.getClassName().equals("org.horizon.loader.jdbc.JDBCCacheStore");
       assert !iclc.getAsyncStoreConfig().isEnabled();
       assert !iclc.isFetchPersistentState();
       assert !iclc.isIgnoreModifications();

Deleted: core/branches/flat/src/test/java/org/horizon/loader/BaseCacheLoaderTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/BaseCacheLoaderTest.java	2009-02-17 18:37:38 UTC (rev 7710)
+++ core/branches/flat/src/test/java/org/horizon/loader/BaseCacheLoaderTest.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -1,238 +0,0 @@
-package org.horizon.loader;
-
-import org.easymock.EasyMock;
-import org.horizon.loader.modifications.Clear;
-import org.horizon.loader.modifications.Modification;
-import org.horizon.loader.modifications.Remove;
-import org.horizon.loader.modifications.Store;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import javax.transaction.Transaction;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
- at Test(groups = "unit")
- at SuppressWarnings("unchecked")
-public abstract class BaseCacheLoaderTest {
-
-   protected abstract CacheStore createCacheStore();
-
-   protected CacheStore cs;
-
-   @BeforeMethod
-   public void setUp() {
-      cs = createCacheStore();
-   }
-
-   @AfterMethod
-   public void tearDown() {
-      if (cs != null) {
-         cs.clear();
-         cs.stop();
-      }
-      cs = null;
-   }
-
-   public void testLoadAndStore() throws InterruptedException {
-      assert !cs.containsKey("k");
-      StoredEntry se = new StoredEntry("k", "v", -1, -1);
-      cs.store(se);
-
-      assert cs.load("k").getValue().equals("v");
-      assert cs.load("k").getLifespan() == -1;
-      assert !cs.load("k").isExpired();
-      assert cs.containsKey("k");
-
-      long now = System.currentTimeMillis();
-      long lifespan = 120000;
-      se = new StoredEntry("k", "v", now, now + lifespan);
-      cs.store(se);
-
-      assert cs.load("k").getValue().equals("v");
-      assert cs.load("k").getLifespan() == lifespan;
-      assert !cs.load("k").isExpired();
-      assert cs.containsKey("k");
-
-      now = System.currentTimeMillis();
-      lifespan = 1;
-      se = new StoredEntry("k", "v", now, now + lifespan);
-      cs.store(se);
-      Thread.sleep(100);
-      assert se.isExpired();
-      assert cs.load("k") == null;
-      assert !cs.containsKey("k");
-   }
-
-   public void testOnePhaseCommit() {
-      List<Modification> mods = new ArrayList<Modification>();
-      mods.add(new Store(new StoredEntry("k1", "v1", -1, -1)));
-      mods.add(new Store(new StoredEntry("k2", "v2", -1, -1)));
-      mods.add(new Remove("k1"));
-      Transaction tx = EasyMock.createNiceMock(Transaction.class);
-      cs.prepare(mods, tx, true);
-
-      assert cs.load("k2").getValue().equals("v2");
-      assert !cs.containsKey("k1");
-
-      cs.clear();
-
-      mods = new ArrayList<Modification>();
-      mods.add(new Store(new StoredEntry("k1", "v1", -1, -1)));
-      mods.add(new Store(new StoredEntry("k2", "v2", -1, -1)));
-      mods.add(new Clear());
-      mods.add(new Store(new StoredEntry("k3", "v3", -1, -1)));
-
-      cs.prepare(mods, tx, true);
-      assert !cs.containsKey("k1");
-      assert !cs.containsKey("k2");
-      assert cs.containsKey("k3");
-   }
-
-   public void testTwoPhaseCommit() {
-      List<Modification> mods = new ArrayList<Modification>();
-      mods.add(new Store(new StoredEntry("k1", "v1", -1, -1)));
-      mods.add(new Store(new StoredEntry("k2", "v2", -1, -1)));
-      mods.add(new Remove("k1"));
-      Transaction tx = EasyMock.createNiceMock(Transaction.class);
-      cs.prepare(mods, tx, false);
-
-      assert !cs.containsKey("k1");
-      assert !cs.containsKey("k2");
-
-      cs.commit(tx);
-
-      assert cs.load("k2").getValue().equals("v2");
-      assert !cs.containsKey("k1");
-
-      cs.clear();
-
-      mods = new ArrayList<Modification>();
-      mods.add(new Store(new StoredEntry("k1", "v1", -1, -1)));
-      mods.add(new Store(new StoredEntry("k2", "v2", -1, -1)));
-      mods.add(new Clear());
-      mods.add(new Store(new StoredEntry("k3", "v3", -1, -1)));
-
-      cs.prepare(mods, tx, false);
-
-      assert !cs.containsKey("k1");
-      assert !cs.containsKey("k2");
-      assert !cs.containsKey("k3");
-
-      cs.commit(tx);
-
-      assert !cs.containsKey("k1");
-      assert !cs.containsKey("k2");
-      assert cs.containsKey("k3");
-   }
-
-   public void testRollback() {
-
-      cs.store(new StoredEntry("old", "old", -1, -1));
-
-      List<Modification> mods = new ArrayList<Modification>();
-      mods.add(new Store(new StoredEntry("k1", "v1", -1, -1)));
-      mods.add(new Store(new StoredEntry("k2", "v2", -1, -1)));
-      mods.add(new Remove("k1"));
-      mods.add(new Remove("old"));
-      Transaction tx = EasyMock.createNiceMock(Transaction.class);
-      cs.prepare(mods, tx, false);
-
-      assert !cs.containsKey("k1");
-      assert !cs.containsKey("k2");
-      assert cs.containsKey("old");
-
-      cs.rollback(tx);
-
-      assert !cs.containsKey("k1");
-      assert !cs.containsKey("k2");
-      assert cs.containsKey("old");
-
-      mods = new ArrayList<Modification>();
-      mods.add(new Store(new StoredEntry("k1", "v1", -1, -1)));
-      mods.add(new Store(new StoredEntry("k2", "v2", -1, -1)));
-      mods.add(new Clear());
-      mods.add(new Store(new StoredEntry("k3", "v3", -1, -1)));
-
-      cs.prepare(mods, tx, false);
-
-      assert !cs.containsKey("k1");
-      assert !cs.containsKey("k2");
-      assert !cs.containsKey("k3");
-
-      cs.rollback(tx);
-
-      assert !cs.containsKey("k1");
-      assert !cs.containsKey("k2");
-      assert !cs.containsKey("k3");
-      assert cs.containsKey("old");
-   }
-
-   public void testCommitAndRollbackWithoutPrepare() {
-      cs.store(new StoredEntry("old", "old", -1, -1));
-      Transaction tx = EasyMock.createNiceMock(Transaction.class);
-      cs.commit(tx);
-      cs.store(new StoredEntry("old", "old", -1, -1));
-      cs.rollback(tx);
-
-      assert cs.containsKey("old");
-   }
-
-   public void testPreload() {
-      cs.store(new StoredEntry("k1", "v1", -1, -1));
-      cs.store(new StoredEntry("k2", "v2", -1, -1));
-      cs.store(new StoredEntry("k3", "v3", -1, -1));
-
-      Set<StoredEntry> set = cs.loadAll();
-
-      assert set.size() == 3;
-      Set expected = new HashSet();
-      expected.add("k1");
-      expected.add("k2");
-      expected.add("k3");
-      for (StoredEntry se : set) assert expected.remove(se.getKey());
-      assert expected.isEmpty();
-   }
-
-   public void testPurgeExpired() throws InterruptedException {
-      long now = System.currentTimeMillis();
-      long lifespan = 1000;
-      cs.store(new StoredEntry("k1", "v1", now, now + lifespan));
-      cs.store(new StoredEntry("k2", "v2", now, now + lifespan));
-      cs.store(new StoredEntry("k3", "v3", now, now + lifespan));
-      Thread.sleep(lifespan + 100);
-      cs.purgeExpired();
-      assert !cs.containsKey("k1");
-      assert !cs.containsKey("k2");
-      assert !cs.containsKey("k3");
-   }
-
-   public void testStreamingAPI() throws IOException, ClassNotFoundException {
-      cs.store(new StoredEntry("k1", "v1", -1, -1));
-      cs.store(new StoredEntry("k2", "v2", -1, -1));
-      cs.store(new StoredEntry("k3", "v3", -1, -1));
-
-      ByteArrayOutputStream out = new ByteArrayOutputStream();
-      cs.load(out);
-      out.flush();
-      out.close();
-      cs.clear();
-      cs.store(new ByteArrayInputStream(out.toByteArray()));
-
-      Set<StoredEntry> set = cs.loadAll();
-
-      assert set.size() == 3;
-      Set expected = new HashSet();
-      expected.add("k1");
-      expected.add("k2");
-      expected.add("k3");
-      for (StoredEntry se : set) assert expected.remove(se.getKey());
-      assert expected.isEmpty();
-   }
-}

Copied: core/branches/flat/src/test/java/org/horizon/loader/BaseCacheStoreTest.java (from rev 7701, core/branches/flat/src/test/java/org/horizon/loader/BaseCacheLoaderTest.java)
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/BaseCacheStoreTest.java	                        (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/loader/BaseCacheStoreTest.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -0,0 +1,310 @@
+package org.horizon.loader;
+
+import org.easymock.EasyMock;
+import org.horizon.Cache;
+import org.horizon.io.ByteBuffer;
+import org.horizon.loader.modifications.Clear;
+import org.horizon.loader.modifications.Modification;
+import org.horizon.loader.modifications.Remove;
+import org.horizon.loader.modifications.Store;
+import org.horizon.marshall.Marshaller;
+import org.horizon.util.Util;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import javax.transaction.Transaction;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+ at Test(groups = "unit")
+ at SuppressWarnings("unchecked")
+public abstract class BaseCacheStoreTest {
+
+   protected abstract CacheStore createCacheStore();
+
+   protected CacheStore cs;
+
+   @BeforeMethod
+   public void setUp() {
+      cs = createCacheStore();
+   }
+
+   @AfterMethod
+   public void tearDown() {
+      if (cs != null) {
+         cs.clear();
+         cs.stop();
+      }
+      cs = null;
+   }
+
+   /**
+    * @return a mock cache for use with the cache store impls
+    */
+   protected Cache getCache() {
+      Cache c = EasyMock.createNiceMock(Cache.class);
+      EasyMock.expect(c.getName()).andReturn("mockCache-" + getClass().getName()).anyTimes();
+      EasyMock.replay(c);
+      return c;
+   }
+
+   /**
+    * @return a mock marshaller for use with the cache store impls
+    */
+   protected Marshaller getMarshaller() {
+      return new Marshaller() {
+
+         public void objectToObjectStream(Object obj, ObjectOutputStream out) throws IOException {
+            out.writeObject(obj);
+         }
+
+         public Object objectFromObjectStream(ObjectInputStream in) throws IOException, ClassNotFoundException {
+            return in.readObject();
+         }
+
+         public Object objectFromStream(InputStream is) throws IOException, ClassNotFoundException {
+            if (is instanceof ObjectInputStream)
+               return objectFromObjectStream((ObjectInputStream) is);
+            else
+               return objectFromObjectStream(new ObjectInputStream(is));
+         }
+
+         public ByteBuffer objectToBuffer(Object o) throws IOException {
+            byte[] b = objectToByteBuffer(o);
+            return new ByteBuffer(b, 0, b.length);
+         }
+
+         public Object objectFromByteBuffer(byte[] buf, int offset, int length) throws IOException, ClassNotFoundException {
+            byte[] newBytes = new byte[length];
+            System.arraycopy(buf, offset, newBytes, 0, length);
+            return objectFromByteBuffer(newBytes);
+         }
+
+         public byte[] objectToByteBuffer(Object obj) throws IOException {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            ObjectOutputStream oos = new ObjectOutputStream(baos);
+            objectToObjectStream(obj, oos);
+            oos.flush();
+            oos.close();
+            baos.close();
+            return baos.toByteArray();
+         }
+
+         public Object objectFromByteBuffer(byte[] buf) throws IOException, ClassNotFoundException {
+            return objectFromObjectStream(new ObjectInputStream(new ByteArrayInputStream(buf)));
+         }
+      };
+   }
+
+
+   public void testLoadAndStore() throws InterruptedException {
+      assert !cs.containsKey("k");
+      StoredEntry se = new StoredEntry("k", "v", -1, -1);
+      cs.store(se);
+
+      assert cs.load("k").getValue().equals("v");
+      assert cs.load("k").getLifespan() == -1;
+      assert !cs.load("k").isExpired();
+      assert cs.containsKey("k");
+
+      long now = System.currentTimeMillis();
+      long lifespan = 120000;
+      se = new StoredEntry("k", "v", now, now + lifespan);
+      cs.store(se);
+
+      assert cs.load("k").getValue().equals("v");
+      assert cs.load("k").getLifespan() == lifespan;
+      assert !cs.load("k").isExpired();
+      assert cs.containsKey("k");
+
+      now = System.currentTimeMillis();
+      lifespan = 1;
+      se = new StoredEntry("k", "v", now, now + lifespan);
+      cs.store(se);
+      Thread.sleep(100);
+      assert se.isExpired();
+      assert cs.load("k") == null;
+      assert !cs.containsKey("k");
+   }
+
+   public void testOnePhaseCommit() {
+      List<Modification> mods = new ArrayList<Modification>();
+      mods.add(new Store(new StoredEntry("k1", "v1", -1, -1)));
+      mods.add(new Store(new StoredEntry("k2", "v2", -1, -1)));
+      mods.add(new Remove("k1"));
+      Transaction tx = EasyMock.createNiceMock(Transaction.class);
+      cs.prepare(mods, tx, true);
+
+      assert cs.load("k2").getValue().equals("v2");
+      assert !cs.containsKey("k1");
+
+      cs.clear();
+
+      mods = new ArrayList<Modification>();
+      mods.add(new Store(new StoredEntry("k1", "v1", -1, -1)));
+      mods.add(new Store(new StoredEntry("k2", "v2", -1, -1)));
+      mods.add(new Clear());
+      mods.add(new Store(new StoredEntry("k3", "v3", -1, -1)));
+
+      cs.prepare(mods, tx, true);
+      assert !cs.containsKey("k1");
+      assert !cs.containsKey("k2");
+      assert cs.containsKey("k3");
+   }
+
+   public void testTwoPhaseCommit() {
+      List<Modification> mods = new ArrayList<Modification>();
+      mods.add(new Store(new StoredEntry("k1", "v1", -1, -1)));
+      mods.add(new Store(new StoredEntry("k2", "v2", -1, -1)));
+      mods.add(new Remove("k1"));
+      Transaction tx = EasyMock.createNiceMock(Transaction.class);
+      cs.prepare(mods, tx, false);
+
+      assert !cs.containsKey("k1");
+      assert !cs.containsKey("k2");
+
+      cs.commit(tx);
+
+      assert cs.load("k2").getValue().equals("v2");
+      assert !cs.containsKey("k1");
+
+      cs.clear();
+
+      mods = new ArrayList<Modification>();
+      mods.add(new Store(new StoredEntry("k1", "v1", -1, -1)));
+      mods.add(new Store(new StoredEntry("k2", "v2", -1, -1)));
+      mods.add(new Clear());
+      mods.add(new Store(new StoredEntry("k3", "v3", -1, -1)));
+
+      cs.prepare(mods, tx, false);
+
+      assert !cs.containsKey("k1");
+      assert !cs.containsKey("k2");
+      assert !cs.containsKey("k3");
+
+      cs.commit(tx);
+
+      assert !cs.containsKey("k1");
+      assert !cs.containsKey("k2");
+      assert cs.containsKey("k3");
+   }
+
+   public void testRollback() {
+
+      cs.store(new StoredEntry("old", "old", -1, -1));
+
+      List<Modification> mods = new ArrayList<Modification>();
+      mods.add(new Store(new StoredEntry("k1", "v1", -1, -1)));
+      mods.add(new Store(new StoredEntry("k2", "v2", -1, -1)));
+      mods.add(new Remove("k1"));
+      mods.add(new Remove("old"));
+      Transaction tx = EasyMock.createNiceMock(Transaction.class);
+      cs.prepare(mods, tx, false);
+
+      assert !cs.containsKey("k1");
+      assert !cs.containsKey("k2");
+      assert cs.containsKey("old");
+
+      cs.rollback(tx);
+
+      assert !cs.containsKey("k1");
+      assert !cs.containsKey("k2");
+      assert cs.containsKey("old");
+
+      mods = new ArrayList<Modification>();
+      mods.add(new Store(new StoredEntry("k1", "v1", -1, -1)));
+      mods.add(new Store(new StoredEntry("k2", "v2", -1, -1)));
+      mods.add(new Clear());
+      mods.add(new Store(new StoredEntry("k3", "v3", -1, -1)));
+
+      cs.prepare(mods, tx, false);
+
+      assert !cs.containsKey("k1");
+      assert !cs.containsKey("k2");
+      assert !cs.containsKey("k3");
+
+      cs.rollback(tx);
+
+      assert !cs.containsKey("k1");
+      assert !cs.containsKey("k2");
+      assert !cs.containsKey("k3");
+      assert cs.containsKey("old");
+   }
+
+   public void testCommitAndRollbackWithoutPrepare() {
+      cs.store(new StoredEntry("old", "old", -1, -1));
+      Transaction tx = EasyMock.createNiceMock(Transaction.class);
+      cs.commit(tx);
+      cs.store(new StoredEntry("old", "old", -1, -1));
+      cs.rollback(tx);
+
+      assert cs.containsKey("old");
+   }
+
+   public void testPreload() {
+      cs.store(new StoredEntry("k1", "v1", -1, -1));
+      cs.store(new StoredEntry("k2", "v2", -1, -1));
+      cs.store(new StoredEntry("k3", "v3", -1, -1));
+
+      Set<StoredEntry> set = cs.loadAll();
+
+      assert set.size() == 3;
+      Set expected = new HashSet();
+      expected.add("k1");
+      expected.add("k2");
+      expected.add("k3");
+      for (StoredEntry se : set) assert expected.remove(se.getKey());
+      assert expected.isEmpty();
+   }
+
+   public void testPurgeExpired() throws InterruptedException {
+      long now = System.currentTimeMillis();
+      long lifespan = 1000;
+      cs.store(new StoredEntry("k1", "v1", now, now + lifespan));
+      cs.store(new StoredEntry("k2", "v2", now, now + lifespan));
+      cs.store(new StoredEntry("k3", "v3", now, now + lifespan));
+      Thread.sleep(lifespan + 100);
+      cs.purgeExpired();
+      assert !cs.containsKey("k1");
+      assert !cs.containsKey("k2");
+      assert !cs.containsKey("k3");
+   }
+
+   public void testStreamingAPI() throws IOException, ClassNotFoundException {
+      cs.store(new StoredEntry("k1", "v1", -1, -1));
+      cs.store(new StoredEntry("k2", "v2", -1, -1));
+      cs.store(new StoredEntry("k3", "v3", -1, -1));
+
+      ByteArrayOutputStream out = new ByteArrayOutputStream();
+      cs.load(out);
+      out.flush();
+      out.close();
+      cs.clear();
+      cs.store(new ByteArrayInputStream(out.toByteArray()));
+
+      Set<StoredEntry> set = cs.loadAll();
+
+      assert set.size() == 3;
+      Set expected = new HashSet();
+      expected.add("k1");
+      expected.add("k2");
+      expected.add("k3");
+      for (StoredEntry se : set) assert expected.remove(se.getKey());
+      assert expected.isEmpty();
+   }
+
+   public void testConfigFile() throws Exception {
+      Class<? extends CacheLoaderConfig> cfgClass = cs.getConfigurationClass();
+      CacheLoaderConfig clc = Util.getInstance(cfgClass);
+      assert clc.getClassName().equals(cs.getClass().getName()) : "Cache loader doesn't provide a proper configuration type that is capable of creating the loader!";
+   }
+}

Modified: core/branches/flat/src/test/java/org/horizon/loader/CacheLoaderFunctionalTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/CacheLoaderFunctionalTest.java	2009-02-17 18:37:38 UTC (rev 7710)
+++ core/branches/flat/src/test/java/org/horizon/loader/CacheLoaderFunctionalTest.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -5,7 +5,7 @@
 import org.horizon.config.Configuration;
 import org.horizon.container.DataContainer;
 import org.horizon.lifecycle.ComponentStatus;
-import org.horizon.loader.dummy.DummyInMemoryCacheLoader;
+import org.horizon.loader.dummy.DummyInMemoryCacheStore;
 import org.horizon.manager.CacheManager;
 import org.horizon.manager.DefaultCacheManager;
 import org.horizon.test.TestingUtil;
@@ -39,7 +39,7 @@
       cfg = new Configuration();
       cfg.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
       CacheLoaderManagerConfig clmc = new CacheLoaderManagerConfig();
-      clmc.addCacheLoaderConfig(new DummyInMemoryCacheLoader.Cfg());
+      clmc.addCacheLoaderConfig(new DummyInMemoryCacheStore.Cfg());
       cfg.setCacheLoaderManagerConfig(clmc);
       cm = new DefaultCacheManager(cfg);
       cache = cm.getCache();
@@ -207,7 +207,7 @@
    public void testPreloading() {
       Configuration preloadingCfg = cfg.clone();
       preloadingCfg.getCacheLoaderManagerConfig().setPreload(true);
-      ((DummyInMemoryCacheLoader.Cfg) preloadingCfg.getCacheLoaderManagerConfig().getFirstCacheLoaderConfig()).setStore("preloadingCache");
+      ((DummyInMemoryCacheStore.Cfg) preloadingCfg.getCacheLoaderManagerConfig().getFirstCacheLoaderConfig()).setStore("preloadingCache");
       cm.defineCache("preloadingCache", preloadingCfg);
       Cache preloadingCache = cm.getCache("preloadingCache");
       CacheStore preloadingStore = TestingUtil.extractComponent(preloadingCache, CacheLoaderManager.class).getCacheStore();
@@ -249,7 +249,7 @@
    public void testPurgeOnStartup() {
       Configuration purgingCfg = cfg.clone();
       purgingCfg.getCacheLoaderManagerConfig().getFirstCacheLoaderConfig().setPurgeOnStartup(true);
-      ((DummyInMemoryCacheLoader.Cfg) purgingCfg.getCacheLoaderManagerConfig().getFirstCacheLoaderConfig()).setStore("purgingCache");
+      ((DummyInMemoryCacheStore.Cfg) purgingCfg.getCacheLoaderManagerConfig().getFirstCacheLoaderConfig()).setStore("purgingCache");
       cm.defineCache("purgingCache", purgingCfg);
       Cache purgingCache = cm.getCache("purgingCache");
       CacheStore purgingStore = TestingUtil.extractComponent(purgingCache, CacheLoaderManager.class).getCacheStore();

Modified: core/branches/flat/src/test/java/org/horizon/loader/PassivationFunctionalTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/PassivationFunctionalTest.java	2009-02-17 18:37:38 UTC (rev 7710)
+++ core/branches/flat/src/test/java/org/horizon/loader/PassivationFunctionalTest.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -3,7 +3,7 @@
 import org.horizon.Cache;
 import org.horizon.config.CacheLoaderManagerConfig;
 import org.horizon.config.Configuration;
-import org.horizon.loader.dummy.DummyInMemoryCacheLoader;
+import org.horizon.loader.dummy.DummyInMemoryCacheStore;
 import org.horizon.manager.CacheManager;
 import org.horizon.manager.DefaultCacheManager;
 import org.horizon.test.TestingUtil;
@@ -39,7 +39,7 @@
       cfg.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
       CacheLoaderManagerConfig clmc = new CacheLoaderManagerConfig();
       clmc.setPassivation(true);
-      clmc.addCacheLoaderConfig(new DummyInMemoryCacheLoader.Cfg());
+      clmc.addCacheLoaderConfig(new DummyInMemoryCacheStore.Cfg());
       cfg.setCacheLoaderManagerConfig(clmc);
       cm = new DefaultCacheManager(cfg);
       cache = cm.getCache();

Modified: core/branches/flat/src/test/java/org/horizon/loader/decorators/AsyncTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/decorators/AsyncTest.java	2009-02-17 18:37:38 UTC (rev 7710)
+++ core/branches/flat/src/test/java/org/horizon/loader/decorators/AsyncTest.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -2,7 +2,7 @@
 
 import org.horizon.CacheException;
 import org.horizon.loader.StoredEntry;
-import org.horizon.loader.dummy.DummyInMemoryCacheLoader;
+import org.horizon.loader.dummy.DummyInMemoryCacheStore;
 import org.horizon.test.TestingUtil;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.AfterTest;
@@ -20,8 +20,8 @@
 
    @BeforeTest
    public void setUp() {
-      store = new AsyncStore(new DummyInMemoryCacheLoader(), new AsyncStoreConfig());
-      DummyInMemoryCacheLoader.Cfg cfg = new DummyInMemoryCacheLoader.Cfg();
+      store = new AsyncStore(new DummyInMemoryCacheStore(), new AsyncStoreConfig());
+      DummyInMemoryCacheStore.Cfg cfg = new DummyInMemoryCacheStore.Cfg();
       cfg.setStore(AsyncTest.class.getName());
       store.init(cfg, null, null);
       store.start();

Modified: core/branches/flat/src/test/java/org/horizon/loader/decorators/ChainingCacheLoaderTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/decorators/ChainingCacheLoaderTest.java	2009-02-17 18:37:38 UTC (rev 7710)
+++ core/branches/flat/src/test/java/org/horizon/loader/decorators/ChainingCacheLoaderTest.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -1,11 +1,11 @@
 package org.horizon.loader.decorators;
 
 import org.easymock.EasyMock;
-import org.horizon.loader.BaseCacheLoaderTest;
+import org.horizon.loader.BaseCacheStoreTest;
 import org.horizon.loader.CacheLoaderConfig;
 import org.horizon.loader.CacheStore;
 import org.horizon.loader.StoredEntry;
-import org.horizon.loader.dummy.DummyInMemoryCacheLoader;
+import org.horizon.loader.dummy.DummyInMemoryCacheStore;
 import org.horizon.loader.modifications.Clear;
 import org.horizon.loader.modifications.Modification;
 import org.horizon.loader.modifications.Remove;
@@ -25,27 +25,27 @@
 import java.util.Set;
 
 @Test(groups = "unit", testName = "loader.decorators.ChainingCacheLoaderTest")
-public class ChainingCacheLoaderTest extends BaseCacheLoaderTest {
+public class ChainingCacheLoaderTest extends BaseCacheStoreTest {
 
-   DummyInMemoryCacheLoader store1, store2;
-   DummyInMemoryCacheLoader[] stores;  // for convenient iteration   
+   DummyInMemoryCacheStore store1, store2;
+   DummyInMemoryCacheStore[] stores;  // for convenient iteration
    private static final long lifespan = 6000000;
 
    protected CacheStore createCacheStore() {
-      ChainingCacheLoader store = new ChainingCacheLoader();
+      ChainingCacheStore store = new ChainingCacheStore();
       CacheLoaderConfig cfg;
-      store1 = new DummyInMemoryCacheLoader();
-      store1.init((cfg = new DummyInMemoryCacheLoader.Cfg("instance1")), null, null);
+      store1 = new DummyInMemoryCacheStore();
+      store1.init((cfg = new DummyInMemoryCacheStore.Cfg("instance1")), null, null);
 
       store.addCacheLoader(store1, cfg);
 
-      store2 = new DummyInMemoryCacheLoader();
-      store2.init((cfg = new DummyInMemoryCacheLoader.Cfg("instance2")), null, null);
+      store2 = new DummyInMemoryCacheStore();
+      store2.init((cfg = new DummyInMemoryCacheStore.Cfg("instance2")), null, null);
       // set store2 up for streaming
       cfg.setFetchPersistentState(true);
       store.addCacheLoader(store2, cfg);
 
-      stores = new DummyInMemoryCacheLoader[]{store1, store2};
+      stores = new DummyInMemoryCacheStore[]{store1, store2};
 
       store.start();
 

Modified: core/branches/flat/src/test/java/org/horizon/loader/decorators/SingletonStoreTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/decorators/SingletonStoreTest.java	2009-02-17 18:37:38 UTC (rev 7710)
+++ core/branches/flat/src/test/java/org/horizon/loader/decorators/SingletonStoreTest.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -8,7 +8,7 @@
 import org.horizon.loader.CacheLoaderManager;
 import org.horizon.loader.CacheStore;
 import org.horizon.loader.StoredEntry;
-import org.horizon.loader.dummy.DummyInMemoryCacheLoader;
+import org.horizon.loader.dummy.DummyInMemoryCacheStore;
 import org.horizon.manager.CacheManager;
 import org.horizon.test.MultipleCacheManagersTest;
 import org.horizon.test.TestingUtil;
@@ -46,7 +46,7 @@
 
       Configuration conf = new Configuration();
       conf.setCacheMode(Configuration.CacheMode.REPL_SYNC);
-      DummyInMemoryCacheLoader.Cfg cfg = new DummyInMemoryCacheLoader.Cfg();
+      DummyInMemoryCacheStore.Cfg cfg = new DummyInMemoryCacheStore.Cfg();
       cfg.setStore("Store-" + storeCounter.getAndIncrement());
       CacheLoaderManagerConfig pushingCfg = new CacheLoaderManagerConfig();
       pushingCfg.addCacheLoaderConfig(cfg);
@@ -58,14 +58,14 @@
 
       // cannot define on ALL cache managers since the same dummy in memory CL bin will be used!
       cm0.defineCache("pushing", conf);
-      ((DummyInMemoryCacheLoader.Cfg) conf.getCacheLoaderManagerConfig().getFirstCacheLoaderConfig()).setStore("Store-" + storeCounter.getAndIncrement());
+      ((DummyInMemoryCacheStore.Cfg) conf.getCacheLoaderManagerConfig().getFirstCacheLoaderConfig()).setStore("Store-" + storeCounter.getAndIncrement());
       cm1.defineCache("pushing", conf);
-      ((DummyInMemoryCacheLoader.Cfg) conf.getCacheLoaderManagerConfig().getFirstCacheLoaderConfig()).setStore("Store-" + storeCounter.getAndIncrement());
+      ((DummyInMemoryCacheStore.Cfg) conf.getCacheLoaderManagerConfig().getFirstCacheLoaderConfig()).setStore("Store-" + storeCounter.getAndIncrement());
       cm2.defineCache("pushing", conf);
 
       conf = new Configuration();
       conf.setCacheMode(Configuration.CacheMode.REPL_SYNC);
-      cfg = new DummyInMemoryCacheLoader.Cfg();
+      cfg = new DummyInMemoryCacheStore.Cfg();
       cfg.setStore("Store-" + storeCounter.getAndIncrement());
       CacheLoaderManagerConfig nonPushingCfg = new CacheLoaderManagerConfig();
       nonPushingCfg.addCacheLoaderConfig(cfg);
@@ -77,9 +77,9 @@
 
       // cannot define on ALL cache managers since the same dummy in memory CL bin will be used!
       cm0.defineCache("nonPushing", conf);
-      ((DummyInMemoryCacheLoader.Cfg) conf.getCacheLoaderManagerConfig().getFirstCacheLoaderConfig()).setStore("Store-" + storeCounter.getAndIncrement());
+      ((DummyInMemoryCacheStore.Cfg) conf.getCacheLoaderManagerConfig().getFirstCacheLoaderConfig()).setStore("Store-" + storeCounter.getAndIncrement());
       cm1.defineCache("nonPushing", conf);
-      ((DummyInMemoryCacheLoader.Cfg) conf.getCacheLoaderManagerConfig().getFirstCacheLoaderConfig()).setStore("Store-" + storeCounter.getAndIncrement());
+      ((DummyInMemoryCacheStore.Cfg) conf.getCacheLoaderManagerConfig().getFirstCacheLoaderConfig()).setStore("Store-" + storeCounter.getAndIncrement());
       cm2.defineCache("nonPushing", conf);
    }
 

Deleted: core/branches/flat/src/test/java/org/horizon/loader/dummy/DummyInMemoryCacheLoader.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/dummy/DummyInMemoryCacheLoader.java	2009-02-17 18:37:38 UTC (rev 7710)
+++ core/branches/flat/src/test/java/org/horizon/loader/dummy/DummyInMemoryCacheLoader.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -1,152 +0,0 @@
-package org.horizon.loader.dummy;
-
-import org.horizon.Cache;
-import org.horizon.loader.AbstractCacheLoaderConfig;
-import org.horizon.loader.AbstractCacheStore;
-import org.horizon.loader.CacheLoaderConfig;
-import org.horizon.loader.StoredEntry;
-import org.horizon.logging.Log;
-import org.horizon.logging.LogFactory;
-import org.horizon.marshall.Marshaller;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-public class DummyInMemoryCacheLoader extends AbstractCacheStore {
-   private static final Log log = LogFactory.getLog(DummyInMemoryCacheLoader.class);
-   static final ConcurrentMap<String, Map> stores = new ConcurrentHashMap<String, Map>();
-   String storeName = "__DEFAULT_STORES__";
-   Map<Object, StoredEntry> store;
-   Cfg config;
-
-   public void store(StoredEntry ed) {
-      store.put(ed.getKey(), ed);
-   }
-
-   @SuppressWarnings("unchecked")
-   public void store(InputStream inputStream) throws IOException, ClassNotFoundException {
-      ObjectInputStream ois = inputStream instanceof ObjectInputStream ? (ObjectInputStream) inputStream :
-            new ObjectInputStream(inputStream);
-      int numEntries = ois.readInt();
-      store.clear();
-      for (int i = 0; i < numEntries; i++) {
-         StoredEntry e = (StoredEntry) ois.readObject();
-         store.put(e.getKey(), e);
-      }
-   }
-
-   public void load(OutputStream outputStream) throws IOException {
-      ObjectOutputStream oos = outputStream instanceof ObjectOutputStream ? (ObjectOutputStream) outputStream :
-            new ObjectOutputStream(outputStream);
-      oos.writeInt(store.size());
-      for (StoredEntry se : store.values()) oos.writeObject(se);
-   }
-
-   public void clear() {
-      store.clear();
-   }
-
-   public boolean remove(Object key) {
-      return store.remove(key) != null;
-   }
-
-   public void purgeExpired() {
-      for (Iterator<StoredEntry> i = store.values().iterator(); i.hasNext();) {
-         StoredEntry se = i.next();
-         if (se.isExpired()) i.remove();
-      }
-   }
-
-   public void init(CacheLoaderConfig config, Cache cache, Marshaller m) {
-      this.config = (Cfg) config;
-   }
-
-   public StoredEntry load(Object key) {
-      if (key == null) return null;
-      StoredEntry se = store.get(key);
-      if (se == null) return null;
-      if (se.isExpired()) {
-         log.debug("Key {0} exists, but has expired.  Entry is {1}", key, se);
-         store.remove(key);
-         return null;
-      }
-
-      return se;
-   }
-
-   public Set<StoredEntry> loadAll() {
-      Set<StoredEntry> s = new HashSet<StoredEntry>();
-      for (Iterator<StoredEntry> i = store.values().iterator(); i.hasNext();) {
-         StoredEntry se = i.next();
-         if (se.isExpired()) {
-            log.debug("Key {0} exists, but has expired.  Entry is {1}", se.getKey(), se);
-            i.remove();
-         } else
-            s.add(se);
-      }
-      return s;
-   }
-
-   public boolean containsKey(Object key) {
-      return load(key) != null;
-   }
-
-   public Class<? extends CacheLoaderConfig> getConfigurationClass() {
-      return Cfg.class;
-   }
-
-   @SuppressWarnings("unchecked")
-   public void start() {
-      storeName = config.getStore();
-      Map m = new ConcurrentHashMap();
-      Map existing = stores.putIfAbsent(storeName, m);
-      store = existing == null ? m : existing;
-   }
-
-   public void stop() {
-   }
-
-   public static class Cfg extends AbstractCacheLoaderConfig {
-      boolean debug;
-      String store = "__DEFAULT_STORE__";
-
-      public Cfg() {
-         setClassName(DummyInMemoryCacheLoader.class.getName());
-      }
-
-      public Cfg(String name) {
-         this();
-         setStore(name);
-      }
-
-      public boolean isDebug() {
-         return debug;
-      }
-
-      public void setDebug(boolean debug) {
-         this.debug = debug;
-      }
-
-      public String getStore() {
-         return store;
-      }
-
-      public void setStore(String store) {
-         this.store = store;
-      }
-
-      @Override
-      public Cfg clone() {
-         return (Cfg) super.clone();
-      }
-   }
-}

Deleted: core/branches/flat/src/test/java/org/horizon/loader/dummy/DummyInMemoryCacheLoaderTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/dummy/DummyInMemoryCacheLoaderTest.java	2009-02-17 18:37:38 UTC (rev 7710)
+++ core/branches/flat/src/test/java/org/horizon/loader/dummy/DummyInMemoryCacheLoaderTest.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -1,18 +0,0 @@
-package org.horizon.loader.dummy;
-
-import org.horizon.loader.BaseCacheLoaderTest;
-import org.horizon.loader.CacheStore;
-import org.testng.annotations.Test;
-
- at Test(groups = "unit", testName = "loader.dummy.DummyInMemoryCacheLoaderTest")
-public class DummyInMemoryCacheLoaderTest extends BaseCacheLoaderTest {
-
-   protected CacheStore createCacheStore() {
-      DummyInMemoryCacheLoader cl = new DummyInMemoryCacheLoader();
-      DummyInMemoryCacheLoader.Cfg cfg = new DummyInMemoryCacheLoader.Cfg();
-      cfg.setStore(DummyInMemoryCacheLoaderTest.class.getName());
-      cl.init(cfg, null, null);
-      cl.start();
-      return cl;
-   }
-}

Copied: core/branches/flat/src/test/java/org/horizon/loader/dummy/DummyInMemoryCacheStore.java (from rev 7701, core/branches/flat/src/test/java/org/horizon/loader/dummy/DummyInMemoryCacheLoader.java)
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/dummy/DummyInMemoryCacheStore.java	                        (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/loader/dummy/DummyInMemoryCacheStore.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -0,0 +1,155 @@
+package org.horizon.loader.dummy;
+
+import org.horizon.Cache;
+import org.horizon.loader.AbstractCacheLoaderConfig;
+import org.horizon.loader.AbstractCacheStore;
+import org.horizon.loader.CacheLoaderConfig;
+import org.horizon.loader.StoredEntry;
+import org.horizon.logging.Log;
+import org.horizon.logging.LogFactory;
+import org.horizon.marshall.Marshaller;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+public class DummyInMemoryCacheStore extends AbstractCacheStore {
+   private static final Log log = LogFactory.getLog(DummyInMemoryCacheStore.class);
+   static final ConcurrentMap<String, Map> stores = new ConcurrentHashMap<String, Map>();
+   String storeName = "__DEFAULT_STORES__";
+   Map<Object, StoredEntry> store;
+   Cfg config;
+   private Marshaller marshaller;
+   private Cache cache;
+
+   public void store(StoredEntry ed) {
+      store.put(ed.getKey(), ed);
+   }
+
+   @SuppressWarnings("unchecked")
+   public void store(InputStream inputStream) throws IOException, ClassNotFoundException {
+      ObjectInputStream ois = inputStream instanceof ObjectInputStream ? (ObjectInputStream) inputStream :
+            new ObjectInputStream(inputStream);
+
+      int numEntries = (Integer) marshaller.objectFromObjectStream(ois);
+      store.clear();
+      for (int i = 0; i < numEntries; i++) {
+         StoredEntry e = (StoredEntry) marshaller.objectFromObjectStream(ois);
+         store.put(e.getKey(), e);
+      }
+   }
+
+   public void load(OutputStream outputStream) throws IOException {
+
+      ObjectOutputStream oos = outputStream instanceof ObjectOutputStream ? (ObjectOutputStream) outputStream :
+            new ObjectOutputStream(outputStream);
+      marshaller.objectToObjectStream(store.size(), oos);
+      for (StoredEntry se : store.values()) marshaller.objectToObjectStream(se, oos);
+   }
+
+   public void clear() {
+      store.clear();
+   }
+
+   public boolean remove(Object key) {
+      return store.remove(key) != null;
+   }
+
+   public void purgeExpired() {
+      for (Iterator<StoredEntry> i = store.values().iterator(); i.hasNext();) {
+         StoredEntry se = i.next();
+         if (se.isExpired()) i.remove();
+      }
+   }
+
+   public void init(CacheLoaderConfig config, Cache cache, Marshaller m) {
+      this.config = (Cfg) config;
+      this.cache = cache;
+      this.marshaller = m;
+   }
+
+   public StoredEntry load(Object key) {
+      if (key == null) return null;
+      StoredEntry se = store.get(key);
+      if (se == null) return null;
+      if (se.isExpired()) {
+         log.debug("Key {0} exists, but has expired.  Entry is {1}", key, se);
+         store.remove(key);
+         return null;
+      }
+
+      return se;
+   }
+
+   public Set<StoredEntry> loadAll() {
+      Set<StoredEntry> s = new HashSet<StoredEntry>();
+      for (Iterator<StoredEntry> i = store.values().iterator(); i.hasNext();) {
+         StoredEntry se = i.next();
+         if (se.isExpired()) {
+            log.debug("Key {0} exists, but has expired.  Entry is {1}", se.getKey(), se);
+            i.remove();
+         } else
+            s.add(se);
+      }
+      return s;
+   }
+
+   public Class<? extends CacheLoaderConfig> getConfigurationClass() {
+      return Cfg.class;
+   }
+
+   @SuppressWarnings("unchecked")
+   public void start() {
+      storeName = config.getStore();
+      storeName += "_" + cache.getName();
+      Map m = new ConcurrentHashMap();
+      Map existing = stores.putIfAbsent(storeName, m);
+      store = existing == null ? m : existing;
+   }
+
+   public void stop() {
+   }
+
+   public static class Cfg extends AbstractCacheLoaderConfig {
+      boolean debug;
+      String store = "__DEFAULT_STORE__";
+
+      public Cfg() {
+         setClassName(DummyInMemoryCacheStore.class.getName());
+      }
+
+      public Cfg(String name) {
+         this();
+         setStore(name);
+      }
+
+      public boolean isDebug() {
+         return debug;
+      }
+
+      public void setDebug(boolean debug) {
+         this.debug = debug;
+      }
+
+      public String getStore() {
+         return store;
+      }
+
+      public void setStore(String store) {
+         this.store = store;
+      }
+
+      @Override
+      public Cfg clone() {
+         return (Cfg) super.clone();
+      }
+   }
+}

Copied: core/branches/flat/src/test/java/org/horizon/loader/dummy/DummyInMemoryCacheStoreTest.java (from rev 7700, core/branches/flat/src/test/java/org/horizon/loader/dummy/DummyInMemoryCacheLoaderTest.java)
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/dummy/DummyInMemoryCacheStoreTest.java	                        (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/loader/dummy/DummyInMemoryCacheStoreTest.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -0,0 +1,18 @@
+package org.horizon.loader.dummy;
+
+import org.horizon.loader.BaseCacheStoreTest;
+import org.horizon.loader.CacheStore;
+import org.testng.annotations.Test;
+
+ at Test(groups = "unit", testName = "loader.dummy.DummyInMemoryCacheStoreTest")
+public class DummyInMemoryCacheStoreTest extends BaseCacheStoreTest {
+
+   protected CacheStore createCacheStore() {
+      DummyInMemoryCacheStore cl = new DummyInMemoryCacheStore();
+      DummyInMemoryCacheStore.Cfg cfg = new DummyInMemoryCacheStore.Cfg();
+      cfg.setStore(DummyInMemoryCacheStoreTest.class.getName());
+      cl.init(cfg, getCache(), getMarshaller());
+      cl.start();
+      return cl;
+   }
+}

Added: core/branches/flat/src/test/java/org/horizon/loader/file/FileCacheStoreTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/file/FileCacheStoreTest.java	                        (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/loader/file/FileCacheStoreTest.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -0,0 +1,27 @@
+package org.horizon.loader.file;
+
+import org.horizon.loader.BaseCacheStoreTest;
+import org.horizon.loader.CacheStore;
+import org.horizon.test.TestingUtil;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.Test;
+
+ at Test(groups = "unit", sequential = true, testName = "loader.file.FileCacheStoreTest")
+public class FileCacheStoreTest extends BaseCacheStoreTest {
+
+   private final String tmpDirectory = "__tempDir/" + getClass().getSimpleName();
+
+   protected CacheStore createCacheStore() {
+      CacheStore cs = new FileCacheStore();
+      FileCacheStoreConfig cfg = new FileCacheStoreConfig();
+      cfg.setLocation(tmpDirectory);
+      cs.init(cfg, getCache(), getMarshaller());
+      cs.start();
+      return cs;
+   }
+
+   @AfterTest
+   public void removeTempDirectory() {
+      TestingUtil.recursiveFileRemove(tmpDirectory);
+   }
+}

Modified: core/branches/flat/src/test/java/org/horizon/marshall/MarshalledValueTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/marshall/MarshalledValueTest.java	2009-02-17 18:37:38 UTC (rev 7710)
+++ core/branches/flat/src/test/java/org/horizon/marshall/MarshalledValueTest.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -3,16 +3,16 @@
 import org.horizon.AdvancedCache;
 import org.horizon.Cache;
 import org.horizon.CacheException;
-import org.horizon.loader.dummy.DummyInMemoryCacheLoader;
-import org.horizon.loader.CacheLoaderConfig;
 import org.horizon.commands.write.PutKeyValueCommand;
-import org.horizon.config.Configuration;
 import org.horizon.config.CacheLoaderManagerConfig;
+import org.horizon.config.Configuration;
 import org.horizon.container.DataContainer;
 import org.horizon.context.InvocationContext;
 import org.horizon.interceptors.InterceptorChain;
 import org.horizon.interceptors.MarshalledValueInterceptor;
 import org.horizon.interceptors.base.CommandInterceptor;
+import org.horizon.loader.CacheLoaderConfig;
+import org.horizon.loader.dummy.DummyInMemoryCacheStore;
 import org.horizon.notifications.Listener;
 import org.horizon.notifications.cachelistener.annotation.CacheEntryModified;
 import org.horizon.notifications.cachelistener.event.CacheEntryModifiedEvent;
@@ -46,7 +46,7 @@
    String k = "key", v = "value";
 
    protected void createCacheManagers() throws Throwable {
-      Configuration replSync = getDefaultConfig();
+      Configuration replSync = new Configuration();
       replSync.setCacheMode(Configuration.CacheMode.REPL_SYNC);
       replSync.setUseLazyDeserialization(true);
 
@@ -151,7 +151,6 @@
    }
 
    public void testNodeReleaseObjectKeyReferences() throws IOException, ClassNotFoundException {
-      assertSerializationCounts(0,0);
       Pojo key = new Pojo();
       cache1.put(key, "value");
 
@@ -180,8 +179,6 @@
       assert o instanceof MarshalledValue;
       mv = (MarshalledValue) o;
       assertSerialized(mv);
-
-      assertSerializationCounts(2, 0);
       assert cache2.get(key).equals("value");
       assertSerializationCounts(2, 1);
       assertDeserialized(mv);
@@ -214,7 +211,7 @@
       Pojo pojo = new Pojo();
       MarshalledValue mv = new MarshalledValue(pojo, true);
 
-      Configuration c = getDefaultConfig();
+      Configuration c = new Configuration();
 //      ComponentRegistry cr = new ComponentRegistry(c, new CacheDelegate("aaa"));
 
       HorizonMarshaller marshaller = new HorizonMarshaller();
@@ -251,44 +248,14 @@
       assertOnlyOneRepresentationExists(recreated);
    }
 
-   public void testCallbackValues() {
-      MockListener l = new MockListener();
-      cache1.addListener(l);
-      Pojo pojo = new Pojo();
-      cache1.put("key", pojo);
-
-      assert l.newValue != null;
-      assert l.newValue instanceof MarshalledValue;
-      MarshalledValue mv = (MarshalledValue) l.newValue;
-      assert mv.instance instanceof Pojo;
-      assertSerializationCounts(1, 0);
-   }
-
-   public void testRemoteCallbackValues() throws Exception {
-      MockListener l = new MockListener();
-      cache2.addListener(l);
-      Pojo pojo = new Pojo();
-      cache1.put("key", pojo);
-
-      assert l.newValue != null;
-      assert l.newValue instanceof MarshalledValue;
-      MarshalledValue mv = (MarshalledValue) l.newValue;
-      assert mv.get() instanceof Pojo;
-      assertSerializationCounts(1, 1);
-   }
-
-   /**
-    * Run this as last method as it creates and stops cache loaders, which might affect other tests.
-    */
-   @Test(dependsOnMethods = "org.horizon.marshall.MarshalledValueTest.test(?!CacheLoaders)[a-zA-Z]*")
    public void testCacheLoaders() throws CloneNotSupportedException {
       tearDown();
 
-      Configuration cacheCofig = getDefaultConfig();
+      Configuration cacheCofig = new Configuration();
       cacheCofig.setCacheMode(Configuration.CacheMode.REPL_SYNC);
       cacheCofig.setUseLazyDeserialization(true);
       CacheLoaderManagerConfig clmc = new CacheLoaderManagerConfig();
-      DummyInMemoryCacheLoader.Cfg clc = new DummyInMemoryCacheLoader.Cfg();
+      DummyInMemoryCacheStore.Cfg clc = new DummyInMemoryCacheStore.Cfg();
       clc.setStore(getClass().getSimpleName());
       clmc.setCacheLoaderConfigs(Collections.singletonList((CacheLoaderConfig) clc));
       cacheCofig.setCacheLoaderManagerConfig(clmc);
@@ -309,7 +276,32 @@
       assertSerializationCounts(1, 1);
    }
 
+   public void testCallbackValues() {
+      MockListener l = new MockListener();
+      cache1.addListener(l);
+      Pojo pojo = new Pojo();
+      cache1.put("key", pojo);
 
+      assert l.newValue != null;
+      assert l.newValue instanceof MarshalledValue;
+      MarshalledValue mv = (MarshalledValue) l.newValue;
+      assert mv.instance instanceof Pojo;
+      assertSerializationCounts(1, 0);
+   }
+
+   public void testRemoteCallbackValues() throws Exception {
+      MockListener l = new MockListener();
+      cache2.addListener(l);
+      Pojo pojo = new Pojo();
+      cache1.put("key", pojo);
+
+      assert l.newValue != null;
+      assert l.newValue instanceof MarshalledValue;
+      MarshalledValue mv = (MarshalledValue) l.newValue;
+      assert mv.get() instanceof Pojo;
+      assertSerializationCounts(1, 1);
+   }
+
    @Listener
    public static class MockListener {
       Object newValue;

Modified: core/branches/flat/src/test/java/org/horizon/notifications/CacheListenerCacheLoaderTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/notifications/CacheListenerCacheLoaderTest.java	2009-02-17 18:37:38 UTC (rev 7710)
+++ core/branches/flat/src/test/java/org/horizon/notifications/CacheListenerCacheLoaderTest.java	2009-02-17 18:39:52 UTC (rev 7711)
@@ -3,7 +3,7 @@
 import org.horizon.Cache;
 import org.horizon.config.CacheLoaderManagerConfig;
 import org.horizon.config.Configuration;
-import org.horizon.loader.dummy.DummyInMemoryCacheLoader;
+import org.horizon.loader.dummy.DummyInMemoryCacheStore;
 import org.horizon.manager.CacheManager;
 import org.horizon.manager.DefaultCacheManager;
 import org.horizon.notifications.cachelistener.annotation.CacheEntryActivated;
@@ -29,13 +29,13 @@
       cm = new DefaultCacheManager();
       Configuration c = new Configuration();
       CacheLoaderManagerConfig clmc = new CacheLoaderManagerConfig();
-      DummyInMemoryCacheLoader.Cfg clc = new DummyInMemoryCacheLoader.Cfg("no_passivation");
+      DummyInMemoryCacheStore.Cfg clc = new DummyInMemoryCacheStore.Cfg("no_passivation");
       clmc.addCacheLoaderConfig(clc);
       c.setCacheLoaderManagerConfig(clmc);
       cm.defineCache("no_passivation", c);
 
       c = c.clone();
-      ((DummyInMemoryCacheLoader.Cfg) c.getCacheLoaderManagerConfig().getFirstCacheLoaderConfig()).setStore("passivation");
+      ((DummyInMemoryCacheStore.Cfg) c.getCacheLoaderManagerConfig().getFirstCacheLoaderConfig()).setStore("passivation");
       c.getCacheLoaderManagerConfig().setPassivation(true);
       cm.defineCache("passivation", c);
    }




More information about the jbosscache-commits mailing list