Author: taylor
Date: Mon Feb 12 16:29:19 2007
New Revision: 506764

URL: http://svn.apache.org/viewvc?view=rev&rev=506764
Log:
https://issues.apache.org/jira/browse/JS2-654
enhance components to use JetspeedCache for distributed environments
initial work: getting the prefs component hooked into the Jetspeed Cache,
which can then be configured via Spring
Will continue implementing this issue throughout this week

Modified:
    
portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/cache/impl/EhCacheImpl.java
    
portals/jetspeed-2/trunk/components/prefs/src/java/org/apache/jetspeed/prefs/impl/PersistenceBrokerPreferencesProvider.java
    
portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedSerializerApplication.java
    
portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedSerializerImpl.java
    portals/jetspeed-2/trunk/maven-plugin/plugin-with-DDLUTILS.jelly
    portals/jetspeed-2/trunk/maven-plugin/plugin.jelly
    portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/cache.xml
    portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/prefs.xml
    portals/jetspeed-2/trunk/src/webapp/WEB-INF/conf/ehcache.xml

Modified: 
portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/cache/impl/EhCacheImpl.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/cache/impl/EhCacheImpl.java?view=diff&rev=506764&r1=506763&r2=506764
==============================================================================
--- 
portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/cache/impl/EhCacheImpl.java
 (original)
+++ 
portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/cache/impl/EhCacheImpl.java
 Mon Feb 12 16:29:19 2007
@@ -96,10 +96,9 @@
     {
         CacheElement element = this.get(key);
         boolean removed = false;
-        if (element != null)
-        {
-            removed = ehcache.remove(key);
-        }
+        if (element == null)
+            return false;
+        removed = ehcache.remove(key);
         EhCacheElementImpl impl = (EhCacheElementImpl)element;
         Element ehl = impl.getImplElement();
         String userKey = impl.getUserKey();

Modified: 
portals/jetspeed-2/trunk/components/prefs/src/java/org/apache/jetspeed/prefs/impl/PersistenceBrokerPreferencesProvider.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/prefs/src/java/org/apache/jetspeed/prefs/impl/PersistenceBrokerPreferencesProvider.java?view=diff&rev=506764&r1=506763&r2=506764
==============================================================================
--- 
portals/jetspeed-2/trunk/components/prefs/src/java/org/apache/jetspeed/prefs/impl/PersistenceBrokerPreferencesProvider.java
 (original)
+++ 
portals/jetspeed-2/trunk/components/prefs/src/java/org/apache/jetspeed/prefs/impl/PersistenceBrokerPreferencesProvider.java
 Mon Feb 12 16:29:19 2007
@@ -17,10 +17,9 @@
 
 import java.io.Serializable;
 import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
 
+import org.apache.jetspeed.cache.CacheElement;
+import org.apache.jetspeed.cache.JetspeedCache;
 import org.apache.jetspeed.components.dao.InitablePersistenceBrokerDaoSupport;
 import org.apache.jetspeed.prefs.FailedToCreateNodeException;
 import org.apache.jetspeed.prefs.NodeAlreadyExistsException;
@@ -61,6 +60,7 @@
 
         public NodeCache(Node node)
         {
+  // System.out.println(this.getClass().getName() + "-" + "NodeCache (node)" + 
node.getFullPath());
             this.node = node;
             this.fullpath = node.getFullPath();
             this.type = node.getNodeType();
@@ -68,48 +68,57 @@
 
         public NodeCache(String fullpath, int type)
         {
-            this.fullpath = fullpath;
+            // System.out.println(this.getClass().getName() + "-" + "NodeCache 
- fullpath=" + fullpath);
+                        this.fullpath = fullpath;
             this.type = type;
         }
 
         public boolean isChildrenLoaded()
         {
+            // System.out.println(this.getClass().getName() + "-" + 
"isChildrenLoaded");
             return childrenLoaded;
         }
 
         public void setChildrenLoaded(boolean childrenLoaded)
         {
+            // System.out.println(this.getClass().getName() + "-" + 
"setChildrenLoaded");
             this.childrenLoaded = childrenLoaded;
         }
 
         public String getFullpath()
         {
-            return fullpath;
+            // System.out.println(this.getClass().getName() + "-" + 
"getFullpath=" + fullpath);
+           return fullpath;
         }
 
         public Node getNode()
         {
+            // System.out.println(this.getClass().getName() + "-" + "getNode=" 
+ node.getFullPath());
             return node;
         }
 
         public void setNode(Node node)
         {
+            // System.out.println(this.getClass().getName() + "-" + 
"setFullpath=" + node.getFullPath());
             this.node = node;
         }
 
         public int getType()
         {
+            // System.out.println(this.getClass().getName() + "-" + "getType=" 
);
             return type;
         }
 
         public Collection getChildren()
         {
+            // System.out.println(this.getClass().getName() + "-" + 
"getCHildren=" );
             return children;
         }
 
         public void setChildren(Collection children)
         {
-            this.children = children;
+            // System.out.println(this.getClass().getName() + "-" + 
"setChildren=" );
+                       this.children = children;
         }
 
         public boolean equals(Object obj)
