[exo-jcr-commits] exo-jcr SVN: r4241 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr: dataflow and 4 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Apr 18 03:58:53 EDT 2011


Author: tolusha
Date: 2011-04-18 03:58:53 -0400 (Mon, 18 Apr 2011)
New Revision: 4241

Added:
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/ReadOnlySupport.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositorySuspendController.java
Removed:
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/RepositorySuspendController.java
Modified:
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/ManageableRepository.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/WorkspaceContainerFacade.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/PersistentDataManager.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/Suspendable.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/jndi/BindableRepositoryImpl.java
Log:
EXOJCR-1292: Allow to know the current repository status

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/ManageableRepository.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/ManageableRepository.java	2011-04-15 19:11:33 UTC (rev 4240)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/ManageableRepository.java	2011-04-18 07:58:53 UTC (rev 4241)
@@ -60,6 +60,16 @@
    final int READONLY = 2;
 
    /**
+    * Repository SUSPENDED status.
+    */
+   final int SUSPENDED = 3;
+
+   /**
+    * Repository UNDEFINED status.
+    */
+   final int UNDEFINED = 4;
+
+   /**
     * Add the items persistence listener to the named workspace.
     * 
     * @param workspaceName - name of workspace
@@ -160,7 +170,7 @@
     * 
     * @param repository state
     */
-   void setState(int state);
+   void setState(int state) throws RepositoryException;
 
    /**
     * Returns repository state.

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/WorkspaceContainerFacade.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/WorkspaceContainerFacade.java	2011-04-15 19:11:33 UTC (rev 4240)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/WorkspaceContainerFacade.java	2011-04-18 07:58:53 UTC (rev 4241)
@@ -18,10 +18,18 @@
  */
 package org.exoplatform.services.jcr.core;
 
+import org.exoplatform.services.jcr.core.security.JCRRuntimePermissions;
+import org.exoplatform.services.jcr.impl.ReadOnlySupport;
 import org.exoplatform.services.jcr.impl.WorkspaceContainer;
+import org.exoplatform.services.jcr.impl.backup.ResumeException;
+import org.exoplatform.services.jcr.impl.backup.SuspendException;
+import org.exoplatform.services.jcr.impl.backup.Suspendable;
 
+import java.util.Collections;
 import java.util.List;
 
