portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwat...@apache.org
Subject svn commit: r724571 [1/3] - in /portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade: ./ components/jetspeed-cm/ components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/ components/jetspeed-page-manager/ components/jetspeed-page-man...
Date Tue, 09 Dec 2008 01:50:18 GMT
Author: rwatler
Date: Mon Dec  8 17:50:16 2008
New Revision: 724571

URL: http://svn.apache.org/viewvc?rev=724571&view=rev
Log:
Jetspeed/EhCache implementation for Database Page Manager

- refactored DBPM cache to use JetspeedCache oid/path instances
- supported distributed Jetspeed/EhCache operation for DBPM cache
- added global distributed cache configuration properties to jetspeed.properties
- added distributed-ehcache.xml configuration file
- new EhCacheConfigResource bean used to select distributed or standalone caches
- minor bug fixes for Jetspeed/EhCache wrappers
- added isDistributed() API to JetspeedCache and PageManager interfaces for runtime detect
- new distributed cache DBPM test that starts multiple DBPM server cache coherency on capable systems


Added:
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheConfigResource.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManagerCacheObject.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/cache/
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/cache/DatabasePageManagerServer.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/cache/TestDatabasePageManagerCache.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/resources/database-page-manager-base.xml
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/resources/distributed-ehcache.xml
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/resources/ehcache.xml
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/resources/log4j-stdout.properties
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/db-ojb/distributed-ehcache.xml
Removed:
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/resources/tx-page-manager.xml
Modified:
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/pom.xml
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheDistributedImpl.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheImpl.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/pom.xml
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/AbstractPageManager.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManager.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManagerCache.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/util/interceptors/PageManagerInterceptor.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestDatabasePageManager.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestSecureDatabasePageManager.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestSecurePermissionsDatabasePageManager.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestTransactions.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/resources/database-page-manager.xml
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/resources/interceptors.xml
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/resources/secure-database-page-manager.xml
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/resources/secure-permissions-database-page-manager.xml
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-portal-site/pom.xml
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-portal-site/src/test/resources/cache-test.xml
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-portal/pom.xml
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-portal/src/test/assembly/cache-test.xml
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-profiler/src/test/resources/cache-test.xml
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/test/resources/cache-test.xml
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-security/src/test/resources/cache-test.xml
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/etc/import/assembly/import-page-manager.xml
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-api/src/main/java/org/apache/jetspeed/cache/JetspeedCache.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-api/src/main/java/org/apache/jetspeed/page/PageManager.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-installer/etc/database/import/assembly/import-page-manager.xml
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/assembly/cache.xml
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/assembly/page-manager.xml
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/conf/jetspeed/jetspeed.properties
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/db-ojb/ehcache.xml
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/pom.xml

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/pom.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/pom.xml?rev=724571&r1=724570&r2=724571&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/pom.xml (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/pom.xml Mon Dec  8 17:50:16 2008
@@ -132,7 +132,7 @@
             <scope>runtime</scope>
         </dependency>
         <dependency>
-        	<groupId>ehcache</groupId>
+        	<groupId>net.sf.ehcache</groupId>
         	<artifactId>ehcache</artifactId>
         </dependency>
          <dependency>

Added: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheConfigResource.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheConfigResource.java?rev=724571&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheConfigResource.java (added)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheConfigResource.java Mon Dec  8 17:50:16 2008
@@ -0,0 +1,296 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.cache.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.springframework.core.io.AbstractResource;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+import org.springframework.beans.factory.InitializingBean;
+
+/**
+ * EhCacheConfigResource
+ * 
+ * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
+ * @version $Id: $
+ */
+public class EhCacheConfigResource extends AbstractResource implements InitializingBean
+{
+    // Constants
+    
+    public static final String EHCACHE_CONFIG_RESOURCE_PROP_NAME = "org.apache.jetspeed.ehcache.config.resource";
+    public static final String EHCACHE_CONFIG_RESOURCE_DEFAULT = "ehcache.xml";
+    public static final String EHCACHE_CONFIG_RESOURCE_DISTRIBUTED_CACHE = "distributed-ehcache.xml";
+
+    public static final String EHCACHE_GROUP_ADDRESS_PROP_NAME = "org.apache.jetspeed.ehcache.group.address";
+    public static final String EHCACHE_GROUP_ADDRESS_DEFAULT = "230.0.0.1";
+    public static final String EHCACHE_GROUP_PORT_PROP_NAME = "org.apache.jetspeed.ehcache.group.port";
+    public static final String EHCACHE_GROUP_PORT_DEFAULT = "4446";
+    public static final String EHCACHE_GROUP_TTL_PROP_NAME = "org.apache.jetspeed.ehcache.group.ttl";
+    public static final String EHCACHE_GROUP_TTL_DEFAULT = "1";
+    public static final String EHCACHE_GROUP_TTL_TEST_DEFAULT = "0";
+    public static final String EHCACHE_HOSTNAME_PROP_NAME = "org.apache.jetspeed.ehcache.hostname";
+    public static final String EHCACHE_HOSTNAME_DEFAULT = "";
+    public static final String EHCACHE_HOSTNAME_TEST_DEFAULT = "localhost";
+    public static final String EHCACHE_PORT_PROP_NAME = "org.apache.jetspeed.ehcache.port";
+    public static final String EHCACHE_PORT_DEFAULT = "40001";
+
+    public static final String EHCACHE_PAGE_MANAGER_MAX_ELEMENTS_LEGACY_PROP_NAME = "db.page.manager.cache.size";
+    public static final String EHCACHE_PAGE_MANAGER_MAX_ELEMENTS_PROP_NAME = "org.apache.jetspeed.ehcache.pagemanager.maxelements";
+    public static final String EHCACHE_PAGE_MANAGER_MAX_ELEMENTS_DEFAULT = "128";
+    public static final String EHCACHE_PAGE_MANAGER_ELEMENT_TTL_LEGACY_PROP_NAME = "db.page.manager.cache.expire";
+    public static final String EHCACHE_PAGE_MANAGER_ELEMENT_TTL_PROP_NAME = "org.apache.jetspeed.ehcache.pagemanager.element.ttl";
+    public static final String EHCACHE_PAGE_MANAGER_ELEMENT_TTL_DEFAULT = "150";
+    public static final String EHCACHE_PAGE_MANAGER_MAX_FILES_LEGACY_PROP_NAME = "page.file.cache.size";
+    public static final String EHCACHE_PAGE_MANAGER_MAX_FILES_PROP_NAME = "org.apache.jetspeed.ehcache.pagemanager.maxfiles";
+    public static final String EHCACHE_PAGE_MANAGER_MAX_FILES_DEFAULT = "1000";
+
+    // Singleton implementation
+    
+    private static EhCacheConfigResource instance;
+    
+    public static EhCacheConfigResource getInstance(final String defaultConfigResource, final boolean test)
+    {
+        // construct and return a default instance
+        if ( instance == null)
+        {
+            instance = new EhCacheConfigResource();
+            instance.setDefaultConfigResource(defaultConfigResource);
+            instance.setTest(test);
+            instance.afterPropertiesSet();
+        }
+        return instance;
+    }
+    
+    // Members
+
+    private String defaultConfigResource;
+    private boolean test;
+    private String defaultGroupAddress;
+    private String defaultGroupPort;
+    private String defaultGroupTTL;
+    private String defaultHostname;
+    private String defaultPort;
+    private String defaultPageManagerMaxElements;
+    private String defaultPageManagerElementTTL;
+    private String defaultPageManagerMaxFiles;
+    
+    private ClassPathResource classPathResource;
+    
+    // InitializingBean implementation
+    
+    /* (non-Javadoc)
+     * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
+     */
+    public void afterPropertiesSet()
+    {
+        // set system properties used in global cache configuration
+        if (System.getProperty(EHCACHE_CONFIG_RESOURCE_PROP_NAME) == null)
+        {
+            System.setProperty(EHCACHE_CONFIG_RESOURCE_PROP_NAME, ((defaultConfigResource != null) ? defaultConfigResource : EHCACHE_CONFIG_RESOURCE_DEFAULT));
+        }
+        if (System.getProperty(EHCACHE_GROUP_ADDRESS_PROP_NAME) == null)
+        {
+            System.setProperty(EHCACHE_GROUP_ADDRESS_PROP_NAME, ((defaultGroupAddress != null) ? defaultGroupAddress : EHCACHE_GROUP_ADDRESS_DEFAULT));
+        }
+        if (System.getProperty(EHCACHE_GROUP_PORT_PROP_NAME) == null)
+        {
+            System.setProperty(EHCACHE_GROUP_PORT_PROP_NAME, ((defaultGroupPort != null) ? defaultGroupPort : EHCACHE_GROUP_PORT_DEFAULT));
+        }
+        if (System.getProperty(EHCACHE_GROUP_TTL_PROP_NAME) == null)
+        {
+            System.setProperty(EHCACHE_GROUP_TTL_PROP_NAME, ((defaultGroupTTL != null) ? defaultGroupTTL : (test ? EHCACHE_GROUP_TTL_TEST_DEFAULT : EHCACHE_GROUP_TTL_DEFAULT)));
+        }
+        if (System.getProperty(EHCACHE_HOSTNAME_PROP_NAME) == null)
+        {
+            System.setProperty(EHCACHE_HOSTNAME_PROP_NAME, ((defaultHostname != null) ? defaultHostname : (test ? EHCACHE_HOSTNAME_TEST_DEFAULT : EHCACHE_HOSTNAME_DEFAULT)));
+        }
+        if (System.getProperty(EHCACHE_PORT_PROP_NAME) == null)
+        {
+            System.setProperty(EHCACHE_PORT_PROP_NAME, ((defaultPort != null) ? defaultPort : EHCACHE_PORT_DEFAULT));
+        }
+        
+        // set system properties used in page manager cache configuration
+        if (System.getProperty(EHCACHE_PAGE_MANAGER_MAX_ELEMENTS_PROP_NAME) == null)
+        {
+            String pageManagerMaxElements = ((defaultPageManagerMaxElements != null) ? defaultPageManagerMaxElements : System.getProperty(EHCACHE_PAGE_MANAGER_MAX_ELEMENTS_LEGACY_PROP_NAME, EHCACHE_PAGE_MANAGER_MAX_ELEMENTS_DEFAULT));
+            if ((pageManagerMaxElements != null) && (Integer.parseInt(pageManagerMaxElements) < 0))
+            {
+                pageManagerMaxElements = EHCACHE_PAGE_MANAGER_MAX_ELEMENTS_DEFAULT;
+            }
+            System.setProperty(EHCACHE_PAGE_MANAGER_MAX_ELEMENTS_PROP_NAME, pageManagerMaxElements);
+        }
+        if (System.getProperty(EHCACHE_PAGE_MANAGER_ELEMENT_TTL_PROP_NAME) == null)
+        {
+            String pageManagerElementTTL = ((defaultPageManagerElementTTL != null) ? defaultPageManagerElementTTL : System.getProperty(EHCACHE_PAGE_MANAGER_ELEMENT_TTL_LEGACY_PROP_NAME, EHCACHE_PAGE_MANAGER_ELEMENT_TTL_DEFAULT));
+            if ((pageManagerElementTTL != null) && (Integer.parseInt(pageManagerElementTTL) < 0))
+            {
+                pageManagerElementTTL = EHCACHE_PAGE_MANAGER_ELEMENT_TTL_DEFAULT;
+            }
+            System.setProperty(EHCACHE_PAGE_MANAGER_ELEMENT_TTL_PROP_NAME, pageManagerElementTTL);
+        }
+        if (System.getProperty(EHCACHE_PAGE_MANAGER_MAX_FILES_PROP_NAME) == null)
+        {
+            System.setProperty(EHCACHE_PAGE_MANAGER_MAX_FILES_PROP_NAME, ((defaultPageManagerMaxFiles != null) ? defaultPageManagerMaxFiles : System.getProperty(EHCACHE_PAGE_MANAGER_MAX_FILES_LEGACY_PROP_NAME, EHCACHE_PAGE_MANAGER_MAX_FILES_DEFAULT)));
+        }
+
+        // setup delegate ClassPathResource
+        classPathResource = new ClassPathResource(System.getProperty(EHCACHE_CONFIG_RESOURCE_PROP_NAME));
+    }
+    
+    // AbstractResource implementation
+
+    /* (non-Javadoc)
+     * @see org.springframework.core.io.AbstractResource#createRelative(java.lang.String)
+     */
+    public Resource createRelative(String relativePath) throws IOException
+    {
+        // delegate to ClassPathResource
+        return classPathResource.createRelative(relativePath);
+    }
+
+    /* (non-Javadoc)
+     * @see org.springframework.core.io.AbstractResource#getFile()
+     */
+    public File getFile() throws IOException
+    {
+        // delegate to ClassPathResource
+        return classPathResource.getFile();
+    }
+
+    /* (non-Javadoc)
+     * @see org.springframework.core.io.AbstractResource#getFilename()
+     */
+    public String getFilename() throws IllegalStateException
+    {
+        // delegate to ClassPathResource
+        return classPathResource.getFilename();
+    }
+
+    /* (non-Javadoc)
+     * @see org.springframework.core.io.AbstractResource#getURL()
+     */
+    public URL getURL() throws IOException
+    {
+        // delegate to ClassPathResource
+        return classPathResource.getURL();
+    }
+
+    /* (non-Javadoc)
+     * @see org.springframework.core.io.Resource#getDescription()
+     */
+    public String getDescription()
+    {
+        // delegate to ClassPathResource
+        return classPathResource.getDescription();
+    }
+
+    /* (non-Javadoc)
+     * @see org.springframework.core.io.InputStreamSource#getInputStream()
+     */
+    public InputStream getInputStream() throws IOException
+    {
+        // delegate to ClassPathResource
+        return classPathResource.getInputStream();
+    }
+    
+    // Data access
+        
+    /**
+     * @param defaultConfigResource the defaultConfigResource to set
+     */
+    public void setDefaultConfigResource(String defaultConfigResource)
+    {
+        this.defaultConfigResource = defaultConfigResource;
+    }
+
+    /**
+     * @param test the test to set
+     */
+    public void setTest(boolean test)
+    {
+        this.test = test;
+    }
+
+    /**
+     * @param defaultGroupAddress the defaultGroupAddress to set
+     */
+    public void setDefaultGroupAddress(String defaultGroupAddress)
+    {
+        this.defaultGroupAddress = defaultGroupAddress;
+    }
+
+    /**
+     * @param defaultGroupPort the defaultGroupPort to set
+     */
+    public void setDefaultGroupPort(String defaultGroupPort)
+    {
+        this.defaultGroupPort = defaultGroupPort;
+    }
+
+    /**
+     * @param defaultGroupTTL the defaultGroupTTL to set
+     */
+    public void setDefaultGroupTTL(String defaultGroupTTL)
+    {
+        this.defaultGroupTTL = defaultGroupTTL;
+    }
+
+    /**
+     * @param defaultHostname the defaultHostname to set
+     */
+    public void setDefaultHostname(String defaultHostname)
+    {
+        this.defaultHostname = defaultHostname;
+    }
+
+    /**
+     * @param defaultPort the defaultPort to set
+     */
+    public void setDefaultPort(String defaultPort)
+    {
+        this.defaultPort = defaultPort;
+    }
+
+    /**
+     * @param defaultPageManagerMaxElements the defaultPageManagerMaxElements to set
+     */
+    public void setDefaultPageManagerMaxElements(String defaultPageManagerMaxElements)
+    {
+        this.defaultPageManagerMaxElements = defaultPageManagerMaxElements;
+    }
+
+    /**
+     * @param defaultPageManagerElementTTL the defaultPageManagerElementTTL to set
+     */
+    public void setDefaultPageManagerElementTTL(String defaultPageManagerElementTTL)
+    {
+        this.defaultPageManagerElementTTL = defaultPageManagerElementTTL;
+    }
+
+    /**
+     * @param defaultPageManagerMaxFiles the defaultPageManagerMaxFiles to set
+     */
+    public void setDefaultPageManagerMaxFiles(String defaultPageManagerMaxFiles)
+    {
+        this.defaultPageManagerMaxFiles = defaultPageManagerMaxFiles;
+    }
+}

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheDistributedImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheDistributedImpl.java?rev=724571&r1=724570&r2=724571&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheDistributedImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheDistributedImpl.java Mon Dec  8 17:50:16 2008
@@ -43,6 +43,7 @@
     protected List remoteListeners = new ArrayList();
 
 	private Map refList = Collections.synchronizedMap(new HashMap());
+	private boolean removeAllLocal = false;
 
 
 	public EhCacheDistributedImpl(Ehcache ehcache)
@@ -91,6 +92,14 @@
 
 	public CacheElement createElement(Object key, Object content)
 	{
+        if (!(key instanceof Serializable))
+        {
+            throw new IllegalArgumentException("The cache key must be serializable.");
+        }
+        if (!(content instanceof DistributedCacheObject))
+        {
+            throw new IllegalArgumentException("The cache content must be a distributed cache object.");
+        }
 		return new EhCacheDistributedElementImpl((Serializable)key, (DistributedCacheObject)content);
 	}
 
@@ -129,7 +138,13 @@
 	
     public void clear()
     {
-        super.clear();
+        // invoke removeAll with local flag set
+        synchronized (refList)
+        {
+            removeAllLocal = true;
+            super.clear();
+            removeAllLocal = false;
+        }
         notifyListeners(true, CacheElement.ActionRemoved,null,null);
     }
 
@@ -242,7 +257,7 @@
 
 	public void notifyElementEvicted(Ehcache cache, Element arg1)
 	{
-			notifyElement(cache, false, arg1,CacheElement.ActionEvicted);
+	    notifyElement(cache, false, arg1,CacheElement.ActionEvicted);
 	}
 
 	public void notifyElementExpired(Ehcache cache, Element arg1)
@@ -253,8 +268,7 @@
 	public void notifyElementPut(Ehcache cache, Element arg1)
 			throws CacheException
 	{
-		
-			notifyElement(cache, false, arg1, CacheElement.ActionAdded);
+		notifyElement(cache, false, arg1, CacheElement.ActionAdded);
 	}
 
 	public void notifyElementRemoved(Ehcache cache, Element arg1)
@@ -277,20 +291,25 @@
 		}
 		try
 		{
-			Iterator it = refList.entrySet().iterator();
-			while (it.hasNext())
-			{
-				EhCacheDistributedElementImpl e = (EhCacheDistributedElementImpl)it.next();
-				notifyListeners(false, CacheElement.ActionRemoved,e.getKey(),e);
-				e.notifyChange(CacheElement.ActionRemoved);
-			}
-			refList.clear();
-		} catch (Exception e)
+		    // synchronize on refList to ensure exclusive
+		    // operation on refList and removeAllLocal flag
+		    synchronized (refList)
+		    {
+		        // notify all listeners of element removal
+		        // and each element of its removal
+		        Iterator it = refList.values().iterator();
+		        while (it.hasNext())
+		        {
+		            EhCacheDistributedElementImpl e = (EhCacheDistributedElementImpl)it.next();
+		            notifyListeners(removeAllLocal, CacheElement.ActionRemoved,e.getKey(),e.getContent());
+		            e.notifyChange(CacheElement.ActionRemoved);
+		        }
+		        refList.clear();
+		    }
+		}
+		catch (Exception e)
 		{
 			e.printStackTrace();
 		}
