/*
* 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 net.jcip.annotations.ThreadSafe;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.Lifecycle;
import org.jboss.cache.Modification;
import org.jboss.cache.RegionManager;
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* A {@link org.jboss.cache.loader.CacheLoader} implementation persists and load keys to and from
* secondary storage, such as a database or filesystem. Typically,
* implementations store a series of keys and values (an entire {@link Map})
* under a single {@link Fqn}. Loading and saving properties of an entire
* {@link Map} should be atomic.
*
* Lifecycle: First an instance of the loader is created, then the
* configuration ({@link #setConfig(org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig)}) and cache ({@link
* #setCache(CacheSPI)}) are set. After this, {@link #create()} is called.
* Then {@link #start()} is called. When re-deployed, {@link #stop()} will be
* called, followed by another {@link #start()}. Finally, when shut down,
* {@link #destroy()} is called, after which the loader is unusable.
*
* An {@link org.jboss.cache.loader.AbstractCacheLoader} is provided as a convenient starting place
* when implementing your own {@link org.jboss.cache.loader.CacheLoader}.
*
* It is important to note that all implementations are thread safe, as concurrent reads and writes, potentially even to
* the same {@link Fqn}, are possible.
*
*
* @author Manik Surtani (manik AT jboss DOT org)
* @see CacheSPI
* @see org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig
* @see org.jboss.cache.loader.AbstractCacheLoader
* @since 2.0.0
*/
@ThreadSafe
public interface CacheLoader extends Lifecycle
{
/**
* Sets the configuration. This is called before {@link #create()} and {@link #start()}.
*
* @param config May be an instance of the {@link org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig} base
* class, in which case the cache loader should use the
* {@link org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig#getProperties()}
* method to find configuration information. Alternatively,
* may be a type-specific subclass of {@link org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig},
* if there is one.
*/
void setConfig(IndividualCacheLoaderConfig config);
/**
* Gets the configuration.
*
* @return the configuration, represented by a {@link org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig} object.
*/
IndividualCacheLoaderConfig getConfig();
/**
* Sets the {@link CacheSPI} that is maintaining this CacheLoader.
* This method allows this CacheLoader to set a reference to the {@link CacheSPI}.
* This method is called be called after the CacheLoader instance has been constructed.
*
* @param c The cache on which this loader works
*/
void setCache(CacheSPI c);
/**
* Returns a set of children node names.
* All names are relative to this parent {@link Fqn}.
* Returns null if the named node is not found or there are no children.
* The returned set must not be modifiable. Implementors can use
* {@link java.util.Collections#unmodifiableSet(java.util.Set)} to make the set unmodifiable.
*
* Implementors may impose restrictions on the contents of an Fqn (such as Strings-only) and as such, indirectly
* impose the same restriction on the contents of a Set returned by getChildrenNames().
*
*
* @param fqn The {@link Fqn} of the parent
* @return Set a set of children. Returns null if no children nodes are
* present, or the parent is not present
*/
Set> getChildrenNames(Fqn fqn) throws Exception;
/**
* Returns all keys and values from the persistent store, given a {@link org.jboss.cache.Fqn}
*
* @param name the {@link Fqn} to search for.
* @return Map