+import javax.jcr.RepositoryException;
+
 /**
  * Created by The eXo Platform SAS .<br/> An entry point to the implementation, used for extending
  * functionality
@@ -92,4 +100,159 @@
    {
       container.registerComponentInstance(key, component);
    }
+
+   /**
+    * Returns current workspace state.
+    * 
+    * @param state
+    * @throws RepositoryException
+    */
+   public int getState()
+   {
+      boolean hasROComponents = false;
+      boolean hasRWComponents = false;
+      List<ReadOnlySupport> readOnlyComponents = getComponentInstancesOfType(ReadOnlySupport.class);
+      for (ReadOnlySupport component : readOnlyComponents)
+      {
+         if (component.isReadOnly())
+         {
+            hasROComponents = true;
+         }
+         else
+         {
+            hasRWComponents = true;
+         }
+      }
+
+      boolean hasSuspendedComponents = false;
+      boolean hasResumedComponents = false;
+      List<Suspendable> suspendableComponents = getComponentInstancesOfType(Suspendable.class);
+      for (Suspendable component : suspendableComponents)
+      {
+         if (component.isSuspended())
+         {
+            hasSuspendedComponents = true;
+         }
+         else
+         {
+            hasResumedComponents = true;
+         }
+      }
+
+      if (hasSuspendedComponents && !hasResumedComponents && !hasROComponents)
+      {
+         return ManageableRepository.SUSPENDED;
+      }
+      else if (hasROComponents && !hasRWComponents && !hasSuspendedComponents)
+      {
+         return ManageableRepository.READONLY;
+      }
+      else if (!hasSuspendedComponents && !hasROComponents)
+      {
+         return ManageableRepository.ONLINE;
+      }
+      else
+      {
+         return ManageableRepository.UNDEFINED;
+      }
+   }
+
+   /**
+    * Set new workspace state.
+    * 
+    * @param state
+    * @throws RepositoryException
+    */
+   public void setState(int state) throws RepositoryException
+   {
+      // Need privileges to manage repository.
+      SecurityManager security = System.getSecurityManager();
+      if (security != null)
+      {
+         security.checkPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);
+      }
+      
+      switch (state)
+      {
+         case ManageableRepository.ONLINE :
+            setOnline();
+            break;
+         case ManageableRepository.OFFLINE :
+            break;
+         case ManageableRepository.READONLY :
+            setReadOnly();
+            break;
+         case ManageableRepository.SUSPENDED :
+            suspend();
+            break;
+         default :
+            return;
+      }
+   }
+
+   /**
+    * Set all components readonly.
+    */
+   private void setReadOnly()
+   {
+      List<ReadOnlySupport> components = getComponentInstancesOfType(ReadOnlySupport.class);
+      for (ReadOnlySupport component : components)
+      {
+         component.setReadOnly(true);
+      }
+   }
+
+   /**
+    * Suspend all components in workspace.
+    * 
+    * @throws RepositoryException
+    */
+   private void suspend() throws RepositoryException
+   {
+      List<Suspendable> components = getComponentInstancesOfType(Suspendable.class);
+      for (Suspendable component : components)
+      {
+         try
+         {
+            component.suspend();
+         }
+         catch (SuspendException e)
+         {
+            throw new RepositoryException("Can't suspend component", e);
+         }
+      }
+   }
+
+   /**
+    * Set all components online.
+    * 
+    * @throws RepositoryException
+    */
+   private void setOnline() throws RepositoryException
+   {
+      List<ReadOnlySupport> readOnlyComponents = getComponentInstancesOfType(ReadOnlySupport.class);
+      for (ReadOnlySupport component : readOnlyComponents)
+      {
+         component.setReadOnly(false);
+      }
+
+      List<Suspendable> suspendableComponents = getComponentInstancesOfType(Suspendable.class);
+      Collections.reverse(suspendableComponents);
+
+      for (Suspendable component : suspendableComponents)
+      {
+         try
+         {
+            if (component.isSuspended())
+            {
+               component.resume();
+            }
+         }
+         catch (ResumeException e)
+         {
+            throw new RepositoryException("Can't resume component", e);
+         }
+      }
+   }
+
 }

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/PersistentDataManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/PersistentDataManager.java	2011-04-15 19:11:33 UTC (rev 4240)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/PersistentDataManager.java	2011-04-18 07:58:53 UTC (rev 4241)
@@ -20,6 +20,7 @@
 
 import org.exoplatform.services.jcr.dataflow.persistent.ItemsPersistenceListener;
 import org.exoplatform.services.jcr.dataflow.persistent.ItemsPersistenceListenerFilter;
+import org.exoplatform.services.jcr.impl.ReadOnlySupport;
 
 /**
  * Created by The eXo Platform SAS.
@@ -29,7 +30,7 @@
  * @author <a href="mailto:peter.nedonosko at exoplatform.com.ua">Peter Nedonosko</a> 
  * @version $Id: PersistentDataManager.java 34801 2009-07-31 15:44:50Z dkatayev $
  */
-public interface PersistentDataManager extends DataManager
+public interface PersistentDataManager extends DataManager, ReadOnlySupport
 {
 
    void addItemPersistenceListener(ItemsPersistenceListener listener);
@@ -40,29 +41,4 @@
 
    void removeItemPersistenceListenerFilter(ItemsPersistenceListenerFilter filter);
 
-   /**
-    * Status of write-operations restrictions.
-    * 
-    * Read-only status is descriptive within the container, i.e. will not prevent any write
-    * operation.
-    * 
-    * Used in DataManager implementations.
-    * 
-    * @return true - if write-operations allowed, false - otherwise.
-    */
-   boolean isReadOnly();
-
-   /**
-    * Set status of write-operations restrictions.
-    * 
-    * Read-only status is descriptive within the container, i.e. will not prevent any write
-    * operation.
-    * 
-    * Used in DataManager implementations.
-    * 
-    * @param status
-    *          , true - if write-operations allowed, false - otherwise.
-    */
-   void setReadOnly(boolean status);
-
 }

Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/ReadOnlySupport.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/ReadOnlySupport.java	                        (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/ReadOnlySupport.java	2011-04-18 07:58:53 UTC (rev 4241)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl;
+
+/**
+ * @author <a href="mailto:anatoliy.bazko at gmail.com">Anatoliy Bazko</a>
+ * @version $Id: ReadOnlySupport.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public interface ReadOnlySupport
+{
+
+   /**
+    * Status of write-operations restrictions.
+    * 
+    * Read-only status is descriptive within the container, i.e. will not prevent any write
+    * operation.
+    * 
+    * Used in DataManager implementations.
+    * 
+    * @return true - if write-operations allowed, false - otherwise.
+    */
+   boolean isReadOnly();
+
+   /**
+    * Set status of write-operations restrictions.
+    * 
+    * Read-only status is descriptive within the container, i.e. will not prevent any write
+    * operation.
+    * 
+    * Used in DataManager implementations.
+    * 
+    * @param status
+    *          , true - if write-operations allowed, false - otherwise.
+    */
+   void setReadOnly(boolean status);
+
+}

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java	2011-04-15 19:11:33 UTC (rev 4240)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java	2011-04-18 07:58:53 UTC (rev 4241)
@@ -34,7 +34,6 @@
 import org.exoplatform.services.jcr.core.nodetype.ExtendedNodeTypeManager;
 import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
 import org.exoplatform.services.jcr.core.security.JCRRuntimePermissions;
