jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: rev 55067 - in incubator/jackrabbit/trunk/src: conf java/org/apache/jackrabbit/core java/org/apache/jackrabbit/core/config test/org/apache/jackrabbit/test
Date Tue, 19 Oct 2004 15:16:07 GMT
Author: stefan
Date: Tue Oct 19 08:16:07 2004
New Revision: 55067

Modified:
   incubator/jackrabbit/trunk/src/conf/repository.xml
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/config.dtd
   incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/JackrabbitRepositoryStub.java
Log:
- adding shutdown hook that shuts down the repository gracefully
- adding inline dtd to repository.xml

Modified: incubator/jackrabbit/trunk/src/conf/repository.xml
==============================================================================
--- incubator/jackrabbit/trunk/src/conf/repository.xml	(original)
+++ incubator/jackrabbit/trunk/src/conf/repository.xml	Tue Oct 19 08:16:07 2004
@@ -1,17 +1,96 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
 <!-- <!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Repository//EN"
"file://config.dtd"> -->
+<!DOCTYPE Repository [
+    <!--
+        the Repository element configures a repository instance;
+        individual workspaces of the repository are configured through
+        separate configuration files called workspace.xml which are
+        located in a subfolder of the workspaces root directory
+        (see Workspaces element).
+
+        it consists of
+
+            a FileSystem element (the virtual file system
+            used by the repository to persist global state such as
+            registered namespaces, custom node types, etc..
+
+            a Workspaces element that specifies to the location of
+            workspaces root directory and the name of default workspace
+
+            a Workspace element that is used as a workspace configuration
+            template; it is used to create the initial workspace if there's
+            no workspace yet and for creating additional workspaces through
+            the api
+    -->
+    <!ELEMENT Repository (FileSystem,Workspaces,Workspace)>
+
+    <!--
+        a virtual file system
+    -->
+    <!ELEMENT FileSystem (param*)>
+    <!ATTLIST FileSystem
+      class CDATA #REQUIRED>
+
+    <!--
+        generic parameter (name/value pair)
+    -->
+    <!ELEMENT param EMPTY>
+    <!ATTLIST param
+      name CDATA #REQUIRED
+      value CDATA #REQUIRED>
+
+    <!--
+        the Workspaces element specifies the workspaces root directory
+        (rootPath attribute) and the name of the default workspace
+        (defaultWorkspace attribute).
+
+        individual workspaces are configured through individual workspace.xml
+        files located in a subfolder each of the workspaces root directory.
+    -->
+    <!ELEMENT Workspaces EMPTY>
+    <!ATTLIST Workspaces
+      rootPath CDATA #REQUIRED
+      defaultWorkspace CDATA #REQUIRED>
+
+    <!--
+        the Workspace element serves as a workspace configuration template;
+        it is used to create the initial workspace if there's no workspace yet
+        and for creating additional workspaces through the api
+    -->
+    <!ELEMENT Workspace (FileSystem,PersistenceManager,SearchIndex)>
+    <!ATTLIST Workspace
+      name CDATA #REQUIRED>
+
+    <!--
+        the PersistenceManager element configures the persistence manager
+        to be used for the workspace; the class attribute specifies the
+        FQN of the class implementing PersistenceManager interface
+    -->
+    <!ELEMENT PersistenceManager (param*)>
+    <!ATTLIST PersistenceManager
+      class CDATA #REQUIRED>
+
+    <!--
+        the SearchIndex element specifies the locaction of the search index
+        (used by the QueryManager)
+    -->
+    <!ELEMENT SearchIndex EMPTY>
+    <!ATTLIST SearchIndex
+      path CDATA #REQUIRED>
+]>
+<!-- Example Repository Configuration File -->
 <Repository>
     <!--
         virtual file system where the repository stores global state
         (e.g. registered namespaces, custom node types, etc.)
     -->
     <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
-    	<param name="path" value="${rep.home}/repository"/>
+        <param name="path" value="${rep.home}/repository"/>
     </FileSystem>
     <!--
         location of workspaces root directory and name of default workspace
     -->
-    <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default" />
+    <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default"/>
     <!--
         workspace configuration template:
         used to create the initial workspace if there's no workspace yet
@@ -25,7 +104,7 @@
             <param name="path" value="${wsp.home}"/>
         </FileSystem>
         <!--
-            persistence of the workspace:
+            persistence manager of the workspace:
             class: FQN of class implementing PersistenceManager interface
         -->
         <PersistenceManager class="org.apache.jackrabbit.core.state.xml.XMLPersistenceManager">

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java	(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java	Tue
Oct 19 08:16:07 2004
@@ -66,6 +66,7 @@
     public static final String STATS_PROP_COUNT_PROPERTY = "jcr.repository.stats.properties.count";
 
     // pre-defined values of well known repository properties
+    // @todo update as necessary
     private static final String SPEC_VERSION = "0.14";
     private static final String SPEC_NAME = "Content Repository API for Java(TM) Technology
Specification";
     private static final String REP_VENDOR = "Apache Software Foundation";
@@ -117,6 +118,9 @@
     private long nodesCount = 0;
     private long propsCount = 0;
 
+    // flag indicating if respository has been shut down
+    private boolean disposed = false;
+
     /**
      * private constructor
      *
@@ -309,6 +313,13 @@
                         "/", true, null, null, false);
             }
         }
+
+        // finally register shutdown hook
+        Runtime.getRuntime().addShutdownHook(new Thread() {
+            public void run() {
+                shutdown();
+            }
+        });
     }
 
     /**
@@ -326,27 +337,57 @@
     }
 
     RepositoryConfig getConfig() {
+        // check state
+        if (disposed) {
+            throw new IllegalStateException("repository instance has been shut down");
+        }
+
         return repConfig;
     }
 
     NamespaceRegistryImpl getNamespaceRegistry() {
+        // check state
+        if (disposed) {
+            throw new IllegalStateException("repository instance has been shut down");
+        }
+
         return nsReg;
     }
 
     NodeTypeRegistry getNodeTypeRegistry() {
+        // check state
+        if (disposed) {
+            throw new IllegalStateException("repository instance has been shut down");
+        }
+
         return ntReg;
     }
 
     VersionManager getVersionManager() {
+        // check state
+        if (disposed) {
+            throw new IllegalStateException("repository instance has been shut down");
+        }
+
         return vMgr;
     }
 
     String getRootNodeUUID() {
+        // check state
+        if (disposed) {
+            throw new IllegalStateException("repository instance has been shut down");
+        }
+
         return rootNodeUUID;
     }
 
     synchronized PersistentItemStateManager getWorkspaceStateManager(String workspaceName)
             throws NoSuchWorkspaceException, RepositoryException {
+        // check state
+        if (disposed) {
+            throw new IllegalStateException("repository instance has been shut down");
+        }
+
         WorkspaceConfig wspConfig = (WorkspaceConfig) wspConfigs.get(workspaceName);
         if (wspConfig == null) {
             throw new NoSuchWorkspaceException(workspaceName);
@@ -370,6 +411,11 @@
 
     synchronized ReferenceManager getWorkspaceReferenceManager(String workspaceName)
             throws NoSuchWorkspaceException, RepositoryException {
+        // check state
+        if (disposed) {
+            throw new IllegalStateException("repository instance has been shut down");
+        }
+
         WorkspaceConfig wspConfig = (WorkspaceConfig) wspConfigs.get(workspaceName);
         if (wspConfig == null) {
             throw new NoSuchWorkspaceException(workspaceName);
@@ -387,6 +433,11 @@
 
     synchronized ObservationManagerFactory getObservationManagerFactory(String workspaceName)
             throws NoSuchWorkspaceException {
+        // check state
+        if (disposed) {
+            throw new IllegalStateException("repository instance has been shut down");
+        }
+
         if (!wspConfigs.containsKey(workspaceName)) {
             throw new NoSuchWorkspaceException(workspaceName);
         }
@@ -414,6 +465,11 @@
      */
     synchronized SearchManager getSearchManager(String workspaceName)
             throws NoSuchWorkspaceException, RepositoryException {
+        // check state
+        if (disposed) {
+            throw new IllegalStateException("repository instance has been shut down");
+        }
+
         WorkspaceConfig wspConfig = (WorkspaceConfig) wspConfigs.get(workspaceName);
         SearchManager searchMgr
                 = (SearchManager) wspSearchMgrs.get(workspaceName);
@@ -437,6 +493,11 @@
 
     synchronized SystemSession getSystemSession(String workspaceName)
             throws NoSuchWorkspaceException, RepositoryException {
+        // check state
+        if (disposed) {
+            throw new IllegalStateException("repository instance has been shut down");
+        }
+
         WorkspaceConfig wspConfig = (WorkspaceConfig) wspConfigs.get(workspaceName);
         if (wspConfig == null) {
             throw new NoSuchWorkspaceException(workspaceName);
@@ -451,9 +512,18 @@
     }
 
     /**
-     * Shuts down this repository
+     * Shuts down this repository. Note that this method is called automatically
+     * through a shutdown hook.
+     *
+     * @see Runtime#addShutdownHook(Thread)
      */
-    protected void shutdown() {
+    protected synchronized void shutdown() {
+        // check state
+        if (disposed) {
+            // there's nothing to do here because the repository has already been shut down
+            return;
+        }
+
         // persist repository properties
         try {
             storeRepProps();
@@ -483,6 +553,9 @@
         } catch (FileSystemException e) {
             log.error("Error while closing filesystem", e);
         }
+
+        // make sure this instance is not used anymore
+        disposed = true;
     }
 
     private void loadRepProps() throws RepositoryException {
@@ -541,6 +614,11 @@
      * @return
      */
     public Properties getProperties() {
+        // check state
+        if (disposed) {
+            throw new IllegalStateException("repository instance has been shut down");
+        }
+
         return (Properties) repProps.clone();
     }
 
@@ -549,6 +627,11 @@
      * @return
      */
     public String getProperty(String key) {
+        // check state
+        if (disposed) {
+            throw new IllegalStateException("repository instance has been shut down");
+        }
+
         return repProps.getProperty(key);
     }
 
@@ -560,6 +643,11 @@
      * @throws RepositoryException
      */
     public NodeImpl getSystemRootNode(SessionImpl session) throws RepositoryException {
+        // check state
+        if (disposed) {
+            throw new IllegalStateException("repository instance has been shut down");
+        }
+
         return ((NodeImpl) session.getRootNode()).getNode(SYSTEM_ROOT_NAME);
     }
 
@@ -569,6 +657,11 @@
      */
     public Session login(Credentials credentials, String workspaceName)
             throws LoginException, NoSuchWorkspaceException, RepositoryException {
+        // check state
+        if (disposed) {
+            throw new IllegalStateException("repository instance has been shut down");
+        }
+
         if (workspaceName == null) {
             workspaceName = repConfig.getDefaultWorkspaceName();
         }
@@ -591,11 +684,17 @@
         }
     }
 
-    //-----------------------------------------------------------< Repository >
+    //--------------------------------------------------------< EventListener >
     /**
      * @see EventListener#onEvent(EventIterator)
      */
     public synchronized void onEvent(EventIterator events) {
+        // check state
+        if (disposed) {
+            // ignore, repository instance has been shut down
+            return;
+        }
+
         while (events.hasNext()) {
             Event event = events.nextEvent();
             long type = event.getType();

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/config.dtd
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/config.dtd	(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/config.dtd	Tue Oct
19 08:16:07 2004
@@ -15,37 +15,79 @@
  * limitations under the License.
  */
 -->
-<!-- -->
-<!ELEMENT Repository (FileSystem)>
-
-<!-- -->
+<!--
+    the Repository element configures a repository instance;
+    individual workspaces of the repository are configured through
+    separate configuration files called workspace.xml which are
+    located in a subfolder of the workspaces root directory
+    (see Workspaces element).
+
+    it consists of
+
+        a FileSystem element (the virtual file system
+        used by the repository to persist global state such as
+        registered namespaces, custom node types, etc..
+
+        a Workspaces element that specifies to the location of
+        workspaces root directory and the name of default workspace
+
+        a Workspace element that is used as a workspace configuration
+        template; it is used to create the initial workspace if there's
+        no workspace yet and for creating additional workspaces through
+        the api
+-->
+<!ELEMENT Repository (FileSystem,Workspaces,Workspace)>
+
+<!--
+    a virtual file system
+-->
 <!ELEMENT FileSystem (param*)>
 <!ATTLIST FileSystem
   class CDATA #REQUIRED>
 
-<!-- -->
+<!--
+    generic parameter (name/value pair)
+-->
 <!ELEMENT param EMPTY>
 <!ATTLIST param
   name CDATA #REQUIRED
   value CDATA #REQUIRED>
 
-<!-- -->
+<!--
+    the Workspaces element specifies the workspaces root directory
+    (rootPath attribute) and the name of the default workspace
+    (defaultWorkspace attribute).
+
+    individual workspaces are configured through individual workspace.xml
+    files located in a subfolder each of the workspaces root directory.
+-->
 <!ELEMENT Workspaces EMPTY>
 <!ATTLIST Workspaces
   rootPath CDATA #REQUIRED
-  name CDATA #REQUIRED>
+  defaultWorkspace CDATA #REQUIRED>
 
-<!-- -->
-<!ELEMENT Workspace (FileSystem,PersistenceManager)>
+<!--
+    the Workspace element serves as a workspace configuration template;
+    it is used to create the initial workspace if there's no workspace yet
+    and for creating additional workspaces through the api
+-->
+<!ELEMENT Workspace (FileSystem,PersistenceManager,SearchIndex)>
 <!ATTLIST Workspace
   name CDATA #REQUIRED>
 
-<!-- -->
+<!--
+    the PersistenceManager element configures the persistence manager
+    to be used for the workspace; the class attribute specifies the
+    FQN of the class implementing PersistenceManager interface
+-->
 <!ELEMENT PersistenceManager (param*)>
 <!ATTLIST PersistenceManager
   class CDATA #REQUIRED>
 
-<!-- -->
+<!--
+    the SearchIndex element specifies the locaction of the search index
+    (used by the QueryManager)
+-->
 <!ELEMENT SearchIndex EMPTY>
 <!ATTLIST SearchIndex
   path CDATA #REQUIRED>

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/JackrabbitRepositoryStub.java
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/JackrabbitRepositoryStub.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/JackrabbitRepositoryStub.java
Tue Oct 19 08:16:07 2004
@@ -81,13 +81,6 @@
                 RegistryHelper.registerRepository(ctx, repName, repConfig, repHome, true);
                 repository = (Repository) ctx.lookup(repName);
 */
-/*
-                Runtime.getRuntime().addShutdownHook(new Thread() {
-                    public void run() {
-                        repository.shutdown();
-                    }
-                });
-*/
             } catch (Exception e) {
                 throw new RepositoryStubException(e.toString());
             }

Mime
View raw message