[gatein-commits] gatein SVN: r1919 - in portal/trunk/component: portal/src/main/java/org/exoplatform/portal/pom/config and 3 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Mar 1 18:13:03 EST 2010


Author: julien_viet
Date: 2010-03-01 18:13:03 -0500 (Mon, 01 Mar 2010)
New Revision: 1919

Added:
   portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/GlobalKey.java
Modified:
   portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/NewPortalConfig.java
   portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/NewPortalConfigListener.java
   portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSession.java
   portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSessionManager.java
   portal/trunk/component/portal/src/test/java/conf/exo.portal.component.portal-configuration1.xml
   portal/trunk/component/test/core/src/main/java/org/exoplatform/component/test/AbstractGateInTest.java
   portal/trunk/component/test/core/src/main/resources/conf/root-configuration.xml
Log:
- properly scope the data in the pom manager cache
- improved the new portal config listener
- log system properties with debug level in unit test


Modified: portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/NewPortalConfig.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/NewPortalConfig.java	2010-03-01 22:18:46 UTC (rev 1918)
+++ portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/NewPortalConfig.java	2010-03-01 23:13:03 UTC (rev 1919)
@@ -126,4 +126,10 @@
       this.ownerType = ownerType;
    }
 
+   @Override
+   public String toString()
+   {
+      return "PortalConfig[predefinedOwner=" + predefinedOwner + ",ownerType=" + ownerType + ",templateName=" + templateName + 
+         "location=" + location + "]";
+   }
 }

Modified: portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/NewPortalConfigListener.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/NewPortalConfigListener.java	2010-03-01 22:18:46 UTC (rev 1918)
+++ portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/NewPortalConfigListener.java	2010-03-01 23:13:03 UTC (rev 1919)
@@ -19,12 +19,10 @@
 
 package org.exoplatform.portal.config;
 
-import org.apache.commons.lang.StringUtils;
 import org.exoplatform.commons.utils.IOUtil;
 import org.exoplatform.container.component.BaseComponentPlugin;
 import org.exoplatform.container.configuration.ConfigurationManager;
 import org.exoplatform.container.xml.InitParams;
-import org.exoplatform.container.xml.ObjectParameter;
 import org.exoplatform.container.xml.ValueParam;
 import org.exoplatform.portal.application.PortletPreferences;
 import org.exoplatform.portal.application.PortletPreferences.PortletPreferencesSet;
@@ -34,23 +32,19 @@
 import org.exoplatform.portal.config.model.PageNode;
 import org.exoplatform.portal.config.model.PortalConfig;
 import org.exoplatform.portal.config.model.Page.PageSet;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
+import org.gatein.common.logging.Logger;
+import org.gatein.common.logging.LoggerFactory;
 import org.jibx.runtime.*;
-import org.jibx.runtime.impl.IXMLReaderFactory;
-import org.jibx.runtime.impl.RuntimeSupport;
 import org.jibx.runtime.impl.UnmarshallingContext;
-import org.jibx.runtime.impl.XMLPullReaderFactory;
-import org.xmlpull.v1.XmlPullParserFactory;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Set;
+import java.util.regex.Pattern;
 
 /**
  * Created by The eXo Platform SARL Author : Tuan Nguyen
@@ -60,16 +54,22 @@
 public class NewPortalConfigListener extends BaseComponentPlugin
 {
 
+   /** . */
    private ConfigurationManager cmanager_;
 
+   /** . */
    private DataStorage dataStorage_;
 
+   /** . */
    private volatile List<NewPortalConfig> configs;
 
+   /** . */
    private List<SiteConfigTemplates> templateConfigs;
 
+   /** . */
    private String pageTemplatesLocation_;
 
+   /** . */
    private String defaultPortal;
    
    /**
@@ -78,9 +78,11 @@
     */
    private boolean defaultPortalSpecified = false;
 
+   /** . */
    private boolean isUseTryCatch;
 
-   private Log log = ExoLogger.getLogger("Portal:UserPortalConfigService");
+   /** . */
+   private Logger log = LoggerFactory.getLogger(getClass());
 
    public NewPortalConfigListener(DataStorage dataStorage, ConfigurationManager cmanager, InitParams params)
       throws Exception