@@ -126,10 +135,16 @@
         {
             return fullpath.hashCode() + type;
         }
+        
+        public String getCacheKey()
+        {
+            return fullpath +  "-" +  type;
+        }
     }
 
-    private Map nodeMap = Collections.synchronizedMap(new HashMap());
-
+    private JetspeedCache preferenceCache;
+    
+    
     /**
      * @param repository
      *            Location of repository mapping file. Must be available 
within the classpath.
@@ -148,12 +163,47 @@
     }
 
     /**
+     * @param repository
+     *            Location of repository mapping file. Must be available 
within the classpath.
+     * @param prefsFactoryImpl
+     *            <code>java.util.prefs.PreferencesFactory</code> 
implementation to use.
+     * @param enablePropertyManager
+     *            Whether or not we chould be suing the property manager.
+     * @throws ClassNotFoundException
+     *             if the <code>prefsFactoryImpl</code> argument does not 
reperesent a Class that exists in the
+     *             current classPath.
+     */
+    public PersistenceBrokerPreferencesProvider(String repositoryPath, 
JetspeedCache preferenceCache)
+            throws ClassNotFoundException
+    {
+        super(repositoryPath);
+        this.preferenceCache = preferenceCache;
+    }
+
+    protected void addToCache(NodeCache content)
+    {
+        CacheElement cachedElement = 
preferenceCache.createElement(content.getCacheKey(), content);
+        
cachedElement.setTimeToIdleSeconds(preferenceCache.getTimeToIdleSeconds());
+        
cachedElement.setTimeToLiveSeconds(preferenceCache.getTimeToLiveSeconds());
+        preferenceCache.put(cachedElement);        
+    }    
+  
+    private NodeCache getNode(String cacheKey)
+    {
+        CacheElement cachedElement = preferenceCache.get(cacheKey);
+        if (cachedElement != null)
+         return (NodeCache)cachedElement.getContent();  
+        return null;
+    }
+    
+    /**
      * @see 
org.apache.jetspeed.prefs.PreferencesProvider#getNode(java.lang.String, int)
      */
     public Node getNode(String fullPath, int nodeType) throws 
