/*
* 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.loader;
import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
import org.jboss.cache.RegionManager;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
import org.jboss.cache.factories.ComponentRegistry;
import org.jboss.cache.factories.annotations.Inject;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* This decorator is used whenever more than one cache loader is configured. READ operations are directed to
* each of the cache loaders (in the order which they were configured) until a non-null (or non-empty in the case
* of retrieving collection objects) result is achieved.
*
* WRITE operations are propagated to ALL registered cacheloaders that specified set ignoreModifications to false.
*
* @author Manik Surtani (manik AT jboss DOT org)
*/
public class ChainingCacheLoader extends AbstractCacheLoader
{
private final List cacheLoaders = new ArrayList(2);
private final List writeCacheLoaders = new ArrayList(2);
private final List cacheLoaderConfigs = new ArrayList(2);
private ComponentRegistry registry;
/**
* Sets the configuration. Will be called before {@link #create()} and {@link #start()}
*
* @param config ignored
*/
public void setConfig(IndividualCacheLoaderConfig config)
{
// don't do much here?
}
public IndividualCacheLoaderConfig getConfig()
{
return null;
}
@Inject
public void injectDependencies(ComponentRegistry registry)
{
this.registry = registry;
}
/**
* Returns a list of children names, all names are relative. Returns null if the parent node is not found.
* The returned set must not be modified, e.g. use Collections.unmodifiableSet(s) to return the result
*
* @param fqn The FQN of the parent
* @return Set>. A list of children. Returns null if no children nodes are present, or the parent is
* not present
*/
public Set> getChildrenNames(Fqn fqn) throws Exception
{
Set> answer = null;
for (CacheLoader l : cacheLoaders)
{
answer = l.getChildrenNames(fqn);
if (answer != null && answer.size() > 0) break;
}
return answer;
}
/**
* Returns all keys and values from the persistent store, given a fully qualified name
*
* @param name
* @return Map