/*
* JBoss, Home of Professional Open Source.
* Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.cache;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.ConfigurationRegistry;
import org.jboss.cache.config.XmlParsingConfigurationRegistry;
import org.jgroups.ChannelFactory;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
/**
* Basic implementation of {@link CacheManager}.
*
* @author Brian Stansberry
* @version $Revision: 1.1 $
*/
public class CacheManagerImpl implements CacheManager
{
private ConfigurationRegistry configRegistry;
private boolean configRegistryInjected;
private final Map> caches = new HashMap>();
private final Map checkouts = new HashMap();
private ChannelFactory channelFactory;
private boolean started;
/**
* Create a new CacheRegistryImpl.
*/
public CacheManagerImpl()
{
}
/**
* Create a new CacheRegistryImpl using the provided ConfigurationRegistry
* and ChannelFactory.
*/
public CacheManagerImpl(ConfigurationRegistry configRegistry, ChannelFactory factory)
{
this.configRegistry = configRegistry;
this.configRegistryInjected = true;
this.channelFactory = factory;
}
/**
* Create a new CacheRegistryImpl using the provided ChannelFactory and
* using the provided file name to create an
* {@link XmlParsingConfigurationRegistry}.
*/
public CacheManagerImpl(String configFileName, ChannelFactory factory)
{
configRegistry = new XmlParsingConfigurationRegistry(configFileName);
this.channelFactory = factory;
}
// ---------------------------------------------------------- CacheRegistry
public ChannelFactory getChannelFactory()
{
return channelFactory;
}
public Set getConfigurationNames()
{
synchronized (caches)
{
Set configNames = configRegistry == null ? new HashSet()
: configRegistry.getConfigurationNames();
configNames.addAll(getCacheNames());
return configNames;
}
}
public Set getCacheNames()
{
synchronized (caches)
{
return new HashSet(caches.keySet());
}
}
public Cache