NodeDoesNotExistException
     {
+        
         NodeCache key = new NodeCache(fullPath, nodeType);
-        NodeCache hit = (NodeCache) nodeMap.get(key);
+        NodeCache hit = getNode(key.getCacheKey());
         if (hit != null)
         {
             return hit.getNode();
@@ -167,8 +217,7 @@
         Node nodeObj = (Node) 
getPersistenceBrokerTemplate().getObjectByQuery(query);
         if (null != nodeObj)
         {
-            key.setNode(nodeObj);
-            nodeMap.put(key, key);
+            addToCache(new NodeCache(nodeObj));
             return nodeObj;
         }
         else
@@ -216,8 +265,7 @@
             try
             {
                 getPersistenceBrokerTemplate().store(nodeObj);
-                NodeCache key = new NodeCache(nodeObj);
-                nodeMap.put(key, key);
+                addToCache(new NodeCache(nodeObj));
                 return nodeObj;
             }
             catch (Exception e)
@@ -235,11 +283,12 @@
     public Collection getChildren(Node parentNode)
     {
         NodeCache key = new NodeCache(parentNode);
-        NodeCache hit = (NodeCache) nodeMap.get(key);
+        NodeCache hit = getNode(key.getCacheKey());
         if (hit == null)
         {
+            
             key.setNode(parentNode);
-            nodeMap.put(key, key);
+            addToCache(key);
             hit = key;
         }
         if (hit.isChildrenLoaded())
@@ -263,7 +312,7 @@
     public void storeNode(Node node)
     {
         NodeCache key = new NodeCache(node);
-        nodeMap.remove(key);
+        preferenceCache.remove(key.getCacheKey()); // not sure we should 
actually do that, could also just update the node
         getPersistenceBrokerTemplate().store(node);
     }
 
@@ -273,14 +322,14 @@
     public void removeNode(Node parentNode, Node node)
     {
         NodeCache key = new NodeCache(node);
-        nodeMap.remove(key);
+        preferenceCache.remove(key.getCacheKey());
         if ( parentNode != null )
         {
             key = new NodeCache(parentNode);
-            key = (NodeCache)nodeMap.get(key);
-            if ( key != null && key.isChildrenLoaded() )
+            NodeCache hit = getNode(key.getCacheKey());
+            if ( hit != null && hit.isChildrenLoaded() )
             {
-                key.getChildren().remove(node);
+                hit.getChildren().remove(node);
             }
         }
         getPersistenceBrokerTemplate().delete(node);        

Modified: 
portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedSerializerApplication.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedSerializerApplication.java?view=diff&rev=506764&r1=506763&r2=506764
==============================================================================
--- 
portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedSerializerApplication.java
 (original)
+++ 
portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedSerializerApplication.java
 Mon Feb 12 16:29:19 2007
@@ -349,6 +349,7 @@
 /**
  * set the application root
  */
+        System.out.println("APP ROOT is " + applicationPath);
                System.setProperty("applicationRoot",applicationPath);
                System.setProperty("portal.name","jetspped");
         SpringJNDIStarter starter = new 
SpringJNDIStarter(context,applicationPath,getTokens(bootConfigFiles),getTokens(configFiles));

Modified: 
portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedSerializerImpl.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedSerializerImpl.java?view=diff&rev=506764&r1=506763&r2=506764
==============================================================================
--- 
portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedSerializerImpl.java
 (original)
+++ 
portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedSerializerImpl.java
 Mon Feb 12 16:29:19 2007
@@ -704,7 +704,8 @@
                                }                                       
                } catch (Exception e)
                {
-                   throw new SerializerException(
+                   e.printStackTrace();
+                throw new SerializerException(
                            SerializerException.CREATE_OBJECT_FAILED
                                    .create(new String[]
                                    { "User", e.getMessage()}));

Modified: portals/jetspeed-2/trunk/maven-plugin/plugin-with-DDLUTILS.jelly
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/maven-plugin/plugin-with-DDLUTILS.jelly?view=diff&rev=506764&r1=506763&r2=506764
==============================================================================
--- portals/jetspeed-2/trunk/maven-plugin/plugin-with-DDLUTILS.jelly (original)
+++ portals/jetspeed-2/trunk/maven-plugin/plugin-with-DDLUTILS.jelly Mon Feb 12 
16:29:19 2007
@@ -947,7 +947,7 @@
                                <pathelement 
path="${org.apache.jetspeed.plugin.root}"/>
                            <pathelement 
path="${org.apache.jetspeed.production.jdbc.drivers.path}"/>                    
      
                          </classpath>
-                           <arg line="-I ${DATAFILE} -b 
${temp.assembly.dir}/boot/ -c ${temp.assembly.dir}/ -dc 
${org.apache.jetspeed.database.driver} -ds ${org.apache.jetspeed.database.url} 
-du ${org.apache.jetspeed.database.user} -dp 
${org.apache.jetspeed.database.password}"/>  
+                           <arg line="-I ${DATAFILE} -a 
./target/${org.apache.jetspeed.portal.artifactId} -b ${temp.assembly.dir}/boot/ 
-c ${temp.assembly.dir}/ -dc ${org.apache.jetspeed.database.driver} -ds 
${org.apache.jetspeed.database.url} -du ${org.apache.jetspeed.database.user} 
-dp ${org.apache.jetspeed.database.password}"/>  
                        </java>
                    </goal>
 

Modified: portals/jetspeed-2/trunk/maven-plugin/plugin.jelly
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/maven-plugin/plugin.jelly?view=diff&rev=506764&r1=506763&r2=506764
==============================================================================
--- portals/jetspeed-2/trunk/maven-plugin/plugin.jelly (original)
+++ portals/jetspeed-2/trunk/maven-plugin/plugin.jelly Mon Feb 12 16:29:19 2007
@@ -1103,7 +1103,8 @@
                <include name="prefs.xml"/>           
                <include name="profiler.xml"/>      
                <include name="registry.xml"/>       
-               <include name="transaction.xml"/>           
+               <include name="transaction.xml"/>       
+               <include name="cache.xml"/>    
       </fileset>
      </copy>
 
@@ -1130,7 +1131,7 @@
         <pathelement path="${org.apache.jetspeed.plugin.root}"/>
         <pathelement 
path="${org.apache.jetspeed.production.jdbc.drivers.path}"/>                    
      
       </classpath>
-        <arg line="-I &quot;${DATAFILE}&quot; -b ${temp.assembly.dir}/boot/ -c 
${temp.assembly.dir}/ -dc ${org.apache.jetspeed.database.driver} -ds 
${org.apache.jetspeed.database.url} -du ${org.apache.jetspeed.database.user} 
-dp ${org.apache.jetspeed.database.password}"/>  
+        <arg line="-I &quot;${DATAFILE}&quot; -a 
./target/${org.apache.jetspeed.portal.artifactId} -b ${temp.assembly.dir}/boot/ 
-c ${temp.assembly.dir}/ -dc ${org.apache.jetspeed.database.driver} -ds 
${org.apache.jetspeed.database.url} -du ${org.apache.jetspeed.database.user} 
-dp ${org.apache.jetspeed.database.password}"/>  
     </java>
     </goal>
 

Modified: portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/cache.xml
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/cache.xml?view=diff&rev=506764&r1=506763&r2=506764
==============================================================================
--- portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/cache.xml (original)
+++ portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/cache.xml Mon Feb 12 
16:29:19 2007
@@ -18,7 +18,7 @@
 <beans>
 
 <bean id="cacheManager" 
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
-        <property name="configLocation" value="/WEB-INF/conf/ehcache.xml"/>
+        <property name="configLocation" 
value="${applicationRoot}/WEB-INF/conf/ehcache.xml"/>
 </bean>
 
 <!-- Factory bean used to instantiate a EHCache with the specified name (and 
corresponding
@@ -35,5 +35,19 @@
        <ref bean="ehPortletContentCache"/>
     </constructor-arg>       
 </bean>
+
+<bean id="ehPreferencesCache" 
class="org.springframework.cache.ehcache.EhCacheFactoryBean">
+<property name="cacheManager">
+<ref local="cacheManager"/>
+</property>
+        <property name="cacheName" value="preferencesCache"/>
+</bean>
+
+<bean id="preferencesCache" class="org.apache.jetspeed.cache.impl.EhCacheImpl">
+    <constructor-arg>
+       <ref bean="ehPreferencesCache"/>
+    </constructor-arg>       
+</bean>
+
 
 </beans>

Modified: portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/prefs.xml
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/prefs.xml?view=diff&rev=506764&r1=506763&r2=506764
==============================================================================
--- portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/prefs.xml (original)
+++ portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/prefs.xml Mon Feb 12 
16:29:19 2007
@@ -22,6 +22,9 @@
         <constructor-arg index="0">
             <value>JETSPEED-INF/ojb/prefs_repository.xml</value>
         </constructor-arg>
+        <constructor-arg index="1">
+            <ref bean="preferencesCache" />
+        </constructor-arg>
     </bean>
 
     <bean id="org.apache.jetspeed.prefs.PreferencesProvider" 
parent="baseTransactionProxy" name="prefsProvider">

Modified: portals/jetspeed-2/trunk/src/webapp/WEB-INF/conf/ehcache.xml
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/src/webapp/WEB-INF/conf/ehcache.xml?view=diff&rev=506764&r1=506763&r2=506764
==============================================================================
--- portals/jetspeed-2/trunk/src/webapp/WEB-INF/conf/ehcache.xml (original)
+++ portals/jetspeed-2/trunk/src/webapp/WEB-INF/conf/ehcache.xml Mon Feb 12 
16:29:19 2007
@@ -329,6 +329,16 @@
            memoryStoreEvictionPolicy="LFU"
             />
 
+   <cache name="preferencesCache"
+           maxElementsInMemory="10000"
+           maxElementsOnDisk="1000"
+           eternal="false"
+           overflowToDisk="false"
+           timeToIdleSeconds="28800"
+           timeToLiveSeconds="28800"
+           memoryStoreEvictionPolicy="LFU"
+            />
+
     <!--
     Sample distributed cache named sampleDistributedCache1.
     This cache replicates using defaults.



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to