@@ -316,16 +318,12 @@
 
    public void createPortalConfig(NewPortalConfig config, String owner) throws Exception
    {
-      String type = config.getOwnerType();
-
-      boolean isTemplate = (config.getTemplateName() != null && config.getTemplateName().trim().length() > 0);
-      String path = getPathConfig(config, owner, type, isTemplate);
-
       try
       {
-         String xml = getDefaultConfig(config.getTemplateLocation(), path);
+         String type = config.getOwnerType();
+         PortalConfig pconfig = getConfig(config, owner, type, PortalConfig.class);
 
-         if (xml == null)
+         if (pconfig == null)
          {
             // Ensure that the PortalConfig has been defined
             // The PortalConfig could be empty if the related PortalConfigListener
@@ -340,13 +338,7 @@
             }
             return;
          }
-         if (isTemplate)
-         {
-            xml = StringUtils.replace(xml, "@owner@", owner);
-         }
 
-         PortalConfig pconfig = fromXML(config.getOwnerType(), owner, xml, PortalConfig.class);
-
          // We use that owner value because it may have been fixed for group names
          owner = pconfig.getName();
 
@@ -361,124 +353,135 @@
             dataStorage_.save(pconfig);
          }
       }
-      catch (JiBXException e)
-      {
-         log.error(e.getMessage() + " file: " + path, e);
-         throw e;
-      }
       catch (IOException e)
       {
-         log.error(e.getMessage() + " file: " + path);
+         log.error("Could not load portal configuration", e);
       }
    }
 
    public void createPage(NewPortalConfig config, String owner) throws Exception
    {
-
-      boolean isTemplate = (config.getTemplateName() != null && config.getTemplateName().trim().length() > 0);
-      String path = getPathConfig(config, owner, "pages", isTemplate);
-
-      try
+      PageSet pageSet = getConfig(config, owner, "pages", PageSet.class);
+      if (pageSet == null)
       {
-         String xml = getDefaultConfig(config.getTemplateLocation(), path);
-         if (xml == null)
-         {
-            return;
-         }
-
-         if (isTemplate)
-         {
-            xml = StringUtils.replace(xml, "@owner@", owner);
-         }
-
-         PageSet pageSet = fromXML(config.getOwnerType(), owner, xml, PageSet.class);
-         ArrayList<Page> list = pageSet.getPages();
-         for (Page page : list)
-         {
-            dataStorage_.create(page);
-         }
+         return;
       }
-      catch (JiBXException e)
+      ArrayList<Page> list = pageSet.getPages();
+      for (Page page : list)
       {
-         log.error(e.getMessage() + " file: " + path, e);
-         throw e;
+         dataStorage_.create(page);
       }
    }
 
    public void createPageNavigation(NewPortalConfig config, String owner) throws Exception
    {
-      boolean isTemplate = (config.getTemplateName() != null && config.getTemplateName().trim().length() > 0);
-      String path = getPathConfig(config, owner, "navigation", isTemplate);
-
-      try
+      PageNavigation navigation = getConfig(config, owner, "navigation", PageNavigation.class);
+      if (navigation == null)
       {
-         String xml = getDefaultConfig(config.getTemplateLocation(), path);
-         if (xml == null)
-         {
-            return;
-         }
-
-         if (isTemplate)
-         {
-            xml = StringUtils.replace(xml, "@owner@", owner);
-         }
-         PageNavigation navigation = fromXML(config.getOwnerType(), owner, xml, PageNavigation.class);
-         PageNavigation currentNavigation = dataStorage_.getPageNavigation(navigation.getOwner());
-         if (currentNavigation == null)
-         {
-            dataStorage_.create(navigation);
-         }
-         else
-         {
-            navigation.merge(currentNavigation);
-            dataStorage_.save(navigation);
-         }
+         return;
       }
-      catch (JiBXException e)
+      PageNavigation currentNavigation = dataStorage_.getPageNavigation(navigation.getOwner());
+      if (currentNavigation == null)
       {
-         log.error(e.getMessage() + " file: " + path, e);
-         throw e;
+         dataStorage_.create(navigation);
       }
+      else
+      {
+         navigation.merge(currentNavigation);
+         dataStorage_.save(navigation);
+      }
    }
 
    public void createPortletPreferences(NewPortalConfig config, String owner) throws Exception
    {
-      boolean isTemplate = (config.getTemplateName() != null && config.getTemplateName().trim().length() > 0);
-      String path = getPathConfig(config, owner, "portlet-preferences", isTemplate);
+      PortletPreferencesSet portletSet = getConfig(config, owner, "portlet-preferences", PortletPreferencesSet.class);
+      if (portletSet == null)
+      {
+         return;
+      }
+      ArrayList<PortletPreferences> list = portletSet.getPortlets();
+      for (PortletPreferences portlet : list)
+      {
+         dataStorage_.save(portlet);
+      }
+   }
 
