/* * 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.CacheSPI; import org.jboss.cache.Fqn; import org.jboss.cache.Node; import org.jboss.cache.NodeSPI; import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.Collections; import java.util.Map; import java.util.Set; /** * DelegatingCacheLoader implementation which delegates to a local (in the same VM) CacheImpl. Sample code: *
* CacheImpl firstLevel=new CacheImpl(); * CacheImpl secondLevel=new CacheImpl(); * DelegatingCacheLoader l=new DelegatingCacheLoader(secondLevel); * l.setCache(firstLevel); * firstLevel.setCacheLoader(l); * secondLevel.start(); * firstLevel.start(); ** * @author Bela Ban * @author Daniel Gredler * */ public class LocalDelegatingCacheLoader extends AbstractCacheLoader { IndividualCacheLoaderConfig config; CacheSPI delegate = null; public void setConfig(IndividualCacheLoaderConfig config) { this.config = config; if (config instanceof LocalDelegatingCacheLoaderConfig) { delegate = (CacheSPI) ((LocalDelegatingCacheLoaderConfig) config).getDelegate(); } } public IndividualCacheLoaderConfig getConfig() { return config; } public Set> getChildrenNames(Fqn fqn) throws Exception { Node node = delegate.getRoot().getChild(fqn); if (node == null) return null; Set cn = node.getChildrenNames(); // the cache loader contract is a bit different from the cache when it comes to dealing with childrenNames if (cn.isEmpty()) return null; return cn; } public Map