-import org.exoplatform.services.jcr.impl.backup.RepositorySuspendController;
 import org.exoplatform.services.jcr.impl.core.AddNamespacePluginHolder;
 import org.exoplatform.services.jcr.impl.core.LocationFactory;
 import org.exoplatform.services.jcr.impl.core.NamespaceDataPersister;

Copied: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositorySuspendController.java (from rev 4234, jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/RepositorySuspendController.java)
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositorySuspendController.java	                        (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositorySuspendController.java	2011-04-18 07:58:53 UTC (rev 4241)
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl;
+
+import org.exoplatform.management.annotations.Managed;
+import org.exoplatform.management.annotations.ManagedDescription;
+import org.exoplatform.management.jmx.annotations.NameTemplate;
+import org.exoplatform.management.jmx.annotations.Property;
+import org.exoplatform.services.jcr.core.ManageableRepository;
+import org.exoplatform.services.jcr.core.security.JCRRuntimePermissions;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.picocontainer.Startable;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * Allows via JMX suspend and resume repository's components.
+ * 
+ * @author <a href="mailto:anatoliy.bazko at gmail.com">Anatoliy Bazko</a>
+ * @version $Id: RepositorySuspendController.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+ at Managed
+ at NameTemplate(@Property(key = "service", value = "RepositorySuspendController"))
+public class RepositorySuspendController implements Startable
+{
+   /**
+    * The current repository.
+    */
+   private final ManageableRepository repository;
+
+   /**
+    * Logger.
+    */
+   protected static Log log = ExoLogger.getLogger("exo.jcr.component.core.RepositorySuspendController");
+
+   /**
+    * RepositoryController constructor.
+    */
+   public RepositorySuspendController(ManageableRepository repository)
+   {
+      this.repository = repository;
+   }
+
+   /**
+    * Suspend repository which means that allow only read operations. All writing threads will wait until resume operations invoked.
+    * 
+    * @return repository state
+    */
+   @Managed
+   @ManagedDescription("Suspend repository which means that allow only read operations. All writing threads will wait until resume operations invoked.")
+   public String suspend()
+   {
+      // Need privileges to manage repository.
+      SecurityManager security = System.getSecurityManager();
+      if (security != null)
+      {
+         security.checkPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);
+      }
+
+      try
+      {
+         repository.setState(ManageableRepository.SUSPENDED);
+      }
+      catch (RepositoryException e)
+      {
+         log.error(e);
+      }
+
+      return getState();
+   }
+
+   /**
+    * Resume repository. All previously suspended threads continue working.
+    * 
+    * @return repository state
+    */
+   @Managed
+   @ManagedDescription("Resume repository. All previously suspended threads continue working.")
+   public String resume()
+   {
+      // Need privileges to manage repository.
+      SecurityManager security = System.getSecurityManager();
+      if (security != null)
+      {
+         security.checkPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);
+      }
+
+      try
+      {
+         repository.setState(ManageableRepository.ONLINE);
+      }
+      catch (RepositoryException e)
+      {
+         log.error(e);
+      }
+
+      return getState();
+   }
+
+   /**
+    * Returns repository state.
+    */
+   @Managed
+   @ManagedDescription("Returns repository state.")
+   public String getState()
+   {
+      return repository.toString();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void start()
+   {
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void stop()
+   {
+   }
+}

Deleted: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/RepositorySuspendController.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/RepositorySuspendController.java	2011-04-15 19:11:33 UTC (rev 4240)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/RepositorySuspendController.java	2011-04-18 07:58:53 UTC (rev 4241)
@@ -1,206 +0,0 @@
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.exoplatform.services.jcr.impl.backup;
-
-import org.exoplatform.management.annotations.Managed;
-import org.exoplatform.management.annotations.ManagedDescription;
-import org.exoplatform.management.jmx.annotations.NameTemplate;
-import org.exoplatform.management.jmx.annotations.Property;
-import org.exoplatform.services.jcr.core.ManageableRepository;
-import org.exoplatform.services.jcr.core.security.JCRRuntimePermissions;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-import org.picocontainer.Startable;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Allows via JMX suspend and resume repository's components.
- * 
- * @author <a href="mailto:anatoliy.bazko at gmail.com">Anatoliy Bazko</a>
- * @version $Id: RepositorySuspendController.java 34360 2009-07-22 23:58:59Z tolusha $
- */
- at Managed
- at NameTemplate(@Property(key = "service", value = "RepositorySuspendController"))
-public class RepositorySuspendController implements Startable
-{
-   /**
-    * Repository ONLINE status.
-    */
-   private final String ONLINE = "online";
-
-   /**
-    * Repository SUSPENDED state.
-    */
-   private final String SUSPENDED = "suspended";
-
-   /**
-    * Undefined state. 
-    */
-   private final String UNDEFINED = "undefined";
-
-   private final ManageableRepository repository;
-
-   /**
-    * Logger.
-    */
-   protected static Log log = ExoLogger.getLogger("exo.jcr.component.core.RepositorySuspendController");
-
-   /**
-    * RepositoryController constructor.
-    */
-   public RepositorySuspendController(ManageableRepository repository)
-   {
-      this.repository = repository;
-   }
-
-   /**
-    * Suspend repository which means that allow only read operations. All writing threads will wait until resume operations invoked.
-    * 
-    * @return repository state
-    */
-   @Managed
-   @ManagedDescription("Suspend repository which means that allow only read operations. All writing threads will wait until resume operations invoked.")
-   public String suspend()
-   {
-      // Need privileges to manage repository.
-      SecurityManager security = System.getSecurityManager();
-      if (security != null)
-      {
-         security.checkPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);
-      }
-
-      for (Suspendable component : getSuspendableComponents())
-      {
-         try
-         {
-            component.suspend();
-         }
-         catch (SuspendException e)
-         {
-            log.error("Can't suspend component", e);
-         }
-      }
-
-      return getState();
-   }
-
-   /**
-    * Resume repository. All previously suspended threads continue working.
-    * 
-    * @return repository state
-    */
-   @Managed
-   @ManagedDescription("Resume repository. All previously suspended threads continue working.")
-   public String resume()
-   {
-      // Need privileges to manage repository.
-      SecurityManager security = System.getSecurityManager();
-      if (security != null)
-      {
-         security.checkPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);
-      }
-
-      List<Suspendable> components = getSuspendableComponents();
-      Collections.reverse(components);
-
-      for (Suspendable component : components)
-      {
-         try
-         {
-            if (component.isSuspended())
-            {
-               component.resume();
-            }
-         }
-         catch (ResumeException e)
-         {
-            log.error("Can't resume component", e);
-         }
-      }
-
-      return getState();
-   }
-
-   /**
-    * Returns repository state.
-    */
-   @Managed
-   @ManagedDescription("Returns repository state.")
-   public String getState()
-   {
-      String state = ONLINE;
-      
-      boolean hasSuspendedComponents = false;
-      boolean hasOnlineComponents = false;
-
-      for (Suspendable component : getSuspendableComponents())
-      {
-         if (component.isSuspended())
-         {
-            hasSuspendedComponents = true;
-
-            if (hasOnlineComponents)
-            {
-               return UNDEFINED;
-            }
-
-            state = SUSPENDED;
-         }
-         else
-         {
-            hasOnlineComponents = true;
-            if (hasSuspendedComponents)
-            {
-               return UNDEFINED;
-            }
-         }
-      }
-
-      return state;
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void start()
-   {
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void stop()
-   {
-   }
-
-   private List<Suspendable> getSuspendableComponents()
-   {
-      List<Suspendable> components = new ArrayList<Suspendable>();
-      for (String workspaceName : repository.getWorkspaceNames())
-      {
-         components.addAll(repository.getWorkspaceContainer(workspaceName).getComponentInstancesOfType(
-            Suspendable.class));
-      }
-
-      return components;
-   }
-}

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/Suspendable.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/Suspendable.java	2011-04-15 19:11:33 UTC (rev 4240)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/Suspendable.java	2011-04-18 07:58:53 UTC (rev 4241)
@@ -27,14 +27,14 @@
    /**
     * Suspend component.
     *  
-    * @throws SuspendException of error occurred 
+    * @throws SuspendException if error occurred 
     */
    void suspend() throws SuspendException;
 
    /**
     * Resume component.
     *  
-    * @throws ResumeException of error occurred 
+    * @throws ResumeException if error occurred 
     */
    void resume() throws ResumeException;
 

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java	2011-04-15 19:11:33 UTC (rev 4240)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java	2011-04-18 07:58:53 UTC (rev 4241)
@@ -137,7 +137,7 @@
    /**
     * Repository state. OFFLINE by default.
     */
-   private int state = OFFLINE;
+   private boolean isOffline = true;
 
    /**
     * RepositoryImpl constructor.
@@ -648,60 +648,55 @@
     */
    public int getState()
    {
-      return state;
+      if (isOffline)
+      {
+         return OFFLINE;
+      }
+      
+      Integer state = null;
+      for (String workspaceName : getWorkspaceNames())
+      {
+         int workspaceState = getWorkspaceContainer(workspaceName).getState();
+         if (state == null)
+         {
+            state = workspaceState;
+         }
+         else if (state != workspaceState)
+         {
+            return UNDEFINED;
+         }
+      }
+      
+      return state == null ? ONLINE : state;
    }
 
    /**
     * {@inheritDoc}
     */
-   public void setState(int state)
+   public void setState(int state) throws RepositoryException
    {
-      // Need privileges to manage repository.
-      SecurityManager security = System.getSecurityManager();
-      if (security != null)
+      if (getState() != ONLINE && !(state == ONLINE || state == OFFLINE))
       {
-         security.checkPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);
+         throw new RepositoryException("First switch repository to ONLINE and then to needed state.\n" + toString());
       }
 
-      switch (state)
+      // set state for all workspaces
+      for (String workspaceName : getWorkspaceNames())
       {
-         case ONLINE :
-            // set ONLINE all workspaces
-            setAllWorkspacesReadOnly(false);
-            break;
-         case OFFLINE :
-            // TODO do nothing
-            break;
-         case READONLY :
-            // set READONLY all workspaces
-            setAllWorkspacesReadOnly(true);
-            break;
+         getWorkspaceContainer(workspaceName).setState(state);
       }
 
-      this.state = state;
+      isOffline = state == OFFLINE;
    }
 
    /**
-    * Set all repository workspaces ReadOnly status.
-    *
-    * @param wsStatus ReadOnly workspace status
+    * {@inheritDoc}
     */