-      try
+   private final Pattern OWNER_PATTERN = Pattern.compile("@owner@");
+
+   /**
+    * Best effort to load and unmarshall a configuration.
+    *
+    * @param config the config object
+    * @param owner the owner
+    * @param fileName the file name
+    * @param type the type to unmarshall to
+    * @return the xml of the config or null
+    * @throws Exception any exception
+    * @param <T> the generic type to unmarshall to
+    */
+   private <T> T getConfig(NewPortalConfig config, String owner, String fileName, Class<T> type) throws Exception
+   {
+      log.debug("About to load config=" + config + " owner=" + owner + " fileName=" + fileName);
+
+      //
+      String ownerType = config.getOwnerType();
+
+      // Get XML
+      String path = "/" + ownerType + "/" + owner + "/" + fileName + ".xml";
+      String xml = getDefaultConfig(config.getTemplateLocation(), path);
+
+      //
+      if (xml == null)
       {
-         String xml = getDefaultConfig(config.getTemplateLocation(), path);
-         if (xml == null)
+         boolean isTemplate = (config.getTemplateName() != null && config.getTemplateName().trim().length() > 0);
+         if (isTemplate)
          {
-            return;
+            path = "/" + ownerType + "/template/" + config.getTemplateName() + "/" + fileName + ".xml";
+            xml = getDefaultConfig(config.getTemplateLocation(), path);
+            if (xml != null)
+            {
+               xml = OWNER_PATTERN.matcher(xml).replaceAll(owner);
+            }
          }
+      }
 
-         if (isTemplate)
+      //
+      if (xml != null)
+      {
+         boolean ok = false;
+         try
          {
-            xml = StringUtils.replace(xml, "@owner@", owner);
+            final T t = fromXML(config.getOwnerType(), owner, xml, type);
+            ok = true;
+            return t;
          }
-
-         PortletPreferencesSet portletSet = fromXML(config.getOwnerType(), owner, xml, PortletPreferencesSet.class);
-         ArrayList<PortletPreferences> list = portletSet.getPortlets();
-         for (PortletPreferences portlet : list)
+         catch (JiBXException e)
          {
-            dataStorage_.save(portlet);
+            log.error(e.getMessage() + " file: " + path, e);
+            throw e;
          }
+         finally
+         {
+            if (!ok)
+            {
+               log.error("Could not load file: " + path);
+            }
+         }
       }
-      catch (JiBXException e)
-      {
-         log.error(e.getMessage() + " file: " + path, e);
-         throw e;
-      }
+
+      //
+      return null;
    }
 
    private String getDefaultConfig(String location, String path) throws Exception
    {
       String s = location + path;
+      log.debug("Attempt to load file " + s);
       try
       {
-         return IOUtil.getStreamContentAsString(cmanager_.getInputStream(location + path));
+         String content = IOUtil.getStreamContentAsString(cmanager_.getInputStream(s));
+         log.debug("Loaded file from path " + s + " with content " + content);
+         return content;
       }
       catch (Exception ignore)
       {
@@ -487,22 +490,6 @@
       }
    }
 
