diff src/org/dancres/blitz/txn/StoragePersonalityFactory.java @ 0:3dc0c5604566

Initial checkin of blitz 2.0 fcs - no installer yet.
author Dan Creswell <dan.creswell@gmail.com>
date Sat, 21 Mar 2009 11:00:06 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/dancres/blitz/txn/StoragePersonalityFactory.java	Sat Mar 21 11:00:06 2009 +0000
@@ -0,0 +1,55 @@
+package org.dancres.blitz.txn;
+
+import java.io.File;
+
+import net.jini.config.ConfigurationException;
+
+import org.dancres.blitz.config.StorageModel;
+import org.dancres.blitz.config.Persistent;
+import org.dancres.blitz.config.TimeBarrierPersistent;
+import org.dancres.blitz.config.Transient;
+import org.dancres.blitz.config.ConfigurationFactory;
+
+/**
+   @see org.dancres.blitz.txn.StoragePersonality
+ */
+public class StoragePersonalityFactory {
+
+    private static StorageModel STORAGE_MODEL;
+
+    private static StoragePersonality STORAGE_PERSONALITY;
+
+    static {
+        try {
+            STORAGE_MODEL =
+                ((StorageModel)
+                 ConfigurationFactory.getEntry("storageModel",
+                                               StorageModel.class));
+            
+            String myLogDir = (String)
+                ConfigurationFactory.getEntry("logDir", String.class);
+
+            new File(myLogDir).mkdirs();
+
+            if (STORAGE_MODEL instanceof Persistent) {
+                STORAGE_PERSONALITY = 
+                    new PersistentPersonality((Persistent) STORAGE_MODEL,
+                                              myLogDir);
+            } else if (STORAGE_MODEL instanceof Transient) {
+                STORAGE_PERSONALITY = new TransientPersonality(myLogDir);
+            } else if (STORAGE_MODEL instanceof TimeBarrierPersistent) {
+                STORAGE_PERSONALITY =
+                    new TimeBarrierPersonality((TimeBarrierPersistent) STORAGE_MODEL, myLogDir);
+            } else {
+                throw new Error("Unrecognised storage personality, fatal: " + STORAGE_MODEL);
+            }
+
+        } catch (ConfigurationException aCE) {
+            throw new Error("Problem loading configuration", aCE);
+        }
+    }
+
+    public static StoragePersonality getPersonality() {
+        return STORAGE_PERSONALITY;
+    }
+}