-
-	
 	}
-
 }

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheImpl.java?rev=724571&r1=724570&r2=724571&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheImpl.java Mon Dec  8 17:50:16 2008
@@ -21,8 +21,10 @@
 import java.util.List;
 import java.util.Map;
 
+import net.sf.ehcache.CacheException;
 import net.sf.ehcache.Ehcache;
 import net.sf.ehcache.Element;
+import net.sf.ehcache.distribution.CacheManagerPeerProvider;
 import net.sf.ehcache.event.CacheEventListener;
 
 import org.apache.jetspeed.cache.CacheElement;
@@ -74,9 +76,18 @@
     
     public CacheElement createElement(Object key, Object content)
     {
-    	if (!((key instanceof Serializable) ||  !(content instanceof Serializable)))
-    		throw new IllegalArgumentException("The cache key and the object to cache must be serializable."); //return null;
-   	    return new EhCacheElementImpl((Serializable)key, (Serializable)content);
+    	if (!(key instanceof Serializable))
+    	{
+    		throw new IllegalArgumentException("The cache key must be serializable.");
+    	}
+    	if (content instanceof Serializable)
+    	{
+            return new EhCacheElementImpl((Serializable)key, (Serializable)content);    	    
+    	}
+    	else
+    	{
+            return new EhCacheElementImpl((Serializable)key, content);
+    	}
     }
 
     public boolean remove(Object key)