-   private String getPathConfig(NewPortalConfig portalConfig, String owner, String fileName, boolean isTemplate)
-   {
-      String path = "";
-      if (isTemplate)
-      {
-         String ownerType = portalConfig.getOwnerType();
-         path = "/" + ownerType + "/template/" + portalConfig.getTemplateName() + "/" + fileName + ".xml";
-      }
-      else
-      {
-         String ownerType = portalConfig.getOwnerType();
-         path = "/" + ownerType + "/" + owner + "/" + fileName + ".xml";
-      }
-      return path;
-   }
-
    public Page createPageFromTemplate(String ownerType, String owner, String temp) throws Exception
    {
       String path = pageTemplatesLocation_ + "/" + temp + "/page.xml";

Added: portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/GlobalKey.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/GlobalKey.java	                        (rev 0)
+++ portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/GlobalKey.java	2010-03-01 23:13:03 UTC (rev 1919)
@@ -0,0 +1,97 @@
+/*
+ * 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.portal.pom.config;
+
+import org.exoplatform.services.jcr.RepositoryService;
+import org.exoplatform.services.jcr.core.ManageableRepository;
+
+import javax.jcr.RepositoryException;
+import java.io.Serializable;
+import java.lang.reflect.UndeclaredThrowableException;
+
+/**
+ * A global key wrapping a local key including the current repository id.
+ *
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class GlobalKey implements Serializable
+{
+
+   public static GlobalKey wrap(RepositoryService repoService, Serializable localKey)
+   {
+      try
+      {
+         ManageableRepository repo = repoService.getCurrentRepository();
+         return new GlobalKey(repo.getConfiguration().getName(), localKey);
+      }
+      catch (RepositoryException e)
+      {
+         throw new UndeclaredThrowableException(e);
+      }
+   }
+
+   /** . */
+   private final String repositoryId;
+
+   /** . */
+   private final Serializable localKey;
+
+   public GlobalKey(String repositoryId, Serializable localKey)
+   {
+      if (repositoryId == null)
+      {
+         throw new NullPointerException();
+      }
+      if (localKey == null)
+      {
+         throw new NullPointerException();
+      }
+      this.repositoryId = repositoryId;
+      this.localKey = localKey;
+   }
+
+   @Override
+   public int hashCode()
+   {
+      return repositoryId.hashCode() ^ localKey.hashCode();
+   }
+
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (obj == this)
+      {
+         return true;
+      }
+      if (obj instanceof GlobalKey)
+      {
+         GlobalKey that = (GlobalKey)obj;
+         return repositoryId.equals(that.repositoryId) && localKey.equals(that.localKey);
+      }
+      return false;
+   }
+
+   @Override
+   public String toString()
+   {
+      return "GlobalKey[repositoryId=" + repositoryId + ",localKey=" + localKey + "]";
+   }
+}

Modified: portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSession.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSession.java	2010-03-01 22:18:46 UTC (rev 1918)
+++ portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSession.java	2010-03-01 23:13:03 UTC (rev 1919)
@@ -117,7 +117,7 @@
       {
          throw new IllegalStateException("Cannot read object in shared cache from a modified session");
       }
-      return mgr.cache.get(key);
+      return mgr.cacheGet(key);
    }
 
    public void putInCache(Serializable key, Object value)
@@ -126,7 +126,7 @@
       {
          throw new IllegalStateException("Cannot put object in shared cache from a modified session");
       }
-      mgr.cache.put(key, value);
+      mgr.cachePut(key, value);
    }
 
    public void scheduleForEviction(Serializable key)
@@ -362,7 +362,7 @@
          {
             for (Serializable key : staleKeys)
             {
-               mgr.cache.remove(key);
+               mgr.cacheRemove(key);
             }
          }
       }

Modified: portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSessionManager.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSessionManager.java	2010-03-01 22:18:46 UTC (rev 1918)
+++ portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSessionManager.java	2010-03-01 23:13:03 UTC (rev 1919)
@@ -25,6 +25,7 @@
 import org.exoplatform.portal.pom.config.cache.DataCache;
 import org.exoplatform.services.cache.CacheService;
 import org.exoplatform.services.cache.ExoCache;
+import org.exoplatform.services.jcr.RepositoryService;
 import org.gatein.mop.core.api.MOPService;
 import org.picocontainer.Startable;
 
@@ -42,7 +43,7 @@
    private MOPService pomService;
 
    /** . */
