permissionsEnabled = pageManager.getPermissionsEnabled();
DatabasePageManagerCache.pageManager = pageManager;
// setup local oid cache listener
final DatabasePageManager databasePageManager = pageManager;
oidCache.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(JetspeedCache cache, boolean local, Object key, Object element)
{
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);
node.setPageManager(databasePageManager);
}
/* (non-Javadoc)
* @see org.apache.jetspeed.cache.JetspeedCacheEventListener#notifyElementChanged(org.apache.jetspeed.cache.JetspeedCache, boolean, java.lang.Object, java.lang.Object)
*/
public void notifyElementChanged(JetspeedCache cache, boolean local, Object key, Object element)
{
notifyElementAdded(cache, local, key, 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(JetspeedCache cache, boolean local, Object key, Object element)
{
notifyElementRemoved(cache, local, key, 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(JetspeedCache cache, boolean local, Object key, Object element)
{
notifyElementRemoved(cache, local, key, 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(JetspeedCache cache, boolean local, Object key, Object element)
{
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(JetspeedCache cache, boolean local, Object key, 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(JetspeedCache cache, boolean local, Object key, 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(JetspeedCache cache, boolean local, Object key, 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(JetspeedCache cache, boolean local, Object key, 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(JetspeedCache cache, boolean local, Object key, Object element)
{
DatabasePageManagerCacheObject cacheObject = (DatabasePageManagerCacheObject)element;
// remove cache object from local caches
Identity oid = ((cacheObject != null) ? cacheObject.getId() : null);
String path = ((cacheObject != null) ? cacheObject.getPath() : (String)key);
if ((oid != null) || (path != null))
{
synchronized (DatabasePageManagerCache.class)
{
if (oid != null)
{
// get object cached by oid
NodeImpl node = (NodeImpl)cacheLookup(oid);
// reset internal FolderImpl caches
if (node instanceof FolderImpl)
{
((FolderImpl)node).resetAll(false);
}
// notify page manager of update
DatabasePageManagerCache.pageManager.notifyUpdatedNode(node);
// remove from cache
DatabasePageManagerCache.oidCache.removeQuiet(oid);
}
if (path != null)
{
// lookup parent object cached by path and oid
int pathLastSeparatorIndex = path.lastIndexOf(Folder.PATH_SEPARATOR);
String parentPath = ((pathLastSeparatorIndex > 0) ? path.substring(0, pathLastSeparatorIndex) : Folder.PATH_SEPARATOR);
NodeImpl parentNode = cacheLookup(parentPath);
// reset internal FolderImpl caches in case element removed
if (parentNode instanceof FolderImpl)
{
((FolderImpl)parentNode).resetAll(false);
}
// remove all indexed fragment keys for page path from
// properties cache index
Set index = (Set)propertiesCacheIndexMap.get(path);
if (index != null)
{
// remove all indexed fragment keys
Iterator fragmentKeyIter = index.iterator();
while (fragmentKeyIter.hasNext())
{
String fragmentKey = (String)fragmentKeyIter.next();
// parse key to extract fragment id
int fragmentId = getFragmentIdFromFragmentKey(fragmentKey);
// remove principal fragment property list caches that have fragment properties
if (fragmentId > 0)
{
clearPrincipalPropertiesCache(fragmentId);
}
// remove fragment property cache
DatabasePageManagerCache.propertiesCache.removeQuiet(fragmentKey);
DatabasePageManagerCache.propertiesPathCache.removeQuiet(fragmentKey);
}
propertiesCacheIndexMap.remove(path);
}
}
}
}
}
}, false);
// setup local properties cache listener
propertiesCache.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(JetspeedCache cache, boolean local, Object key, Object element)
{
String fragmentKey = (String)key;
DatabasePageManagerCachedFragmentPropertyList fragmentPropertyList = (DatabasePageManagerCachedFragmentPropertyList)element;
if (fragmentPropertyList != null)
{
// add cache key to properties cache index
String path = fragmentPropertyList.getBaseFragmentsElementPath();
synchronized (DatabasePageManagerCache.class)
{
Set index = (Set)propertiesCacheIndexMap.get(path);
if (index == null)
{
index = new HashSet();
propertiesCacheIndexMap.put(path, index);
}
index.add(fragmentKey);
}
}
}
/* (non-Javadoc)
* @see org.apache.jetspeed.cache.JetspeedCacheEventListener#notifyElementChanged(org.apache.jetspeed.cache.JetspeedCache, boolean, java.lang.Object, java.lang.Object)
*/
public void notifyElementChanged(JetspeedCache cache, boolean local, Object key, Object element)
{
notifyElementAdded(cache, local, key, 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(JetspeedCache cache, boolean local, Object key, Object element)
{
notifyElementRemoved(cache, local, key, 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(JetspeedCache cache, boolean local, Object key, Object element)
{
notifyElementRemoved(cache, local, key, 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(JetspeedCache cache, boolean local, Object key, Object element)
{
String fragmentKeyOrPath = (String)key;
DatabasePageManagerCachedFragmentPropertyList fragmentPropertyList = (DatabasePageManagerCachedFragmentPropertyList)element;
if (fragmentPropertyList != null)
{
// remove single cache key from properties cache index
String path = fragmentPropertyList.getBaseFragmentsElementPath();
synchronized (DatabasePageManagerCache.class)
{
Set index = (Set)propertiesCacheIndexMap.get(path);
if (index != null)
{
index.remove(fragmentKeyOrPath);
if (index.isEmpty())
{
propertiesCacheIndexMap.remove(path);
}
}
}
}
else if (fragmentKeyOrPath != null)
{
// remove all indexed cache keys from properties cache index
synchronized (DatabasePageManagerCache.class)
{
Set index = (Set)propertiesCacheIndexMap.get(fragmentKeyOrPath);
if (index != null)
{
// remove all indexed cache keys
Iterator fragmentKeyIter = index.iterator();
while (fragmentKeyIter.hasNext())
{
String fragmentKey = (String)fragmentKeyIter.next();
DatabasePageManagerCache.propertiesCache.removeQuiet(fragmentKey);
}
propertiesCacheIndexMap.remove(fragmentKeyOrPath);
}
}
}
else if (fragmentKeyOrPath != null)
{
// remove all cache keys from properties cache index
synchronized (DatabasePageManagerCache.class)
{
propertiesCacheIndexMap.clear();
}
}
}
}, true);
// setup remote properties path cache listener
propertiesPathCache.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(JetspeedCache cache, boolean local, Object key, 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(JetspeedCache cache, boolean local, Object key, 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(JetspeedCache cache, boolean local, Object key, 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(JetspeedCache cache, boolean local, Object key, 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(JetspeedCache cache, boolean local, Object key, Object element)
{
DatabasePageManagerFragmentKeyCacheObject cacheObject = (DatabasePageManagerFragmentKeyCacheObject)element;
// remove cache object from local properties cache
String fragmentKey = ((cacheObject != null) ? cacheObject.getFragmentKey() : (String)key);
if (fragmentKey != null)
{
// parse key to extract fragment id
int fragmentId = getFragmentIdFromFragmentKey(fragmentKey);
// remove cached objects
synchronized (DatabasePageManagerCache.class)
{
// remove principal fragment property list caches that have fragment properties
if (fragmentId > 0)
{
clearPrincipalPropertiesCache(fragmentId);
}
// remove from fragment property list cache
DatabasePageManagerCache.propertiesCache.remove(fragmentKey);
}
}
}
}, false);
// setup remote principal properties path cache listener
principalPropertiesPathCache.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(JetspeedCache cache, boolean local, Object key, Object element)