@@ -117,27 +128,27 @@
         {
            public void notifyElementEvicted(Ehcache cache, Element element)
            {
-               listener.notifyElementEvicted(EhCacheImpl.this, local, element.getKey(), element.getValue());
+               listener.notifyElementEvicted(EhCacheImpl.this, local, element.getKey(), element.getObjectValue());
            }
            
            public void notifyElementExpired(Ehcache cache, Element element)
            {
-               listener.notifyElementExpired(EhCacheImpl.this, local, element.getKey(), element.getValue());
+               listener.notifyElementExpired(EhCacheImpl.this, local, element.getKey(), element.getObjectValue());
            }
            
            public void notifyElementPut(Ehcache cache, Element element)
            {
-               listener.notifyElementAdded(EhCacheImpl.this, local, element.getKey(), element.getValue());
+               listener.notifyElementAdded(EhCacheImpl.this, local, element.getKey(), element.getObjectValue());
            }
            
            public void notifyElementUpdated(Ehcache cache, Element element)
            {
-               listener.notifyElementChanged(EhCacheImpl.this, local, element.getKey(), element.getValue());
+               listener.notifyElementChanged(EhCacheImpl.this, local, element.getKey(), element.getObjectValue());
            }
            
            public void notifyElementRemoved(Ehcache cache, Element element)
            {
-               listener.notifyElementRemoved(EhCacheImpl.this, local, element.getKey(), null);
+               listener.notifyElementRemoved(EhCacheImpl.this, local, element.getKey(), ((element == null) ? null : element.getObjectValue()));
            }
            
            public void notifyRemoveAll(Ehcache cache)
@@ -176,6 +187,20 @@
     {
         return ehcache.getKeys();
     }
+    
+    public boolean isDistributed()
+    {
+        // check if cache part of a distributed cluster
+        try
+        {
+            CacheManagerPeerProvider peerProvider = ehcache.getCacheManager().getCachePeerProvider();
+            return ((peerProvider != null) && (peerProvider.listRemoteCachePeers(ehcache).size() > 0));
+        }
+        catch (CacheException ce)
+        {
+        }
+        return false;
+    }
    
     // ------------------------------------------------------
     

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/pom.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/pom.xml?rev=724571&r1=724570&r2=724571&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/pom.xml (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/pom.xml Mon Dec  8 17:50:16 2008
@@ -124,6 +124,11 @@
             <artifactId>junit</artifactId>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>commons-jexl</groupId>
+            <artifactId>commons-jexl</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
     
     <build>
@@ -162,6 +167,7 @@
                                     </resource>
                                     <resource>
                                         <path>db-ojb</path>
+                                        <exclude>ehcache.xml,distributed-ehcache.xml</exclude>
                                         <destination>test-classes</destination>
                                     </resource>
                                 </resources>
@@ -171,17 +177,5 @@
                 </executions>
             </plugin>
         </plugins>
-        <testResources>
-            <testResource>
-                <directory>src/test/resources</directory>
-                <filtering>true</filtering>
-            </testResource>
-            <testResource>
-                <directory>src/test/java</directory>
-                <excludes>
-                    <exclude>**/*.java</exclude>
-                </excludes>
-            </testResource>
-        </testResources>
     </build>
 </project>

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/AbstractPageManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/AbstractPageManager.java?rev=724571&r1=724570&r2=724571&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/AbstractPageManager.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/AbstractPageManager.java Mon Dec  8 17:50:16 2008
@@ -702,6 +702,14 @@
         // nothing to shutdown by default
     }
 
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.page.PageManager#isDistributed()
+     */
+    public boolean isDistributed()
+    {
+        return false;
+    }
+
     /**
      * notifyNewNode - notify page manager event listeners of
      *                 new node event

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManager.java?rev=724571&r1=724570&r2=724571&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManager.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManager.java Mon Dec  8 17:50:16 2008
@@ -25,6 +25,7 @@
 import javax.security.auth.Subject;
 
 import org.apache.jetspeed.JetspeedActions;
+import org.apache.jetspeed.cache.JetspeedCache;
 import org.apache.jetspeed.components.dao.InitablePersistenceBrokerDaoSupport;
 import org.apache.jetspeed.om.common.SecurityConstraint;
 import org.apache.jetspeed.om.common.SecurityConstraints;
@@ -100,10 +101,6 @@
  */
 public class DatabasePageManager extends InitablePersistenceBrokerDaoSupport implements PageManager
 {
-    private static final int DEFAULT_CACHE_SIZE = 128;
-    private static final int MIN_CACHE_EXPIRES_SECONDS = 30;
-    private static final int DEFAULT_CACHE_EXPIRES_SECONDS = 150;
-
     private static Map modelClasses = new HashMap();
     static
     {
@@ -134,50 +131,13 @@
 
     private DelegatingPageManager delegator;
     
-    private int cacheSize;
-
-    private int cacheExpiresSeconds;
-
     private PageManager pageManagerProxy;
 
-    public DatabasePageManager(String repositoryPath, int cacheSize, int cacheExpiresSeconds, boolean isPermissionsSecurity, boolean isConstraintsSecurity)
+    public DatabasePageManager(String repositoryPath, boolean isPermissionsSecurity, boolean isConstraintsSecurity, JetspeedCache oidCache, JetspeedCache pathCache)
     {
         super(repositoryPath);
         delegator = new DelegatingPageManager(isPermissionsSecurity, isConstraintsSecurity, modelClasses);
-        this.cacheSize = Math.max(cacheSize, DEFAULT_CACHE_SIZE);
-        if (cacheExpiresSeconds < 0)
-        {
-            this.cacheExpiresSeconds = DEFAULT_CACHE_EXPIRES_SECONDS;
-        }
-        else if (cacheExpiresSeconds == 0)
-        {
-            this.cacheExpiresSeconds = 0;
-        }
-        else
-        {
-            this.cacheExpiresSeconds = Math.max(cacheExpiresSeconds, MIN_CACHE_EXPIRES_SECONDS);
-        }
-        DatabasePageManagerCache.cacheInit(this);
-    }
-
-    /**
-     * getCacheSize
-     *
-     * @return configured cache size
-     */
-    public int getCacheSize()
-    {
-        return cacheSize;
-    }
-
-    /**
-     * getCacheExpiresSeconds
-     *
-     * @return configured cache expiration in seconds
-     */
-    public int getCacheExpiresSeconds()
-    {
-        return cacheExpiresSeconds;
+        DatabasePageManagerCache.cacheInit(oidCache, pathCache, this);
     }
 
     /**
@@ -1882,5 +1842,12 @@
         }
         return pages.length;
     }
-    
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.page.PageManager#isDistributed()
+     */
+    public boolean isDistributed()
+    {
+        return DatabasePageManagerCache.isDistributed();
+    }
 }

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManagerCache.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManagerCache.java?rev=724571&r1=724570&r2=724571&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManagerCache.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManagerCache.java Mon Dec  8 17:50:16 2008
@@ -16,12 +16,15 @@
  */
 package org.apache.jetspeed.page.impl;
 
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Properties;
 
+import org.apache.jetspeed.cache.CacheElement;
+import org.apache.jetspeed.cache.JetspeedCache;
+import org.apache.jetspeed.cache.JetspeedCacheEventListener;
+import org.apache.jetspeed.om.folder.Folder;
 import org.apache.jetspeed.om.folder.impl.FolderImpl;
 import org.apache.jetspeed.page.PageManager;
 import org.apache.jetspeed.page.document.impl.NodeImpl;
@@ -37,15 +40,17 @@
  */
 public class DatabasePageManagerCache implements ObjectCache
 {
-    private static HashMap cacheByOID;
-    private static LinkedList cacheLRUList;
-    private static HashMap cacheByPath;
-    private static int cacheSize;
-    private static int cacheExpiresSeconds;
+    // Members
+    
+    private static JetspeedCache oidCache;
+    private static JetspeedCache pathCache;
     private static boolean constraintsEnabled;
     private static boolean permissionsEnabled;
     private static PageManager pageManager;
+    private static ThreadLocal transactionedOperations = new ThreadLocal();
 
+    // Implementation
+    
     /**
      * cacheInit
      *
@@ -53,28 +58,176 @@
      *
      * @param pageManager configured page manager
      */
-    public synchronized static void cacheInit(DatabasePageManager dbPageManager)
+    public synchronized static void cacheInit(final JetspeedCache oidCache, final JetspeedCache pathCache, final DatabasePageManager pageManager)
     {
-        if (pageManager != null)
+        // initialize
+        DatabasePageManagerCache.oidCache = oidCache;
+        DatabasePageManagerCache.pathCache = pathCache;
+        constraintsEnabled = pageManager.getConstraintsEnabled();
+        permissionsEnabled = pageManager.getPermissionsEnabled();
+        
+        // setup local oid cache listener
+        oidCache.addEventListener(new JetspeedCacheEventListener()
         {
-            cacheClear();
-        }
-        cacheByOID = new HashMap();
-        cacheLRUList = new LinkedList();
-        cacheByPath = new HashMap();
-        cacheSize = dbPageManager.getCacheSize();
-        cacheExpiresSeconds = dbPageManager.getCacheExpiresSeconds();
-        constraintsEnabled = dbPageManager.getConstraintsEnabled();
-        permissionsEnabled = dbPageManager.getPermissionsEnabled();
-        pageManager = dbPageManager;
+            /* (non-Javadoc)
+             * @see org.apache.jetspeed.cache.JetspeedCacheEventListener#notifyElementAdded(org.apache.jetspeed.cache.JetspeedCache, boolean, java.lang.Object, java.lang.Object)
+             */
+            public void notifyElementAdded(final JetspeedCache cache, final boolean local, final Object key, final Object element)
+            {
+                final NodeImpl node = (NodeImpl)element;
+                // infuse node with page manager configuration
+                // or the page manager itself and add to the
+                // paths cache 
+                node.setConstraintsEnabled(constraintsEnabled);
+                node.setPermissionsEnabled(permissionsEnabled);
+                if (node instanceof FolderImpl)
+                {
+                    ((FolderImpl)node).setPageManager(pageManager);
+                }
+            }
+
+            /* (non-Javadoc)
+             * @see org.apache.jetspeed.cache.JetspeedCacheEventListener#notifyElementChanged(org.apache.jetspeed.cache.JetspeedCache, boolean, java.lang.Object, java.lang.Object)
+             */
+            public void notifyElementChanged(final JetspeedCache cache, final boolean local, final Object key, final Object element)
+            {
+                final NodeImpl node = (NodeImpl)element;
+                // infuse node with page manager configuration
+                // or the page manager itself and add to the
+                // paths cache 
+                node.setConstraintsEnabled(constraintsEnabled);
+                node.setPermissionsEnabled(permissionsEnabled);
+                if (node instanceof FolderImpl)
+                {
+                    ((FolderImpl)node).setPageManager(pageManager);
+                }
+            }
+
+            /* (non-Javadoc)
+             * @see org.apache.jetspeed.cache.JetspeedCacheEventListener#notifyElementEvicted(org.apache.jetspeed.cache.JetspeedCache, boolean, java.lang.Object, java.lang.Object)
+             */
+            public void notifyElementEvicted(final JetspeedCache cache, final boolean local, final Object key, final Object element)
+            {
+                final NodeImpl node = (NodeImpl)element;
+                // reset internal FolderImpl caches
+                if (node instanceof FolderImpl)
+                {
+                    ((FolderImpl)node).resetAll(false);
+                }
+            }
+
+            /* (non-Javadoc)
+             * @see org.apache.jetspeed.cache.JetspeedCacheEventListener#notifyElementExpired(org.apache.jetspeed.cache.JetspeedCache, boolean, java.lang.Object, java.lang.Object)
+             */
+            public void notifyElementExpired(final JetspeedCache cache, final boolean local, final Object key, final Object element)
+            {
+                final NodeImpl node = (NodeImpl)element;
+                // reset internal FolderImpl caches
+                if (node instanceof FolderImpl)
+                {
+                    ((FolderImpl)node).resetAll(false);
+                }
+            }
+
+            /* (non-Javadoc)
+             * @see org.apache.jetspeed.cache.JetspeedCacheEventListener#notifyElementRemoved(org.apache.jetspeed.cache.JetspeedCache, boolean, java.lang.Object, java.lang.Object)
+             */
+            public void notifyElementRemoved(final JetspeedCache cache, final boolean local, final Object key, final Object element)
+            {
+                final NodeImpl node = (NodeImpl)element;
+                // reset internal FolderImpl caches
+                if (node instanceof FolderImpl)
+                {
+                    ((FolderImpl)node).resetAll(false);
+                }
+            }
+        }, true);
+        
+        // setup remote path cache listener
+        pathCache.addEventListener(new JetspeedCacheEventListener()
+        {
+            /* (non-Javadoc)
+             * @see org.apache.jetspeed.cache.JetspeedCacheEventListener#notifyElementAdded(org.apache.jetspeed.cache.JetspeedCache, boolean, java.lang.Object, java.lang.Object)
+             */
+            public void notifyElementAdded(final JetspeedCache cache, final boolean local, final Object key, final Object element)
+            {
+            }
+
+            /* (non-Javadoc)
+             * @see org.apache.jetspeed.cache.JetspeedCacheEventListener#notifyElementChanged(org.apache.jetspeed.cache.JetspeedCache, boolean, java.lang.Object, java.lang.Object)
+             */
+            public void notifyElementChanged(final JetspeedCache cache, final boolean local, final Object key, final Object element)
+            {
+            }
+
+            /* (non-Javadoc)
+             * @see org.apache.jetspeed.cache.JetspeedCacheEventListener#notifyElementEvicted(org.apache.jetspeed.cache.JetspeedCache, boolean, java.lang.Object, java.lang.Object)
+             */
+            public void notifyElementEvicted(final JetspeedCache cache, final boolean local, final Object key, final Object element)
+            {
+            }
+
+            /* (non-Javadoc)
+             * @see org.apache.jetspeed.cache.JetspeedCacheEventListener#notifyElementExpired(org.apache.jetspeed.cache.JetspeedCache, boolean, java.lang.Object, java.lang.Object)
+             */
+            public void notifyElementExpired(final JetspeedCache cache, final boolean local, final Object key, final Object element)
+            {
+            }
+
+            /* (non-Javadoc)
+             * @see org.apache.jetspeed.cache.JetspeedCacheEventListener#notifyElementRemoved(org.apache.jetspeed.cache.JetspeedCache, boolean, java.lang.Object, java.lang.Object)
+             */
+            public void notifyElementRemoved(final JetspeedCache cache, final boolean local, final Object key, final Object element)
+            {
+                final DatabasePageManagerCacheObject cacheObject = (DatabasePageManagerCacheObject)element;
+                // remove cache object from local oid cache
+                if (cacheObject != null)
+                {
+                    final Identity oid = cacheObject.getId();
+                    final String path = cacheObject.getPath();
+                    if ((oid != null) || (path != null))
+                    {
+                        synchronized (DatabasePageManagerCache.class)
+                        {
+                            if (oid != null)
+                            {
+                                // get object cached by oid
+                                final NodeImpl node = (NodeImpl)cacheLookup(oid);
+                                // reset internal FolderImpl caches
+                                if (node instanceof FolderImpl)
+                                {
+                                    ((FolderImpl)node).resetAll(false);
+                                }
+                                // remove from cache
+                                oidCache.removeQuiet(oid);
+                            }
+                            if (path != null)
+                            {
+                                // lookup parent object cached by path and oid
+                                final int pathLastSeparatorIndex = path.lastIndexOf(Folder.PATH_SEPARATOR);
+                                final String parentPath = ((pathLastSeparatorIndex > 0) ? path.substring(0, pathLastSeparatorIndex) : Folder.PATH_SEPARATOR);
+                                final NodeImpl parentNode = cacheLookup(parentPath);
+                                // reset internal FolderImpl caches in case element removed
+                                if (parentNode instanceof FolderImpl)
+                                {
+                                    ((FolderImpl)parentNode).resetAll(false);
+                                }
+                                // remove from cache
+                                pathCache.removeQuiet(path);
+                            }
+                        }                        
+                    }
+                }
+            }
+        }, false);
     }
 
     /**
-     * setPageManagerProxy
+     * Override page manager specified during create with proxy.
      *
      * @param proxy proxied page manager interface used to
-     *              inject into Folder instances to provide
-     *              transaction/interception
+     *               inject into Folder instances to provide
+     *               transaction/intercept
      */
     public synchronized static void setPageManagerProxy(PageManager proxy)
     {
@@ -88,283 +241,211 @@
     }
 
     /**
-     * cacheLookup
-     *
-     * Lookup node instances by unique path.
+     * Lookup object instances by unique path.
      *
      * @param path node unique path
      * @return cached node
      */
-    public synchronized static NodeImpl cacheLookup(String path)
+    public synchronized static NodeImpl cacheLookup(final String path)
     {
         if (path != null)
         {
-            // return valid object cached by path
-            return (NodeImpl)cacheValidateEntry((Entry)cacheByPath.get(path));
+            // return valid object cached by path and oid
+            final CacheElement pathElement = pathCache.get(path);
+            if (pathElement != null)
+            {
+                final DatabasePageManagerCacheObject cacheObject = (DatabasePageManagerCacheObject)pathElement.getContent();
+                final NodeImpl node = (NodeImpl)cacheLookup(cacheObject.getId());
+                return node;
+            }
         }
         return null;
     }
 
     /**
-     * cacheAdd
-     *
-     * Add object to cache and cache node instances by unique path;
+     * Add object to cache and cache instances by unique path;
      * infuse nodes loaded by OJB with page manager configuration.
      *
-     * @param oid object/node indentity
+     * @param oid object/node identity
      * @param obj object/node to cache
      */
-    public synchronized static void cacheAdd(Identity oid, Object obj)
+    public synchronized static void cacheAdd(final Identity oid, final Object obj)
     {
-        Entry entry = (Entry)cacheByOID.get(oid);
-        if (entry != null)
+        if (obj instanceof NodeImpl)
         {
-            // update cache LRU order
-            cacheLRUList.remove(entry);
-            cacheLRUList.addFirst(entry);
-            // refresh cache entry
-            entry.touch();
-        }
-        else
-        {
-            // create new cache entry and map
-            entry = new Entry(obj, oid);
-            cacheByOID.put(oid, entry);
-            cacheLRUList.addFirst(entry);
-            // infuse node with page manager configuration
-            // or the page manager itself and add to the
-            // paths cache 
-            if (obj instanceof NodeImpl)
-            {
-                NodeImpl node = (NodeImpl)obj;
-                node.setConstraintsEnabled(constraintsEnabled);
-                node.setPermissionsEnabled(permissionsEnabled);
-                cacheByPath.put(node.getPath(), entry);
-                if (obj instanceof FolderImpl)
-                {
-                    ((FolderImpl)obj).setPageManager(pageManager);
-                }
-            }
-            // trim cache as required to maintain cache size
-            while (cacheLRUList.size() > cacheSize)
-            {
-                cacheRemoveEntry((Entry)cacheLRUList.getLast(), true);
-            }
+            final NodeImpl node = (NodeImpl)obj;
+            final String nodePath = node.getPath();
+
+            // add node to caches
+            oidCache.remove(oid);
+            final CacheElement element = oidCache.createElement(oid, node);
+            oidCache.put(element);
+            pathCache.remove(nodePath);
+            final CacheElement pathElement = pathCache.createElement(nodePath, new DatabasePageManagerCacheObject(oid, nodePath));
+            pathCache.put(pathElement);
         }
     }
 
     /**
-     * cacheClear
-     *
-     * Clear object and node caches.
+     * Clear object and path caches.
      */
     public synchronized static void cacheClear()
     {
-        // remove all cache entries
-        Iterator removeIter = cacheLRUList.iterator();
-        while (removeIter.hasNext())
+        // remove all items from oid cache individually
+        // to ensure notifications are run to detach
+        // elements; do not invoke oidCache.clear()
+        final Iterator removeOidIter = oidCache.getKeys().iterator();
+        while (removeOidIter.hasNext())
+        {
+            oidCache.remove((Identity)removeOidIter.next());
+        }
+        // remove all items from path cache individually
+        // to avoid potential distributed clear invocation
+        // that would be performed against all peers; do
+        // not invoke pathCache.clear()
+        final Iterator removePathIter = pathCache.getKeys().iterator();
+        while (removePathIter.hasNext())
         {
-            cacheRemoveEntry((Entry)removeIter.next(), false);
+            pathCache.removeQuiet(removePathIter.next());
         }
-        // clear cache
-        cacheByOID.clear();
-        cacheLRUList.clear();
-        cacheByPath.clear();
     }
 
     /**
-     * cacheLookup
-     *
      * Lookup objects by identity.
      *
      * @param oid object identity
      * @return cached object
      */
-    public synchronized static Object cacheLookup(Identity oid)
+    public synchronized static Object cacheLookup(final Identity oid)
     {
         if (oid != null)
         {
             // return valid object cached by oid
-            return cacheValidateEntry((Entry)cacheByOID.get(oid));
+            final CacheElement element = oidCache.get(oid);
+            if (element != null)
+            {
+                return element.getContent();
+            }
         }
         return null;
     }
 
     /**
-     * cacheRemove
-     *
-     * Remove identified object from object and node caches.
+     * Remove identified object from object and path caches.
      *
      * @param oid object identity
      */
-    public synchronized static void cacheRemove(Identity oid)
+    public synchronized static void cacheRemove(final Identity oid)
     {
         // remove from cache by oid
-        cacheRemoveEntry((Entry)cacheByOID.get(oid), true);
+        if (oid != null)
+        {
+            final NodeImpl node = (NodeImpl)cacheLookup(oid);
+            if (node != null)
+            {
+                // remove from caches
+                oidCache.remove(oid);
+                pathCache.remove(node.getPath());
+            }
+        }
     }
 
     /**
-     * cacheRemove
-     *
-     * Remove identified object from object and node caches.
+     * Remove identified object from object and path caches.
      *
      * @param path object path
      */
-    public synchronized static void cacheRemove(String path)
+    public synchronized static void cacheRemove(final String path)
     {
         // remove from cache by path
-        cacheRemoveEntry((Entry)cacheByPath.get(path), true);
+        if (path != null)
+        {
+            final CacheElement pathElement = pathCache.get(path);
+            if (pathElement != null)
+            {
+                final DatabasePageManagerCacheObject cacheObject = (DatabasePageManagerCacheObject)pathElement.getContent();
+                // remove from caches
+                oidCache.remove(cacheObject.getId());
+                pathCache.remove(path);
+            }
+        }
     }
     
     /**
-     * cacheValidateEntry
-     *
-     * Validate specified entry from cache, returning cached
-     * object if valid.
-     *
-     * @param entry cache entry to validate
-     * @return validated object from cache
+     * Reset cached security constraints in all cached objects.
      */
-    private synchronized static Object cacheValidateEntry(Entry entry)
+    public synchronized static void resetCachedSecurityConstraints()
     {
-        if (entry != null)
+        // reset cached objects
+        final Iterator resetIter = oidCache.getKeys().iterator();
+        while (resetIter.hasNext())
         {
-            if (!entry.isExpired())
-            {
-                // update cache LRU order
-                cacheLRUList.remove(entry);
-                cacheLRUList.addFirst(entry);
-                // refresh cache entry and return object
-                entry.touch();
-                return entry.getObject();
-            }
-            else
-            {
-                // remove expired entry
-                cacheRemoveEntry(entry, true);
-            }
+            final NodeImpl node = (NodeImpl)cacheLookup((Identity)resetIter.next());
+            node.resetCachedSecurityConstraints();
         }
-        return null;
     }
     
     /**
-     * cacheRemoveEntry
-     *
-     * Remove specified entry from cache.
-     *
-     * @param entry cache entry to remove
-     * @param remove enable removal from cache
+     * Get transactions registered on current thread
+     * 
+     * @return transactions list
      */
-    private synchronized static void cacheRemoveEntry(Entry entry, boolean remove)
+    public static List getTransactions()
     {
-        if (entry != null)
+        List operations = (List)transactionedOperations.get();
+        if (operations == null)
         {
-            Object removeObj = entry.getObject();
-            if (remove)
-            {
-                // remove entry, optimize for removal from end
-                // of list as cache size is met or entries expire
-                if (cacheLRUList.getLast() == entry)
-                {
-                    cacheLRUList.removeLast();
-                }
-                else
-                {
-                    int removeIndex = cacheLRUList.lastIndexOf(entry);
-                    if (removeIndex > 0)
-                    {
-                        cacheLRUList.remove(removeIndex);
-                    }
-                }
-                // unmap entry
-                cacheByOID.remove(entry.getOID());
-                if (removeObj instanceof NodeImpl)
-                {
-                    cacheByPath.remove(((NodeImpl)removeObj).getPath());
-                }
-            }
-            // reset internal FolderImpl caches
-            if (removeObj instanceof FolderImpl)
-            {
-                ((FolderImpl)removeObj).resetAll(false);
-            }
+            operations = new LinkedList();
+            transactionedOperations.set(operations);
         }
+        return operations;
     }
 
     /**
-     * resetCachedSecurityConstraints
-     *
-     * Reset cached security constraints in all cached node objects.
+     * Register transactions with current thread
+     * 
+     * @param operation transaction operation
      */
-    public synchronized static void resetCachedSecurityConstraints()
+    public static void addTransaction(TransactionedOperation operation)
     {
-        // reset cached objects
-        Iterator resetIter = cacheLRUList.iterator();
-        while (resetIter.hasNext())
-        {
-            Object obj = ((Entry)resetIter.next()).getObject();
-            if (obj instanceof NodeImpl)
-            {
-                ((NodeImpl)obj).resetCachedSecurityConstraints();
-            }
-        }
+        final List transactions = getTransactions();        
+        transactions.add(operation);
     }
-
+    
     /**
-     * Entry
-     *
-     * Cache entry class adding entry timestamp to track expiration
+     * Rollback transactions registered with current thread.
      */
-    private static class Entry
+    public synchronized static void rollbackTransactions()
     {
-        public long timestamp;
-        public Object object;
-        public Identity oid;
-
-        public Entry(Object object, Identity oid)
-        {
-            touch();
-            this.object = object;
-            this.oid = oid;
-        }
-
-        public boolean isExpired()
-        {
-            if (DatabasePageManagerCache.cacheExpiresSeconds > 0)
-            {
-                long now = System.currentTimeMillis();
-                if (((now - timestamp) / 1000) < DatabasePageManagerCache.cacheExpiresSeconds)
-                {
-                    timestamp = now;
-                    return false;
-                }
-                return true;
-            }
-            return false;
-        }
-        
-        public void touch()
+        final Iterator transactions = getTransactions().iterator();
+        while (transactions.hasNext())
         {
-            if (DatabasePageManagerCache.cacheExpiresSeconds > 0)
-            {
-                timestamp = System.currentTimeMillis();
-            }
+            final TransactionedOperation operation = (TransactionedOperation)transactions.next();
+            cacheRemove(operation.getPath());
         }
+    }
 
-        public Object getObject()
-        {
-            return object;
-        }
+    /**
+     * Clear transactions registered with current thread.
+     */
+    public synchronized static void clearTransactions()
+    {
+        transactionedOperations.remove();
+    }
 
-        public Identity getOID()
-        {
-            return oid;
-        }
+    /**
+     * Returns whether this cache is currently part of a distributed cache cluster.
+     * 
+     * @return distributed flag
+     */
+    public static boolean isDistributed()
+    {
+        return pathCache.isDistributed();
     }
 
+    // OJB Constructor
+    
     /**
-     * DatabasePageManagerCache
-     *
      * Construct a cache instance using OJB compliant signatures.
      *
      * @param broker broker that is to own cache
@@ -374,6 +455,8 @@
     {
     }
 
+    // OJB ObjectCache Implementation
+    
     /* (non-Javadoc)
      * @see org.apache.ojb.broker.cache.ObjectCache#cache(org.apache.ojb.broker.Identity, java.lang.Object)
      */
@@ -406,57 +489,21 @@
         cacheRemove(oid);
     }
 
-    public synchronized static void dump()
-    {
-        System.out.println("--------------------------1");        
-        Iterator dumpIter = cacheLRUList.iterator();
-        while (dumpIter.hasNext())
-        {
-            Entry entry = (Entry)dumpIter.next();
-            Object entryObject = entry.getObject();
-            if (entryObject instanceof NodeImpl)
-            {
-                System.out.println("entry = " + ((NodeImpl)entryObject).getPath() + ", " + entry.getOID());
-            }
-            else
-            {
-                System.out.println("entry = <none>, " + entry.getOID());
-            }
-        }
-        System.out.println("--------------------------2");
-    }
-    
-    protected static ThreadLocal transactionedOperations = new ThreadLocal();
+    // Utilities
     
-    public static List getTransactions()
-    {
-        List operations = (List)transactionedOperations.get();
-        if (operations == null)
-        {
-            operations = new LinkedList();
-            transactionedOperations.set(operations);
-        }
-        
-        return operations;
-    }
-
     /**
-     * @param principal
-     *            The principal to set.
+     * Dump cache paths and oids to standard out.
      */
-    public static void addTransaction(TransactionedOperation operation)
-    {
-        List transactions = getTransactions();        
-        transactions.add(operation);
-    }
-    
-    public static void rollbackTransactions()
+    public synchronized static void dump()
     {
-        Iterator transactions = getTransactions().iterator();
-        while (transactions.hasNext())
+        System.out.println("--------------------------");        
+        final Iterator dumpIter = oidCache.getKeys().iterator();
+        while (dumpIter.hasNext())
         {
-            TransactionedOperation operation = (TransactionedOperation)transactions.next();
-            cacheRemove(operation.getPath());
+            final Identity oid = (Identity)dumpIter.next();
+            final NodeImpl node = (NodeImpl)cacheLookup(oid);
+            System.out.println("node="+node.getPath()+", oid="+oid);
         }
-    }
+        System.out.println("--------------------------");
+    }    
 }