-   final ExoCache<Serializable, Object> cache;
+   private final ExoCache<GlobalKey, Object> cache;
 
    /** . */
    final ChromatticManager manager;
@@ -53,15 +54,34 @@
    /** . */
    private final TaskExecutionDecorator executor;
 
-   public POMSessionManager(ChromatticManager manager, CacheService cacheService)
+   /** . */
+   private final RepositoryService repositoryService;
+
+   public POMSessionManager(RepositoryService repositoryService, ChromatticManager manager, CacheService cacheService)
    {
       //
+      this.repositoryService = repositoryService;
       this.manager = manager;
       this.cache = cacheService.getCacheInstance(POMSessionManager.class.getSimpleName());
       this.pomService = null;
       this.executor = new DataCache(new ExecutorDispatcher());
    }
 
+   public void cachePut(Serializable key, Object value)
+   {
+      cache.put(GlobalKey.wrap(repositoryService, key), value);
+   }
+
+   public Object cacheGet(Serializable key)
+   {
+      return cache.get(GlobalKey.wrap(repositoryService, key));
+   }
+
+   public void cacheRemove(Serializable key)
+   {
+      cache.remove(GlobalKey.wrap(repositoryService, key));
+   }
+
    public void start()
    {
       try

Modified: portal/trunk/component/portal/src/test/java/conf/exo.portal.component.portal-configuration1.xml
===================================================================
--- portal/trunk/component/portal/src/test/java/conf/exo.portal.component.portal-configuration1.xml	2010-03-01 22:18:46 UTC (rev 1918)
+++ portal/trunk/component/portal/src/test/java/conf/exo.portal.component.portal-configuration1.xml	2010-03-01 23:13:03 UTC (rev 1919)
@@ -34,8 +34,8 @@
         <description>The default cache configuration</description>
         <object type="org.exoplatform.services.cache.ExoCacheConfig">
           <field name="name"><string>default</string></field>
-          <field name="maxSize"><int>300</int></field>
-          <field name="liveTime"><long>6000</long></field>
+          <field name="maxSize"><int>30000</int></field>
+          <field name="liveTime"><long>60000</long></field>
           <field name="distributed"><boolean>false</boolean></field>
           <field name="implementation"><string>org.exoplatform.services.cache.concurrent.ConcurrentFIFOExoCache</string></field>
         </object>

Modified: portal/trunk/component/test/core/src/main/java/org/exoplatform/component/test/AbstractGateInTest.java
===================================================================
--- portal/trunk/component/test/core/src/main/java/org/exoplatform/component/test/AbstractGateInTest.java	2010-03-01 22:18:46 UTC (rev 1918)
+++ portal/trunk/component/test/core/src/main/java/org/exoplatform/component/test/AbstractGateInTest.java	2010-03-01 23:13:03 UTC (rev 1919)
@@ -74,14 +74,7 @@
          if (entry.getKey() instanceof String)
          {
             String key = (String)entry.getKey();
-            if (key.startsWith("gatein."))
-            {
-               log.info(key + "=" + entry.getValue());
-            }
-            else
-            {
-               log.debug(key + "=" + entry.getValue());
-            }
+            log.debug(key + "=" + entry.getValue());
          }
       }
 

Modified: portal/trunk/component/test/core/src/main/resources/conf/root-configuration.xml
===================================================================
--- portal/trunk/component/test/core/src/main/resources/conf/root-configuration.xml	2010-03-01 22:18:46 UTC (rev 1918)
+++ portal/trunk/component/test/core/src/main/resources/conf/root-configuration.xml	2010-03-01 23:13:03 UTC (rev 1919)
@@ -28,17 +28,4 @@
     <type>org.exoplatform.container.definition.PortalContainerConfig</type>
   </component>
 
-<!--
-  <component>
-    <key>org.exoplatform.container.PropertyConfigurator</key>
-    <type>org.exoplatform.container.PropertyConfigurator</type>
-    <init-params>
-      <value-param>
-        <name>properties.url</name>
-        <value>jar:/conf/test-configuration.properties</value>
-      </value-param>
-    </init-params>
-  </component>
--->
-
 </configuration>



More information about the gatein-commits mailing list