jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r190379 - /incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java
Date Mon, 13 Jun 2005 10:29:33 GMT
Author: tripod
Date: Mon Jun 13 03:29:30 2005
New Revision: 190379

URL: http://svn.apache.org/viewcvs?rev=190379&view=rev
Log:
- adding better error handling for failing persistence managers

Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java?rev=190379&r1=190378&r2=190379&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java Mon
Jun 13 03:29:30 2005
@@ -163,7 +163,77 @@
         }
         metaDataStore = new BasedFileSystem(repStore, fsRootPath);
 
-        FileSystemResource uuidFile = new FileSystemResource(metaDataStore, "rootUUID");
+        // init root node uuid
+        rootNodeUUID = loadRootNodeUUID(metaDataStore);
+
+        // load repository properties
+        repProps = new Properties();
+        loadRepProps();
+        nodesCount = Long.parseLong(repProps.getProperty(STATS_NODE_COUNT_PROPERTY, "0"));
+        propsCount = Long.parseLong(repProps.getProperty(STATS_PROP_COUNT_PROPERTY, "0"));
+
+        // create registries
+        nsReg = createNamespaceRegistry(new BasedFileSystem(repStore, "/namespaces"));
+        ntReg = createNodeTypeRegistry(nsReg, new BasedFileSystem(repStore, "/nodetypes"));
+
+        // init workspace configs
+        Iterator iter = repConfig.getWorkspaceConfigs().iterator();
+        while (iter.hasNext()) {
+            WorkspaceConfig config = (WorkspaceConfig) iter.next();
+            WorkspaceInfo info = new WorkspaceInfo(config);
+            wspInfos.put(config.getName(), info);
+        }
+
+        // init version manager
+        VersioningConfig vConfig = repConfig.getVersioningConfig();
+        PersistenceManager pm = createPersistenceManager(vConfig.getHomeDir(),
+                vConfig.getFileSystem(),
+                vConfig.getPersistenceManagerConfig(),
+                rootNodeUUID,
+                nsReg,
+                ntReg);
+        pvMgr = new NativePVM(pm, getNodeTypeRegistry());
+        vMgr = new VersionManagerImpl(pvMgr, ntReg, delegatingDispatcher,
+                VERSION_STORAGE_NODE_UUID, SYSTEM_ROOT_NODE_UUID);
+
+        // init virtual nodetype manager
+        virtNTMgr = new VirtualNodeTypeStateManager(getNodeTypeRegistry(),
+                delegatingDispatcher, NODETYPES_NODE_UUID, SYSTEM_ROOT_NODE_UUID);
+
+        // initialize workspaces
+        try {
+            iter = wspInfos.keySet().iterator();
+            while (iter.hasNext()) {
+                String wspName = (String) iter.next();
+                initWorkspace(wspName);
+            }
+        } catch (RepositoryException e) {
+            // if any workspace failed to initialize, shutdown again
+            log.error("Unable to start repository. forcing shutdown.");
+            shutdown();
+            throw e;
+        }
+
+        // after the workspaces are initialized, we setup a system session for
+        // the virtual nodetype manager
+        virtNTMgr.setSession(getSystemSession(repConfig.getDefaultWorkspaceName()));
+
+        // finally register shutdown hook
+        Runtime.getRuntime().addShutdownHook(new Thread() {
+            public void run() {
+                shutdown();
+            }
+        });
+    }
+
+    /**
+     * Returns the root node uuid.
+     * @param fs
+     * @return
+     * @throws RepositoryException
+     */
+    protected String loadRootNodeUUID(FileSystem fs) throws RepositoryException {
+        FileSystemResource uuidFile = new FileSystemResource(fs, "rootUUID");
         try {
             if (uuidFile.exists()) {
                 try {
@@ -195,7 +265,7 @@
                             // ignore
                         }
                     }
-                    rootNodeUUID = new UUID(new String(chars)).toString();
+                    return new UUID(new String(chars)).toString();
                 } catch (Exception e) {
                     String msg = "failed to load persisted repository state";
                     log.debug(msg);
@@ -213,7 +283,6 @@
                  * hard-coded uuid makes it easier to copy/move entire
                  * workspaces from one repository instance to another.
                  */
-                rootNodeUUID = ROOT_NODE_UUID;
                 try {
                     // persist uuid of the repository's root node
                     OutputStream out = uuidFile.getOutputStream();
@@ -232,7 +301,7 @@
                     // store uuid in text format for better readability
                     OutputStreamWriter writer = new OutputStreamWriter(out);
                     try {
-                        writer.write(rootNodeUUID);
+                        writer.write(ROOT_NODE_UUID);
                     } finally {
                         try {
                             writer.close();
@@ -240,6 +309,7 @@
                             // ignore
                         }
                     }
+                    return ROOT_NODE_UUID;
                 } catch (Exception e) {
                     String msg = "failed to persist repository state";
                     log.debug(msg);
@@ -251,58 +321,6 @@
             log.debug(msg);
             throw new RepositoryException(msg, fse);
         }
-
-        // load repository properties
-        repProps = new Properties();
-        loadRepProps();
-        nodesCount = Long.parseLong(repProps.getProperty(STATS_NODE_COUNT_PROPERTY, "0"));
-        propsCount = Long.parseLong(repProps.getProperty(STATS_PROP_COUNT_PROPERTY, "0"));
-
-        // workspaces
-        Iterator iter = repConfig.getWorkspaceConfigs().iterator();
-        while (iter.hasNext()) {
-            WorkspaceConfig config = (WorkspaceConfig) iter.next();
-            WorkspaceInfo info = new WorkspaceInfo(config);
-            wspInfos.put(config.getName(), info);
-        }
-
-        nsReg = createNamespaceRegistry(new BasedFileSystem(repStore, "/namespaces"));
-
-        ntReg = createNodeTypeRegistry(nsReg, new BasedFileSystem(repStore, "/nodetypes"));
-
-        // init version manager
-        VersioningConfig vConfig = repConfig.getVersioningConfig();
-        PersistenceManager pm = createPersistenceManager(vConfig.getHomeDir(),
-                vConfig.getFileSystem(),
-                vConfig.getPersistenceManagerConfig(),
-                rootNodeUUID,
-                nsReg,
-                ntReg);
-        pvMgr = new NativePVM(pm, getNodeTypeRegistry());
-        vMgr = new VersionManagerImpl(pvMgr, ntReg, delegatingDispatcher,
-                VERSION_STORAGE_NODE_UUID, SYSTEM_ROOT_NODE_UUID);
-
-        // init virtual nodetype manager
-        virtNTMgr = new VirtualNodeTypeStateManager(getNodeTypeRegistry(),
-                delegatingDispatcher, NODETYPES_NODE_UUID, SYSTEM_ROOT_NODE_UUID);
-
-        // initialize workspaces
-        iter = wspInfos.keySet().iterator();
-        while (iter.hasNext()) {
-            String wspName = (String) iter.next();
-            initWorkspace(wspName);
-        }
-
-        // after the workspaces are initialized, we setup a system session for
-        // the virtual nodetype manager
-        virtNTMgr.setSession(getSystemSession(repConfig.getDefaultWorkspaceName()));
-
-        // finally register shutdown hook
-        Runtime.getRuntime().addShutdownHook(new Thread() {
-            public void run() {
-                shutdown();
-            }
-        });
     }
 
     /**



Mime
View raw message