JBoss Cache SVN: r4686 - core/trunk/src/test/resources/META-INF.
by jbosscache-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2007-10-25 02:00:40 -0400 (Thu, 25 Oct 2007)
New Revision: 4686
Added:
core/trunk/src/test/resources/META-INF/jbc2-configs.xml
Log:
[JBCACHE-1156] Test of registry for caches and configurations
Added: core/trunk/src/test/resources/META-INF/jbc2-configs.xml
===================================================================
(Binary files differ)
Property changes on: core/trunk/src/test/resources/META-INF/jbc2-configs.xml
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
18 years
JBoss Cache SVN: r4685 - in core/trunk/src/test/java/org/jboss/cache: registry and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2007-10-25 01:59:28 -0400 (Thu, 25 Oct 2007)
New Revision: 4685
Added:
core/trunk/src/test/java/org/jboss/cache/registry/
core/trunk/src/test/java/org/jboss/cache/registry/CacheRegistryTest.java
Log:
[JBCACHE-1156] Test of registry for caches and configurations
Added: core/trunk/src/test/java/org/jboss/cache/registry/CacheRegistryTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/registry/CacheRegistryTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/registry/CacheRegistryTest.java 2007-10-25 05:59:28 UTC (rev 4685)
@@ -0,0 +1,141 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.cache.registry;
+
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertNull;
+import static org.testng.AssertJUnit.assertTrue;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheStatus;
+import org.jboss.cache.config.Configuration;
+import org.jgroups.JChannelFactory;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Tests CacheRegistryImpl.
+ *
+ * @author Brian Stansberry
+ */
+@Test(groups = {"functional"})
+public class CacheRegistryTest
+{
+ /** A file that includes every configuration element I could think of */
+ public static final String DEFAULT_CONFIGURATION_FILE = "META-INF/jbc2-configs.xml";
+
+ private Set<Cache<Object, Object>> caches = new HashSet<Cache<Object, Object>>();
+
+ @AfterMethod(alwaysRun = true)
+ public void tearDown() throws Exception
+ {
+ for (Cache<Object, Object> cache : caches)
+ {
+ try
+ {
+ cache.stop();
+ cache.destroy();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.out);
+ }
+ }
+ }
+
+ /**
+ * A test that instantiates a CacheRegistryImpl and cycles through all its
+ * configs, creating and releasing each.
+ *
+ * TODO It's late; I just put a bunch of stuff in one test method.
+ * Refactor or something.
+ *
+ * @throws Exception
+ */
+ public void testBasic() throws Exception
+ {
+ JChannelFactory cf = new JChannelFactory();
+ cf.setMultiplexerConfig("stacks.xml"); // the default stacks in jgroups.jar
+ CacheRegistryImpl registry = new CacheRegistryImpl(DEFAULT_CONFIGURATION_FILE, cf);
+ registry.start();
+
+ ConfigurationRegistry configRegistry = registry.getConfigurationRegistry();
+
+ Set<String> configNames = registry.getConfigurationNames();
+ assertEquals(7, configNames.size());
+ Set<String> cacheNames = registry.getCacheNames();
+ assertEquals(0, cacheNames.size());
+
+ for (String configName : configNames)
+ {
+ assertNull(configName + " not created", registry.getCache(configName, false));
+ Cache<Object, Object> cache = registry.getCache(configName, true);
+ caches.add(cache);
+ assertEquals(CacheStatus.INSTANTIATED, cache.getCacheStatus());
+ cache.create();
+ cache.start();
+ Configuration rawConfig = configRegistry.getConfiguration(configName);
+ Configuration realConfig = cache.getConfiguration();
+ assertFalse(rawConfig == realConfig);
+ assertEquals(rawConfig.getClusterName(), realConfig.getClusterName());
+ }
+
+ cacheNames = registry.getCacheNames();
+ assertEquals(configNames, cacheNames);
+
+ for (String configName : configNames)
+ {
+ registry.releaseCache(configName);
+ }
+
+ cacheNames = registry.getCacheNames();
+ assertEquals(0, cacheNames.size());
+
+ Set<String> configNames2 = registry.getConfigurationNames();
+ assertEquals(configNames, configNames2);
+
+ for (Iterator<Cache<Object, Object>> it = caches.iterator(); it.hasNext();)
+ {
+ assertEquals(CacheStatus.DESTROYED, it.next().getCacheStatus());
+ it.remove();
+ }
+
+ String configName = configNames.iterator().next();
+ assertNull(configName + " not created", registry.getCache(configName, false));
+ Cache<Object, Object> cache = registry.getCache(configName, true);
+ assertFalse(null == cache);
+ caches.add(cache);
+
+ cache.create();
+ cache.start();
+
+ Cache<Object, Object> cache2 = registry.getCache(configName, true);
+
+ assertTrue(cache == cache2);
+
+ registry.releaseCache(configName);
+
+ // One release does not cause registry to stop cache
+ assertEquals(CacheStatus.STARTED, cache.getCacheStatus());
+
+ registry.stop();
+
+ // Now it's stopped
+ assertEquals(CacheStatus.DESTROYED, cache.getCacheStatus());
+ caches.remove(cache);
+
+ cacheNames = registry.getCacheNames();
+ assertEquals(0, cacheNames.size());
+ assertEquals(cacheNames, registry.getConfigurationNames());
+ }
+}
18 years
JBoss Cache SVN: r4684 - in core/trunk/src/main/java/org/jboss/cache: registry and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2007-10-25 01:59:01 -0400 (Thu, 25 Oct 2007)
New Revision: 4684
Added:
core/trunk/src/main/java/org/jboss/cache/registry/
core/trunk/src/main/java/org/jboss/cache/registry/CacheConfigsXmlParser.java
core/trunk/src/main/java/org/jboss/cache/registry/CacheRegistry.java
core/trunk/src/main/java/org/jboss/cache/registry/CacheRegistryImpl.java
core/trunk/src/main/java/org/jboss/cache/registry/ConfigurationRegistry.java
core/trunk/src/main/java/org/jboss/cache/registry/XmlParsingConfigurationRegistry.java
Log:
[JBCACHE-1156] Registry for caches and configurations
Added: core/trunk/src/main/java/org/jboss/cache/registry/CacheConfigsXmlParser.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/registry/CacheConfigsXmlParser.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/registry/CacheConfigsXmlParser.java 2007-10-25 05:59:01 UTC (rev 4684)
@@ -0,0 +1,122 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.registry;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.ConfigurationException;
+import org.jboss.cache.factories.XmlConfigurationParser;
+import org.jboss.cache.xml.XmlHelper;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class CacheConfigsXmlParser
+ {
+ /** Name of the root element in a cache configs XML document*/
+ public static final String DOCUMENT_ROOT = "cache-configs";
+ /**
+ * Name of the element that represents an individual cache configuration
+ * in a cache configs XML document.
+ */
+ public static final String CONFIG_ROOT = "cache-config";
+ /**
+ * Name of the attribute in a {@link #CONFIG_ROOT cache-config} element that specifies
+ * the name of the configuration.
+ */
+ public static final String CONFIG_NAME = "name";
+
+ private static final Log log = LogFactory.getLog(CacheConfigsXmlParser.class);
+
+ private final XmlConfigurationParser parser = new XmlConfigurationParser();
+
+ public Map<String, Configuration> parseConfigs(String fileName) throws CloneNotSupportedException
+ {
+ InputStream is = getAsInputStreamFromClassLoader(fileName);
+ if (is == null)
+ {
+ if (log.isDebugEnabled())
+ log.debug("Unable to find configuration file " + fileName + " in classpath; searching for this file on the filesystem instead.");
+ try
+ {
+ is = new FileInputStream(fileName);
+ }
+ catch (FileNotFoundException e)
+ {
+ throw new ConfigurationException("Unable to find config file " + fileName + " either in classpath or on the filesystem!", e);
+ }
+ }
+
+ return parseConfigs(is);
+ }
+
+ public Map<String, Configuration> parseConfigs(InputStream stream) throws CloneNotSupportedException
+ {
+ // loop through all elements in XML.
+ Element root = XmlHelper.getDocumentRoot(stream);
+ NodeList list = root.getElementsByTagName(CONFIG_ROOT);
+ if (list == null || list.getLength() == 0)
+ throw new ConfigurationException("Can't find " + CONFIG_ROOT + " tag");
+
+ Map<String, Configuration> result = new HashMap<String, Configuration>();
+
+ for (int i = 0; i < list.getLength(); i++)
+ {
+ Node node = list.item(i);
+ if (node.getNodeType() != Node.ELEMENT_NODE)
+ {
+ continue;
+ }
+
+ Element element = (Element) node;
+ String name = element.getAttribute(CONFIG_NAME);
+ if (name == null || name.trim().length() == 0)
+ throw new ConfigurationException("Element " + element + " has no name attribute");
+
+ Configuration c = parser.parseConfiguration(element);
+ // Prove that we can successfully clone it
+ c = c.clone();
+ result.put(name.trim(), c);
+ }
+
+ return result;
+ }
+
+ protected InputStream getAsInputStreamFromClassLoader(String filename)
+ {
+ InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename);
+ if (is == null)
+ {
+ // check system class loader
+ is = getClass().getClassLoader().getResourceAsStream(filename);
+ }
+ return is;
+ }
+ }
\ No newline at end of file
Property changes on: core/trunk/src/main/java/org/jboss/cache/registry/CacheConfigsXmlParser.java
___________________________________________________________________
Name: svn:executable
+ *
Added: core/trunk/src/main/java/org/jboss/cache/registry/CacheRegistry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/registry/CacheRegistry.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/registry/CacheRegistry.java 2007-10-25 05:59:01 UTC (rev 4684)
@@ -0,0 +1,95 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
+package org.jboss.cache.registry;
+
+import java.util.Set;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.config.Configuration;
+import org.jgroups.ChannelFactory;
+import org.jgroups.JChannelFactory;
+
+/**
+ * Factory and registry for JBoss Cache instances configured using
+ * named configurations.
+ *
+ * @author <a href="brian.stansberry(a)jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1 $
+ */
+public interface CacheRegistry {
+
+ /**
+ * Gets the names of all the configurations of which this object
+ * is aware.
+ *
+ * @return a set of names. Will not be <code>null</code>.
+ */
+ Set<String> getConfigurationNames();
+
+ /**
+ * Gets the name of all caches that are registered, i.e. that can be
+ * by a call to {@link #getCache(String, boolean) getCache(name, false)}.
+ *
+ * @return a set of names. Will not be <code>null</code>.
+ */
+ Set<String> getCacheNames();
+
+ /**
+ * Gets the JGroups <code>ChannelFactory</code> that will be injected
+ * into any {@link Configuration} that has a
+ * {@link Configuration#getMultiplexerStack() multiplexer stack}
+ * configured.
+ *
+ * @return
+ */
+ ChannelFactory getChannelFactory();
+
+ /**
+ * Get a cache configured according to the given configuration name,
+ * optionally instantiating the cache if it hasn't already been
+ * instantiated.
+ * <p>
+ * The caller is free to invoke the {@link Cache#create()} and
+ * {@link Cache#start()} lifecycle methods on the returned cache, but
+ * the @link Cache#stop()} and {@link Cache#destroy()} methods should not
+ * be invoked, since it is quite possible other users are still using the
+ * cache. Use {@link #releaseCache(String)} to notify this
+ * registry that the caller is no longer using a cache; let the registry
+ * control stopping and destroying the cache.
+ * </p>
+ * <p>
+ * If invoking this method leads to the instantiation of the cache,
+ * <code>create()</code> and <code>start()</code> will not be invoked
+ * on the cache before it is returned.
+ * </p>
+ *
+ * @param configName the name of the configuration
+ * @param create should the cache be instantiated if it
+ * hasn't already been?
+ * @return the cache, or <code>null</code> if
+ * <code>create</code> is false and the cache hasn't
+ * been created previously.
+ *
+ * @throws IllegalArgumentException if this object is unaware of
+ * <code>configName</code>; i.e. the set
+ * returned from {@link #getConfigurationNames()}
+ * does not include <code>configName</code>
+ * @throws Exception if there is a problem instantiating the cache
+ */
+ Cache<Object, Object> getCache(String configName, boolean create) throws Exception;
+
+ /**
+ * Notifies the registry that the caller is no longer using the given
+ * cache. The registry may perform cleanup operations, such as
+ * stopping and destroying the cache.
+ *
+ * @param configName
+ */
+ void releaseCache(String configName);
+
+}
\ No newline at end of file
Property changes on: core/trunk/src/main/java/org/jboss/cache/registry/CacheRegistry.java
___________________________________________________________________
Name: svn:executable
+ *
Added: core/trunk/src/main/java/org/jboss/cache/registry/CacheRegistryImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/registry/CacheRegistryImpl.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/registry/CacheRegistryImpl.java 2007-10-25 05:59:01 UTC (rev 4684)
@@ -0,0 +1,257 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Brian Stansberry
+ */
+
+package org.jboss.cache.registry;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheStatus;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.config.Configuration;
+import org.jgroups.ChannelFactory;
+
+/**
+ * Basic implementation of {@link CacheRegistry}.
+ *
+ * @author <a href="brian.stansberry(a)jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1 $
+ */
+public class CacheRegistryImpl implements CacheRegistry
+{
+ private ConfigurationRegistry configRegistry;
+
+ private boolean configRegistryInjected;
+
+ private Map<String, Cache<Object, Object>> caches = new HashMap<String, Cache<Object, Object>>();
+
+ private Map<String, Integer> checkouts = new HashMap<String, Integer>();
+
+ private ChannelFactory channelFactory;
+
+ private boolean started;
+
+ /**
+ * Create a new CacheRegistryImpl.
+ */
+ public CacheRegistryImpl()
+ {
+ }
+
+ /**
+ * Create a new CacheRegistryImpl using the provided ConfigurationRegistry
+ * and ChannelFactory.
+ */
+ public CacheRegistryImpl(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 CacheRegistryImpl(String configFileName, ChannelFactory factory)
+ {
+ configRegistry = new XmlParsingConfigurationRegistry(configFileName);
+ this.channelFactory = factory;
+ }
+
+ // ---------------------------------------------------------- CacheRegistry
+
+ public ChannelFactory getChannelFactory()
+ {
+ return channelFactory;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Set<String> getConfigurationNames()
+ {
+ synchronized (caches)
+ {
+ Set<String> configNames = configRegistry == null ? new HashSet<String>()
+ : configRegistry.getConfigurationNames();
+ configNames.addAll(getCacheNames());
+ return configNames;
+ }
+ }
+
+ public Set<String> getCacheNames()
+ {
+ synchronized (caches)
+ {
+ return new HashSet<String>(caches.keySet());
+ }
+ }
+
+ public Cache<Object, Object> getCache(String configName, boolean create) throws Exception
+ {
+ Cache<Object, Object> cache = null;
+ synchronized (caches)
+ {
+ cache = (Cache<Object, Object>) caches.get(configName);
+ if (cache == null && create)
+ {
+ Configuration config = configRegistry.getConfiguration(configName);
+ if (channelFactory != null && config.getMultiplexerStack() != null) {
+ config.getRuntimeConfig().setMuxChannelFactory(channelFactory);
+ }
+ cache = DefaultCacheFactory.getInstance().createCache(config, false);
+ registerCache(cache, configName);
+ }
+ else if (cache != null)
+ {
+ incrementCheckout(configName);
+ }
+ }
+
+ return cache;
+ }
+
+ public void releaseCache(String configName)
+ {
+ synchronized (caches)
+ {
+ if (!caches.containsKey(configName))
+ throw new IllegalStateException(configName + " not registered");
+ if (decrementCheckout(configName) == 0)
+ {
+ Cache<Object, Object> cache = caches.remove(configName);
+ destroyCache(cache);
+ }
+ }
+ }
+
+ // ----------------------------------------------------------------- Public
+
+ public ConfigurationRegistry getConfigurationRegistry()
+ {
+ return configRegistry;
+ }
+
+ public void setConfigurationRegistry(ConfigurationRegistry configRegistry)
+ {
+ this.configRegistry = configRegistry;
+ this.configRegistryInjected = true;
+ }
+
+ public void setChannelFactory(ChannelFactory channelFactory)
+ {
+ this.channelFactory = channelFactory;
+ }
+
+ public void registerCache(Cache<Object, Object> cache, String configName)
+ {
+ synchronized (caches)
+ {
+ if (caches.containsKey(configName))
+ throw new IllegalStateException(configName + " already registered");
+ caches.put(configName, cache);
+ incrementCheckout(configName);
+ }
+ }
+
+ public void start() throws Exception
+ {
+ if (!started)
+ {
+ if (configRegistry == null)
+ throw new IllegalStateException("Must configure a ConfigurationRegistry before calling start()");
+ if (channelFactory == null)
+ throw new IllegalStateException("Must provide a ChannelFactory before calling start()");
+
+ if (!configRegistryInjected)
+ {
+ ((XmlParsingConfigurationRegistry) configRegistry).start();
+ }
+
+ started = true;
+ }
+ }
+
+ public void stop()
+ {
+ if (started)
+ {
+ synchronized (caches)
+ {
+ for (Iterator<Map.Entry<String, Cache<Object, Object>>> it = caches.entrySet().iterator(); it.hasNext();)
+ {
+ Map.Entry<String, Cache<Object, Object>> entry = it.next();
+ destroyCache(entry.getValue());
+ it.remove();
+ }
+ caches.clear();
+ checkouts.clear();
+ }
+
+ if (!configRegistryInjected)
+ {
+ ((XmlParsingConfigurationRegistry) configRegistry).stop();
+ }
+
+ started = false;
+ }
+ }
+
+ // ---------------------------------------------------------------- Private
+
+ private int incrementCheckout(String configName)
+ {
+ synchronized (checkouts)
+ {
+ Integer count = (Integer) checkouts.get(configName);
+ if (count == null)
+ count = new Integer(0);
+ Integer newVal = new Integer(count.intValue() + 1);
+ checkouts.put(configName, newVal);
+ return newVal.intValue();
+ }
+ }
+
+ private int decrementCheckout(String configName)
+ {
+ synchronized (checkouts)
+ {
+ Integer count = (Integer) checkouts.get(configName);
+ if (count == null || count.intValue() < 1)
+ throw new IllegalStateException("invalid count of " + count + " for " + configName);
+
+ Integer newVal = new Integer(count.intValue() - 1);
+ checkouts.put(configName, newVal);
+ return newVal.intValue();
+ }
+ }
+
+ private void destroyCache(Cache<Object, Object> cache)
+ {
+ if (cache.getCacheStatus() == CacheStatus.STARTED)
+ {
+ cache.stop();
+ }
+ if (cache.getCacheStatus() != CacheStatus.DESTROYED && cache.getCacheStatus() != CacheStatus.INSTANTIATED)
+ {
+ cache.destroy();
+ }
+ }
+}
Property changes on: core/trunk/src/main/java/org/jboss/cache/registry/CacheRegistryImpl.java
___________________________________________________________________
Name: svn:executable
+ *
Added: core/trunk/src/main/java/org/jboss/cache/registry/ConfigurationRegistry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/registry/ConfigurationRegistry.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/registry/ConfigurationRegistry.java 2007-10-25 05:59:01 UTC (rev 4684)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.cache.registry;
+
+import java.util.Set;
+
+import org.jboss.cache.config.Configuration;
+
+/**
+ * A registry for {@link Configuration}s.
+ *
+ * @author Brian Stansberry
+ * @version $Revision$
+ */
+public interface ConfigurationRegistry
+{
+ /**
+ * Gets a {@link Configuration#clone() clone} of the {@link Configuration}
+ * registered under the given name.
+ * <p>
+ * The returned object is a clone of the internally held configuration,
+ * so any changes made to it by the caller will not affect the internal
+ * state of this registry.
+ *
+ * @param configName the name of the configuration
+ * @return a <code>Configuration</code>. Will not be <code>null</code>.
+ * @throws IllegalArgumentException if no configuration is registered
+ * under <code>configName</code>
+ */
+ Configuration getConfiguration(String configName) throws Exception;
+
+ /**
+ * Register the given configuration under the given name.
+ * <p>
+ * The configuration will be cloned before being stored internally,
+ * so the copy under the control of the registry will not be affected
+ * by any external changes.
+ *
+ * @param configName the name of the configuration
+ * @param config the configuration
+ *
+ * @throws CloneNotSupportedException
+ * @throws IllegalStateException if a configuration is already registered
+ * under <code>configName</code>
+ */
+ void registerConfiguration(String configName, Configuration config) throws CloneNotSupportedException;
+
+ /**
+ * Unregisters the named configuration.
+ *
+ * @param configName the name of the configuration
+ * @throws IllegalStateException if no configuration is registered
+ * under <code>configName</code>
+ */
+ void unregisterConfiguration(String configName);
+
+ /**
+ * Gets the names of all registered configurations.
+ *
+ * @return
+ */
+ Set<String> getConfigurationNames();
+}
\ No newline at end of file
Property changes on: core/trunk/src/main/java/org/jboss/cache/registry/ConfigurationRegistry.java
___________________________________________________________________
Name: svn:executable
+ *
Added: core/trunk/src/main/java/org/jboss/cache/registry/XmlParsingConfigurationRegistry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/registry/XmlParsingConfigurationRegistry.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/registry/XmlParsingConfigurationRegistry.java 2007-10-25 05:59:01 UTC (rev 4684)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
+package org.jboss.cache.registry;
+
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.cache.config.Configuration;
+
+/**
+ * {@link ConfigurationRegistry} that obtains its initial set of configurations
+ * by parsing an XML document.
+ *
+ * @author <a href="brian.stansberry(a)jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1 $
+ */
+public class XmlParsingConfigurationRegistry implements ConfigurationRegistry
+{
+ private CacheConfigsXmlParser parser;
+ private String configResource;
+ private Map<String, Configuration> configs = new Hashtable<String, Configuration>();
+ private boolean started;
+
+ public XmlParsingConfigurationRegistry(String configResource)
+ {
+ parser = new CacheConfigsXmlParser();
+ this.configResource = configResource;
+ }
+
+ public void start() throws Exception
+ {
+ if (!started)
+ {
+ configs.putAll(parser.parseConfigs(configResource));
+ started = true;
+ }
+ }
+
+ public void stop()
+ {
+ if (started)
+ {
+ synchronized (configs)
+ {
+ configs.clear();
+ }
+ started = false;
+ }
+ }
+
+ public String getConfigResource()
+ {
+ return configResource;
+ }
+
+ public Set<String> getConfigurationNames()
+ {
+ return new HashSet<String>(configs.keySet());
+ }
+
+ public void registerConfiguration(String configName, Configuration config)
+ throws CloneNotSupportedException
+ {
+ synchronized (configs) {
+ if (configs.containsKey(configName))
+ throw new IllegalStateException(configName + " already registered");
+ configs.put(configName, config.clone());
+ }
+ }
+
+ public void unregisterConfiguration(String configName)
+ {
+ synchronized (configs) {
+ if (configs.remove(configName) == null)
+ throw new IllegalStateException(configName + " not registered");
+ }
+ }
+
+ public Configuration getConfiguration(String configName)
+ {
+ Configuration config = null;
+ synchronized (configs)
+ {
+ config = configs.get(configName);
+ }
+
+ if (config == null)
+ throw new IllegalArgumentException("unknown config " + configName);
+
+ // Don't hand out a ref to our master copy
+ try
+ {
+ return config.clone();
+ }
+ catch (CloneNotSupportedException e)
+ {
+ // This should not happen, as we already cloned the config
+ throw new RuntimeException("Could not clone configuration " + configName, e);
+ }
+ }
+}
Property changes on: core/trunk/src/main/java/org/jboss/cache/registry/XmlParsingConfigurationRegistry.java
___________________________________________________________________
Name: svn:executable
+ *
18 years
JBoss Cache SVN: r4683 - core/trunk/src/main/java/org/jboss/cache/factories.
by jbosscache-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2007-10-25 01:57:46 -0400 (Thu, 25 Oct 2007)
New Revision: 4683
Modified:
core/trunk/src/main/java/org/jboss/cache/factories/XmlConfigurationParser.java
Log:
[JBCACHE-1156] Expose a method to parse a Configuration from the containing Element
Modified: core/trunk/src/main/java/org/jboss/cache/factories/XmlConfigurationParser.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/XmlConfigurationParser.java 2007-10-24 21:58:48 UTC (rev 4682)
+++ core/trunk/src/main/java/org/jboss/cache/factories/XmlConfigurationParser.java 2007-10-25 05:57:46 UTC (rev 4683)
@@ -90,7 +90,12 @@
Element root = XmlHelper.getDocumentRoot(stream);
Element mbeanElement = getMBeanElement(root);
- ParsedAttributes attributes = extractAttributes(mbeanElement);
+ return parseConfiguration(mbeanElement);
+ }
+
+ public Configuration parseConfiguration(Element configurationRoot)
+ {
+ ParsedAttributes attributes = extractAttributes(configurationRoot);
// Deal with legacy attributes we no longer support
handleRemovedAttributes(attributes);
@@ -103,7 +108,7 @@
// Special handling for XML elements -- we hard code the parsing
setXmlValues(c, attributes.xmlAttribs);
- return c;
+ return c;
}
/**
18 years
JBoss Cache SVN: r4682 - in core/trunk/src: main/java/org/jboss/cache/config and 7 other directories.
by jbosscache-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2007-10-24 17:58:48 -0400 (Wed, 24 Oct 2007)
New Revision: 4682
Added:
core/trunk/src/main/resources/META-INF/clonable-config-service.xml
core/trunk/src/test/java/org/jboss/cache/config/ConfigurationCloningTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/buddyreplication/NextMemberBuddyLocatorConfig.java
core/trunk/src/main/java/org/jboss/cache/config/BuddyReplicationConfig.java
core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java
core/trunk/src/main/java/org/jboss/cache/config/Configuration.java
core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java
core/trunk/src/main/java/org/jboss/cache/config/EvictionRegionConfig.java
core/trunk/src/main/java/org/jboss/cache/config/RuntimeConfig.java
core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeConfiguration.java
core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationConfiguration.java
core/trunk/src/main/java/org/jboss/cache/eviction/FIFOConfiguration.java
core/trunk/src/main/java/org/jboss/cache/eviction/LFUConfiguration.java
core/trunk/src/main/java/org/jboss/cache/eviction/LRUConfiguration.java
core/trunk/src/main/java/org/jboss/cache/eviction/MRUConfiguration.java
core/trunk/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderConfig.java
core/trunk/src/main/java/org/jboss/cache/loader/AsyncCacheLoaderConfig.java
core/trunk/src/main/java/org/jboss/cache/loader/ClusteredCacheLoaderConfig.java
core/trunk/src/main/java/org/jboss/cache/loader/FileCacheLoaderConfig.java
core/trunk/src/main/java/org/jboss/cache/loader/TcpDelegatingCacheLoaderConfig.java
core/trunk/src/main/java/org/jboss/cache/loader/bdbje/BdbjeCacheLoaderConfig.java
core/trunk/src/main/java/org/jboss/cache/loader/jdbm/JdbmCacheLoaderConfig.java
core/trunk/src/test/java/org/jboss/cache/eviction/DummyEvictionConfiguration.java
Log:
[JBCACHE-1206] Improve cloning of configuration elements
Modified: core/trunk/src/main/java/org/jboss/cache/buddyreplication/NextMemberBuddyLocatorConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/buddyreplication/NextMemberBuddyLocatorConfig.java 2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/buddyreplication/NextMemberBuddyLocatorConfig.java 2007-10-24 21:58:48 UTC (rev 4682)
@@ -84,6 +84,7 @@
}
}
+ @Override
public boolean equals(Object obj)
{
if (this == obj)
@@ -98,6 +99,7 @@
return false;
}
+ @Override
public int hashCode()
{
int result = 13;
@@ -106,5 +108,13 @@
return result;
}
+ @Override
+ public NextMemberBuddyLocatorConfig clone() throws CloneNotSupportedException
+ {
+ return (NextMemberBuddyLocatorConfig) super.clone();
+ }
+
+
+
}
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/config/BuddyReplicationConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/BuddyReplicationConfig.java 2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/config/BuddyReplicationConfig.java 2007-10-24 21:58:48 UTC (rev 4682)
@@ -162,6 +162,15 @@
return result;
}
+ @Override
+ public BuddyReplicationConfig clone() throws CloneNotSupportedException
+ {
+ BuddyReplicationConfig clone = (BuddyReplicationConfig) super.clone();
+ if (buddyLocatorConfig != null)
+ clone.setBuddyLocatorConfig(buddyLocatorConfig.clone());
+ return clone;
+ }
+
public static class BuddyLocatorConfig extends ConfigurationComponent
{
private static final long serialVersionUID = -8003634097931826091L;
@@ -226,5 +235,16 @@
" properties=" + buddyLocatorProperties;
}
+ @Override
+ public BuddyLocatorConfig clone() throws CloneNotSupportedException
+ {
+ BuddyLocatorConfig clone = (BuddyLocatorConfig) super.clone();
+ if (buddyLocatorProperties != null)
+ clone.buddyLocatorProperties = (Properties) buddyLocatorProperties.clone();
+ return clone;
+ }
+
+
+
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java 2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java 2007-10-24 21:58:48 UTC (rev 4682)
@@ -107,6 +107,7 @@
return shared;
}
+ @Override
public boolean equals(Object obj)
{
if (this == obj)
@@ -123,6 +124,7 @@
return false;
}
+ @Override
public int hashCode()
{
int result = 19;
@@ -132,8 +134,29 @@
result = 51 * result + (cacheLoaderConfigs == null ? 0 : cacheLoaderConfigs.hashCode());
return result;
}
+
+
+ @Override
+ public CacheLoaderConfig clone() throws CloneNotSupportedException
+ {
+ CacheLoaderConfig clone = (CacheLoaderConfig) super.clone();
+ if (cacheLoaderConfigs != null)
+ {
+ List<IndividualCacheLoaderConfig> clcs = new ArrayList<IndividualCacheLoaderConfig>(cacheLoaderConfigs.size());
+ for (IndividualCacheLoaderConfig clc : cacheLoaderConfigs)
+ {
+ clcs.add(clc.clone());
+ }
+ clone.setIndividualCacheLoaderConfigs(clcs);
+ }
+ return clone;
+ }
+
+
+
+
/**
* Configuration object that holds the confguration of an individual cache loader.
*
@@ -259,10 +282,12 @@
public void setSingletonStoreConfig(SingletonStoreConfig singletonStoreConfig)
{
- testImmutability("singletonStoreConfig");
+ testImmutability("singletonStoreConfig");
+ replaceChildConfig(this.singletonStoreConfig, singletonStoreConfig);
this.singletonStoreConfig = singletonStoreConfig;
}
+ @Override
public boolean equals(Object obj)
{
if (!(obj instanceof IndividualCacheLoaderConfig))
@@ -286,6 +311,7 @@
}
+ @Override
public int hashCode()
{
return 31 * hashCodeExcludingProperties() + (properties == null ? 0 : properties.hashCode());
@@ -303,6 +329,7 @@
return result;
}
+ @Override
public String toString()
{
return new StringBuffer().append("IndividualCacheLoaderConfig{").append("className='").append(className).append('\'')
@@ -314,7 +341,22 @@
.append("SingletonStoreConfig{").append(singletonStoreConfig).append('}')
.toString();
}
+
+
+ @Override
+ public IndividualCacheLoaderConfig clone() throws CloneNotSupportedException
+ {
+ IndividualCacheLoaderConfig clone = (IndividualCacheLoaderConfig) super.clone();
+ if (properties != null)
+ clone.properties = (Properties) properties.clone();
+ if (singletonStoreConfig != null)
+ clone.setSingletonStoreConfig(singletonStoreConfig.clone());
+ return clone;
+ }
+
+
+
/**
* Configuration for a SingletonStoreCacheLoader
*/
@@ -411,6 +453,17 @@
" class=" + singletonStoreClass +
" properties=" + singletonStoreproperties;
}
+
+ @Override
+ public SingletonStoreConfig clone() throws CloneNotSupportedException
+ {
+ SingletonStoreConfig clone = (SingletonStoreConfig) super.clone();
+ if (singletonStoreproperties != null)
+ clone.singletonStoreproperties = (Properties) singletonStoreproperties.clone();
+ return clone;
+ }
+
+
}
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/config/Configuration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/Configuration.java 2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/config/Configuration.java 2007-10-24 21:58:48 UTC (rev 4682)
@@ -754,19 +754,19 @@
Configuration c = (Configuration) super.clone();
if (buddyReplicationConfig != null)
{
- c.setBuddyReplicationConfig((BuddyReplicationConfig) buddyReplicationConfig.clone());
+ c.setBuddyReplicationConfig(buddyReplicationConfig.clone());
}
if (evictionConfig != null)
{
- c.setEvictionConfig((EvictionConfig) evictionConfig.clone());
+ c.setEvictionConfig(evictionConfig.clone());
}
if (cacheLoaderConfig != null)
{
- c.setCacheLoaderConfig((CacheLoaderConfig) cacheLoaderConfig.clone());
+ c.setCacheLoaderConfig(cacheLoaderConfig.clone());
}
if (runtimeConfig != null)
{
- c.setRuntimeConfig((RuntimeConfig) runtimeConfig.clone());
+ c.setRuntimeConfig(runtimeConfig.clone());
// always make sure we reset the runtime when cloning.
c.getRuntimeConfig().reset();
}
Modified: core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java 2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java 2007-10-24 21:58:48 UTC (rev 4682)
@@ -24,6 +24,7 @@
import org.jboss.cache.RegionManager;
import org.jboss.cache.eviction.EvictionPolicy;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -141,6 +142,7 @@
this.wakeupIntervalSeconds = wakeupIntervalSeconds;
}
+ @Override
public boolean equals(Object obj)
{
if (this == obj)
@@ -156,6 +158,7 @@
return false;
}
+ @Override
public int hashCode()
{
int result = 17;
@@ -164,4 +167,22 @@
result = 37 * result + (evictionRegionConfigs == null ? 0 : evictionRegionConfigs.hashCode());
return result;
}
+
+ @Override
+ public EvictionConfig clone() throws CloneNotSupportedException
+ {
+ EvictionConfig clone = (EvictionConfig) super.clone();
+ if (evictionRegionConfigs != null)
+ {
+ List<EvictionRegionConfig> ercs = new ArrayList<EvictionRegionConfig>(evictionRegionConfigs.size());
+ for (EvictionRegionConfig erc : evictionRegionConfigs)
+ {
+ ercs.add(erc.clone());
+ }
+ clone.setEvictionRegionConfigs(ercs);
+ }
+ return clone;
+ }
+
+
}
Modified: core/trunk/src/main/java/org/jboss/cache/config/EvictionRegionConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/EvictionRegionConfig.java 2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/config/EvictionRegionConfig.java 2007-10-24 21:58:48 UTC (rev 4682)
@@ -21,6 +21,8 @@
*/
package org.jboss.cache.config;
+import java.lang.reflect.Method;
+
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
@@ -136,5 +138,41 @@
return result;
}
+ @Override
+ public EvictionRegionConfig clone() throws CloneNotSupportedException
+ {
+ EvictionRegionConfig clone = (EvictionRegionConfig) super.clone();
+ if (evictionPolicyConfig != null)
+ {
+ if (!(evictionPolicyConfig instanceof Cloneable))
+ {
+ throw new CloneNotSupportedException(evictionPolicyConfig + " is not Cloneable");
+ }
+
+ if (evictionPolicyConfig instanceof ConfigurationComponent)
+ {
+ clone.setEvictionPolicyConfig((EvictionPolicyConfig) ((ConfigurationComponent) evictionPolicyConfig).clone());
+ }
+ else {
+ try
+ {
+ Method cloneMethod = evictionPolicyConfig.getClass().getDeclaredMethod("clone", new Class[]{});
+ EvictionPolicyConfig epc = (EvictionPolicyConfig) cloneMethod.invoke(evictionPolicyConfig, new Object[]{});
+ clone.setEvictionPolicyConfig(epc);
+ }
+ catch (Exception e)
+ {
+ CloneNotSupportedException cnse = new CloneNotSupportedException("Cannot invoke clone() on " + evictionPolicyConfig);
+ cnse.initCause(e);
+ throw cnse;
+ }
+ }
+ }
+
+ return clone;
+ }
+
+
+
}
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/config/RuntimeConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/RuntimeConfig.java 2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/config/RuntimeConfig.java 2007-10-24 21:58:48 UTC (rev 4682)
@@ -193,4 +193,12 @@
{
return rpcManager;
}
+
+ @Override
+ public RuntimeConfig clone() throws CloneNotSupportedException
+ {
+ return (RuntimeConfig) super.clone();
+ }
+
+
}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeConfiguration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeConfiguration.java 2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeConfiguration.java 2007-10-24 21:58:48 UTC (rev 4682)
@@ -108,4 +108,12 @@
super.reset();
setMaxElementsPerNode(-1);
}
+
+ @Override
+ public ElementSizeConfiguration clone() throws CloneNotSupportedException
+ {
+ return (ElementSizeConfiguration) super.clone();
+ }
+
+
}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationConfiguration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationConfiguration.java 2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationConfiguration.java 2007-10-24 21:58:48 UTC (rev 4682)
@@ -79,6 +79,14 @@
public void setTimeToLiveSeconds(int timeToLiveSeconds)
{
this.timeToLiveSeconds = timeToLiveSeconds;
+ }
+
+ @Override
+ public ExpirationConfiguration clone() throws CloneNotSupportedException
+ {
+ return (ExpirationConfiguration) super.clone();
}
+
+
}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/FIFOConfiguration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/FIFOConfiguration.java 2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/FIFOConfiguration.java 2007-10-24 21:58:48 UTC (rev 4682)
@@ -74,4 +74,12 @@
{
setMaxNodes(-1);
}
+
+ @Override
+ public FIFOConfiguration clone() throws CloneNotSupportedException
+ {
+ return (FIFOConfiguration) super.clone();
+ }
+
+
}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/LFUConfiguration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LFUConfiguration.java 2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LFUConfiguration.java 2007-10-24 21:58:48 UTC (rev 4682)
@@ -78,4 +78,10 @@
return result;
}
+ @Override
+ public LFUConfiguration clone() throws CloneNotSupportedException
+ {
+ return (LFUConfiguration) super.clone();
+ }
+
}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/LRUConfiguration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LRUConfiguration.java 2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LRUConfiguration.java 2007-10-24 21:58:48 UTC (rev 4682)
@@ -120,5 +120,11 @@
super.reset();
setTimeToLiveSeconds(-1);
}
+
+ @Override
+ public LRUConfiguration clone() throws CloneNotSupportedException
+ {
+ return (LRUConfiguration) super.clone();
+ }
}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/MRUConfiguration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/MRUConfiguration.java 2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/MRUConfiguration.java 2007-10-24 21:58:48 UTC (rev 4682)
@@ -73,5 +73,11 @@
{
setMaxNodes(-1);
}
+
+ @Override
+ public MRUConfiguration clone() throws CloneNotSupportedException
+ {
+ return (MRUConfiguration) super.clone();
+ }
}
Modified: core/trunk/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderConfig.java 2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderConfig.java 2007-10-24 21:58:48 UTC (rev 4682)
@@ -393,4 +393,10 @@
return result;
}
+ @Override
+ public AdjListJDBCCacheLoaderConfig clone() throws CloneNotSupportedException
+ {
+ return (AdjListJDBCCacheLoaderConfig) super.clone();
+ }
+
}
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/loader/AsyncCacheLoaderConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/AsyncCacheLoaderConfig.java 2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/loader/AsyncCacheLoaderConfig.java 2007-10-24 21:58:48 UTC (rev 4682)
@@ -136,5 +136,11 @@
return result;
}
+ @Override
+ public AsyncCacheLoaderConfig clone() throws CloneNotSupportedException
+ {
+ return (AsyncCacheLoaderConfig) super.clone();
+ }
+
}
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/loader/ClusteredCacheLoaderConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/ClusteredCacheLoaderConfig.java 2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/loader/ClusteredCacheLoaderConfig.java 2007-10-24 21:58:48 UTC (rev 4682)
@@ -70,4 +70,10 @@
return 31 * hashCodeExcludingProperties() + (int) timeout;
}
+ @Override
+ public ClusteredCacheLoaderConfig clone() throws CloneNotSupportedException
+ {
+ return (ClusteredCacheLoaderConfig) super.clone();
+ }
+
}
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/loader/FileCacheLoaderConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/FileCacheLoaderConfig.java 2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/loader/FileCacheLoaderConfig.java 2007-10-24 21:58:48 UTC (rev 4682)
@@ -77,4 +77,10 @@
return 31 * hashCodeExcludingProperties() + (location == null ? 0 : location.hashCode());
}
+ @Override
+ public FileCacheLoaderConfig clone() throws CloneNotSupportedException
+ {
+ return (FileCacheLoaderConfig) super.clone();
+ }
+
}
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/loader/TcpDelegatingCacheLoaderConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/TcpDelegatingCacheLoaderConfig.java 2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/loader/TcpDelegatingCacheLoaderConfig.java 2007-10-24 21:58:48 UTC (rev 4682)
@@ -101,5 +101,11 @@
return result;
}
+ @Override
+ public TcpDelegatingCacheLoaderConfig clone() throws CloneNotSupportedException
+ {
+ return (TcpDelegatingCacheLoaderConfig) super.clone();
+ }
+
}
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/loader/bdbje/BdbjeCacheLoaderConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/bdbje/BdbjeCacheLoaderConfig.java 2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/loader/bdbje/BdbjeCacheLoaderConfig.java 2007-10-24 21:58:48 UTC (rev 4682)
@@ -37,12 +37,14 @@
this.location = location;
}
+ @Override
public void setProperties(Properties props)
{
super.setProperties(props);
setLocation(props != null ? props.getProperty("location") : null);
}
+ @Override
public boolean equals(Object obj)
{
if (obj instanceof BdbjeCacheLoaderConfig && equalsExcludingProperties(obj))
@@ -52,9 +54,18 @@
return false;
}
+ @Override
public int hashCode()
{
return 31 * hashCodeExcludingProperties() + (location == null ? 0 : location.hashCode());
}
+ @Override
+ public BdbjeCacheLoaderConfig clone() throws CloneNotSupportedException
+ {
+ return (BdbjeCacheLoaderConfig) super.clone();
+ }
+
+
+
}
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/loader/jdbm/JdbmCacheLoaderConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/jdbm/JdbmCacheLoaderConfig.java 2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/loader/jdbm/JdbmCacheLoaderConfig.java 2007-10-24 21:58:48 UTC (rev 4682)
@@ -37,12 +37,14 @@
this.location = location;
}
+ @Override
public void setProperties(Properties props)
{
super.setProperties(props);
setLocation(props != null ? props.getProperty("location") : null);
}
+ @Override
public boolean equals(Object obj)
{
if (obj instanceof JdbmCacheLoaderConfig && equalsExcludingProperties(obj))
@@ -52,9 +54,16 @@
return false;
}
+ @Override
public int hashCode()
{
return 31 * hashCodeExcludingProperties() + (location == null ? 0 : location.hashCode());
}
+ @Override
+ public JdbmCacheLoaderConfig clone() throws CloneNotSupportedException
+ {
+ return (JdbmCacheLoaderConfig) super.clone();
+ }
+
}
\ No newline at end of file
Added: core/trunk/src/main/resources/META-INF/clonable-config-service.xml
===================================================================
--- core/trunk/src/main/resources/META-INF/clonable-config-service.xml (rev 0)
+++ core/trunk/src/main/resources/META-INF/clonable-config-service.xml 2007-10-24 21:58:48 UTC (rev 4682)
@@ -0,0 +1,262 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Cache configuration file that attempts to utilize all known elements.
+ Intent here is not to create such a cache; rather it is to create
+ a Configuration and then see if that Configuration can be cloned.
+ Basically just for testing the clone() method of the various
+ configuration elements.
+-->
+
+<server>
+
+ <mbean code="org.jboss.cache.jmx.CacheJmxWrapper"
+ name="jboss.cache:service=testTreeCache">
+
+ <attribute name="TransactionManagerLookupClass">org.jboss.cache.transaction.GenericTransactionManagerLookup
+ </attribute>
+
+ <attribute name="NodeLockingScheme">OPTIMISTIC</attribute>
+ <attribute name="IsolationLevel">SERIALIZABLE</attribute>
+ <attribute name="CacheMode">INVALIDATION_SYNC</attribute>
+
+ <attribute name="ClusterName">CloneCluster</attribute>
+
+ <!-- Use both a stack name and a ClusterConfig so we can test both -->
+ <attribute name="MultiplexerStack">udp</attribute>
+ <attribute name="ClusterConfig">
+ <config>
+ <UDP mcast_addr="228.10.10.10"
+ mcast_port="45588"
+ tos="8"
+ ucast_recv_buf_size="20000000"
+ ucast_send_buf_size="640000"
+ mcast_recv_buf_size="25000000"
+ mcast_send_buf_size="640000"
+ loopback="false"
+ discard_incompatible_packets="true"
+ max_bundle_size="64000"
+ max_bundle_timeout="30"
+ use_incoming_packet_handler="true"
+ ip_ttl="2"
+ enable_bundling="false"
+ enable_diagnostics="true"
+
+ use_concurrent_stack="true"
+
+ thread_naming_pattern="pl"
+
+ thread_pool.enabled="true"
+ thread_pool.min_threads="1"
+ thread_pool.max_threads="25"
+ thread_pool.keep_alive_time="30000"
+ thread_pool.queue_enabled="true"
+ thread_pool.queue_max_size="10"
+ thread_pool.rejection_policy="Run"
+
+ oob_thread_pool.enabled="true"
+ oob_thread_pool.min_threads="1"
+ oob_thread_pool.max_threads="4"
+ oob_thread_pool.keep_alive_time="10000"
+ oob_thread_pool.queue_enabled="true"
+ oob_thread_pool.queue_max_size="10"
+ oob_thread_pool.rejection_policy="Run"/>
+
+ <PING timeout="2000" num_initial_members="3"/>
+ <MERGE2 max_interval="30000" min_interval="10000"/>
+ <FD_SOCK/>
+ <FD timeout="10000" max_tries="5" shun="true"/>
+ <VERIFY_SUSPECT timeout="1500"/>
+ <pbcast.NAKACK
+ use_mcast_xmit="false" gc_lag="0"
+ retransmit_timeout="300,600,1200,2400,4800"
+ discard_delivered_msgs="true"/>
+ <UNICAST timeout="300,600,1200,2400,3600"/>
+ <pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
+ max_bytes="400000"/>
+ <pbcast.GMS print_local_addr="true" join_timeout="5000"
+ join_retry_timeout="2000" shun="false"
+ view_bundling="true" view_ack_collection_timeout="5000"/>
+ <FRAG2 frag_size="60000"/>
+ <pbcast.STREAMING_STATE_TRANSFER use_reading_thread="true"/>
+ <!-- <pbcast.STATE_TRANSFER/> -->
+ <pbcast.FLUSH timeout="0"/>
+ </config>
+ </attribute>
+
+ <attribute name="FetchInMemoryState">false</attribute>
+ <attribute name="StateRetrievalTimeout">3</attribute>
+ <attribute name="SyncReplTimeout">2</attribute>
+ <attribute name="LockAcquisitionTimeout">1</attribute>
+
+
+ <attribute name="BuddyReplicationConfig">
+ <config>
+ <buddyReplicationEnabled>true</buddyReplicationEnabled>
+ <buddyLocatorClass>org.jboss.cache.buddyreplication.NextMemberBuddyLocator</buddyLocatorClass>
+ <buddyLocatorProperties>
+ numBuddies = 11
+ ignoreColocatedBuddies = true
+ </buddyLocatorProperties>
+
+ <buddyPoolName>cloneGroup</buddyPoolName>
+ <buddyCommunicationTimeout>7</buddyCommunicationTimeout>
+
+ <autoDataGravitation>false</autoDataGravitation>
+ <dataGravitationRemoveOnFind>true</dataGravitationRemoveOnFind>
+ <dataGravitationSearchBackupTrees>true</dataGravitationSearchBackupTrees>
+
+ </config>
+ </attribute>
+
+ <attribute name="EvictionPolicyConfig">
+ <config>
+ <attribute name="wakeUpIntervalSeconds">45</attribute>
+ <attribute name="eventQueueSize">4</attribute>
+ <attribute name="policyClass">org.jboss.cache.eviction.LRUPolicy</attribute>
+
+ <!-- Cache wide default -->
+ <region name="/_default_">
+ <attribute name="maxNodes">5000</attribute>
+ <attribute name="timeToLiveSeconds">1000</attribute>
+ <attribute name="maxAge">15000</attribute>
+ </region>
+ <region name="/fifo" policyClass="org.jboss.cache.eviction.FIFOPolicy">
+ <attribute name="maxNodes">5000</attribute>
+ </region>
+ <region name="/mru" policyClass="org.jboss.cache.eviction.MRUPolicy">
+ <attribute name="maxNodes">10000</attribute>
+ </region>
+ <region name="/lfu" policyClass="org.jboss.cache.eviction.LFUPolicy">
+ <attribute name="maxNodes">5000</attribute>
+ <attribute name="minNodes">4000</attribute>
+ </region>
+ </config>
+ </attribute>
+
+ <attribute name="CacheLoaderConfig">
+ <config>
+ <!-- if passivation is true, only the first cache loader is used; the rest are ignored -->
+ <passivation>false</passivation>
+ <preload>/</preload>
+ <shared>true</shared>
+
+ <!-- we can now have multiple cache loaders, which get chained -->
+ <cacheloader>
+ <class>org.jboss.cache.loader.FileCacheLoader</class>
+ <properties>
+ location=/tmp/FileCacheLoader
+ </properties>
+ <async>false</async>
+ <!-- only one cache loader in the chain may set fetchPersistentState to true.-->
+ <fetchPersistentState>true</fetchPersistentState>
+ <ignoreModifications>false</ignoreModifications>
+ <singletonStore>
+ <enabled>false</enabled>
+ <properties>
+ pushStateWhenCoordinator=true
+ pushStateWhenCoordinatorTimeout=5000
+ </properties>
+ </singletonStore>
+ </cacheloader>
+
+ <cacheloader>
+ <class>org.jboss.cache.loader.bdbje.BdbjeCacheLoader</class>
+ <properties>
+ location=/tmp/BdbjeCacheLoader
+ </properties>
+ <async>false</async>
+ <!-- only one cache loader in the chain may set fetchPersistentState to true.-->
+ <fetchPersistentState>false</fetchPersistentState>
+ <ignoreModifications>false</ignoreModifications>
+ <singletonStore>
+ <enabled>false</enabled>
+ <properties>
+ pushStateWhenCoordinator=true
+ pushStateWhenCoordinatorTimeout=5000
+ </properties>
+ </singletonStore>
+ </cacheloader>
+
+ <cacheloader>
+ <class>org.jboss.cache.loader.jdbm.JdbmCacheLoader</class>
+ <properties>
+ location=/tmp/JdbmCacheLoader
+ </properties>
+ <async>false</async>
+ <!-- only one cache loader in the chain may set fetchPersistentState to true.-->
+ <fetchPersistentState>false</fetchPersistentState>
+ <ignoreModifications>false</ignoreModifications>
+ <singletonStore>
+ <enabled>false</enabled>
+ <properties>
+ pushStateWhenCoordinator=true
+ pushStateWhenCoordinatorTimeout=5000
+ </properties>
+ </singletonStore>
+ </cacheloader>
+
+ <cacheloader>
+ <class>org.jboss.cache.loader.JDBCCacheLoader</class>
+ <properties>
+ cache.jdbc.driver=com.foo.jdbc.Driver
+ cache.jdbc.url=foo://driver
+ cache.jdbc.user=sa
+ cache.jdbc.password=secret
+ </properties>
+ <async>false</async>
+ <!-- only one cache loader in the chain may set fetchPersistentState to true.-->
+ <fetchPersistentState>false</fetchPersistentState>
+ <ignoreModifications>false</ignoreModifications>
+ <singletonStore>
+ <enabled>false</enabled>
+ <properties>
+ pushStateWhenCoordinator=true
+ pushStateWhenCoordinatorTimeout=5000
+ </properties>
+ </singletonStore>
+ </cacheloader>
+
+ <cacheloader>
+ <class>org.jboss.cache.loader.TcpDelegatingCacheLoader</class>
+ <properties>
+ host=127.0.0.1\nport=12121
+ </properties>
+ <async>false</async>
+ <!-- only one cache loader in the chain may set fetchPersistentState to true.-->
+ <fetchPersistentState>false</fetchPersistentState>
+ <ignoreModifications>false</ignoreModifications>
+ <singletonStore>
+ <enabled>false</enabled>
+ <properties>
+ pushStateWhenCoordinator=true
+ pushStateWhenCoordinatorTimeout=5000
+ </properties>
+ </singletonStore>
+ </cacheloader>
+
+ <cacheloader>
+ <class>org.jboss.cache.loader.ClusteredCacheLoader</class>
+ <properties>
+ timeout=500
+ </properties>
+ <async>false</async>
+ <!-- only one cache loader in the chain may set fetchPersistentState to true.-->
+ <fetchPersistentState>false</fetchPersistentState>
+ <ignoreModifications>false</ignoreModifications>
+ <singletonStore>
+ <enabled>false</enabled>
+ <properties>
+ pushStateWhenCoordinator=true
+ pushStateWhenCoordinatorTimeout=5000
+ </properties>
+ </singletonStore>
+ </cacheloader>
+
+ </config>
+ </attribute>
+
+ </mbean>
+
+
+</server>
Added: core/trunk/src/test/java/org/jboss/cache/config/ConfigurationCloningTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/config/ConfigurationCloningTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/config/ConfigurationCloningTest.java 2007-10-24 21:58:48 UTC (rev 4682)
@@ -0,0 +1,154 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.cache.config;
+
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertTrue;
+import static org.testng.AssertJUnit.fail;
+
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.config.BuddyReplicationConfig.BuddyLocatorConfig;
+import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
+import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig;
+import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.config.Configuration.NodeLockingScheme;
+import org.jboss.cache.eviction.LRUPolicy;
+import org.jboss.cache.factories.XmlConfigurationParser;
+import org.testng.annotations.Test;
+
+/**
+ * Tests the ability to clone Configuration elements and end up with
+ * independently modifiable configurations.
+ *
+ * @author Brian Stansberry
+ */
+@Test(groups = {"functional"})
+public class ConfigurationCloningTest
+{
+ /** A file that includes every configuration element I could think of */
+ public static final String DEFAULT_CONFIGURATION_FILE = "META-INF/clonable-config-service.xml";
+
+ private static final Log log = LogFactory.getLog(ConfigurationCloningTest.class);
+
+ public void testClone() throws Exception
+ {
+ XmlConfigurationParser parser = new XmlConfigurationParser();
+ Configuration c = parser.parseFile(DEFAULT_CONFIGURATION_FILE);
+
+ try {
+ Configuration clone = c.clone();
+
+ // Test a few simple properties
+ assertEquals(NodeLockingScheme.OPTIMISTIC, clone.getNodeLockingScheme());
+ assertEquals(CacheMode.INVALIDATION_SYNC, clone.getCacheMode());
+ assertEquals("CloneCluster", clone.getClusterName());
+ assertEquals(c.getClusterConfig(), clone.getClusterConfig());
+ assertEquals(3, clone.getStateRetrievalTimeout());
+
+ // Buddy replication config
+ BuddyReplicationConfig brc1 = c.getBuddyReplicationConfig();
+ BuddyReplicationConfig brc2 = clone.getBuddyReplicationConfig();
+
+ assertFalse(brc1 == brc2);
+
+ assertEquals(7, brc2.getBuddyCommunicationTimeout());
+ assertEquals("cloneGroup", brc2.getBuddyPoolName());
+
+ BuddyLocatorConfig blc1 = brc1.getBuddyLocatorConfig();
+ BuddyLocatorConfig blc2 = brc2.getBuddyLocatorConfig();
+ assertFalse(blc1 == blc2);
+ Properties p1 = blc1.getBuddyLocatorProperties();
+ Properties p2 = blc2.getBuddyLocatorProperties();
+ assertFalse(p1 == p2);
+ assertEquals(p1, p2);
+
+ // Eviction
+ EvictionConfig ec1 = c.getEvictionConfig();
+ EvictionConfig ec2 = clone.getEvictionConfig();
+
+ assertFalse(ec1 == ec2);
+
+ assertEquals(4, ec2.getDefaultEventQueueSize());
+ assertEquals(45, ec2.getWakeupIntervalSeconds());
+ assertEquals(LRUPolicy.class.getName(), ec2.getDefaultEvictionPolicyClass());
+
+ List<EvictionRegionConfig> ercs1 = ec1.getEvictionRegionConfigs();
+ List<EvictionRegionConfig> ercs2 = ec2.getEvictionRegionConfigs();
+ assertEquals(ercs1.size(), ercs2.size());
+ for (int i = 0; i < ercs1.size(); i++)
+ {
+ compareEvictionRegionConfigs(ercs1.get(i), ercs2.get(i));
+ }
+
+ // Cache loading
+ CacheLoaderConfig clc1 = c.getCacheLoaderConfig();
+ CacheLoaderConfig clc2 = clone.getCacheLoaderConfig();
+
+ assertFalse(clc1 == clc2);
+
+ assertFalse(clc2.isPassivation());
+ assertTrue(clc2.isShared());
+
+ List<IndividualCacheLoaderConfig> clcs1 = clc1.getIndividualCacheLoaderConfigs();
+ List<IndividualCacheLoaderConfig> clcs2 = clc2.getIndividualCacheLoaderConfigs();
+ assertEquals(clcs1.size(), clcs2.size());
+ for (int i = 0; i < clcs1.size(); i++)
+ {
+ compareCacheLoaderConfigs(clcs1.get(i), clcs2.get(i));
+ }
+
+ RuntimeConfig rc1 = c.getRuntimeConfig();
+ RuntimeConfig rc2 = clone.getRuntimeConfig();
+ assertFalse(rc1 == rc2);
+ assertEquals(rc1, rc2);
+
+ }
+ catch (CloneNotSupportedException e)
+ {
+ log.error(e.getMessage(), e);
+ fail("Cloning failed -- " + e.getMessage());
+ }
+ }
+
+ private void compareEvictionRegionConfigs(EvictionRegionConfig erc1,
+ EvictionRegionConfig erc2)
+ {
+ assertEquals(erc1.getRegionName(), erc2.getRegionName());
+ assertEquals(erc1.getRegionFqn(), erc2.getRegionFqn());
+ assertEquals(erc1.getEventQueueSize(), erc2.getEventQueueSize());
+
+ EvictionPolicyConfig epc1 = erc1.getEvictionPolicyConfig();
+ EvictionPolicyConfig epc2 = erc2.getEvictionPolicyConfig();
+
+ assertFalse(epc1 == epc2);
+ assertEquals(epc1, epc2);
+ }
+
+ private void compareCacheLoaderConfigs(IndividualCacheLoaderConfig clc1,
+ IndividualCacheLoaderConfig clc2)
+ {
+ assertFalse(clc1 == clc2);
+ assertEquals(clc1, clc2);
+
+ Properties p1 = clc1.getProperties();
+ Properties p2 = clc2.getProperties();
+ assertFalse(p1 == p2);
+ assertEquals(p1, p2);
+
+ SingletonStoreConfig ssc1 = clc1.getSingletonStoreConfig();
+ SingletonStoreConfig ssc2 = clc2.getSingletonStoreConfig();
+ assertFalse(ssc1 == ssc2);
+ assertEquals(ssc1, ssc2);
+ }
+
+}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/DummyEvictionConfiguration.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/DummyEvictionConfiguration.java 2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/DummyEvictionConfiguration.java 2007-10-24 21:58:48 UTC (rev 4682)
@@ -29,5 +29,13 @@
public void reset()
{
// no-op
+ }
+
+ @Override
+ public DummyEvictionConfiguration clone() throws CloneNotSupportedException
+ {
+ return (DummyEvictionConfiguration) super.clone();
}
+
+
}
18 years
JBoss Cache SVN: r4681 - core/trunk/src/main/java/org/jboss/cache.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-10-24 12:09:31 -0400 (Wed, 24 Oct 2007)
New Revision: 4681
Modified:
core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
Log:
Conditional registration of VM shutdown hook
Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-10-24 14:42:44 UTC (rev 4680)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-10-24 16:09:31 UTC (rev 4681)
@@ -67,6 +67,7 @@
import org.jgroups.util.RspList;
import org.jgroups.util.Util;
+import javax.management.MBeanServerFactory;
import javax.transaction.Status;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
@@ -830,22 +831,36 @@
notifier.notifyCacheStarted(this, getInvocationContext());
- // install a VM shutdown hook
- Thread shutdownHook = new Thread()
- {
- public void run()
- {
- CacheImpl.this.stop();
- }
- };
+ addShutdownHook();
- Runtime.getRuntime().addShutdownHook(shutdownHook);
-
log.info("JBoss Cache version: " + getVersion());
cacheStatus = CacheStatus.STARTED;
}
+ private void addShutdownHook()
+ {
+ ArrayList al = MBeanServerFactory.findMBeanServer(null);
+ if (al.size() == 0)
+ {
+ // the only MBean server is the system (JDK) server. So we need to register a shutdown hook.
+ // install a VM shutdown hook
+ Thread shutdownHook = new Thread()
+ {
+ public void run()
+ {
+ CacheImpl.this.stop();
+ }
+ };
+
+ Runtime.getRuntime().addShutdownHook(shutdownHook);
+ }
+ else
+ {
+ log.trace("Running in an MBeanServer environment. Not registering a shutdown hook with the VM as the MBeanServer will handle lifecycle.");
+ }
+ }
+
/**
* Lifecycle method.
*/
18 years
JBoss Cache SVN: r4680 - core/trunk/src/main/java/org/jboss/cache.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-10-24 10:42:44 -0400 (Wed, 24 Oct 2007)
New Revision: 4680
Modified:
core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
Log:
Rolled back genman's changes re: MinMapUtil as this was causing breakages
Modified: core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2007-10-24 12:45:45 UTC (rev 4679)
+++ core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2007-10-24 14:42:44 UTC (rev 4680)
@@ -14,7 +14,6 @@
import org.jboss.cache.marshall.MethodDeclarations;
import org.jboss.cache.optimistic.DataVersion;
import org.jboss.cache.transaction.GlobalTransaction;
-import org.jboss.cache.util.MinMapUtil;
import java.util.Collections;
import java.util.HashMap;
@@ -67,10 +66,10 @@
/**
* Map of general data keys to values.
*/
- private Map<K, V> data = Collections.emptyMap();
+ private final Map<K, V> data = new HashMap<K, V>();
private boolean lockForChildInsertRemove;
-
+
/**
* Node moved or removed.
*/
@@ -96,7 +95,7 @@
init(child_name, fqn, cache);
setInternalState(data);
}
-
+
/**
* Initializes with a name and FQN and cache.
*/
@@ -203,13 +202,13 @@
public Map<K, V> getData()
{
assertValid();
- if (cache == null)
- return Collections.emptyMap();
+ if (cache == null) return Collections.emptyMap();
return cache.getData(getFqn());
}
public Map<K, V> getDataDirect()
{
+ if (data == null) return Collections.emptyMap();
return Collections.unmodifiableMap(data);
}
@@ -221,9 +220,7 @@
public V putDirect(K key, V value)
{
- V v = data.get(key);
- data = MinMapUtil.put(data, key, value);
- return v;
+ return data.put(key, value);
}
public NodeSPI<K, V> getOrCreateChild(Object child_name, GlobalTransaction gtx)
@@ -296,9 +293,8 @@
public V removeDirect(K key)
{
- V v = data.get(key);
- data = MinMapUtil.remove(data, key);
- return v;
+ if (data == null) return null;
+ return data.remove(key);
}
public void printDetails(StringBuffer sb, int indent)
@@ -324,9 +320,12 @@
{
sb.append("[ ").append(fqn);
}
- synchronized (data)
+ if (data != null)
{
- sb.append(" data=").append(data.keySet());
+ synchronized (data)
+ {
+ sb.append(" data=").append(data.keySet());
+ }
}
if (children != null && !children.isEmpty())
{
@@ -390,7 +389,7 @@
public void clearDataDirect()
{
- data = Collections.emptyMap();
+ if (data != null) data.clear();
}
public Node<K, V> getChild(Fqn fqn)
@@ -438,7 +437,7 @@
public Set<K> getKeysDirect()
{
- if (data.isEmpty())
+ if (data == null)
{
return Collections.emptySet();
}
@@ -562,7 +561,8 @@
public void putAllDirect(Map<K, V> data)
{
- MinMapUtil.putAll(this.data, data);
+ if (data == null) return;
+ this.data.putAll(data);
}
public void removeChildrenDirect()
@@ -671,8 +671,7 @@
public Set<Node<K, V>> getChildren()
{
assertValid();
- if (cache == null)
- return Collections.emptySet();
+ if (cache == null) return Collections.emptySet();
Set<Node<K, V>> children = new HashSet<Node<K, V>>();
for (Object c : cache.getChildrenNames(getFqn()))
{
@@ -801,6 +800,7 @@
if (onlyInternalState)
return new HashMap(0);
// don't bother doing anything here
+ if (data == null) return new HashMap(0);
return new HashMap(data);
}
}
18 years
JBoss Cache SVN: r4679 - core/trunk/src/test/java/org/jboss/cache/statetransfer.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2007-10-24 08:45:45 -0400 (Wed, 24 Oct 2007)
New Revision: 4679
Modified:
core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferConcurrencyTest.java
core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferTestBase.java
Log:
fixed tests
Modified: core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferConcurrencyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferConcurrencyTest.java 2007-10-23 20:53:27 UTC (rev 4678)
+++ core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferConcurrencyTest.java 2007-10-24 12:45:45 UTC (rev 4679)
@@ -99,7 +99,7 @@
CacheSPI[] caches = new CacheSPI[count];
for (int i = 0; i < count; i++)
{
- activators[i] = new CacheActivator(semaphore, names[i], sync);
+ activators[i] = new CacheActivator(semaphore, names[i], sync, caches);
caches[i] = activators[i].getCacheSPI();
activators[i].start();
}
@@ -149,7 +149,6 @@
"VALUE", activators[i].getCacheValue(fqn));
// System.out.println(names[i] + ":" + fqn + " = " + activators[i].getCacheValue(fqn));
}
-
}
}
catch (Exception ex)
@@ -647,18 +646,23 @@
private class CacheActivator extends CacheUser
{
+ private CacheSPI[] caches;
+
CacheActivator(Semaphore semaphore,
String name,
- boolean sync)
+ boolean sync, CacheSPI[] caches)
throws Exception
{
super(semaphore, name, sync, false);
+ this.caches = caches;
}
void useCache() throws Exception
{
+ System.out.println("---- Cache" + name + " = " + cache.getLocalAddress() + " being used");
TestingUtil.sleepRandom(5000);
createAndActivateRegion(cache, A_B);
+ waitUntillAllChachesActivatedRegion();
System.out.println(name + " activated region" + " " + System.currentTimeMillis());
Fqn<String> childFqn = new Fqn<String>(A_B, name);
@@ -667,6 +671,34 @@
}
+ /**
+ * If we do not wait for all being activated, following scenario might happen:
+ * A activates the /a/b
+ * A puts something in /a/b and replicates
+ * B fails to accept the replication as it has the /a/b region inactive.
+ *
+ * So we cannot expect all the put operation to replicate accross all the members from the cluser, WITHOUTH
+ * having the region active on ALL members.
+ *
+ */
+ private void waitUntillAllChachesActivatedRegion()
+ {
+ boolean allActive = true;
+ do
+ {
+ allActive = true;
+ for (Cache cache : caches)
+ {
+ if (cache.getRegion(A_B, false) == null || !cache.getRegion(A_B, false).isActive())
+ {
+ allActive = false;
+ }
+ }
+ TestingUtil.sleepThread(1000);
+ } while (!allActive);
+ System.out.println("---- /a/b is active on all cache instances");
+ }
+
public Object getCacheValue(Fqn fqn) throws CacheException
{
return cache.get(fqn, "KEY");
Modified: core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferTestBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferTestBase.java 2007-10-23 20:53:27 UTC (rev 4678)
+++ core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferTestBase.java 2007-10-24 12:45:45 UTC (rev 4679)
@@ -480,7 +480,7 @@
public void start()
{
- thread = new Thread(this);
+ thread = new Thread(this, name);
thread.start();
}
18 years