-   private void setAllWorkspacesReadOnly(boolean wsStatus)
-   {
-      WorkspaceContainerFacade wsFacade;
-      for (String workspaceName : getWorkspaceNames())
-      {
-         wsFacade = getWorkspaceContainer(workspaceName);
-         PersistentDataManager dataManager = (PersistentDataManager)wsFacade.getComponent(PersistentDataManager.class);
-         dataManager.setReadOnly(wsStatus);
-      }
-   }
-
    @Override
    public String toString()
    {
       String stateTitle;
-      switch (state)
+      switch (getState())
       {
          case ONLINE :
             stateTitle = "online";
@@ -712,13 +707,17 @@
          case READONLY :
             stateTitle = "readonly";
             break;
+         case SUSPENDED :
+            stateTitle = "suspended";
+            break;
          default :
             stateTitle = "undefined";
+            break;
       }
+
       String defaultWorkspaceName = config.getDefaultWorkspaceName();
       return String.format(
          "Repository {\n name: %s;\n system workspace: %s;\n default workspace: %s;\n workspaces: %s;\n state: %s \n}",
          name, systemWorkspaceName, defaultWorkspaceName, Arrays.toString(getWorkspaceNames()), stateTitle);
    }
-
 }

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/jndi/BindableRepositoryImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/jndi/BindableRepositoryImpl.java	2011-04-15 19:11:33 UTC (rev 4240)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/jndi/BindableRepositoryImpl.java	2011-04-18 07:58:53 UTC (rev 4241)
@@ -237,7 +237,7 @@
       return delegatee.getState();
    }
 
-   public void setState(int state)
+   public void setState(int state) throws RepositoryException
    {
       delegatee.setState(state);
    }



More information about the exo-jcr-commits mailing list