Added: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManagerCacheObject.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManagerCacheObject.java?rev=724571&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManagerCacheObject.java (added)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManagerCacheObject.java Mon Dec  8 17:50:16 2008
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.page.impl;
+
+import org.apache.jetspeed.cache.CacheElement;
+import org.apache.jetspeed.cache.DistributedCacheObject;
+import org.apache.ojb.broker.Identity;
+
+/**
+ * DatabasePageManagerCacheObject
+ * 
+ * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
+ * @version $Id: $
+*/
+public class DatabasePageManagerCacheObject implements DistributedCacheObject
+{
+    private static final long serialVersionUID = 3575475610695136850L;
+
+    // Members
+    
+    private Identity id = null;
+    private String path = null;
+
+    // Constructor
+    
+    /**
+     * Construct new cache object with id and path
+     * 
+     * @param id
+     * @param path
+     */
+    public DatabasePageManagerCacheObject(final Identity id, final String path)
+    {
+        this.path = path;
+        this.id = id;
+    }
+
+    /**
+     * Serialization constructor
+     */
+    public DatabasePageManagerCacheObject()
+    {
+    }
+
+    // Implementation
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.cache.DistributedCacheObject#notifyChange(int)
+     */
+    public void notifyChange(int action)
+    {
+        switch (action)
+        {
+            case CacheElement.ActionAdded:
+            case CacheElement.ActionChanged:
+            case CacheElement.ActionRemoved:
+            case CacheElement.ActionEvicted:
+            case CacheElement.ActionExpired:
+                break;
+            default:
+                return;
+        }
+        return;
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    public boolean equals(Object obj)
+    {
+        if ((obj != null) && (obj instanceof DatabasePageManagerCacheObject))
+        {
+            final DatabasePageManagerCacheObject other = (DatabasePageManagerCacheObject) obj;
+            return getPath().equals(other.getPath());
+        }
+        return false;
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#hashCode()
+     */
+    public int hashCode()
+    {
+        return getPath().hashCode();
+    }
+
+    // Data access
+    
+    /**
+     * @return wrapper id
+     */
+    public Identity getId()
+    {
+        return id;
+    }
+
+    /**
+     * @return wrapper path
+     */
+    public String getPath()
+    {
+        return path;
+    }
+}

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/util/interceptors/PageManagerInterceptor.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/util/interceptors/PageManagerInterceptor.java?rev=724571&r1=724570&r2=724571&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/util/interceptors/PageManagerInterceptor.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/util/interceptors/PageManagerInterceptor.java Mon Dec  8 17:50:16 2008
@@ -46,6 +46,10 @@
             DatabasePageManagerCache.rollbackTransactions();
             throw exp;
         }
+        finally
+        {
+            DatabasePageManagerCache.clearTransactions();            
+        }
     }
 
 }

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestDatabasePageManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestDatabasePageManager.java?rev=724571&r1=724570&r2=724571&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestDatabasePageManager.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestDatabasePageManager.java Mon Dec  8 17:50:16 2008
@@ -100,8 +100,7 @@
     
     protected String[] getConfigurations()
     {
-        return new String[]
-        { "database-page-manager.xml", "transaction.xml" };
+        return new String[]{"database-page-manager.xml", "transaction.xml"};
     }
 
     public void firstTestSetup() throws Exception

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestSecureDatabasePageManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestSecureDatabasePageManager.java?rev=724571&r1=724570&r2=724571&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestSecureDatabasePageManager.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestSecureDatabasePageManager.java Mon Dec  8 17:50:16 2008
@@ -43,8 +43,7 @@
     
     protected String[] getConfigurations()
     {
-        return new String[]
-        { "secure-database-page-manager.xml", "transaction.xml" };
+        return new String[]{"secure-database-page-manager.xml", "transaction.xml"};
     }
 
     public void testSecurePageManager() throws Exception

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestSecurePermissionsDatabasePageManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestSecurePermissionsDatabasePageManager.java?rev=724571&r1=724570&r2=724571&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestSecurePermissionsDatabasePageManager.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestSecurePermissionsDatabasePageManager.java Mon Dec  8 17:50:16 2008
@@ -53,7 +53,6 @@
     
     protected String[] getConfigurations()
     {
-        return new String[]
-        { "secure-permissions-database-page-manager.xml", "transaction.xml" };
+        return new String[]{"secure-permissions-database-page-manager.xml", "transaction.xml"};
     }
 }

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestTransactions.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestTransactions.java?rev=724571&r1=724570&r2=724571&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestTransactions.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestTransactions.java Mon Dec  8 17:50:16 2008
@@ -48,16 +48,9 @@
     
     protected String[] getConfigurations()
     {
-        return new String[]
-        { "tx-page-manager.xml", "transaction.xml", "interceptors.xml" }; 
+        return new String[]{"database-page-manager.xml", "transaction.xml"}; 
     }
 
