org.opencms.ade.configuration.CmsGlobalConfigurationCacheEventHandler Maven / Gradle / Ivy
Show all versions of opencms-test Show documentation
/*
* File : $Source$
* Date : $Date$
* Version: $Revision$
*
* This library is part of OpenCms -
* the Open Source Content Management System
*
* Copyright (C) 2002 - 2011 Alkacon Software (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about Alkacon Software, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.opencms.ade.configuration;
import org.opencms.db.CmsDriverManager;
import org.opencms.db.CmsPublishedResource;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsResource;
import org.opencms.main.CmsEvent;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.I_CmsEventListener;
import org.opencms.util.CmsCollectionsGenericWrapper;
import org.opencms.util.CmsUUID;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
/**
*
* This event handler manages cache instances which are instances of the interface {@link I_CmsGlobalConfigurationCache}.
* It keeps a list of cache instance pairs, each containing one cache for the online mode and one for the offline mode,
* and handles events caused by changed resources by notifying the cache instances.
*
* Note that *all* changed resources will get passed to the underlying cache instances, so those instances will need to check
* whether the resource passed into the update or remove methods is actually a resource with which the cache instance is concerned.
*
* This class should be used if you have an indefinite number of configuration files at arbitrary locations in the VFS.
* If you need to cache e.g. a single configuration file with a known, fixed path, using {@link org.opencms.cache.CmsVfsMemoryObjectCache} is
* easier.
*/
public class CmsGlobalConfigurationCacheEventHandler implements I_CmsEventListener {
/**
* A pair of cache instances, one for the offline mode and one for the online mode.
*/
private class CachePair {
/** A name for debugging. */
@SuppressWarnings("unused")
private String m_debugName;
/** The offline cache instance. */
private I_CmsGlobalConfigurationCache m_offlineCache;
/** The online cache instance. */
private I_CmsGlobalConfigurationCache m_onlineCache;
/**
* Creates a new cache pair.
*
* @param offlineCache the offline cache instance
* @param onlineCache the online cache instance
* @param debugName the name for debugging
*/
public CachePair(
I_CmsGlobalConfigurationCache offlineCache,
I_CmsGlobalConfigurationCache onlineCache,
String debugName) {
m_offlineCache = offlineCache;
m_onlineCache = onlineCache;
m_debugName = debugName;
}
/**
* Gets the offline cache instance.
*
* @return the offline cache instance
*/
public I_CmsGlobalConfigurationCache getOfflineCache() {
return m_offlineCache;
}
/**
* Gets the online cache instance.
*
* @return the online cache instance
*/
public I_CmsGlobalConfigurationCache getOnlineCache() {
return m_onlineCache;
}
}
/** The logger instance for this class. */
private static final Log LOG = CmsLog.getLog(CmsGlobalConfigurationCacheEventHandler.class);
/** The list of cache pairs. */
private List m_caches = new ArrayList();
/** An online CMS object. */
private CmsObject m_onlineCms;
/** Creates a new cache event handler.
*
* @param onlineCms an online CMS object
**/
public CmsGlobalConfigurationCacheEventHandler(CmsObject onlineCms) {
m_onlineCms = onlineCms;
}
/**
* Adds a new pair of cache instances which should be managed by this event handler.
*
* @param offlineCache the offline cache instance
* @param onlineCache the online cache instance
* @param debugName an identifier used for debugging
*/
public void addCache(
I_CmsGlobalConfigurationCache offlineCache,
I_CmsGlobalConfigurationCache onlineCache,
String debugName) {
CachePair cachePair = new CachePair(offlineCache, onlineCache, debugName);
m_caches.add(cachePair);
}
/**
* @see org.opencms.main.I_CmsEventListener#cmsEvent(org.opencms.main.CmsEvent)
*/
public void cmsEvent(CmsEvent event) {
CmsResource resource = null;
List resources = null;
List