-    protected String[] getBootConfigurations()
-    {
-        return new String[]
-        { "boot/datasource.xml"};
-    }
-    
     public void testTx() throws Exception
     {
         PageManager pageManager = (PageManager)scm.getComponent("pageManager");
@@ -87,11 +80,11 @@
         catch (Exception e)
         {
             System.out.println("Exception adding pages" + e);
-           // e.printStackTrace();
-            
         }
+
         System.out.println("--- after rollback");
         DatabasePageManagerCache.dump();
+
         assertFalse("page 1 found", pageManager.pageExists("/tx__test1.psml"));
         assertFalse("page 2 found", pageManager.pageExists("/tx__test2.psml"));
         assertFalse("page 3 found", pageManager.pageExists("/tx__test3.psml"));

Added: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/cache/DatabasePageManagerServer.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/cache/DatabasePageManagerServer.java?rev=724571&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/cache/DatabasePageManagerServer.java (added)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/cache/DatabasePageManagerServer.java Mon Dec  8 17:50:16 2008
@@ -0,0 +1,207 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.page.cache;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+
+import org.apache.commons.jexl.JexlContext;
+import org.apache.commons.jexl.JexlHelper;
+import org.apache.commons.jexl.Script;
+import org.apache.commons.jexl.ScriptFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.components.JetspeedBeanDefinitionFilter;
+import org.apache.jetspeed.components.SpringComponentManager;
+import org.apache.jetspeed.components.jndi.JetspeedTestJNDIComponent;
+import org.apache.jetspeed.page.PageManager;
+
+/**
+ * DatabasePageManagerServer
+ * 
+ * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
+ * @version $Id: $
+ */
+public class DatabasePageManagerServer
+{
+    protected static Log log = LogFactory.getLog(DatabasePageManagerServer.class);
+    
+    // Constants
+    
+    public static final String SCRIPT_RESULT_LINE_PREFIX = "> ";
+    
+    // Members
+    
+    private JetspeedTestJNDIComponent jndiDS;
+    private String baseDir;
+    private SpringComponentManager scm;
+    private PageManager pageManager;
+    private JexlContext jexlContext;
+    private boolean exit;
+    
+    // Life cycle
+    
+    /**
+     * Initialize page manager server instance and script context.
+     * 
+     * @throws Exception
+     */
+    public void initialize() throws Exception
+    {
+        // setup jetspeed test datasource and component manager
+        jndiDS = new JetspeedTestJNDIComponent();
+        jndiDS.setup();
+        final JetspeedBeanDefinitionFilter beanDefinitionFilter = new JetspeedBeanDefinitionFilter("default,jdbcDS");
+        final String [] bootConfigurations = new String[]{"boot/datasource.xml"};
+        final String [] configurations = new String[]{"database-page-manager.xml", "transaction.xml"};
+        baseDir = System.getProperty("basedir");
+        if ((baseDir == null) || (baseDir.length() == 0))
+        {
+            baseDir = System.getProperty("user.dir");
+        }
+        final String appRoot = baseDir+"/target/test-classes/webapp";
+        scm = new SpringComponentManager(beanDefinitionFilter, bootConfigurations, configurations, appRoot, false);
+        scm.start();
+
+        // access page manager
+        pageManager = (PageManager)scm.getComponent("pageManager");
+        
+        // craete jexl context
+        jexlContext = JexlHelper.createContext();
+        jexlContext.getVars().put("pageManager", pageManager);
+        jexlContext.getVars().put("pageManagerServer", this);
+        
+        log.info( "DatabasePageManager server initialized");
+    }
+    
+    /**
+     * Terminate page manager server instance.
+     * 
+     * @throws Exception
+     */
+    public void terminate() throws Exception
+    {
+        // shutdown page manager
+        pageManager.shutdown();
+
+        // tear down jetspeed component manager and test datasource
+        scm.stop();
+        jndiDS.tearDown();
+
+        log.info( "DatabasePageManager server terminated");
+    }
+    
+    // Implementation
+    
+    /**
+     * Execute a single line script against page manager server context.
+     * 
+     * @param scriptLine jexl script
+     * @return script result line
+     */
+    public String execute(final String scriptLine)
+    {
+        // execute script line and return result line
+        String resultLine = scriptLine;
+        try
+        {
+            final Script jexlScript = ScriptFactory.createScript(scriptLine);
+            final Object result = jexlScript.execute(jexlContext);
+            if (result != null)
+            {
+                resultLine += " -> "+result;
+            }
+        }
+        catch (final Exception e)
+        {
+            resultLine += " -> "+e;            
+        }
+        return resultLine;
+    }
+
+    /**
+     * Sets server exit flag.
+     */
+    public void exit()
+    {
+        exit = true;
+    }
+    
+    // Data access
+    
+    /**
+     * @return server exit flag
+     */
+    public boolean isExit()
+    {
+        return exit;
+    }
+    
+    // Application entry point
+    
+    /**
+     * Server main entry point.
+     * 
+     * @param args not used
+     */
+    public static void main(final String [] args)
+    {
+        try
+        {
+            // create and initialize server
+            final DatabasePageManagerServer server = new DatabasePageManagerServer();
+            server.initialize();
+            
+            // simple server reads script lines from standard
+            // input and writes results on standard output
+            final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
+            final PrintWriter out = new PrintWriter(System.out, true);
+            do
+            {
+                // read single line scripts to execute
+                String scriptLine = in.readLine();
+                if (scriptLine != null)
+                {
+                    scriptLine = scriptLine.trim();
+                    String resultLine = "";
+                    if (scriptLine.length() > 0)
+                    {
+                        // execute script
+                        resultLine = server.execute(scriptLine);
+                    }
+
+                    // write prefixed single line results
+                    out.println(SCRIPT_RESULT_LINE_PREFIX+resultLine);
+                }
+                else
+                {
+                    // exit server on input EOF
+                    server.exit();
+                }
+            }
+            while (!server.isExit());
+            
+            // terminate server
+            server.terminate();
+        }
+        catch (final Throwable t)
+        {
+            log.error( "Unexpected exception: "+t, t);
+        }
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message