JBoss Cache SVN: r7482 - in core/trunk/src: test/java/org/jboss/cache/eviction and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2009-01-15 15:53:44 -0500 (Thu, 15 Jan 2009)
New Revision: 7482
Modified:
core/trunk/src/main/java/org/jboss/cache/loader/C3p0ConnectionFactory.java
core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java
core/trunk/src/test/java/org/jboss/cache/loader/C3p0ConnectionFactoryTest.java
Log:
fix test for jdk6
Modified: core/trunk/src/main/java/org/jboss/cache/loader/C3p0ConnectionFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/C3p0ConnectionFactory.java 2009-01-15 18:46:35 UTC (rev 7481)
+++ core/trunk/src/main/java/org/jboss/cache/loader/C3p0ConnectionFactory.java 2009-01-15 20:53:44 UTC (rev 7482)
@@ -22,6 +22,7 @@
package org.jboss.cache.loader;
import com.mchange.v2.c3p0.DataSources;
+import com.mchange.v2.c3p0.PooledDataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -41,47 +42,29 @@
private static final Log log = LogFactory.getLog(C3p0ConnectionFactory.class);
private static final boolean trace = log.isTraceEnabled();
- private DataSource ds;
+ private PooledDataSource ds;
+ private Properties config = new Properties();
@Override
public void setConfig(AdjListJDBCCacheLoaderConfig config)
{
super.setConfig(config);
- Properties properties = config.getProperties();
+ writeProps(config.getProperties());
+ writeProps(System.getProperties());
+ if (trace) log.trace("Using props: " + this.config);
+ }
+
+ private void writeProps(Properties properties)
+ {
Enumeration e = properties.propertyNames();
while (e.hasMoreElements())
{
String property = (String) e.nextElement();
if (property.startsWith("c3p0."))
{
- /* System properties should come before settings from XML configuration.
-
- For simplicity (c3p0 manual says overrides should not carry c3p0. start whereas system properties yes)
- and to avoid parsing, it's easier to set the values from XML configuration that should be c3p0. as
- system properties.
-
- So, this check allows us to determine if the System property was not set, in which case, we take the
- value from the XML configuration and set it to be a System property. If the value from the XML config
- was already set as System property, we do nothing, original System property should stand. */
-
- String xmlPropertyValue = properties.getProperty(property);
- String sysPropertyValue = System.getProperty(property);
- if (System.getProperty(property) == null)
- {
- System.setProperty(property, xmlPropertyValue);
- if (log.isDebugEnabled())
- {
- log.debug("c3p0 property defined in XML: " + property + "=" + xmlPropertyValue);
- }
- }
- else
- {
- if (log.isDebugEnabled())
- {
- log.debug(property + "=" + sysPropertyValue + " defined as system property. It will override the value defined in XML which was: " + xmlPropertyValue);
- }
- }
+ String newName = property.substring("c3p0.".length());
+ this.config.put(newName, properties.get(property));
}
}
}
@@ -93,7 +76,7 @@
super.start();
DataSource unpooled = DataSources.unpooledDataSource(getUrl(), getUsr(), getPwd());
- ds = DataSources.pooledDataSource(unpooled);
+ ds = (PooledDataSource) DataSources.pooledDataSource(unpooled, config);
if (log.isDebugEnabled())
{
@@ -104,9 +87,16 @@
@Override
public Connection checkoutConnection() throws SQLException
{
+ if (trace)
+ {
+ log.trace("DataSource before checkout (NumBusyConnectionsAllUsers) : " + ds.getNumBusyConnectionsAllUsers());
+ log.trace("DataSource before checkout (NumConnectionsAllUsers) : " + ds.getNumConnectionsAllUsers());
+ }
Connection connection = ds.getConnection();
if (trace)
{
+ log.trace("DataSource after checkout (NumBusyConnectionsAllUsers) : " + ds.getNumBusyConnectionsAllUsers());
+ log.trace("DataSource after checkout (NumConnectionsAllUsers) : " + ds.getNumConnectionsAllUsers());
log.trace("Connection checked out: " + connection);
}
return connection;
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java 2009-01-15 18:46:35 UTC (rev 7481)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java 2009-01-15 20:53:44 UTC (rev 7482)
@@ -21,7 +21,6 @@
*/
@Test(groups = "functional", testName = "eviction.LRUAlgorithmTest")
public class LRUAlgorithmTest extends EvictionTestsBase
-
{
RegionManager regionManager;
LRUAlgorithm algorithm;
Modified: core/trunk/src/test/java/org/jboss/cache/loader/C3p0ConnectionFactoryTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/C3p0ConnectionFactoryTest.java 2009-01-15 18:46:35 UTC (rev 7481)
+++ core/trunk/src/test/java/org/jboss/cache/loader/C3p0ConnectionFactoryTest.java 2009-01-15 20:53:44 UTC (rev 7482)
@@ -24,7 +24,7 @@
*
* @author <a href="mailto:galder.zamarreno@jboss.com">Galder Zamarreno</a>
*/
-@Test(groups = {"functional"}, sequential = true, testName = "loader.C3p0ConnectionFactoryTest")
+@Test(groups = {"functional"}, testName = "loader.C3p0ConnectionFactoryTest")
public class C3p0ConnectionFactoryTest
{
private C3p0ConnectionFactory cf;
17 years, 2 months
JBoss Cache SVN: r7481 - in core/branches/flat/src: main/java/org/jboss/starobrno/commands and 14 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-01-15 13:46:35 -0500 (Thu, 15 Jan 2009)
New Revision: 7481
Added:
core/branches/flat/src/main/java/org/jboss/starobrno/config/GlobalConfiguration.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/AbstractComponentRegistry.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentRegistry.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/GlobalComponentRegistry.java
core/branches/flat/src/main/java/org/jboss/starobrno/remoting/transport/
core/branches/flat/src/main/java/org/jboss/starobrno/remoting/transport/Address.java
core/branches/flat/src/main/java/org/jboss/starobrno/remoting/transport/Transport.java
Removed:
core/branches/flat/src/main/java/org/jboss/starobrno/config/SharedConfiguration.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentRegistry.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/HierarchicalComponentRegistry.java
Modified:
core/branches/flat/src/main/java/org/jboss/starobrno/EvictionManager.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/CommandsFactory.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/ConfigurationComponent.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParser.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParserImpl.java
core/branches/flat/src/main/java/org/jboss/starobrno/container/DataContainer.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentFactory.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/DefaultCacheFactory.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/scopes/Scopes.java
core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/InterceptorChain.java
core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/CommandInterceptor.java
core/branches/flat/src/main/java/org/jboss/starobrno/invocation/InvocationContextContainer.java
core/branches/flat/src/main/java/org/jboss/starobrno/loader/CacheLoader.java
core/branches/flat/src/main/java/org/jboss/starobrno/manager/CacheManager.java
core/branches/flat/src/main/java/org/jboss/starobrno/notifications/NotifierImpl.java
core/branches/flat/src/main/java/org/jboss/starobrno/remoting/RPCManager.java
core/branches/flat/src/test/java/org/jboss/starobrno/factories/scopes/ScopeDetectorTest.java
Log:
Initial implementation of stuff
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/EvictionManager.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/EvictionManager.java 2009-01-15 16:48:16 UTC (rev 7480)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/EvictionManager.java 2009-01-15 18:46:35 UTC (rev 7481)
@@ -11,7 +11,7 @@
*/
@ThreadSafe
@NonVolatile
-(a)Scope(Scopes.CACHE_ONLY)
+(a)Scope(Scopes.NAMED_CACHE)
public interface EvictionManager
{
/**
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/CommandsFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/CommandsFactory.java 2009-01-15 16:48:16 UTC (rev 7480)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/CommandsFactory.java 2009-01-15 18:46:35 UTC (rev 7481)
@@ -45,7 +45,7 @@
/**
* @author Mircea.Markus(a)jboss.com
*/
-(a)Scope(Scopes.CACHE_ONLY)
+(a)Scope(Scopes.NAMED_CACHE)
public interface CommandsFactory
{
PutKeyValueCommand buildPutKeyValueCommand(Object key, Object value);
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/config/ConfigurationComponent.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/ConfigurationComponent.java 2009-01-15 16:48:16 UTC (rev 7480)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/ConfigurationComponent.java 2009-01-15 18:46:35 UTC (rev 7481)
@@ -46,7 +46,7 @@
* @version $Revision$
* @see #testImmutability(String)
*/
-(a)Scope(Scopes.CACHE_ONLY)
+(a)Scope(Scopes.NAMED_CACHE)
public abstract class ConfigurationComponent implements CloneableConfigurationComponent
{
private static final long serialVersionUID = 4879873994727821938L;
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/config/GlobalConfiguration.java (from rev 7474, core/branches/flat/src/main/java/org/jboss/starobrno/config/SharedConfiguration.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/GlobalConfiguration.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/GlobalConfiguration.java 2009-01-15 18:46:35 UTC (rev 7481)
@@ -0,0 +1,208 @@
+package org.jboss.starobrno.config;
+
+import org.jboss.starobrno.CacheException;
+
+import java.util.Properties;
+
+/**
+ * Configuration component that encapsulates the global configuration.
+ *
+ * @author Manik Surtani
+ */
+public class GlobalConfiguration extends ConfigurationComponent
+{
+ String asyncListenerExecutorFactoryClass;
+ String asyncSerializationExecutorFactoryClass;
+ String evictionScheduledExecutorFactoryClass;
+ String replicationQueueScheduledExecutorFactoryClass;
+ String marshallerClass;
+ String marshallVersion;
+ int objectInputStreamPoolSize;
+ int objectOutputStreamPoolSize;
+ String transportClass;
+ Properties transportProperties;
+ Configuration defaultConfiguration;
+
+ public String getAsyncListenerExecutorFactoryClass()
+ {
+ return asyncListenerExecutorFactoryClass;
+ }
+
+ public void setAsyncListenerExecutorFactoryClass(String asyncListenerExecutorFactoryClass)
+ {
+ testImmutability("asyncListenerExecutorFactoryClass");
+ this.asyncListenerExecutorFactoryClass = asyncListenerExecutorFactoryClass;
+ }
+
+ public String getAsyncSerializationExecutorFactoryClass()
+ {
+ return asyncSerializationExecutorFactoryClass;
+ }
+
+ public void setAsyncSerializationExecutorFactoryClass(String asyncSerializationExecutorFactoryClass)
+ {
+ testImmutability("asyncSerializationExecutorFactoryClass");
+ this.asyncSerializationExecutorFactoryClass = asyncSerializationExecutorFactoryClass;
+ }
+
+ public String getEvictionScheduledExecutorFactoryClass()
+ {
+ return evictionScheduledExecutorFactoryClass;
+ }
+
+ public void setEvictionScheduledExecutorFactoryClass(String evictionScheduledExecutorFactoryClass)
+ {
+ testImmutability("evictionScheduledExecutorFactoryClass");
+ this.evictionScheduledExecutorFactoryClass = evictionScheduledExecutorFactoryClass;
+ }
+
+ public String getReplicationQueueScheduledExecutorFactoryClass()
+ {
+ return replicationQueueScheduledExecutorFactoryClass;
+ }
+
+ public void setReplicationQueueScheduledExecutorFactoryClass(String replicationQueueScheduledExecutorFactoryClass)
+ {
+ testImmutability("replicationQueueScheduledExecutorFactoryClass");
+ this.replicationQueueScheduledExecutorFactoryClass = replicationQueueScheduledExecutorFactoryClass;
+ }
+
+ public String getMarshallerClass()
+ {
+ return marshallerClass;
+ }
+
+ public void setMarshallerClass(String marshallerClass)
+ {
+ testImmutability("marshallerClass");
+ this.marshallerClass = marshallerClass;
+ }
+
+ public String getMarshallVersion()
+ {
+ return marshallVersion;
+ }
+
+ public void setMarshallVersion(String marshallVersion)
+ {
+ testImmutability("marshallVersion");
+ this.marshallVersion = marshallVersion;
+ }
+
+ public int getObjectInputStreamPoolSize()
+ {
+ return objectInputStreamPoolSize;
+ }
+
+ public void setObjectInputStreamPoolSize(int objectInputStreamPoolSize)
+ {
+ testImmutability("objectInputStreamPoolSize");
+ this.objectInputStreamPoolSize = objectInputStreamPoolSize;
+ }
+
+ public int getObjectOutputStreamPoolSize()
+ {
+ return objectOutputStreamPoolSize;
+ }
+
+ public void setObjectOutputStreamPoolSize(int objectOutputStreamPoolSize)
+ {
+ testImmutability("objectOutputStreamPoolSize");
+ this.objectOutputStreamPoolSize = objectOutputStreamPoolSize;
+ }
+
+ public String getTransportClass()
+ {
+ return transportClass;
+ }
+
+ public void setTransportClass(String transportClass)
+ {
+ testImmutability("transportClass");
+ this.transportClass = transportClass;
+ }
+
+ public Properties getTransportProperties()
+ {
+ return transportProperties;
+ }
+
+ public void setTransportProperties(Properties transportProperties)
+ {
+ testImmutability("transportProperties");
+ this.transportProperties = transportProperties;
+ }
+
+ public Configuration getDefaultConfiguration()
+ {
+ return defaultConfiguration;
+ }
+
+ public void setDefaultConfiguration(Configuration defaultConfiguration)
+ {
+ testImmutability("defaultConfiguration");
+ this.defaultConfiguration = defaultConfiguration;
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ GlobalConfiguration that = (GlobalConfiguration) o;
+
+ if (objectInputStreamPoolSize != that.objectInputStreamPoolSize) return false;
+ if (objectOutputStreamPoolSize != that.objectOutputStreamPoolSize) return false;
+ if (asyncListenerExecutorFactoryClass != null ? !asyncListenerExecutorFactoryClass.equals(that.asyncListenerExecutorFactoryClass) : that.asyncListenerExecutorFactoryClass != null)
+ return false;
+ if (asyncSerializationExecutorFactoryClass != null ? !asyncSerializationExecutorFactoryClass.equals(that.asyncSerializationExecutorFactoryClass) : that.asyncSerializationExecutorFactoryClass != null)
+ return false;
+ if (defaultConfiguration != null ? !defaultConfiguration.equals(that.defaultConfiguration) : that.defaultConfiguration != null)
+ return false;
+ if (evictionScheduledExecutorFactoryClass != null ? !evictionScheduledExecutorFactoryClass.equals(that.evictionScheduledExecutorFactoryClass) : that.evictionScheduledExecutorFactoryClass != null)
+ return false;
+ if (marshallVersion != null ? !marshallVersion.equals(that.marshallVersion) : that.marshallVersion != null)
+ return false;
+ if (marshallerClass != null ? !marshallerClass.equals(that.marshallerClass) : that.marshallerClass != null)
+ return false;
+ if (replicationQueueScheduledExecutorFactoryClass != null ? !replicationQueueScheduledExecutorFactoryClass.equals(that.replicationQueueScheduledExecutorFactoryClass) : that.replicationQueueScheduledExecutorFactoryClass != null)
+ return false;
+ if (transportClass != null ? !transportClass.equals(that.transportClass) : that.transportClass != null)
+ return false;
+ if (transportProperties != null ? !transportProperties.equals(that.transportProperties) : that.transportProperties != null)
+ return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = asyncListenerExecutorFactoryClass != null ? asyncListenerExecutorFactoryClass.hashCode() : 0;
+ result = 31 * result + (asyncSerializationExecutorFactoryClass != null ? asyncSerializationExecutorFactoryClass.hashCode() : 0);
+ result = 31 * result + (evictionScheduledExecutorFactoryClass != null ? evictionScheduledExecutorFactoryClass.hashCode() : 0);
+ result = 31 * result + (replicationQueueScheduledExecutorFactoryClass != null ? replicationQueueScheduledExecutorFactoryClass.hashCode() : 0);
+ result = 31 * result + (marshallerClass != null ? marshallerClass.hashCode() : 0);
+ result = 31 * result + (marshallVersion != null ? marshallVersion.hashCode() : 0);
+ result = 31 * result + objectInputStreamPoolSize;
+ result = 31 * result + objectOutputStreamPoolSize;
+ result = 31 * result + (transportClass != null ? transportClass.hashCode() : 0);
+ result = 31 * result + (transportProperties != null ? transportProperties.hashCode() : 0);
+ result = 31 * result + (defaultConfiguration != null ? defaultConfiguration.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public GlobalConfiguration clone()
+ {
+ try
+ {
+ return (GlobalConfiguration) super.clone();
+ }
+ catch (CloneNotSupportedException e)
+ {
+ throw new CacheException("Problems cloning configuration component!", e);
+ }
+ }
+}
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/config/SharedConfiguration.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/SharedConfiguration.java 2009-01-15 16:48:16 UTC (rev 7480)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/SharedConfiguration.java 2009-01-15 18:46:35 UTC (rev 7481)
@@ -1,42 +0,0 @@
-package org.jboss.starobrno.config;
-
-/**
- * // TODO: Manik: Document this!
- *
- * @author Manik Surtani
- */
-public class SharedConfiguration extends ConfigurationComponent
-{
- /*
- <asyncListenerExecutor factory="org.jboss.starobrno.executors.DefaultExecutorFactory">
- <property name="maxThreads">5</property>
- <property name="threadNamePrefix">AsyncListenerThread</property>
- </asyncListenerExecutor>
-
- <asyncSerializationExecutor factory="org.jboss.starobrno.executors.DefaultExecutorFactory">
- <property name="maxThreads">25</property>
- <property name="threadNamePrefix">AsyncSerializationThread</property>
- </asyncSerializationExecutor>
-
- <evictionScheduledExecutor factory="org.jboss.starobrno.executors.DefaultScheduledExecutorFactory">
- <property name="threadNamePrefix">EvictionThread</property>
- </evictionScheduledExecutor>
-
- <replicationQueueScheduledExecutor factory="org.jboss.starobrno.executors.DefaultScheduledExecutorFactory">
- <property name="threadNamePrefix">ReplicationQueueThread</property>
- </replicationQueueScheduledExecutor>
-
- <jgroupsConfig configFile="udp.xml"/>
-
- <serialization marshallerClass="org.jboss.starobrno.marshall.CacheMarshallerStarobrno" version="1.0"
- objectInputStreamPoolSize="100" objectOutputStreamPoolSize="100"/>
- */
- String asyncListenerExecutorFactoryClass;
- String asyncSerializationExecutorFactoryClass;
- String evictionScheduledExecutorFactoryClass;
- String replicationQueueScheduledExecutorFactoryClass;
- String marshallerClass;
- String marshallVersion;
- int objectInputStreamPoolSize;
- int objectOutputStreamPoolSize;
-}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParser.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParser.java 2009-01-15 16:48:16 UTC (rev 7480)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParser.java 2009-01-15 18:46:35 UTC (rev 7481)
@@ -2,6 +2,7 @@
import org.jboss.starobrno.config.Configuration;
import org.jboss.starobrno.config.ConfigurationException;
+import org.jboss.starobrno.config.GlobalConfiguration;
import java.io.IOException;
import java.io.InputStream;
@@ -33,18 +34,19 @@
void initialize(InputStream inputStream) throws IOException;
/**
- * Parses and retrieves the default configuration. This is typically used to configure the {@link org.jboss.starobrno.manager.CacheManager}.
+ * Parses and retrieves configuration overrides for named caches.
*
- * @return a Configuration
+ * @return a Map of Configuration overrides keyed on cache name
* @throws ConfigurationException if there is a problem parsing the configuration XML
*/
- Configuration parseDefaultConfiguration() throws ConfigurationException;
+ Map<String, Configuration> parseNamedConfigurations() throws ConfigurationException;
/**
- * Parses and retrieves configuration overrides for named caches.
+ * GlobalConfiguration would also have a reference to the template default configuration, accessible via {@link org.jboss.starobrno.config.GlobalConfiguration#getDefaultConfiguration()}
+ * <p/>
+ * This is typically used to configure a {@link org.jboss.starobrno.manager.CacheManager}
*
- * @return a Map of Configuration overrides keyed on cache name
- * @throws ConfigurationException if there is a problem parsing the configuration XML
+ * @return a GlobalConfiguration as parsed from the configuration file.
*/
- Map<String, Configuration> parseNamedConfigurations() throws ConfigurationException;
+ GlobalConfiguration parseGlobalConfiguration();
}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParserImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParserImpl.java 2009-01-15 16:48:16 UTC (rev 7480)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParserImpl.java 2009-01-15 18:46:35 UTC (rev 7481)
@@ -2,6 +2,7 @@
import org.jboss.starobrno.config.Configuration;
import org.jboss.starobrno.config.ConfigurationException;
+import org.jboss.starobrno.config.GlobalConfiguration;
import org.jboss.starobrno.util.FileLookup;
import org.w3c.dom.Element;
@@ -93,6 +94,11 @@
return namedConfigurations;
}
+ public GlobalConfiguration parseGlobalConfiguration()
+ {
+ throw new RuntimeException("Implement me");
+ }
+
private void assertInitialized()
{
if (!initialized)
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/container/DataContainer.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/container/DataContainer.java 2009-01-15 16:48:16 UTC (rev 7480)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/container/DataContainer.java 2009-01-15 18:46:35 UTC (rev 7481)
@@ -32,7 +32,7 @@
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
* @since 3.0
*/
-(a)Scope(Scopes.CACHE_ONLY)
+(a)Scope(Scopes.NAMED_CACHE)
public interface DataContainer<K, V>
{
V get(K k);
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/factories/AbstractComponentRegistry.java (from rev 7474, core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentRegistry.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/AbstractComponentRegistry.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/AbstractComponentRegistry.java 2009-01-15 18:46:35 UTC (rev 7481)
@@ -0,0 +1,966 @@
+/*
+ * 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.starobrno.factories;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheStatus;
+import org.jboss.cache.Version;
+import org.jboss.starobrno.CacheException;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.config.ConfigurationException;
+import org.jboss.starobrno.config.RuntimeConfig;
+import org.jboss.starobrno.factories.annotations.DefaultFactoryFor;
+import org.jboss.starobrno.factories.annotations.Destroy;
+import org.jboss.starobrno.factories.annotations.Inject;
+import org.jboss.starobrno.factories.annotations.NonVolatile;
+import org.jboss.starobrno.factories.annotations.Start;
+import org.jboss.starobrno.factories.annotations.Stop;
+import org.jboss.starobrno.factories.scopes.Scope;
+import org.jboss.starobrno.factories.scopes.Scopes;
+import org.jboss.starobrno.lifecycle.Lifecycle;
+import org.jboss.starobrno.util.BeanUtils;
+import org.jboss.starobrno.util.ReflectionUtil;
+
+import javax.management.MBeanServerFactory;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A registry where components which have been created are stored. Components are stored as singletons, registered under
+ * a specific name.
+ * <p/>
+ * Components can be retrieved from the registry using {@link #getComponent(Class)}.
+ * <p/>
+ * Components can be registered using {@link #registerComponent(Object, Class)}, which will cause any dependencies to be
+ * wired in as well. Components that need to be created as a result of wiring will be done using {@link #getOrCreateComponent(Class)},
+ * which will look up the default factory for the component type (factories annotated with the appropriate {@link DefaultFactoryFor} annotation.
+ * <p/>
+ * Default factories are treated as components too and will need to be wired before being used.
+ * <p/>
+ * The registry can exist in one of several states, as defined by the {@link CacheStatus} enumeration. In terms of the cache,
+ * state changes in the following manner:
+ * <ul>
+ * <li>INSTANTIATED - when first constructed</li>
+ * <li>CONSTRUCTED - when created using the DefaultCacheFactory</li>
+ * <li>When {@link org.jboss.cache.Cache_Legacy#create()} is called, the components are rewired.</li>
+ * <li>STARTED - when {@link org.jboss.cache.Cache_Legacy#start()} is called</li>
+ * <li>STOPPED - when {@link org.jboss.cache.Cache_Legacy#stop()} is called</li>
+ * <li>DESTROYED - when {@link org.jboss.cache.Cache_Legacy#destroy()} is called.</li>
+ * </ul>
+ * <p/>
+ * Cache configuration can only be changed and will only be reinjected if the cache is not in the {@link org.jboss.cache.CacheStatus#STARTED} state.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 2.1.0
+ */
+@NonVolatile
+(a)Scope(Scopes.NAMED_CACHE)
+public abstract class AbstractComponentRegistry implements Lifecycle
+{
+ /**
+ * Contains class definitions of component factories that can be used to construct certain components
+ */
+ private Map<Class, Class<? extends ComponentFactory>> defaultFactories = null;
+
+ private static final Log log = LogFactory.getLog(AbstractComponentRegistry.class);
+ private static final boolean trace = log.isTraceEnabled();
+ protected static final Object NULL_COMPONENT = new Object();
+
+ // component and method containers
+ final Map<String, Component> componentLookup = new HashMap<String, Component>();
+
+ CacheStatus state = CacheStatus.INSTANTIATED;
+
+ /**
+ * Hook to shut down the cache when the JVM exits.
+ */
+ private Thread shutdownHook;
+ /**
+ * A flag that the shutdown hook sets before calling cache.stop(). Allows stop() to identify if it has been called
+ * from a shutdown hook.
+ */
+ private boolean invokedFromShutdownHook;
+
+ /**
+ * Retrieves the state of the registry
+ *
+ * @return state of the registry
+ */
+ public CacheStatus getState()
+ {
+ return state;
+ }
+
+ /**
+ * Wires an object instance with dependencies annotated with the {@link org.jboss.cache.factories.annotations.Inject} annotation, creating more components
+ * as needed based on the Configuration passed in if these additional components don't exist in the
+ * {@link ComponentRegistry}. Strictly for components that don't otherwise live in the registry and have a lifecycle, such as Nodes.
+ *
+ * @param target object to wire
+ * @throws ConfigurationException if there is a problem wiring the instance
+ */
+ public void wireDependencies(Object target) throws ConfigurationException
+ {
+ try
+ {
+ // don't use the reflection cache for wireDependencies calls since these are not managed by the ComponentRegistry
+ // and may be invoked at any time, even after the cache starts.
+ List<Method> methods = ReflectionUtil.getAllMethods(target.getClass(), Inject.class);
+
+ // search for anything we need to inject
+ for (Method method : methods) invokeInjectionMethod(target, method);
+ }
+ catch (Exception e)
+ {
+ throw new ConfigurationException("Unable to configure component (type: " + target.getClass() + ", instance " + target + ")", e);
+ }
+ }
+
+ /**
+ * This is hard coded for now, since scanning the classpath for factories annotated with {@link org.jboss.cache.factories.annotations.DefaultFactoryFor}
+ * does not work with all class loaders. This is a temporary solution until a more elegant one can be designed.
+ * <p/>
+ * BE SURE TO ADD ANY NEW FACTORY TYPES ANNOTATED WITH DefaultFactoryFor TO THIS SET!!
+ * <p/>
+ *
+ * @return set of known factory types.
+ */
+ private Set<Class<? extends ComponentFactory>> getHardcodedFactories()
+ {
+ Set<Class<? extends ComponentFactory>> s = new HashSet<Class<? extends ComponentFactory>>();
+ s.add(BootstrapFactory.class);
+ s.add(BuddyManagerFactory.class);
+ s.add(EmptyConstructorFactory.class);
+ s.add(InterceptorChainFactory.class);
+ s.add(RuntimeConfigAwareFactory.class);
+ s.add(TransactionManagerFactory.class);
+ s.add(ReplicationQueueFactory.class);
+ s.add(StateTransferManagerFactory.class);
+ s.add(StateTransferFactory.class);
+ s.add(NullComponentFactory.class);
+ s.add(LockManagerFactory.class);
+ s.add(DataContainerFactory.class);
+ s.add(EvictionManagerFactory.class);
+ return s;
+ }
+
+ /**
+ * Registers a component in the registry under the given type, and injects any dependencies needed. If a component
+ * of this type already exists, it is overwritten.
+ *
+ * @param component component to register
+ * @param type type of component
+ */
+ public void registerComponent(Object component, Class type)
+ {
+
+ String name = type.getName();
+ Component old = componentLookup.get(name);
+
+ if (old != null)
+ {
+ // if they are equal don't bother
+ if (old.instance.equals(component))
+ {
+ if (trace)
+ log.trace("Attempting to register a component equal to one that already exists under the same name (" + name + "). Not doing anything.");
+ return;
+ }
+ }
+
+ Component c;
+ if (old != null)
+ {
+ if (trace) log.trace("Replacing old component " + old + " with new instance " + component);
+ old.instance = component;
+ old.methodsScanned = false;
+ c = old;
+
+ if (state == CacheStatus.STARTED) populateLifecycleMethods();
+ }
+ else
+ {
+ c = new Component();
+ c.name = name;
+ c.instance = component;
+ if (trace) log.trace("Registering component " + c + " under name " + name);
+ componentLookup.put(name, c);
+ }
+ c.nonVolatile = component.getClass().isAnnotationPresent(NonVolatile.class) || type.isAnnotationPresent(NonVolatile.class);
+ addComponentDependencies(c);
+ // inject dependencies for this component
+ c.injectDependencies();
+ }
+
+ /**
+ * Adds component dependencies for a given component, by populating {@link Component#injectionMethods}.
+ *
+ * @param c component to add dependencies to
+ */
+ protected void addComponentDependencies(Component c)
+ {
+ Class type = c.instance.getClass();
+ List<Method> methods = ReflectionUtil.getAllMethods(type, Inject.class);
+ c.injectionMethods.clear();
+ c.injectionMethods.addAll(methods);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void invokeInjectionMethod(Object o, Method m)
+ {
+ Class[] dependencies = m.getParameterTypes();
+ Object[] params = new Object[dependencies.length];
+
+ for (int i = 0; i < dependencies.length; i++)
+ {
+ params[i] = getOrCreateComponent(dependencies[i]);
+ }
+
+ ReflectionUtil.invokeAccessibly(o, m, params);
+ }
+
+ /**
+ * Retrieves a component if one exists, and if not, attempts to find a factory capable of constructing the component
+ * (factories annotated with the {@link DefaultFactoryFor} annotation that is capable of creating the component class).
+ * <p/>
+ * If an instance needs to be constructed, dependencies are then automatically wired into the instance, based on methods
+ * on the component type annotated with {@link Inject}.
+ * <p/>
+ * Summing it up, component retrieval happens in the following order:<br />
+ * 1. Look for a component that has already been created and registered.
+ * 2. Look for an appropriate component that exists in the {@link Configuration} that may be injected from an external system.
+ * 3. Look for a class definition passed in to the {@link org.jboss.cache.config.Configuration} - such as an EvictionPolicy implementation
+ * 4. Attempt to create it by looking for an appropriate factory (annotated with {@link DefaultFactoryFor})
+ * <p/>
+ *
+ * @param componentClass type of component to be retrieved. Should not be null.
+ * @return a fully wired component instance, or null if one cannot be found or constructed.
+ * @throws ConfigurationException if there is a problem with consructing or wiring the instance.
+ */
+ protected <T> T getOrCreateComponent(Class<T> componentClass)
+ {
+
+ T component = getComponent(componentClass);
+
+ if (component == null)
+ {
+ // first see if this has been injected externally.
+ component = getFromConfiguration(componentClass);
+ boolean attemptedFactoryConstruction = false;
+
+ if (component == null)
+ {
+ // create this component and add it to the registry
+ ComponentFactory factory = getFactory(componentClass);
+ component = factory.construct(componentClass);
+ attemptedFactoryConstruction = true;
+
+ }
+
+ if (component != null)
+ {
+ registerComponent(component, componentClass);
+ }
+ else if (attemptedFactoryConstruction)
+ {
+ if (trace) log.trace("Registering a null for component " + componentClass.getSimpleName());
+ registerNullComponent(componentClass);
+ }
+ }
+
+ return component;
+ }
+
+ /**
+ * Retrieves a component factory instance capable of constructing components of a specified type. If the factory doesn't
+ * exist in the registry, one is created.
+ *
+ * @param componentClass type of component to construct
+ * @return component factory capable of constructing such components
+ */
+ protected ComponentFactory getFactory(Class componentClass)
+ {
+ Map<Class, Class<? extends ComponentFactory>> defaultFactoryMap = getDefaultFactoryMap();
+ Class<? extends ComponentFactory> cfClass = defaultFactoryMap.get(componentClass);
+ if (cfClass == null)
+ throw new ConfigurationException("No registered default factory for component " + componentClass + " found!");
+ // a component factory is a component too! See if one has been created and exists in the registry
+ ComponentFactory cf = getComponent(cfClass);
+ if (cf == null)
+ {
+ // hasn't yet been created. Create and put in registry
+ cf = instantiateFactory(cfClass);
+ if (cf == null)
+ throw new ConfigurationException("Unable to locate component factory for component " + componentClass);
+ // we simply register this factory. Registration will take care of constructing any dependencies.
+ registerComponent(cf, cfClass);
+ }
+
+ // ensure the component factory is in the STARTED state!
+ Component c = componentLookup.get(cfClass.getName());
+ if (c.instance != cf)
+ throw new ConfigurationException("Component factory " + cfClass + " incorrectly registered!");
+ return cf;
+ }
+
+ protected Map<Class, Class<? extends ComponentFactory>> getDefaultFactoryMap()
+ {
+ if (defaultFactories == null) scanDefaultFactories();
+ return defaultFactories;
+ }
+
+ /**
+ * Scans the class path for classes annotated with {@link org.jboss.cache.factories.annotations.DefaultFactoryFor}, and
+ * analyses which components can be created by such factories.
+ */
+ void scanDefaultFactories()
+ {
+ defaultFactories = new HashMap<Class, Class<? extends ComponentFactory>>();
+
+ Set<Class<? extends ComponentFactory>> factories = getHardcodedFactories();
+
+ for (Class<? extends ComponentFactory> factory : factories)
+ {
+ DefaultFactoryFor dFFAnnotation = factory.getAnnotation(DefaultFactoryFor.class);
+ for (Class targetClass : dFFAnnotation.classes()) defaultFactories.put(targetClass, factory);
+ }
+ }
+
+ /**
+ * No such thing as a meta factory yet. Factories are created using this method which attempts to use an empty public
+ * constructor.
+ *
+ * @param factory class of factory to be created
+ * @return factory instance
+ */
+ ComponentFactory instantiateFactory(Class<? extends ComponentFactory> factory)
+ {
+ try
+ {
+ return factory.newInstance();
+ }
+ catch (Exception e)
+ {
+ // unable to get a hold of an instance!!
+ throw new ConfigurationException("Unable to instantiate factory " + factory, e);
+ }
+ }
+
+ /**
+ * registers a special "null" component that has no dependencies.
+ *
+ * @param type type of component to register as a null
+ */
+ void registerNullComponent(Class type)
+ {
+ registerComponent(NULL_COMPONENT, type);
+ }
+
+ /**
+ * Retrieves a component from the {@link Configuration} or {@link RuntimeConfig}.
+ *
+ * @param componentClass component type
+ * @return component, or null if it cannot be found
+ */
+ @SuppressWarnings("unchecked")
+ protected <T> T getFromConfiguration(Class<T> componentClass)
+ {
+ if (log.isDebugEnabled())
+ log.debug("Looking in configuration for an instance of " + componentClass + " that may have been injected from an external source.");
+ Method getter = BeanUtils.getterMethod(Configuration.class, componentClass);
+ T returnValue = null;
+
+ if (getter != null)
+ {
+ try
+ {
+ returnValue = (T) getter.invoke(getConfiguration());
+ }
+ catch (Exception e)
+ {
+ log.warn("Unable to invoke getter " + getter + " on Configuration.class!", e);
+ }
+ }
+
+ // now try the RuntimeConfig - a legacy "registry" of sorts.
+ if (returnValue == null)
+ {
+ getter = BeanUtils.getterMethod(RuntimeConfig.class, componentClass);
+ if (getter != null)
+ {
+ try
+ {
+ returnValue = (T) getter.invoke(getConfiguration().getRuntimeConfig());
+ }
+ catch (Exception e)
+ {
+ log.warn("Unable to invoke getter " + getter + " on RuntimeConfig.class!", e);
+ }
+ }
+ }
+ return returnValue;
+ }
+
+ /**
+ * Retrieves the configuration component.
+ *
+ * @return a Configuration object
+ */
+ protected Configuration getConfiguration()
+ {
+ // this is assumed to always be present as a part of the bootstrap/construction of a ComponentRegistry.
+ return getComponent(Configuration.class);
+ }
+
+ /**
+ * Retrieves a component of a specified type from the registry, or null if it cannot be found.
+ *
+ * @param type type to find
+ * @return component, or null
+ */
+ @SuppressWarnings("unchecked")
+ public <T> T getComponent(Class<T> type)
+ {
+ Component wrapper = componentLookup.get(type.getName());
+ if (wrapper == null) return null;
+
+ return (T) (wrapper.instance == NULL_COMPONENT ? null : wrapper.instance);
+ }
+
+ /**
+ * Rewires components. Can only be called if the current state is WIRED or STARTED.
+ */
+ public void rewire()
+ {
+ // need to re-inject everything again.
+ for (Component c : new HashSet<Component>(componentLookup.values()))
+ {
+ // inject dependencies for this component
+ c.injectDependencies();
+ }
+ }
+
+ /**
+ * Scans each registered component for lifecycle methods, and adds them to the appropriate lists, and then sorts them
+ * by priority.
+ */
+ private void populateLifecycleMethods()
+ {
+ for (Component c : componentLookup.values())
+ {
+ if (!c.methodsScanned)
+ {
+ c.methodsScanned = true;
+ c.startMethods.clear();
+ c.stopMethods.clear();
+ c.destroyMethods.clear();
+
+ List<Method> methods = ReflectionUtil.getAllMethods(c.instance.getClass(), Start.class);
+ for (Method m : methods)
+ {
+ PrioritizedMethod em = new PrioritizedMethod();
+ em.component = c;
+ em.method = m;
+ em.priority = m.getAnnotation(Start.class).priority();
+ c.startMethods.add(em);
+ }
+
+ methods = ReflectionUtil.getAllMethods(c.instance.getClass(), Stop.class);
+ for (Method m : methods)
+ {
+ PrioritizedMethod em = new PrioritizedMethod();
+ em.component = c;
+ em.method = m;
+ em.priority = m.getAnnotation(Stop.class).priority();
+ c.stopMethods.add(em);
+ }
+
+ methods = ReflectionUtil.getAllMethods(c.instance.getClass(), Destroy.class);
+ for (Method m : methods)
+ {
+ PrioritizedMethod em = new PrioritizedMethod();
+ em.component = c;
+ em.method = m;
+ em.priority = m.getAnnotation(Destroy.class).priority();
+ c.destroyMethods.add(em);
+ }
+ }
+ }
+ }
+
+ /**
+ * Removes any components not annotated as @NonVolatile.
+ */
+ public void resetNonVolatile()
+ {
+ // destroy all components to clean up resources
+ for (Component c : new HashSet<Component>(componentLookup.values()))
+ {
+ // the component is volatile!!
+ if (!c.nonVolatile)
+ {
+ componentLookup.remove(c.name);
+ }
+ }
+
+ if (trace) log.trace("Reset volatile components. Registry now contains " + componentLookup.keySet());
+ }
+
+ // ------------------------------ START: Publicly available lifecycle methods -----------------------------
+ // These methods perform a check for appropriate transition and then delegate to similarly named internal methods.
+
+ /**
+ * Creates the components needed by a cache instance and sets the cache status to {@link org.jboss.cache.CacheStatus#CREATED}
+ * when it is done.
+ */
+ public void create()
+ {
+ if (!state.createAllowed())
+ {
+ if (state.needToDestroyFailedCache())
+ destroy();
+ else
+ return;
+ }
+
+ try
+ {
+ internalCreate();
+ }
+ catch (Throwable t)
+ {
+ handleLifecycleTransitionFailure(t);
+ }
+ }
+
+ /**
+ * This starts the components in the cache, connecting to channels, starting service threads, etc. If the cache is
+ * not in the {@link org.jboss.cache.CacheStatus#CREATED} state, {@link #create()} will be invoked first.
+ */
+ public void start()
+ {
+ boolean createdInStart = false;
+ if (!state.startAllowed())
+ {
+ if (state.needToDestroyFailedCache())
+ destroy(); // this will take us back to DESTROYED
+
+ if (state.needCreateBeforeStart())
+ {
+ create();
+ createdInStart = true;
+ }
+ else
+ return;
+ }
+
+ try
+ {
+ internalStart(createdInStart);
+ }
+ catch (Throwable t)
+ {
+ handleLifecycleTransitionFailure(t);
+ }
+ }
+
+ /**
+ * Stops the cache and sets the cache status to {@link org.jboss.cache.CacheStatus#STOPPED} once it is done. If the cache is not in
+ * the {@link org.jboss.cache.CacheStatus#STARTED} state, this is a no-op.
+ */
+ public void stop()
+ {
+ if (!state.stopAllowed())
+ {
+ return;
+ }
+
+ // Trying to stop() from FAILED is valid, but may not work
+ boolean failed = state == CacheStatus.FAILED;
+
+ try
+ {
+ internalStop();
+ }
+ catch (Throwable t)
+ {
+ if (failed)
+ {
+ log.warn("Attempted to stop() from FAILED state, but caught exception; try calling destroy()", t);
+ }
+ failed = true;
+ handleLifecycleTransitionFailure(t);
+ }
+ finally
+ {
+ if (!failed) state = CacheStatus.STOPPED;
+ }
+ }
+
+ /**
+ * Destroys the cache and frees up any resources. Sets the cache status to {@link CacheStatus#DESTROYED} when it is done.
+ * <p/>
+ * If the cache is in {@link org.jboss.cache.CacheStatus#STARTED} when this method is called, it will first call {@link #stop()}
+ * to stop the cache.
+ */
+ public void destroy()
+ {
+ if (!state.destroyAllowed())
+ {
+ if (state.needStopBeforeDestroy())
+ {
+ try
+ {
+ stop();
+ }
+ catch (CacheException e)
+ {
+ log.warn("Needed to call stop() before destroying but stop() threw exception. Proceeding to destroy", e);
+ }
+ }
+ else
+ return;
+ }
+
+ try
+ {
+ internalDestroy();
+ }
+ finally
+ {
+ // We always progress to destroyed
+ state = CacheStatus.DESTROYED;
+ }
+ }
+ // ------------------------------ END: Publicly available lifecycle methods -----------------------------
+
+ // ------------------------------ START: Actual internal lifecycle methods --------------------------------
+
+ /**
+ * Sets the cacheStatus to FAILED and rethrows the problem as one
+ * of the declared types. Converts any non-RuntimeException Exception
+ * to CacheException.
+ *
+ * @param t throwable thrown during failure
+ */
+ private void handleLifecycleTransitionFailure(Throwable t)
+ {
+ state = CacheStatus.FAILED;
+ if (t instanceof CacheException)
+ throw (CacheException) t;
+ else if (t instanceof RuntimeException)
+ throw (RuntimeException) t;
+ else if (t instanceof Error)
+ throw (Error) t;
+ else
+ throw new CacheException(t);
+ }
+
+ /**
+ * The actual create implementation.
+ */
+ private void internalCreate()
+ {
+ state = CacheStatus.CREATING;
+ resetNonVolatile();
+ rewire();
+ state = CacheStatus.CREATED;
+ }
+
+ private void internalStart(boolean createdInStart) throws CacheException, IllegalArgumentException
+ {
+ if (!createdInStart)
+ {
+ // re-wire all dependencies in case stuff has changed since the cache was created
+ // remove any components whose construction may have depended upon a configuration that may have changed.
+ resetNonVolatile();
+ rewire();
+ }
+
+ state = CacheStatus.STARTING;
+
+ // start all internal components
+ // first cache all start, stop and destroy methods.
+ populateLifecycleMethods();
+
+ List<PrioritizedMethod> startMethods = new ArrayList<PrioritizedMethod>(componentLookup.size());
+ for (Component c : componentLookup.values()) startMethods.addAll(c.startMethods);
+
+ // sort the start methods by priority
+ Collections.sort(startMethods);
+
+ // fire all START methods according to priority
+
+
+ for (PrioritizedMethod em : startMethods) em.invoke();
+
+ addShutdownHook();
+
+ log.info("JBoss Cache version: " + Version.printVersion());
+ state = CacheStatus.STARTED;
+ }
+
+ private void addShutdownHook()
+ {
+ ArrayList al = MBeanServerFactory.findMBeanServer(null);
+ boolean registerShutdownHook = (getConfiguration().getShutdownHookBehavior() == Configuration.ShutdownHookBehavior.DEFAULT && al.size() == 0)
+ || getConfiguration().getShutdownHookBehavior() == Configuration.ShutdownHookBehavior.REGISTER;
+
+ if (registerShutdownHook)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Registering a shutdown hook. Configured behavior = " + getConfiguration().getShutdownHookBehavior());
+ shutdownHook = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ invokedFromShutdownHook = true;
+ AbstractComponentRegistry.this.stop();
+ }
+ finally
+ {
+ invokedFromShutdownHook = false;
+ }
+ }
+ };
+
+ Runtime.getRuntime().addShutdownHook(shutdownHook);
+ }
+ else
+ {
+ if (log.isTraceEnabled())
+ log.trace("Not registering a shutdown hook. Configured behavior = " + getConfiguration().getShutdownHookBehavior());
+ }
+ }
+
+ /**
+ * Actual stop
+ */
+ private void internalStop()
+ {
+ state = CacheStatus.STOPPING;
+ // if this is called from a source other than the shutdown hook, deregister the shutdown hook.
+ if (!invokedFromShutdownHook && shutdownHook != null) Runtime.getRuntime().removeShutdownHook(shutdownHook);
+
+ List<PrioritizedMethod> stopMethods = new ArrayList<PrioritizedMethod>(componentLookup.size());
+ for (Component c : componentLookup.values()) stopMethods.addAll(c.stopMethods);
+
+ Collections.sort(stopMethods);
+
+ // fire all STOP methods according to priority
+ for (PrioritizedMethod em : stopMethods) em.invoke();
+
+ state = CacheStatus.STOPPED;
+ }
+
+ /**
+ * Actual destroy
+ */
+ private void internalDestroy()
+ {
+
+ state = CacheStatus.DESTROYING;
+
+ resetNonVolatile();
+
+ List<PrioritizedMethod> destroyMethods = new ArrayList<PrioritizedMethod>(componentLookup.size());
+ for (Component c : componentLookup.values()) destroyMethods.addAll(c.destroyMethods);
+
+ Collections.sort(destroyMethods);
+
+ // fire all DESTROY methods according to priority
+ for (PrioritizedMethod em : destroyMethods) em.invoke();
+
+ state = CacheStatus.DESTROYED;
+ }
+
+ // ------------------------------ END: Actual internal lifecycle methods --------------------------------
+
+ /**
+ * Asserts whether invocations are allowed on the cache or not. Returns <tt>true</tt> if invocations are to be allowed,
+ * <tt>false</tt> otherwise. If the origin of the call is remote and the cache status is {@link org.jboss.cache.CacheStatus#STARTING},
+ * this method will block for up to {@link org.jboss.cache.config.Configuration#getStateRetrievalTimeout()} millis, checking
+ * for a valid state.
+ *
+ * @param originLocal true if the call originates locally (i.e., from the {@link org.jboss.cache.invocation.CacheInvocationDelegate} or false if it originates remotely, i.e., from the {@link org.jboss.cache.marshall.CommandAwareRpcDispatcher}.
+ * @return true if invocations are allowed, false otherwise.
+ */
+ public boolean invocationsAllowed(boolean originLocal)
+ {
+ log.trace("Testing if invocations are allowed.");
+ if (state.allowInvocations()) return true;
+
+ // if this is a locally originating call and the cache is not in a valid state, return false.
+ if (originLocal) return false;
+
+ log.trace("Is remotely originating.");
+
+ // else if this is a remote call and the status is STARTING, wait until the cache starts.
+ if (state == CacheStatus.STARTING)
+ {
+ log.trace("Cache is starting; block.");
+ try
+ {
+ blockUntilCacheStarts();
+ return true;
+ }
+ catch (InterruptedException e)
+ {
+ Thread.currentThread().interrupt();
+ }
+ }
+ else
+ {
+ log.warn("Received a remote call but the cache is not in STARTED state - ignoring call.");
+ }
+ return false;
+ }
+
+ /**
+ * Blocks until the current cache instance is in its {@link org.jboss.cache.CacheStatus#STARTED started} phase. Blocks
+ * for up to {@link org.jboss.cache.config.Configuration#getStateRetrievalTimeout()} milliseconds, throwing an IllegalStateException
+ * if the cache doesn't reach this state even after this maximum wait time.
+ *
+ * @throws InterruptedException if interrupted while waiting
+ * @throws IllegalStateException if even after waiting the cache has not started.
+ */
+ private void blockUntilCacheStarts() throws InterruptedException, IllegalStateException
+ {
+ int pollFrequencyMS = 100;
+ long startupWaitTime = getConfiguration().getStateRetrievalTimeout();
+ long giveUpTime = System.currentTimeMillis() + startupWaitTime;
+
+ while (System.currentTimeMillis() < giveUpTime)
+ {
+ if (state.allowInvocations()) break;
+ Thread.sleep(pollFrequencyMS);
+ }
+
+ // check if we have started.
+ if (!state.allowInvocations())
+ throw new IllegalStateException("Cache not in STARTED state, even after waiting " + getConfiguration().getStateRetrievalTimeout() + " millis.");
+ }
+
+ /**
+ * A wrapper representing a component in the registry
+ */
+ public class Component
+ {
+ /**
+ * A reference to the object instance for this component.
+ */
+ Object instance;
+ /**
+ * The name of the component
+ */
+ String name;
+ boolean methodsScanned;
+ /**
+ * List of injection methods used to inject dependencies into the component
+ */
+ List<Method> injectionMethods = new ArrayList<Method>(2);
+ List<PrioritizedMethod> startMethods = new ArrayList<PrioritizedMethod>(2);
+ List<PrioritizedMethod> stopMethods = new ArrayList<PrioritizedMethod>(2);
+ List<PrioritizedMethod> destroyMethods = new ArrayList<PrioritizedMethod>(2);
+ /**
+ * If true, then this component is not flushed before starting the ComponentRegistry.
+ */
+ boolean nonVolatile;
+
+ @Override
+ public String toString()
+ {
+ return "Component{" +
+ "instance=" + instance +
+ ", name=" + name +
+ ", nonVolatile=" + nonVolatile +
+ '}';
+ }
+
+ /**
+ * Injects dependencies into this component.
+ */
+ public void injectDependencies()
+ {
+ for (Method m : injectionMethods) invokeInjectionMethod(instance, m);
+ }
+
+ public Object getInstance()
+ {
+ return instance;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+ }
+
+
+ /**
+ * Wrapper to encapsulate a method along with a priority
+ */
+ static class PrioritizedMethod implements Comparable<PrioritizedMethod>
+ {
+ Method method;
+ Component component;
+ int priority;
+
+ public int compareTo(PrioritizedMethod o)
+ {
+ return (priority < o.priority ? -1 : (priority == o.priority ? 0 : 1));
+ }
+
+ void invoke()
+ {
+ ReflectionUtil.invokeAccessibly(component.instance, method, null);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "PrioritizedMethod{" +
+ "method=" + method +
+ ", priority=" + priority +
+ '}';
+ }
+ }
+
+ /**
+ * Returns an immutable set contating all the components that exists in the reporsitory at this moment.
+ */
+ public Set<Component> getRegiteredComponents()
+ {
+ HashSet<Component> defensiveCopy = new HashSet<Component>(componentLookup.values());
+ return Collections.unmodifiableSet(defensiveCopy);
+ }
+}
Property changes on: core/branches/flat/src/main/java/org/jboss/starobrno/factories/AbstractComponentRegistry.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentFactory.java 2009-01-15 16:48:16 UTC (rev 7480)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentFactory.java 2009-01-15 18:46:35 UTC (rev 7481)
@@ -42,7 +42,7 @@
* @see ComponentRegistry
* @since 2.1.0
*/
-(a)Scope(Scopes.CACHE_ONLY)
+(a)Scope(Scopes.NAMED_CACHE)
public abstract class ComponentFactory
{
protected final Log log = LogFactory.getLog(getClass());
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentRegistry.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentRegistry.java 2009-01-15 16:48:16 UTC (rev 7480)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentRegistry.java 2009-01-15 18:46:35 UTC (rev 7481)
@@ -1,1002 +0,0 @@
-/*
- * 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.starobrno.factories;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheStatus;
-import org.jboss.cache.Version;
-import org.jboss.starobrno.CacheException;
-import org.jboss.starobrno.CacheSPI;
-import org.jboss.starobrno.config.Configuration;
-import org.jboss.starobrno.config.ConfigurationException;
-import org.jboss.starobrno.config.RuntimeConfig;
-import org.jboss.starobrno.factories.annotations.DefaultFactoryFor;
-import org.jboss.starobrno.factories.annotations.Destroy;
-import org.jboss.starobrno.factories.annotations.Inject;
-import org.jboss.starobrno.factories.annotations.NonVolatile;
-import org.jboss.starobrno.factories.annotations.Start;
-import org.jboss.starobrno.factories.annotations.Stop;
-import org.jboss.starobrno.factories.scopes.Scope;
-import org.jboss.starobrno.factories.scopes.Scopes;
-import org.jboss.starobrno.lifecycle.Lifecycle;
-import org.jboss.starobrno.util.BeanUtils;
-import org.jboss.starobrno.util.ReflectionUtil;
-
-import javax.management.MBeanServerFactory;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * A registry where components which have been created are stored. Components are stored as singletons, registered under
- * a specific name.
- * <p/>
- * Components can be retrieved from the registry using {@link #getComponent(Class)}.
- * <p/>
- * Components can be registered using {@link #registerComponent(Object, Class)}, which will cause any dependencies to be
- * wired in as well. Components that need to be created as a result of wiring will be done using {@link #getOrCreateComponent(Class)},
- * which will look up the default factory for the component type (factories annotated with the appropriate {@link DefaultFactoryFor} annotation.
- * <p/>
- * Default factories are treated as components too and will need to be wired before being used.
- * <p/>
- * The registry can exist in one of several states, as defined by the {@link CacheStatus} enumeration. In terms of the cache,
- * state changes in the following manner:
- * <ul>
- * <li>INSTANTIATED - when first constructed</li>
- * <li>CONSTRUCTED - when created using the DefaultCacheFactory</li>
- * <li>When {@link org.jboss.cache.Cache_Legacy#create()} is called, the components are rewired.</li>
- * <li>STARTED - when {@link org.jboss.cache.Cache_Legacy#start()} is called</li>
- * <li>STOPPED - when {@link org.jboss.cache.Cache_Legacy#stop()} is called</li>
- * <li>DESTROYED - when {@link org.jboss.cache.Cache_Legacy#destroy()} is called.</li>
- * </ul>
- * <p/>
- * Cache configuration can only be changed and will only be reinjected if the cache is not in the {@link org.jboss.cache.CacheStatus#STARTED} state.
- *
- * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
- * @since 2.1.0
- */
-@NonVolatile
-(a)Scope(Scopes.CACHE_ONLY)
-public class ComponentRegistry implements Lifecycle
-{
- /**
- * Contains class definitions of component factories that can be used to construct certain components
- */
- private Map<Class, Class<? extends ComponentFactory>> defaultFactories = null;
-
- private static final Log log = LogFactory.getLog(ComponentRegistry.class);
- private static final boolean trace = log.isTraceEnabled();
- protected static final Object NULL_COMPONENT = new Object();
-
- // component and method containers
- final Map<String, Component> componentLookup = new HashMap<String, Component>();
-
- CacheStatus state = CacheStatus.INSTANTIATED;
-
- /**
- * Hook to shut down the cache when the JVM exits.
- */
- private Thread shutdownHook;
- /**
- * A flag that the shutdown hook sets before calling cache.stop(). Allows stop() to identify if it has been called
- * from a shutdown hook.
- */
- private boolean invokedFromShutdownHook;
-
- /**
- * Creates an instance of the component registry. The configuration passed in is automatically registered.
- *
- * @param configuration configuration with which this is created
- */
- public ComponentRegistry(Configuration configuration, CacheSPI cache)
- {
- try
- {
- // bootstrap.
- registerDefaultClassLoader(null);
- registerComponent(this, ComponentRegistry.class);
- registerComponent(configuration, Configuration.class);
- registerComponent(new BootstrapFactory(cache, configuration, this), BootstrapFactory.class);
- }
- catch (Exception e)
- {
- throw new CacheException("Unable to construct ComponentRegistry", e);
- }
- }
-
- /**
- * Retrieves the state of the registry
- *
- * @return state of the registry
- */
- public CacheStatus getState()
- {
- return state;
- }
-
- /**
- * Wires an object instance with dependencies annotated with the {@link org.jboss.cache.factories.annotations.Inject} annotation, creating more components
- * as needed based on the Configuration passed in if these additional components don't exist in the
- * {@link ComponentRegistry}. Strictly for components that don't otherwise live in the registry and have a lifecycle, such as Nodes.
- *
- * @param target object to wire
- * @throws ConfigurationException if there is a problem wiring the instance
- */
- public void wireDependencies(Object target) throws ConfigurationException
- {
- try
- {
- // don't use the reflection cache for wireDependencies calls since these are not managed by the ComponentRegistry
- // and may be invoked at any time, even after the cache starts.
- List<Method> methods = ReflectionUtil.getAllMethods(target.getClass(), Inject.class);
-
- // search for anything we need to inject
- for (Method method : methods) invokeInjectionMethod(target, method);
- }
- catch (Exception e)
- {
- throw new ConfigurationException("Unable to configure component (type: " + target.getClass() + ", instance " + target + ")", e);
- }
- }
-
- /**
- * Registers the default class loader. This method *must* be called before any other components are registered,
- * typically called by bootstrap code. Defensively, it is called in the constructor of ComponentRegistry with a null
- * parameter.
- *
- * @param loader a class loader to use by default. If this is null, the class loader used to load this instance of ComponentRegistry is used.
- */
- public void registerDefaultClassLoader(ClassLoader loader)
- {
- registerComponent(loader == null ? getClass().getClassLoader() : loader, ClassLoader.class);
- // make sure the class loader is non-volatile, so it survives restarts.
- componentLookup.get(ClassLoader.class.getName()).nonVolatile = true;
- }
-
- /**
- * This is hard coded for now, since scanning the classpath for factories annotated with {@link org.jboss.cache.factories.annotations.DefaultFactoryFor}
- * does not work with all class loaders. This is a temporary solution until a more elegant one can be designed.
- * <p/>
- * BE SURE TO ADD ANY NEW FACTORY TYPES ANNOTATED WITH DefaultFactoryFor TO THIS SET!!
- * <p/>
- *
- * @return set of known factory types.
- */
- private Set<Class<? extends ComponentFactory>> getHardcodedFactories()
- {
- Set<Class<? extends ComponentFactory>> s = new HashSet<Class<? extends ComponentFactory>>();
- s.add(BootstrapFactory.class);
- s.add(BuddyManagerFactory.class);
- s.add(EmptyConstructorFactory.class);
- s.add(InterceptorChainFactory.class);
- s.add(RuntimeConfigAwareFactory.class);
- s.add(TransactionManagerFactory.class);
- s.add(ReplicationQueueFactory.class);
- s.add(StateTransferManagerFactory.class);
- s.add(StateTransferFactory.class);
- s.add(NullComponentFactory.class);
- s.add(LockManagerFactory.class);
- s.add(DataContainerFactory.class);
- s.add(EvictionManagerFactory.class);
- return s;
- }
-
- /**
- * Registers a component in the registry under the given type, and injects any dependencies needed. If a component
- * of this type already exists, it is overwritten.
- *
- * @param component component to register
- * @param type type of component
- */
- public void registerComponent(Object component, Class type)
- {
-
- String name = type.getName();
- Component old = componentLookup.get(name);
-
- if (old != null)
- {
- // if they are equal don't bother
- if (old.instance.equals(component))
- {
- if (trace)
- log.trace("Attempting to register a component equal to one that already exists under the same name (" + name + "). Not doing anything.");
- return;
- }
- }
-
- Component c;
- if (old != null)
- {
- if (trace) log.trace("Replacing old component " + old + " with new instance " + component);
- old.instance = component;
- old.methodsScanned = false;
- c = old;
-
- if (state == CacheStatus.STARTED) populateLifecycleMethods();
- }
- else
- {
- c = new Component();
- c.name = name;
- c.instance = component;
- if (trace) log.trace("Registering component " + c + " under name " + name);
- componentLookup.put(name, c);
- }
- c.nonVolatile = component.getClass().isAnnotationPresent(NonVolatile.class) || type.isAnnotationPresent(NonVolatile.class);
- addComponentDependencies(c);
- // inject dependencies for this component
- c.injectDependencies();
- }
-
- /**
- * Adds component dependencies for a given component, by populating {@link Component#injectionMethods}.
- *
- * @param c component to add dependencies to
- */
- protected void addComponentDependencies(Component c)
- {
- Class type = c.instance.getClass();
- List<Method> methods = ReflectionUtil.getAllMethods(type, Inject.class);
- c.injectionMethods.clear();
- c.injectionMethods.addAll(methods);
- }
-
- @SuppressWarnings("unchecked")
- protected void invokeInjectionMethod(Object o, Method m)
- {
- Class[] dependencies = m.getParameterTypes();
- Object[] params = new Object[dependencies.length];
-
- for (int i = 0; i < dependencies.length; i++)
- {
- params[i] = getOrCreateComponent(dependencies[i]);
- }
-
- ReflectionUtil.invokeAccessibly(o, m, params);
- }
-
- /**
- * Retrieves a component if one exists, and if not, attempts to find a factory capable of constructing the component
- * (factories annotated with the {@link DefaultFactoryFor} annotation that is capable of creating the component class).
- * <p/>
- * If an instance needs to be constructed, dependencies are then automatically wired into the instance, based on methods
- * on the component type annotated with {@link Inject}.
- * <p/>
- * Summing it up, component retrieval happens in the following order:<br />
- * 1. Look for a component that has already been created and registered.
- * 2. Look for an appropriate component that exists in the {@link Configuration} that may be injected from an external system.
- * 3. Look for a class definition passed in to the {@link org.jboss.cache.config.Configuration} - such as an EvictionPolicy implementation
- * 4. Attempt to create it by looking for an appropriate factory (annotated with {@link DefaultFactoryFor})
- * <p/>
- *
- * @param componentClass type of component to be retrieved. Should not be null.
- * @return a fully wired component instance, or null if one cannot be found or constructed.
- * @throws ConfigurationException if there is a problem with consructing or wiring the instance.
- */
- protected <T> T getOrCreateComponent(Class<T> componentClass)
- {
-
- T component = getComponent(componentClass);
-
- if (component == null)
- {
- // first see if this has been injected externally.
- component = getFromConfiguration(componentClass);
- boolean attemptedFactoryConstruction = false;
-
- if (component == null)
- {
- // create this component and add it to the registry
- ComponentFactory factory = getFactory(componentClass);
- component = factory.construct(componentClass);
- attemptedFactoryConstruction = true;
-
- }
-
- if (component != null)
- {
- registerComponent(component, componentClass);
- }
- else if (attemptedFactoryConstruction)
- {
- if (trace) log.trace("Registering a null for component " + componentClass.getSimpleName());
- registerNullComponent(componentClass);
- }
- }
-
- return component;
- }
-
- /**
- * Retrieves a component factory instance capable of constructing components of a specified type. If the factory doesn't
- * exist in the registry, one is created.
- *
- * @param componentClass type of component to construct
- * @return component factory capable of constructing such components
- */
- protected ComponentFactory getFactory(Class componentClass)
- {
- Map<Class, Class<? extends ComponentFactory>> defaultFactoryMap = getDefaultFactoryMap();
- Class<? extends ComponentFactory> cfClass = defaultFactoryMap.get(componentClass);
- if (cfClass == null)
- throw new ConfigurationException("No registered default factory for component " + componentClass + " found!");
- // a component factory is a component too! See if one has been created and exists in the registry
- ComponentFactory cf = getComponent(cfClass);
- if (cf == null)
- {
- // hasn't yet been created. Create and put in registry
- cf = instantiateFactory(cfClass);
- if (cf == null)
- throw new ConfigurationException("Unable to locate component factory for component " + componentClass);
- // we simply register this factory. Registration will take care of constructing any dependencies.
- registerComponent(cf, cfClass);
- }
-
- // ensure the component factory is in the STARTED state!
- Component c = componentLookup.get(cfClass.getName());
- if (c.instance != cf)
- throw new ConfigurationException("Component factory " + cfClass + " incorrectly registered!");
- return cf;
- }
-
- protected Map<Class, Class<? extends ComponentFactory>> getDefaultFactoryMap()
- {
- if (defaultFactories == null) scanDefaultFactories();
- return defaultFactories;
- }
-
- /**
- * Scans the class path for classes annotated with {@link org.jboss.cache.factories.annotations.DefaultFactoryFor}, and
- * analyses which components can be created by such factories.
- */
- void scanDefaultFactories()
- {
- defaultFactories = new HashMap<Class, Class<? extends ComponentFactory>>();
-
- Set<Class<? extends ComponentFactory>> factories = getHardcodedFactories();
-
- for (Class<? extends ComponentFactory> factory : factories)
- {
- DefaultFactoryFor dFFAnnotation = factory.getAnnotation(DefaultFactoryFor.class);
- for (Class targetClass : dFFAnnotation.classes()) defaultFactories.put(targetClass, factory);
- }
- }
-
- /**
- * No such thing as a meta factory yet. Factories are created using this method which attempts to use an empty public
- * constructor.
- *
- * @param factory class of factory to be created
- * @return factory instance
- */
- ComponentFactory instantiateFactory(Class<? extends ComponentFactory> factory)
- {
- try
- {
- return factory.newInstance();
- }
- catch (Exception e)
- {
- // unable to get a hold of an instance!!
- throw new ConfigurationException("Unable to instantiate factory " + factory, e);
- }
- }
-
- /**
- * registers a special "null" component that has no dependencies.
- *
- * @param type type of component to register as a null
- */
- void registerNullComponent(Class type)
- {
- registerComponent(NULL_COMPONENT, type);
- }
-
- /**
- * Retrieves a component from the {@link Configuration} or {@link RuntimeConfig}.
- *
- * @param componentClass component type
- * @return component, or null if it cannot be found
- */
- @SuppressWarnings("unchecked")
- protected <T> T getFromConfiguration(Class<T> componentClass)
- {
- if (log.isDebugEnabled())
- log.debug("Looking in configuration for an instance of " + componentClass + " that may have been injected from an external source.");
- Method getter = BeanUtils.getterMethod(Configuration.class, componentClass);
- T returnValue = null;
-
- if (getter != null)
- {
- try
- {
- returnValue = (T) getter.invoke(getConfiguration());
- }
- catch (Exception e)
- {
- log.warn("Unable to invoke getter " + getter + " on Configuration.class!", e);
- }
- }
-
- // now try the RuntimeConfig - a legacy "registry" of sorts.
- if (returnValue == null)
- {
- getter = BeanUtils.getterMethod(RuntimeConfig.class, componentClass);
- if (getter != null)
- {
- try
- {
- returnValue = (T) getter.invoke(getConfiguration().getRuntimeConfig());
- }
- catch (Exception e)
- {
- log.warn("Unable to invoke getter " + getter + " on RuntimeConfig.class!", e);
- }
- }
- }
- return returnValue;
- }
-
- /**
- * Retrieves the configuration component.
- *
- * @return a Configuration object
- */
- protected Configuration getConfiguration()
- {
- // this is assumed to always be present as a part of the bootstrap/construction of a ComponentRegistry.
- return getComponent(Configuration.class);
- }
-
- /**
- * Retrieves a component of a specified type from the registry, or null if it cannot be found.
- *
- * @param type type to find
- * @return component, or null
- */
- @SuppressWarnings("unchecked")
- public <T> T getComponent(Class<T> type)
- {
- Component wrapper = componentLookup.get(type.getName());
- if (wrapper == null) return null;
-
- return (T) (wrapper.instance == NULL_COMPONENT ? null : wrapper.instance);
- }
-
- /**
- * Rewires components. Can only be called if the current state is WIRED or STARTED.
- */
- public void rewire()
- {
- // need to re-inject everything again.
- for (Component c : new HashSet<Component>(componentLookup.values()))
- {
- // inject dependencies for this component
- c.injectDependencies();
- }
- }
-
- /**
- * Scans each registered component for lifecycle methods, and adds them to the appropriate lists, and then sorts them
- * by priority.
- */
- private void populateLifecycleMethods()
- {
- for (Component c : componentLookup.values())
- {
- if (!c.methodsScanned)
- {
- c.methodsScanned = true;
- c.startMethods.clear();
- c.stopMethods.clear();
- c.destroyMethods.clear();
-
- List<Method> methods = ReflectionUtil.getAllMethods(c.instance.getClass(), Start.class);
- for (Method m : methods)
- {
- PrioritizedMethod em = new PrioritizedMethod();
- em.component = c;
- em.method = m;
- em.priority = m.getAnnotation(Start.class).priority();
- c.startMethods.add(em);
- }
-
- methods = ReflectionUtil.getAllMethods(c.instance.getClass(), Stop.class);
- for (Method m : methods)
- {
- PrioritizedMethod em = new PrioritizedMethod();
- em.component = c;
- em.method = m;
- em.priority = m.getAnnotation(Stop.class).priority();
- c.stopMethods.add(em);
- }
-
- methods = ReflectionUtil.getAllMethods(c.instance.getClass(), Destroy.class);
- for (Method m : methods)
- {
- PrioritizedMethod em = new PrioritizedMethod();
- em.component = c;
- em.method = m;
- em.priority = m.getAnnotation(Destroy.class).priority();
- c.destroyMethods.add(em);
- }
- }
- }
- }
-
- /**
- * Removes any components not annotated as @NonVolatile.
- */
- public void resetNonVolatile()
- {
- // destroy all components to clean up resources
- for (Component c : new HashSet<Component>(componentLookup.values()))
- {
- // the component is volatile!!
- if (!c.nonVolatile)
- {
- componentLookup.remove(c.name);
- }
- }
-
- if (trace) log.trace("Reset volatile components. Registry now contains " + componentLookup.keySet());
- }
-
- // ------------------------------ START: Publicly available lifecycle methods -----------------------------
- // These methods perform a check for appropriate transition and then delegate to similarly named internal methods.
-
- /**
- * Creates the components needed by a cache instance and sets the cache status to {@link org.jboss.cache.CacheStatus#CREATED}
- * when it is done.
- */
- public void create()
- {
- if (!state.createAllowed())
- {
- if (state.needToDestroyFailedCache())
- destroy();
- else
- return;
- }
-
- try
- {
- internalCreate();
- }
- catch (Throwable t)
- {
- handleLifecycleTransitionFailure(t);
- }
- }
-
- /**
- * This starts the components in the cache, connecting to channels, starting service threads, etc. If the cache is
- * not in the {@link org.jboss.cache.CacheStatus#CREATED} state, {@link #create()} will be invoked first.
- */
- public void start()
- {
- boolean createdInStart = false;
- if (!state.startAllowed())
- {
- if (state.needToDestroyFailedCache())
- destroy(); // this will take us back to DESTROYED
-
- if (state.needCreateBeforeStart())
- {
- create();
- createdInStart = true;
- }
- else
- return;
- }
-
- try
- {
- internalStart(createdInStart);
- }
- catch (Throwable t)
- {
- handleLifecycleTransitionFailure(t);
- }
- }
-
- /**
- * Stops the cache and sets the cache status to {@link org.jboss.cache.CacheStatus#STOPPED} once it is done. If the cache is not in
- * the {@link org.jboss.cache.CacheStatus#STARTED} state, this is a no-op.
- */
- public void stop()
- {
- if (!state.stopAllowed())
- {
- return;
- }
-
- // Trying to stop() from FAILED is valid, but may not work
- boolean failed = state == CacheStatus.FAILED;
-
- try
- {
- internalStop();
- }
- catch (Throwable t)
- {
- if (failed)
- {
- log.warn("Attempted to stop() from FAILED state, but caught exception; try calling destroy()", t);
- }
- failed = true;
- handleLifecycleTransitionFailure(t);
- }
- finally
- {
- if (!failed) state = CacheStatus.STOPPED;
- }
- }
-
- /**
- * Destroys the cache and frees up any resources. Sets the cache status to {@link CacheStatus#DESTROYED} when it is done.
- * <p/>
- * If the cache is in {@link org.jboss.cache.CacheStatus#STARTED} when this method is called, it will first call {@link #stop()}
- * to stop the cache.
- */
- public void destroy()
- {
- if (!state.destroyAllowed())
- {
- if (state.needStopBeforeDestroy())
- {
- try
- {
- stop();
- }
- catch (CacheException e)
- {
- log.warn("Needed to call stop() before destroying but stop() threw exception. Proceeding to destroy", e);
- }
- }
- else
- return;
- }
-
- try
- {
- internalDestroy();
- }
- finally
- {
- // We always progress to destroyed
- state = CacheStatus.DESTROYED;
- }
- }
- // ------------------------------ END: Publicly available lifecycle methods -----------------------------
-
- // ------------------------------ START: Actual internal lifecycle methods --------------------------------
-
- /**
- * Sets the cacheStatus to FAILED and rethrows the problem as one
- * of the declared types. Converts any non-RuntimeException Exception
- * to CacheException.
- *
- * @param t throwable thrown during failure
- */
- private void handleLifecycleTransitionFailure(Throwable t)
- {
- state = CacheStatus.FAILED;
- if (t instanceof CacheException)
- throw (CacheException) t;
- else if (t instanceof RuntimeException)
- throw (RuntimeException) t;
- else if (t instanceof Error)
- throw (Error) t;
- else
- throw new CacheException(t);
- }
-
- /**
- * The actual create implementation.
- */
- private void internalCreate()
- {
- state = CacheStatus.CREATING;
- resetNonVolatile();
- rewire();
- state = CacheStatus.CREATED;
- }
-
- private void internalStart(boolean createdInStart) throws CacheException, IllegalArgumentException
- {
- if (!createdInStart)
- {
- // re-wire all dependencies in case stuff has changed since the cache was created
- // remove any components whose construction may have depended upon a configuration that may have changed.
- resetNonVolatile();
- rewire();
- }
-
- state = CacheStatus.STARTING;
-
- // start all internal components
- // first cache all start, stop and destroy methods.
- populateLifecycleMethods();
-
- List<PrioritizedMethod> startMethods = new ArrayList<PrioritizedMethod>(componentLookup.size());
- for (Component c : componentLookup.values()) startMethods.addAll(c.startMethods);
-
- // sort the start methods by priority
- Collections.sort(startMethods);
-
- // fire all START methods according to priority
-
-
- for (PrioritizedMethod em : startMethods) em.invoke();
-
- addShutdownHook();
-
- log.info("JBoss Cache version: " + Version.printVersion());
- state = CacheStatus.STARTED;
- }
-
- private void addShutdownHook()
- {
- ArrayList al = MBeanServerFactory.findMBeanServer(null);
- boolean registerShutdownHook = (getConfiguration().getShutdownHookBehavior() == Configuration.ShutdownHookBehavior.DEFAULT && al.size() == 0)
- || getConfiguration().getShutdownHookBehavior() == Configuration.ShutdownHookBehavior.REGISTER;
-
- if (registerShutdownHook)
- {
- if (log.isTraceEnabled())
- log.trace("Registering a shutdown hook. Configured behavior = " + getConfiguration().getShutdownHookBehavior());
- shutdownHook = new Thread()
- {
- @Override
- public void run()
- {
- try
- {
- invokedFromShutdownHook = true;
- ComponentRegistry.this.stop();
- }
- finally
- {
- invokedFromShutdownHook = false;
- }
- }
- };
-
- Runtime.getRuntime().addShutdownHook(shutdownHook);
- }
- else
- {
- if (log.isTraceEnabled())
- log.trace("Not registering a shutdown hook. Configured behavior = " + getConfiguration().getShutdownHookBehavior());
- }
- }
-
- /**
- * Actual stop
- */
- private void internalStop()
- {
- state = CacheStatus.STOPPING;
- // if this is called from a source other than the shutdown hook, deregister the shutdown hook.
- if (!invokedFromShutdownHook && shutdownHook != null) Runtime.getRuntime().removeShutdownHook(shutdownHook);
-
- List<PrioritizedMethod> stopMethods = new ArrayList<PrioritizedMethod>(componentLookup.size());
- for (Component c : componentLookup.values()) stopMethods.addAll(c.stopMethods);
-
- Collections.sort(stopMethods);
-
- // fire all STOP methods according to priority
- for (PrioritizedMethod em : stopMethods) em.invoke();
-
- state = CacheStatus.STOPPED;
- }
-
- /**
- * Actual destroy
- */
- private void internalDestroy()
- {
-
- state = CacheStatus.DESTROYING;
-
- resetNonVolatile();
-
- List<PrioritizedMethod> destroyMethods = new ArrayList<PrioritizedMethod>(componentLookup.size());
- for (Component c : componentLookup.values()) destroyMethods.addAll(c.destroyMethods);
-
- Collections.sort(destroyMethods);
-
- // fire all DESTROY methods according to priority
- for (PrioritizedMethod em : destroyMethods) em.invoke();
-
- state = CacheStatus.DESTROYED;
- }
-
- // ------------------------------ END: Actual internal lifecycle methods --------------------------------
-
- /**
- * Asserts whether invocations are allowed on the cache or not. Returns <tt>true</tt> if invocations are to be allowed,
- * <tt>false</tt> otherwise. If the origin of the call is remote and the cache status is {@link org.jboss.cache.CacheStatus#STARTING},
- * this method will block for up to {@link org.jboss.cache.config.Configuration#getStateRetrievalTimeout()} millis, checking
- * for a valid state.
- *
- * @param originLocal true if the call originates locally (i.e., from the {@link org.jboss.cache.invocation.CacheInvocationDelegate} or false if it originates remotely, i.e., from the {@link org.jboss.cache.marshall.CommandAwareRpcDispatcher}.
- * @return true if invocations are allowed, false otherwise.
- */
- public boolean invocationsAllowed(boolean originLocal)
- {
- log.trace("Testing if invocations are allowed.");
- if (state.allowInvocations()) return true;
-
- // if this is a locally originating call and the cache is not in a valid state, return false.
- if (originLocal) return false;
-
- log.trace("Is remotely originating.");
-
- // else if this is a remote call and the status is STARTING, wait until the cache starts.
- if (state == CacheStatus.STARTING)
- {
- log.trace("Cache is starting; block.");
- try
- {
- blockUntilCacheStarts();
- return true;
- }
- catch (InterruptedException e)
- {
- Thread.currentThread().interrupt();
- }
- }
- else
- {
- log.warn("Received a remote call but the cache is not in STARTED state - ignoring call.");
- }
- return false;
- }
-
- /**
- * Blocks until the current cache instance is in its {@link org.jboss.cache.CacheStatus#STARTED started} phase. Blocks
- * for up to {@link org.jboss.cache.config.Configuration#getStateRetrievalTimeout()} milliseconds, throwing an IllegalStateException
- * if the cache doesn't reach this state even after this maximum wait time.
- *
- * @throws InterruptedException if interrupted while waiting
- * @throws IllegalStateException if even after waiting the cache has not started.
- */
- private void blockUntilCacheStarts() throws InterruptedException, IllegalStateException
- {
- int pollFrequencyMS = 100;
- long startupWaitTime = getConfiguration().getStateRetrievalTimeout();
- long giveUpTime = System.currentTimeMillis() + startupWaitTime;
-
- while (System.currentTimeMillis() < giveUpTime)
- {
- if (state.allowInvocations()) break;
- Thread.sleep(pollFrequencyMS);
- }
-
- // check if we have started.
- if (!state.allowInvocations())
- throw new IllegalStateException("Cache not in STARTED state, even after waiting " + getConfiguration().getStateRetrievalTimeout() + " millis.");
- }
-
- /**
- * A wrapper representing a component in the registry
- */
- public class Component
- {
- /**
- * A reference to the object instance for this component.
- */
- Object instance;
- /**
- * The name of the component
- */
- String name;
- boolean methodsScanned;
- /**
- * List of injection methods used to inject dependencies into the component
- */
- List<Method> injectionMethods = new ArrayList<Method>(2);
- List<PrioritizedMethod> startMethods = new ArrayList<PrioritizedMethod>(2);
- List<PrioritizedMethod> stopMethods = new ArrayList<PrioritizedMethod>(2);
- List<PrioritizedMethod> destroyMethods = new ArrayList<PrioritizedMethod>(2);
- /**
- * If true, then this component is not flushed before starting the ComponentRegistry.
- */
- boolean nonVolatile;
-
- @Override
- public String toString()
- {
- return "Component{" +
- "instance=" + instance +
- ", name=" + name +
- ", nonVolatile=" + nonVolatile +
- '}';
- }
-
- /**
- * Injects dependencies into this component.
- */
- public void injectDependencies()
- {
- for (Method m : injectionMethods) invokeInjectionMethod(instance, m);
- }
-
- public Object getInstance()
- {
- return instance;
- }
-
- public String getName()
- {
- return name;
- }
- }
-
-
- /**
- * Wrapper to encapsulate a method along with a priority
- */
- static class PrioritizedMethod implements Comparable<PrioritizedMethod>
- {
- Method method;
- Component component;
- int priority;
-
- public int compareTo(PrioritizedMethod o)
- {
- return (priority < o.priority ? -1 : (priority == o.priority ? 0 : 1));
- }
-
- void invoke()
- {
- ReflectionUtil.invokeAccessibly(component.instance, method, null);
- }
-
- @Override
- public String toString()
- {
- return "PrioritizedMethod{" +
- "method=" + method +
- ", priority=" + priority +
- '}';
- }
- }
-
- /**
- * Returns an immutable set contating all the components that exists in the reporsitory at this moment.
- */
- public Set<Component> getRegiteredComponents()
- {
- HashSet<Component> defensiveCopy = new HashSet<Component>(componentLookup.values());
- return Collections.unmodifiableSet(defensiveCopy);
- }
-}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentRegistry.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentRegistry.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentRegistry.java 2009-01-15 18:46:35 UTC (rev 7481)
@@ -0,0 +1,93 @@
+package org.jboss.starobrno.factories;
+
+import org.jboss.starobrno.CacheException;
+import org.jboss.starobrno.CacheSPI;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.factories.scopes.ScopeDetector;
+import org.jboss.starobrno.factories.scopes.Scopes;
+
+import java.util.Map;
+
+/**
+ * // TODO: Manik: Document this!
+ *
+ * @author Manik Surtani
+ */
+public class ComponentRegistry extends AbstractComponentRegistry
+{
+ GlobalComponentRegistry globalComponents;
+
+ /**
+ * Creates an instance of the component registry. The configuration passed in is automatically registered.
+ *
+ * @param configuration configuration with which this is created
+ * @param cache cache
+ * @param globalComponents Shared Component Registry to delegate to
+ */
+ public ComponentRegistry(Configuration configuration, CacheSPI cache, GlobalComponentRegistry globalComponents)
+ {
+
+ try
+ {
+ registerDefaultClassLoader(null);
+ registerComponent(this, ComponentRegistry.class);
+ registerComponent(configuration, Configuration.class);
+ registerComponent(new BootstrapFactory(cache, configuration, this), BootstrapFactory.class);
+
+ this.globalComponents = globalComponents;
+ }
+ catch (Exception e)
+ {
+ throw new CacheException("Unable to construct a ComponentRegistry!", e);
+ }
+ }
+
+ /**
+ * Registers the default class loader. This method *must* be called before any other components are registered,
+ * typically called by bootstrap code. Defensively, it is called in the constructor of ComponentRegistry with a null
+ * parameter.
+ *
+ * @param loader a class loader to use by default. If this is null, the class loader used to load this instance of ComponentRegistry is used.
+ */
+ public void registerDefaultClassLoader(ClassLoader loader)
+ {
+ registerComponent(loader == null ? getClass().getClassLoader() : loader, ClassLoader.class);
+ // make sure the class loader is non-volatile, so it survives restarts.
+ componentLookup.get(ClassLoader.class.getName()).nonVolatile = true;
+ }
+
+
+ @Override
+ public <T> T getComponent(Class<T> componentType)
+ {
+ // first try in the local registry
+ Scopes componentScope = ScopeDetector.detectScope(componentType);
+ switch (componentScope)
+ {
+ case GLOBAL:
+ return globalComponents.getComponent(componentType);
+ case NAMED_CACHE:
+ return super.getComponent(componentType);
+ default:
+ throw new IllegalArgumentException("Unknown component scope " + componentScope);
+ }
+ }
+
+ @Override
+ protected Map<Class, Class<? extends ComponentFactory>> getDefaultFactoryMap()
+ {
+ // delegate to parent. No sense maintaining multiple copies of this map.
+ return globalComponents.getDefaultFactoryMap();
+ }
+
+ @Override
+ protected ComponentFactory getFactory(Class componentClass)
+ {
+ return super.getFactory(componentClass);
+ }
+
+ public GlobalComponentRegistry getSharedComponentRegistry()
+ {
+ return globalComponents;
+ }
+}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/factories/DefaultCacheFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/DefaultCacheFactory.java 2009-01-15 16:48:16 UTC (rev 7480)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/DefaultCacheFactory.java 2009-01-15 18:46:35 UTC (rev 7481)
@@ -51,11 +51,11 @@
* @return a cache
* @throws ConfigurationException if there are problems with the cfg
*/
- public Cache<K, V> createCache(Configuration configuration, ComponentRegistry parentComponentRegistry, String cacheName) throws ConfigurationException
+ public Cache<K, V> createCache(Configuration configuration, GlobalComponentRegistry globalComponentRegistry, String cacheName) throws ConfigurationException
{
try
{
- CacheSPI<K, V> cache = createAndWire(configuration, parentComponentRegistry, cacheName);
+ CacheSPI<K, V> cache = createAndWire(configuration, globalComponentRegistry, cacheName);
cache.start();
return cache;
}
@@ -78,23 +78,23 @@
return createCache(configuration, null, CacheManager.DEFAULT_CACHE_NAME);
}
- protected CacheSPI<K, V> createAndWire(Configuration configuration, ComponentRegistry parentComponentRegistry, String cacheName) throws Exception
+ protected CacheSPI<K, V> createAndWire(Configuration configuration, GlobalComponentRegistry globalComponentRegistry, String cacheName) throws Exception
{
CacheSPI<K, V> spi = new CacheDelegate<K, V>(cacheName);
- bootstrap(spi, configuration, parentComponentRegistry);
+ bootstrap(spi, configuration, globalComponentRegistry);
return spi;
}
/**
* Bootstraps this factory with a Configuration and a ComponentRegistry.
*/
- private void bootstrap(CacheSPI spi, Configuration configuration, ComponentRegistry parentComponentRegistry)
+ private void bootstrap(CacheSPI spi, Configuration configuration, GlobalComponentRegistry globalComponentRegistry)
{
- // injection bootstrap stuff
- componentRegistry = parentComponentRegistry == null ? new ComponentRegistry(configuration, spi) : new HierarchicalComponentRegistry(configuration, spi, parentComponentRegistry);
- componentRegistry.registerDefaultClassLoader(defaultClassLoader);
this.configuration = configuration;
+ // injection bootstrap stuff
+ componentRegistry = new ComponentRegistry(configuration, spi, globalComponentRegistry);
+ componentRegistry.registerDefaultClassLoader(defaultClassLoader);
componentRegistry.registerComponent(spi, CacheSPI.class);
componentRegistry.registerComponent(new PlatformMBeanServerRegistration(), PlatformMBeanServerRegistration.class);
}
@@ -114,9 +114,4 @@
{
throw new UnsupportedOperationException("Should never be invoked - this is a bootstrap factory.");
}
-
-// public Cache<K, V> createCache() throws ConfigurationException
-// {
-// throw new UnsupportedOperationException("Should never be invoked - this is a bootstrap factory.");
-// }
}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/factories/GlobalComponentRegistry.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/GlobalComponentRegistry.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/GlobalComponentRegistry.java 2009-01-15 18:46:35 UTC (rev 7481)
@@ -0,0 +1,30 @@
+package org.jboss.starobrno.factories;
+
+import org.jboss.starobrno.CacheException;
+import org.jboss.starobrno.config.GlobalConfiguration;
+
+/**
+ * // TODO: Manik: Document this!
+ *
+ * @author Manik Surtani
+ */
+public class GlobalComponentRegistry extends AbstractComponentRegistry
+{
+ /**
+ * Creates an instance of the component registry. The configuration passed in is automatically registered.
+ *
+ * @param configuration configuration with which this is created
+ */
+ public GlobalComponentRegistry(GlobalConfiguration configuration)
+ {
+ try
+ {
+ registerComponent(configuration, GlobalConfiguration.class);
+ registerComponent(this, GlobalComponentRegistry.class);
+ }
+ catch (Exception e)
+ {
+ throw new CacheException("Unable to construct a GlobalComponentRegistry!", e);
+ }
+ }
+}
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/factories/HierarchicalComponentRegistry.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/HierarchicalComponentRegistry.java 2009-01-15 16:48:16 UTC (rev 7480)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/HierarchicalComponentRegistry.java 2009-01-15 18:46:35 UTC (rev 7481)
@@ -1,60 +0,0 @@
-package org.jboss.starobrno.factories;
-
-import org.jboss.starobrno.CacheSPI;
-import org.jboss.starobrno.config.Configuration;
-import org.jboss.starobrno.factories.scopes.ScopeDetector;
-import org.jboss.starobrno.factories.scopes.Scopes;
-
-import java.util.Map;
-
-/**
- * // TODO: Manik: Document this!
- *
- * @author Manik Surtani
- */
-public class HierarchicalComponentRegistry extends ComponentRegistry
-{
- ComponentRegistry parent;
-
- /**
- * Creates an instance of the component registry. The configuration passed in is automatically registered.
- *
- * @param configuration configuration with which this is created
- * @param cache cache
- * @param parent parent Component Registry to delegate to
- */
- public HierarchicalComponentRegistry(Configuration configuration, CacheSPI cache, ComponentRegistry parent)
- {
- super(configuration, cache);
- this.parent = parent;
- }
-
- @Override
- public <T> T getComponent(Class<T> componentType)
- {
- // first try in the local registry
- Scopes componentScope = ScopeDetector.detectScope(componentType);
- switch (componentScope)
- {
- case CACHE_MANAGER_ONLY:
- return parent.getComponent(componentType);
- case CACHE_ONLY:
- return super.getComponent(componentType);
- default:
- throw new IllegalArgumentException("Unknown component scope " + componentScope);
- }
- }
-
- @Override
- protected Map<Class, Class<? extends ComponentFactory>> getDefaultFactoryMap()
- {
- // delegate to parent. No sense maintaining multiple copies of this map.
- return parent.getDefaultFactoryMap();
- }
-
- @Override
- protected ComponentFactory getFactory(Class componentClass)
- {
- return super.getFactory(componentClass);
- }
-}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/factories/scopes/Scopes.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/scopes/Scopes.java 2009-01-15 16:48:16 UTC (rev 7480)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/scopes/Scopes.java 2009-01-15 18:46:35 UTC (rev 7481)
@@ -2,7 +2,7 @@
/**
* The different scopes that can be declared for a component in the cache system. If components are not bounded to a
- * specific scope explicity, then it defaults to the {@link #CACHE_ONLY} scope.
+ * specific scope explicity, then it defaults to the {@link #NAMED_CACHE} scope.
*
* @author Manik Surtani
* @see Scope
@@ -13,16 +13,16 @@
* Components bounded to this scope can only be created by a {@link org.jboss.starobrno.manager.CacheManager} and exist in the
* {@link org.jboss.starobrno.manager.CacheManager}'s {@link org.jboss.starobrno.factories.ComponentRegistry}.
*/
- CACHE_MANAGER_ONLY,
+ GLOBAL,
/**
* Components bounded to this scope can only be created by a {@link org.jboss.starobrno.Cache} and exist in the
* {@link org.jboss.starobrno.Cache}'s {@link org.jboss.starobrno.factories.ComponentRegistry}.
*/
- CACHE_ONLY;
+ NAMED_CACHE;
public static Scopes getDefaultScope()
{
- return CACHE_ONLY;
+ return NAMED_CACHE;
}
}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/InterceptorChain.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/InterceptorChain.java 2009-01-15 16:48:16 UTC (rev 7480)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/InterceptorChain.java 2009-01-15 18:46:35 UTC (rev 7481)
@@ -46,7 +46,7 @@
* todo - if you add the same interceptor instance twice, things get really dirty.
* -- this should be treated as an missuse and an exception should be thrown
*/
-(a)Scope(Scopes.CACHE_ONLY)
+(a)Scope(Scopes.NAMED_CACHE)
public class InterceptorChain
{
/**
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/CommandInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/CommandInterceptor.java 2009-01-15 16:48:16 UTC (rev 7480)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/CommandInterceptor.java 2009-01-15 18:46:35 UTC (rev 7481)
@@ -54,7 +54,7 @@
* @see org.jboss.cache.interceptors.InterceptorChain
* @since 2.2
*/
-(a)Scope(Scopes.CACHE_ONLY)
+(a)Scope(Scopes.NAMED_CACHE)
public class CommandInterceptor extends AbstractVisitor
{
private CommandInterceptor next;
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/invocation/InvocationContextContainer.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/invocation/InvocationContextContainer.java 2009-01-15 16:48:16 UTC (rev 7480)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/invocation/InvocationContextContainer.java 2009-01-15 18:46:35 UTC (rev 7481)
@@ -36,7 +36,7 @@
* @since 2.1.0
*/
@NonVolatile
-(a)Scope(Scopes.CACHE_ONLY)
+(a)Scope(Scopes.NAMED_CACHE)
public class InvocationContextContainer extends ThreadLocal<InvocationContext>
{
ContextFactory contextFactory;
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/loader/CacheLoader.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/loader/CacheLoader.java 2009-01-15 16:48:16 UTC (rev 7480)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/loader/CacheLoader.java 2009-01-15 18:46:35 UTC (rev 7481)
@@ -62,7 +62,7 @@
* @since 2.0.0
*/
@ThreadSafe
-(a)Scope(Scopes.CACHE_ONLY)
+(a)Scope(Scopes.NAMED_CACHE)
public interface CacheLoader<K, V>
{
/**
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/manager/CacheManager.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/manager/CacheManager.java 2009-01-15 16:48:16 UTC (rev 7480)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/manager/CacheManager.java 2009-01-15 18:46:35 UTC (rev 7481)
@@ -25,10 +25,11 @@
import org.jboss.starobrno.CacheSPI;
import org.jboss.starobrno.config.Configuration;
import org.jboss.starobrno.config.ConfigurationException;
+import org.jboss.starobrno.config.GlobalConfiguration;
import org.jboss.starobrno.config.parsing.XmlConfigurationParser;
import org.jboss.starobrno.config.parsing.XmlConfigurationParserImpl;
-import org.jboss.starobrno.factories.ComponentRegistry;
import org.jboss.starobrno.factories.DefaultCacheFactory;
+import org.jboss.starobrno.factories.GlobalComponentRegistry;
import org.jboss.starobrno.lifecycle.Lifecycle;
import java.io.IOException;
@@ -81,10 +82,10 @@
public class CacheManager implements Lifecycle
{
public static final String DEFAULT_CACHE_NAME = "org.jboss.starobrno.manager.CacheManager.DEFAULT_CACHE_NAME";
- protected Configuration configuration;
+ protected GlobalConfiguration globalConfiguration;
private final ConcurrentMap<String, Cache> caches = new ConcurrentHashMap<String, Cache>();
private final ConcurrentMap<String, Configuration> configurationOverrides = new ConcurrentHashMap<String, Configuration>();
- private ComponentRegistry sharedComponentRegistry;
+ private GlobalComponentRegistry globalComponentRegistry;
/**
@@ -92,7 +93,7 @@
*/
public CacheManager()
{
- this(false);
+ this(null, null, true);
}
/**
@@ -102,32 +103,72 @@
*/
public CacheManager(boolean start)
{
- configuration = new Configuration();
- if (start) start();
+ this(null, null, start);
}
/**
- * Constructs and starts a new instance of the CacheManager, using the configuration file passed in.
+ * Constructs and starts a new instance of the CacheManager, using the default configuration passed in. Uses
+ * defaults for a {@link org.jboss.starobrno.config.GlobalConfiguration}.
*
- * @param configuration configuration file to use as a template for all caches created
+ * @param defaultConfiguration configuration to use as a template for all caches created
*/
- public CacheManager(Configuration configuration)
+ public CacheManager(Configuration defaultConfiguration)
{
- this(configuration, true);
+ this(null, defaultConfiguration, true);
}
/**
- * Constructs a new instance of the CacheManager, using the configuration file passed in.
+ * Constructs a new instance of the CacheManager, using the default configuration passed in. Uses
+ * defaults for a {@link org.jboss.starobrno.config.GlobalConfiguration}.
*
- * @param configuration configuration file to use as a template for all caches created
- * @param start if true, the cache manager is started
+ * @param defaultConfiguration configuration file to use as a template for all caches created
+ * @param start if true, the cache manager is started
*/
- public CacheManager(Configuration configuration, boolean start)
+ public CacheManager(Configuration defaultConfiguration, boolean start)
{
- this.configuration = configuration.clone();
+ this(null, defaultConfiguration, start);
+ }
+
+ /**
+ * Constructs and starts a new instance of the CacheManager, using the global configuration passed in, and
+ * system defaults for the default named cache configuration.
+ *
+ * @param globalConfiguration GlobalConfiguration to use for all caches created
+ */
+ public CacheManager(GlobalConfiguration globalConfiguration)
+ {
+ this(globalConfiguration, null, true);
+ }
+
+ /**
+ * Constructs a new instance of the CacheManager, using the global configuration passed in, and
+ * system defaults for the default named cache configuration.
+ *
+ * @param globalConfiguration GlobalConfiguration to use for all caches created
+ * @param start if true, the cache manager is started.
+ */
+ public CacheManager(GlobalConfiguration globalConfiguration, boolean start)
+ {
+ this(globalConfiguration, null, start);
+ }
+
+ /**
+ * Constructs a new instance of the CacheManager, using the global and default configurations passed in. If either
+ * of these are null, system defaults are used.
+ *
+ * @param globalConfiguration global configuration to use. If null, a default instance is created.
+ * @param defaultConfiguration default configuration to use. If null, a default instance is created.
+ * @param start if true, the cache manager is started
+ */
+ public CacheManager(GlobalConfiguration globalConfiguration, Configuration defaultConfiguration, boolean start)
+ {
+ this.globalConfiguration = globalConfiguration == null ? new GlobalConfiguration() : globalConfiguration.clone();
+ this.globalConfiguration.setDefaultConfiguration(defaultConfiguration == null ? new Configuration() : defaultConfiguration.clone());
+ globalComponentRegistry = new GlobalComponentRegistry(globalConfiguration);
if (start) start();
}
+
/**
* Constructs and starts a new instance of the CacheManager, using the configuration file name passed in. This constructor
* first searches for the named file on the classpath, and failing that, treats the file name as an absolute
@@ -196,7 +237,7 @@
private void initialize(XmlConfigurationParser initializedParser)
{
- configuration = initializedParser.parseDefaultConfiguration();
+ this.globalConfiguration = initializedParser.parseGlobalConfiguration();
configurationOverrides.putAll(initializedParser.parseNamedConfigurations());
}
@@ -260,14 +301,14 @@
private Cache createCache(String cacheName)
{
- Configuration c = configuration.clone();
+ Configuration c = globalConfiguration.getDefaultConfiguration().clone();
if (!cacheName.equals(DEFAULT_CACHE_NAME))
{
Configuration overrides = configurationOverrides.get(cacheName);
if (overrides != null) c.applyOverrides(overrides);
}
- Cache cache = new DefaultCacheFactory().createCache(c, sharedComponentRegistry, cacheName);
+ Cache cache = new DefaultCacheFactory().createCache(c, globalComponentRegistry, cacheName);
Cache other = caches.putIfAbsent(cacheName, cache);
if (other == null)
{
@@ -284,7 +325,7 @@
{
// get a hold of the "default" cache to start this?
CacheSPI defaultCache = (CacheSPI) getCache();
- sharedComponentRegistry = defaultCache.getComponentRegistry();
+ globalComponentRegistry = defaultCache.getComponentRegistry().getSharedComponentRegistry();
}
public void stop()
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/notifications/NotifierImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/notifications/NotifierImpl.java 2009-01-15 16:48:16 UTC (rev 7480)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/notifications/NotifierImpl.java 2009-01-15 18:46:35 UTC (rev 7481)
@@ -65,7 +65,7 @@
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
*/
@NonVolatile
-(a)Scope(Scopes.CACHE_ONLY)
+(a)Scope(Scopes.NAMED_CACHE)
public class NotifierImpl implements Notifier
{
private static final Log log = LogFactory.getLog(NotifierImpl.class);
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/remoting/RPCManager.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/remoting/RPCManager.java 2009-01-15 16:48:16 UTC (rev 7480)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/remoting/RPCManager.java 2009-01-15 18:46:35 UTC (rev 7481)
@@ -45,7 +45,7 @@
* @author Manik Surtani
* @since 2.1.0
*/
-(a)Scope(Scopes.CACHE_MANAGER_ONLY)
+(a)Scope(Scopes.GLOBAL)
public interface RPCManager
{
/**
Added: core/branches/flat/src/main/java/org/jboss/starobrno/remoting/transport/Address.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/remoting/transport/Address.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/remoting/transport/Address.java 2009-01-15 18:46:35 UTC (rev 7481)
@@ -0,0 +1,10 @@
+package org.jboss.starobrno.remoting.transport;
+
+/**
+ * // TODO: Manik: Document this!
+ *
+ * @author Manik Surtani
+ */
+public interface Address
+{
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/remoting/transport/Transport.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/remoting/transport/Transport.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/remoting/transport/Transport.java 2009-01-15 18:46:35 UTC (rev 7481)
@@ -0,0 +1,22 @@
+package org.jboss.starobrno.remoting.transport;
+
+import org.jboss.starobrno.lifecycle.Lifecycle;
+
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * // TODO: Manik: Document this!
+ *
+ * @author Manik Surtani
+ */
+public interface Transport extends Lifecycle
+{
+ void setProperties(Properties p);
+
+ Address getAddress();
+
+ boolean isCoordinator();
+
+ List<Address> getMembers();
+}
Modified: core/branches/flat/src/test/java/org/jboss/starobrno/factories/scopes/ScopeDetectorTest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/factories/scopes/ScopeDetectorTest.java 2009-01-15 16:48:16 UTC (rev 7480)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/factories/scopes/ScopeDetectorTest.java 2009-01-15 18:46:35 UTC (rev 7481)
@@ -10,28 +10,28 @@
{
public void testScopeOnClass()
{
- testScopes(Test1.class, Scopes.CACHE_MANAGER_ONLY);
+ testScopes(Test1.class, Scopes.GLOBAL);
}
public void testScopeOnInterface()
{
- testScopes(Test2.class, Scopes.CACHE_MANAGER_ONLY);
+ testScopes(Test2.class, Scopes.GLOBAL);
}
public void testScopeOnSuperClass()
{
- testScopes(Test3.class, Scopes.CACHE_MANAGER_ONLY);
+ testScopes(Test3.class, Scopes.GLOBAL);
}
public void testScopeOnSuperInterface()
{
- testScopes(Test4.class, Scopes.CACHE_MANAGER_ONLY);
+ testScopes(Test4.class, Scopes.GLOBAL);
}
public void testNoScopes()
{
- testScopes(Test6.class, Scopes.CACHE_ONLY);
+ testScopes(Test6.class, Scopes.NAMED_CACHE);
}
private void testScopes(Class clazz, Scopes expected)
@@ -45,13 +45,13 @@
}
- @Scope(Scopes.CACHE_MANAGER_ONLY)
+ @Scope(Scopes.GLOBAL)
public static interface Scoped
{
}
- @Scope(Scopes.CACHE_MANAGER_ONLY)
+ @Scope(Scopes.GLOBAL)
public static class SuperScoped
{
@@ -62,7 +62,7 @@
}
- @Scope(Scopes.CACHE_MANAGER_ONLY)
+ @Scope(Scopes.GLOBAL)
public static class Test1
{
17 years, 2 months
JBoss Cache SVN: r7480 - in core/branches/flat/src: main/java/org/jboss/starobrno/factories/scopes and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-01-15 11:48:16 -0500 (Thu, 15 Jan 2009)
New Revision: 7480
Modified:
core/branches/flat/src/main/java/org/jboss/starobrno/factories/HierarchicalComponentRegistry.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/scopes/Scopes.java
core/branches/flat/src/test/java/org/jboss/starobrno/factories/scopes/ScopeDetectorTest.java
Log:
Removed unused Scope
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/factories/HierarchicalComponentRegistry.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/HierarchicalComponentRegistry.java 2009-01-15 16:45:01 UTC (rev 7479)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/HierarchicalComponentRegistry.java 2009-01-15 16:48:16 UTC (rev 7480)
@@ -40,14 +40,6 @@
return parent.getComponent(componentType);
case CACHE_ONLY:
return super.getComponent(componentType);
- case EITHER:
- T t = super.getComponent(componentType);
- if (t == null)
- {
- // delegate to parent
- t = parent.getComponent(componentType);
- }
- return t;
default:
throw new IllegalArgumentException("Unknown component scope " + componentScope);
}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/factories/scopes/Scopes.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/scopes/Scopes.java 2009-01-15 16:45:01 UTC (rev 7479)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/scopes/Scopes.java 2009-01-15 16:48:16 UTC (rev 7480)
@@ -19,14 +19,8 @@
* Components bounded to this scope can only be created by a {@link org.jboss.starobrno.Cache} and exist in the
* {@link org.jboss.starobrno.Cache}'s {@link org.jboss.starobrno.factories.ComponentRegistry}.
*/
- CACHE_ONLY,
+ CACHE_ONLY;
- /**
- * Components bounded to this scope could be created by either the CacheManager or the Cache, depending on where it is
- * first configured and encountered.
- */
- EITHER;
-
public static Scopes getDefaultScope()
{
return CACHE_ONLY;
Modified: core/branches/flat/src/test/java/org/jboss/starobrno/factories/scopes/ScopeDetectorTest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/factories/scopes/ScopeDetectorTest.java 2009-01-15 16:45:01 UTC (rev 7479)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/factories/scopes/ScopeDetectorTest.java 2009-01-15 16:48:16 UTC (rev 7480)
@@ -29,11 +29,6 @@
testScopes(Test4.class, Scopes.CACHE_MANAGER_ONLY);
}
- public void testMultipleScopes()
- {
- testScopes(Test5.class, Scopes.EITHER);
- }
-
public void testNoScopes()
{
testScopes(Test6.class, Scopes.CACHE_ONLY);
@@ -88,12 +83,6 @@
}
- @Scope(Scopes.EITHER)
- public static class Test5 implements Scoped
- {
-
- }
-
public static class Test6 extends SuperUnScoped implements Unscoped
{
17 years, 2 months
JBoss Cache SVN: r7479 - core/branches/flat/src/main/java/org/jboss/starobrno/factories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-01-15 11:45:01 -0500 (Thu, 15 Jan 2009)
New Revision: 7479
Modified:
core/branches/flat/src/main/java/org/jboss/starobrno/factories/EntryFactoryImpl.java
Log:
Removed unused field
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/factories/EntryFactoryImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/EntryFactoryImpl.java 2009-01-15 16:29:26 UTC (rev 7478)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/EntryFactoryImpl.java 2009-01-15 16:45:01 UTC (rev 7479)
@@ -23,7 +23,6 @@
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.starobrno.config.Configuration;
-import org.jboss.starobrno.container.DataContainer;
import org.jboss.starobrno.container.MVCCEntry;
import org.jboss.starobrno.container.NullMarkerEntry;
import org.jboss.starobrno.container.ReadCommittedEntry;
@@ -41,14 +40,11 @@
{
private boolean useRepeatableRead;
private static final NullMarkerEntry NULL_MARKER = new NullMarkerEntry();
- private DataContainer dataContainer;
private Configuration configuration;
@Inject
- public void injectDependencies(Configuration configuration,
- DataContainer dataContainer)
+ public void injectDependencies(Configuration configuration)
{
- this.dataContainer = dataContainer;
this.configuration = configuration;
}
17 years, 2 months
JBoss Cache SVN: r7477 - core/trunk/src/test/java/org/jboss/cache/factories.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2009-01-15 11:15:45 -0500 (Thu, 15 Jan 2009)
New Revision: 7477
Modified:
core/trunk/src/test/java/org/jboss/cache/factories/LifeCycleWithReplTest.java
Log:
fix test for jdk6
Modified: core/trunk/src/test/java/org/jboss/cache/factories/LifeCycleWithReplTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/factories/LifeCycleWithReplTest.java 2009-01-15 01:03:53 UTC (rev 7476)
+++ core/trunk/src/test/java/org/jboss/cache/factories/LifeCycleWithReplTest.java 2009-01-15 16:15:45 UTC (rev 7477)
@@ -92,7 +92,6 @@
updater.start();
- first.stop();
running.add(false);
running.remove(true);
updater.join();
17 years, 2 months
JBoss Cache SVN: r7476 - enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/de-DE.
by jbosscache-commits@lists.jboss.org
Author: xhuang(a)jboss.com
Date: 2009-01-14 20:03:53 -0500 (Wed, 14 Jan 2009)
New Revision: 7476
Added:
enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/de-DE/Author_Group.po
enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/de-DE/JBoss_Cache_Tree_Cache_Guide.po
enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/de-DE/Revision_History.po
enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/de-DE/Tree_Cache_Guide.po
Log:
update
Added: enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/de-DE/Author_Group.po
===================================================================
--- enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/de-DE/Author_Group.po (rev 0)
+++ enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/de-DE/Author_Group.po 2009-01-15 01:03:53 UTC (rev 7476)
@@ -0,0 +1,20 @@
+# Language de-DE translations for JBoss_EAP package.
+# Automatically generated, 2009.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: JBoss_EAP 4_3\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2009-01-15 01:03+0000\n"
+"PO-Revision-Date: 2009-01-15 01:03+0000\n"
+"Last-Translator: Automatically generated\n"
+"Language-Team: none\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: firstname
+#: Author_Group.xml:6
+#, no-c-format
+msgid "Ben Wang, Bela Ban, Manik Surtani, Brian Stansberry, Daniel Huang"
+msgstr ""
Added: enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/de-DE/JBoss_Cache_Tree_Cache_Guide.po
===================================================================
--- enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/de-DE/JBoss_Cache_Tree_Cache_Guide.po (rev 0)
+++ enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/de-DE/JBoss_Cache_Tree_Cache_Guide.po 2009-01-15 01:03:53 UTC (rev 7476)
@@ -0,0 +1,82 @@
+# Language de-DE translations for JBoss_EAP package.
+# Automatically generated, 2009.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: JBoss_EAP 4_3\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2009-01-15 01:03+0000\n"
+"PO-Revision-Date: 2009-01-15 01:03+0000\n"
+"Last-Translator: Automatically generated\n"
+"Language-Team: none\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: JBoss_Cache_Tree_Cache_Guide.xml:6
+#, no-c-format
+msgid "Preface"
+msgstr ""
+
+#. Tag: para
+#: JBoss_Cache_Tree_Cache_Guide.xml:7
+#, no-c-format
+msgid ""
+"This and its accompanying documents describe JBoss Cache's TreeCache, a tree-"
+"structured replicated, transactional cache. JBoss Cache's PojoCache, an "
+"\"object-oriented\" cache that is the AOP-enabled subclass of TreeCache, "
+"allowing for Plain Old Java Objects (POJOs) to be inserted and replicated "
+"transactionally in a cluster, is described separately in a similar user "
+"guide."
+msgstr ""
+
+#. Tag: para
+#: JBoss_Cache_Tree_Cache_Guide.xml:10
+#, no-c-format
+msgid ""
+"The TreeCache is fully configurable. Aspects of the system such as "
+"replication mechanisms, transaction isolation levels, eviction policies, and "
+"transaction managers are all configurable. The TreeCache can be used in a "
+"standalone fashion - independent of JBoss Application Server or any other "
+"application server. PojoCache on the other hand requires both TreeCache and "
+"the JBossAOP standalone subsystem. PojoCache, documented separately, is the "
+"first in the market to provide a POJO cache functionality."
+msgstr ""
+
+#. Tag: para
+#: JBoss_Cache_Tree_Cache_Guide.xml:13
+#, no-c-format
+msgid ""
+"This document is meant to be a user guide to explain the architecture, api, "
+"configuration, and examples for JBoss Cache's TreeCache. Good knowledge of "
+"the Java programming language along with a string appreciation and "
+"understanding of transactions and concurrent threads is presumed. No prior "
+"knowledge of JBoss Application Server is expected or required."
+msgstr ""
+
+#. Tag: para
+#: JBoss_Cache_Tree_Cache_Guide.xml:16
+#, no-c-format
+msgid ""
+"If you have questions, use the <ulink url=\"http://www.jboss.com/index.html?"
+"module=bb&op=viewforum&f=157\">user forum </ulink> linked on the "
+"<ulink url=\"http://labs.jboss.com/jbosscache\">JBoss Cache website</"
+"ulink> . We also provide a mechanism for tracking bug reports and feature "
+"requests on the <ulink url=\"http://jira.jboss.com\">JBoss JIRA issue "
+"tracker </ulink> . If you are interested in the development of JBoss Cache "
+"or in translating this documentation into other languages, we'd love to hear "
+"from you. Please post a message on the user forum or contact us on the "
+"<ulink url=\"http://lists.jboss.org\">developer mailing list </ulink> ."
+msgstr ""
+
+#. Tag: para
+#: JBoss_Cache_Tree_Cache_Guide.xml:19
+#, no-c-format
+msgid ""
+"JBoss Cache is an open-source product based on LGPL. Commercial development "
+"support, production support and training for JBoss Cache is available "
+"through <ulink url=\"http://www.jboss.com\">JBoss Inc.</ulink> JBoss Cache "
+"is a product in JBoss Professional Open Source <ulink url=\"http://www.jboss."
+"com/products/index\">JEMS</ulink> (JBoss Enterprise Middleware Suite)."
+msgstr ""
Added: enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/de-DE/Revision_History.po
===================================================================
--- enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/de-DE/Revision_History.po (rev 0)
+++ enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/de-DE/Revision_History.po 2009-01-15 01:03:53 UTC (rev 7476)
@@ -0,0 +1,26 @@
+# Language de-DE translations for JBoss_EAP package.
+# Automatically generated, 2009.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: JBoss_EAP 4_3\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2009-01-15 01:03+0000\n"
+"PO-Revision-Date: 2009-01-15 01:03+0000\n"
+"Last-Translator: Automatically generated\n"
+"Language-Team: none\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: Revision_History.xml:6
+#, no-c-format
+msgid "Revision History"
+msgstr ""
+
+#. Tag: author
+#: Revision_History.xml:12
+#, no-c-format
+msgid "<firstname></firstname> <surname></surname> <email></email>"
+msgstr ""
Added: enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/de-DE/Tree_Cache_Guide.po
===================================================================
--- enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/de-DE/Tree_Cache_Guide.po (rev 0)
+++ enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/de-DE/Tree_Cache_Guide.po 2009-01-15 01:03:53 UTC (rev 7476)
@@ -0,0 +1,82 @@
+# Language de-DE translations for JBoss_EAP package.
+# Automatically generated, 2009.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: JBoss_EAP 4_3\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2008-08-11 01:09+0000\n"
+"PO-Revision-Date: 2008-08-11 01:09+0000\n"
+"Last-Translator: Automatically generated\n"
+"Language-Team: none\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: Tree_Cache_Guide.xml:11
+#, no-c-format
+msgid "Preface"
+msgstr ""
+
+#. Tag: para
+#: Tree_Cache_Guide.xml:12
+#, no-c-format
+msgid ""
+"This and its accompanying documents describe JBoss Cache's TreeCache, a tree-"
+"structured replicated, transactional cache. JBoss Cache's PojoCache, an "
+"\"object-oriented\" cache that is the AOP-enabled subclass of TreeCache, "
+"allowing for Plain Old Java Objects (POJOs) to be inserted and replicated "
+"transactionally in a cluster, is described separately in a similar user "
+"guide."
+msgstr ""
+
+#. Tag: para
+#: Tree_Cache_Guide.xml:15
+#, no-c-format
+msgid ""
+"The TreeCache is fully configurable. Aspects of the system such as "
+"replication mechanisms, transaction isolation levels, eviction policies, and "
+"transaction managers are all configurable. The TreeCache can be used in a "
+"standalone fashion - independent of JBoss Application Server or any other "
+"application server. PojoCache on the other hand requires both TreeCache and "
+"the JBossAOP standalone subsystem. PojoCache, documented separately, is the "
+"first in the market to provide a POJO cache functionality."
+msgstr ""
+
+#. Tag: para
+#: Tree_Cache_Guide.xml:18
+#, no-c-format
+msgid ""
+"This document is meant to be a user guide to explain the architecture, api, "
+"configuration, and examples for JBoss Cache's TreeCache. Good knowledge of "
+"the Java programming language along with a string appreciation and "
+"understanding of transactions and concurrent threads is presumed. No prior "
+"knowledge of JBoss Application Server is expected or required."
+msgstr ""
+
+#. Tag: para
+#: Tree_Cache_Guide.xml:21
+#, no-c-format
+msgid ""
+"If you have questions, use the <ulink url=\"http://www.jboss.com/index.html?"
+"module=bb&op=viewforum&f=157\">user forum </ulink> linked on the "
+"<ulink url=\"http://labs.jboss.com/jbosscache\">JBoss Cache website</"
+"ulink> . We also provide a mechanism for tracking bug reports and feature "
+"requests on the <ulink url=\"http://jira.jboss.com\">JBoss JIRA issue "
+"tracker </ulink> . If you are interested in the development of JBoss Cache "
+"or in translating this documentation into other languages, we'd love to hear "
+"from you. Please post a message on the user forum or contact us on the "
+"<ulink url=\"http://lists.jboss.org\">developer mailing list </ulink> ."
+msgstr ""
+
+#. Tag: para
+#: Tree_Cache_Guide.xml:24
+#, no-c-format
+msgid ""
+"JBoss Cache is an open-source product based on LGPL. Commercial development "
+"support, production support and training for JBoss Cache is available "
+"through <ulink url=\"http://www.jboss.com\">JBoss Inc.</ulink> JBoss Cache "
+"is a product in JBoss Professional Open Source <ulink url=\"http://www.jboss."
+"com/products/index\">JEMS</ulink> (JBoss Enterprise Middleware Suite)."
+msgstr ""
17 years, 2 months
JBoss Cache SVN: r7475 - enterprise-docs/tags/JBoss_EAP_4_3/Cache_Pojo_Cache_Guide/de-DE.
by jbosscache-commits@lists.jboss.org
Author: xhuang(a)jboss.com
Date: 2009-01-14 19:58:45 -0500 (Wed, 14 Jan 2009)
New Revision: 7475
Added:
enterprise-docs/tags/JBoss_EAP_4_3/Cache_Pojo_Cache_Guide/de-DE/Author_Group.po
enterprise-docs/tags/JBoss_EAP_4_3/Cache_Pojo_Cache_Guide/de-DE/JBoss_Cache_Pojo_Cache_Guide.po
enterprise-docs/tags/JBoss_EAP_4_3/Cache_Pojo_Cache_Guide/de-DE/Revision_History.po
Log:
udpate
Added: enterprise-docs/tags/JBoss_EAP_4_3/Cache_Pojo_Cache_Guide/de-DE/Author_Group.po
===================================================================
--- enterprise-docs/tags/JBoss_EAP_4_3/Cache_Pojo_Cache_Guide/de-DE/Author_Group.po (rev 0)
+++ enterprise-docs/tags/JBoss_EAP_4_3/Cache_Pojo_Cache_Guide/de-DE/Author_Group.po 2009-01-15 00:58:45 UTC (rev 7475)
@@ -0,0 +1,20 @@
+# Language de-DE translations for JBoss_EAP package.
+# Automatically generated, 2009.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: JBoss_EAP 4_3\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2009-01-15 00:58+0000\n"
+"PO-Revision-Date: 2009-01-15 00:58+0000\n"
+"Last-Translator: Automatically generated\n"
+"Language-Team: none\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: firstname
+#: Author_Group.xml:6
+#, no-c-format
+msgid "Ben Wang, Scott Marlow"
+msgstr ""
Added: enterprise-docs/tags/JBoss_EAP_4_3/Cache_Pojo_Cache_Guide/de-DE/JBoss_Cache_Pojo_Cache_Guide.po
===================================================================
--- enterprise-docs/tags/JBoss_EAP_4_3/Cache_Pojo_Cache_Guide/de-DE/JBoss_Cache_Pojo_Cache_Guide.po (rev 0)
+++ enterprise-docs/tags/JBoss_EAP_4_3/Cache_Pojo_Cache_Guide/de-DE/JBoss_Cache_Pojo_Cache_Guide.po 2009-01-15 00:58:45 UTC (rev 7475)
@@ -0,0 +1,92 @@
+# Language de-DE translations for JBoss_EAP package.
+# Automatically generated, 2009.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: JBoss_EAP 4_3\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2009-01-15 00:58+0000\n"
+"PO-Revision-Date: 2009-01-15 00:58+0000\n"
+"Last-Translator: Automatically generated\n"
+"Language-Team: none\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: JBoss_Cache_Pojo_Cache_Guide.xml:6
+#, no-c-format
+msgid "Preface"
+msgstr ""
+
+#. Tag: para
+#: JBoss_Cache_Pojo_Cache_Guide.xml:7
+#, no-c-format
+msgid ""
+"PojoCache is an in-memomy, transactional, and replicated POJO (plain old "
+"Java object) cache system that allows users to operate on a POJO "
+"transparently without active user management of either replication or "
+"persistency aspects. PojoCache, a component of JBossCache (uses PojoCache "
+"class as an internal implementation, the old implementation TreeCacheAop has "
+"been deprecated.), is the first in the market to provide a POJO cache "
+"functionality. JBossCache by itself is a 100% Java based library that "
+"can be run either as a standalone program or inside an application server."
+msgstr ""
+
+#. Tag: para
+#: JBoss_Cache_Pojo_Cache_Guide.xml:10
+#, no-c-format
+msgid ""
+"This document is meant to be a user guide to explain the architecture, api, "
+"configuration, and examples for PojoCache. We assume the readers are "
+"familiar with both JGroups and TreeCache usages. Since PojoCache uses "
+"JBossAop framework, an introduction will also be given there."
+msgstr ""
+
+#. Tag: para
+#: JBoss_Cache_Pojo_Cache_Guide.xml:13
+#, no-c-format
+msgid ""
+"If you have questions, use the user <ulink url=\"http://www.jboss.com/index."
+"html?module=bb&op=viewforum&f=157\">forum</ulink> linked on the "
+"JBossCache website. We also provide tracking links for tracking bug reports "
+"and feature requests on <ulink url=\"http://jira.jboss.com\">JBoss Jira web "
+"site</ulink> . If you are interested in the development of PojoCache, post a "
+"message on the forum. If you are interested in translating this "
+"documentation into your language, contact us on the developer mailing list."
+msgstr ""
+
+#. Tag: para
+#: JBoss_Cache_Pojo_Cache_Guide.xml:16
+#, no-c-format
+msgid ""
+"JBossCache is an open-source product based on LGPL. Commercial development "
+"support, production support and training for JBoss Cache is available "
+"through JBoss Inc. (see <ulink url=\"http://www.jboss.com\">JBoss web site</"
+"ulink> ). JBoss Cache is a project of the JBoss Professional Open Source "
+"product suite."
+msgstr ""
+
+#. Tag: para
+#: JBoss_Cache_Pojo_Cache_Guide.xml:19
+#, no-c-format
+msgid ""
+"In some of the example listings, what is meant to be displayed on one line "
+"does not fit inside the available page width. These lines have been broken "
+"up. A '\' at the end of a line means that a break has been introduced to "
+"fit in the page, with the following lines indented. So: <programlisting>\n"
+" Let's pretend to have an extremely \\n"
+" long line that \\n"
+" does not fit\n"
+" This one is short\n"
+" \n"
+"</programlisting> Is really:"
+msgstr ""
+
+#. Tag: programlisting
+#: JBoss_Cache_Pojo_Cache_Guide.xml:21
+#, no-c-format
+msgid ""
+"Let's pretend to have an extremely long line that does not fit\n"
+" This one is short"
+msgstr ""
Added: enterprise-docs/tags/JBoss_EAP_4_3/Cache_Pojo_Cache_Guide/de-DE/Revision_History.po
===================================================================
--- enterprise-docs/tags/JBoss_EAP_4_3/Cache_Pojo_Cache_Guide/de-DE/Revision_History.po (rev 0)
+++ enterprise-docs/tags/JBoss_EAP_4_3/Cache_Pojo_Cache_Guide/de-DE/Revision_History.po 2009-01-15 00:58:45 UTC (rev 7475)
@@ -0,0 +1,26 @@
+# Language de-DE translations for JBoss_EAP package.
+# Automatically generated, 2009.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: JBoss_EAP 4_3\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2009-01-15 00:58+0000\n"
+"PO-Revision-Date: 2009-01-15 00:58+0000\n"
+"Last-Translator: Automatically generated\n"
+"Language-Team: none\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: Revision_History.xml:6
+#, no-c-format
+msgid "Revision History"
+msgstr ""
+
+#. Tag: author
+#: Revision_History.xml:12
+#, no-c-format
+msgid "<firstname></firstname> <surname></surname> <email></email>"
+msgstr ""
17 years, 2 months
JBoss Cache SVN: r7474 - in core/branches/flat/src: main/java/org/jboss/cache and 25 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-01-14 12:00:40 -0500 (Wed, 14 Jan 2009)
New Revision: 7474
Added:
core/branches/flat/src/main/java/org/jboss/starobrno/config/SharedConfiguration.java
core/branches/flat/src/main/java/org/jboss/starobrno/executors/
core/branches/flat/src/main/java/org/jboss/starobrno/executors/DefaultExecutorFactory.java
core/branches/flat/src/main/java/org/jboss/starobrno/executors/DefaultScheduledExecutorFactory.java
core/branches/flat/src/main/java/org/jboss/starobrno/executors/ExecutorFactory.java
core/branches/flat/src/main/java/org/jboss/starobrno/executors/ScheduledExecutorFactory.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/DefaultCacheFactory.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/HierarchicalComponentRegistry.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/scopes/
core/branches/flat/src/main/java/org/jboss/starobrno/factories/scopes/Scope.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/scopes/ScopeDetector.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/scopes/Scopes.java
core/branches/flat/src/test/java/org/jboss/starobrno/factories/
core/branches/flat/src/test/java/org/jboss/starobrno/factories/scopes/
core/branches/flat/src/test/java/org/jboss/starobrno/factories/scopes/ScopeDetectorTest.java
core/branches/flat/src/test/java/org/jboss/starobrno/manager/
core/branches/flat/src/test/java/org/jboss/starobrno/manager/CacheManagerComponentRegistryTest.java
core/branches/flat/src/test/java/org/jboss/starobrno/manager/CacheManagerTest.java
core/branches/flat/src/test/java/org/jboss/starobrno/manager/CacheManagerXmlConfigurationTest.java
core/branches/flat/src/test/resources/configs/named-cache-test.xml
Removed:
core/branches/flat/src/main/java/org/jboss/cache/DefaultCacheFactory.java
Modified:
core/branches/flat/src/main/docbook/userguide/en/modules/deployment.xml
core/branches/flat/src/main/java/org/jboss/cache/CacheFactory.java
core/branches/flat/src/main/java/org/jboss/cache/CacheManagerImpl.java
core/branches/flat/src/main/java/org/jboss/cache/jmx/CacheJmxWrapper.java
core/branches/flat/src/main/java/org/jboss/cache/loader/tcp/TcpCacheServer.java
core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java
core/branches/flat/src/main/java/org/jboss/starobrno/EvictionManager.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/CommandsFactory.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/Configuration.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/ConfigurationComponent.java
core/branches/flat/src/main/java/org/jboss/starobrno/container/DataContainer.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentFactory.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentRegistry.java
core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/InterceptorChain.java
core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/CommandInterceptor.java
core/branches/flat/src/main/java/org/jboss/starobrno/invocation/InvocationContextContainer.java
core/branches/flat/src/main/java/org/jboss/starobrno/loader/CacheLoader.java
core/branches/flat/src/main/java/org/jboss/starobrno/manager/CacheManager.java
core/branches/flat/src/main/java/org/jboss/starobrno/notifications/NotifierImpl.java
core/branches/flat/src/main/java/org/jboss/starobrno/remoting/RPCManager.java
core/branches/flat/src/main/java/org/jboss/starobrno/util/ReflectionUtil.java
core/branches/flat/src/main/resources/schema/starobrno-config-1.0.xsd
core/branches/flat/src/test/java/org/jboss/starobrno/UnitTestCacheFactory.java
core/branches/flat/src/test/java/org/jboss/starobrno/atomic/APITest.java
core/branches/flat/src/test/java/org/jboss/starobrno/profiling/MemConsumptionTest.java
Log:
Scopes + executor factories
Modified: core/branches/flat/src/main/docbook/userguide/en/modules/deployment.xml
===================================================================
--- core/branches/flat/src/main/docbook/userguide/en/modules/deployment.xml 2009-01-14 16:55:34 UTC (rev 7473)
+++ core/branches/flat/src/main/docbook/userguide/en/modules/deployment.xml 2009-01-14 17:00:40 UTC (rev 7474)
@@ -1,112 +1,112 @@
<chapter id="deployment">
- <title>Deploying JBoss Cache</title>
- <section id="deployment.standalone">
- <title>Standalone Use / Programatic Deployment</title>
- <para>
- When used in a standalone Java program, all that needs to be done is to instantiate the cache using the
- <literal>CacheFactory</literal>
- and a
- <literal>Configuration</literal>
- instance or an XML file, as discussed
- in the
- <link linkend="api.create_start">User API</link>
- and
- <link linkend="configuration.creation">Configuration</link>
- chapters.
- </para>
+ <title>Deploying JBoss Cache</title>
+ <section id="deployment.standalone">
+ <title>Standalone Use / Programatic Deployment</title>
+ <para>
+ When used in a standalone Java program, all that needs to be done is to instantiate the cache using the
+ <literal>CacheFactory</literal>
+ and a
+ <literal>Configuration</literal>
+ instance or an XML file, as discussed
+ in the
+ <link linkend="api.create_start">User API</link>
+ and
+ <link linkend="configuration.creation">Configuration</link>
+ chapters.
+ </para>
- <para>
- The same techniques can be used when an application running in an application
- server wishes to programatically deploy a cache rather than relying on an application server's
- deployment features. An example of this would be
- a webapp deploying a cache via a
- <literal>javax.servlet.ServletContextListener</literal>
- .
- </para>
+ <para>
+ The same techniques can be used when an application running in an application
+ server wishes to programatically deploy a cache rather than relying on an application server's
+ deployment features. An example of this would be
+ a webapp deploying a cache via a
+ <literal>javax.servlet.ServletContextListener</literal>
+ .
+ </para>
- <para>
- If, after deploying your cache you wish to expose a management interface
- to it in JMX, see the
- <link linkend="jmx.registration.programatic">section on Programatic Registration in JMX</link>
- .
- </para>
- </section>
+ <para>
+ If, after deploying your cache you wish to expose a management interface
+ to it in JMX, see the
+ <link linkend="jmx.registration.programatic">section on Programatic Registration in JMX</link>
+ .
+ </para>
+ </section>
- <section id="deployment.microkernel">
- <title>JMX-Based Deployment in JBoss AS (JBoss AS 5.x and 4.x)</title>
- <para>If JBoss Cache is run in JBoss AS then the cache can be deployed as an
- MBean simply by copying a standard cache configuration file to the server's
- <literal>deploy</literal>
- directory. The standard format of JBoss Cache's
- standard XML configuration file (as shown in the
- <link linkend="sample_xml_file">Configuration Reference</link>
- ) is the same
- as a JBoss AS MBean deployment descriptor, so the AS's SAR Deployer has
- no trouble handling it. Also, you don't have to place the configuration
- file directly in
- <literal>deploy</literal>
- ; you can package it along
- with other services or JEE components in a SAR or EAR.
- </para>
+ <section id="deployment.microkernel">
+ <title>JMX-Based Deployment in JBoss AS (JBoss AS 5.x and 4.x)</title>
+ <para>If JBoss Cache is run in JBoss AS then the cache can be deployed as an
+ MBean simply by copying a standard cache configuration file to the server's
+ <literal>deploy</literal>
+ directory. The standard format of JBoss Cache's
+ standard XML configuration file (as shown in the
+ <link linkend="sample_xml_file">Configuration Reference</link>
+ ) is the same
+ as a JBoss AS MBean deployment descriptor, so the AS's SAR Deployer has
+ no trouble handling it. Also, you don't have to place the configuration
+ file directly in
+ <literal>deploy</literal>
+ ; you can package it along
+ with other services or JEE components in a SAR or EAR.
+ </para>
- <para>
- In AS 5, if you're using a server config based on the standard
- <literal>all</literal>
- config, then that's all you need to do; all required
- jars will be on the classpath. Otherwise, you will need to ensure
- <literal>jbosscache.jar</literal>
- and
- <literal>jgroups-all.jar</literal>
- are on the classpath. You may need to add other jars if you're using
- things like
- <literal>JdbmCacheLoader</literal>
- . The simplest way to do
- this is to copy the jars from the JBoss Cache distribution's
- <literal>lib</literal>
- directory to the server config's
- <literal>lib</literal>
- directory. You could also package the jars with the configuration file
- in Service Archive (.sar) file or an EAR.
- </para>
+ <para>
+ In AS 5, if you're using a server config based on the standard
+ <literal>all</literal>
+ config, then that's all you need to do; all required
+ jars will be on the classpath. Otherwise, you will need to ensure
+ <literal>jbosscache.jar</literal>
+ and
+ <literal>jgroups-all.jar</literal>
+ are on the classpath. You may need to add other jars if you're using
+ things like
+ <literal>JdbmCacheLoader</literal>
+ . The simplest way to do
+ this is to copy the jars from the JBoss Cache distribution's
+ <literal>lib</literal>
+ directory to the server config's
+ <literal>lib</literal>
+ directory. You could also package the jars with the configuration file
+ in Service Archive (.sar) file or an EAR.
+ </para>
- <para>
- It is possible to deploy a JBoss Cache 2.0 instance in JBoss AS 4.x
- (at least in 4.2.0.GA; other AS releases are completely untested).
- However, the significant API changes between the JBoss Cache 2.x and 1.x releases
- mean none of the standard AS 4.x clustering services (e.g.
- http session replication) that rely on JBoss Cache will work with
- JBoss Cache 2.x. Also, be aware that usage of JBoss Cache 2.x in AS 4.x is not
- something the JBoss Cache developers are making any significant effort to test,
- so be sure to test your application well (which of course you're doing anyway.)
- </para>
+ <para>
+ It is possible to deploy a JBoss Cache 2.0 instance in JBoss AS 4.x
+ (at least in 4.2.0.GA; other AS releases are completely untested).
+ However, the significant API changes between the JBoss Cache 2.x and 1.x releases
+ mean none of the standard AS 4.x clustering services (e.g.
+ http session replication) that rely on JBoss Cache will work with
+ JBoss Cache 2.x. Also, be aware that usage of JBoss Cache 2.x in AS 4.x is not
+ something the JBoss Cache developers are making any significant effort to test,
+ so be sure to test your application well (which of course you're doing anyway.)
+ </para>
- <para>
- Note in the
- <link linkend="sample_xml_file">example</link>
- the value of the
- <literal>mbean</literal>
- element's
- <literal>code</literal>
- attribute:
- <literal>org.jboss.cache.jmx.CacheJmxWrapper</literal>
- . This is the
- class JBoss Cache uses to handle JMX integration; the
- <literal>Cache</literal>
- itself does not expose an MBean
- interface. See the
- <link linkend="jmx.mbeans">JBoss Cache MBeans section</link>
- for more on the
- <literal>CacheJmxWrapper</literal>
- .
- </para>
+ <para>
+ Note in the
+ <link linkend="sample_xml_file">example</link>
+ the value of the
+ <literal>mbean</literal>
+ element's
+ <literal>code</literal>
+ attribute:
+ <literal>org.jboss.cache.jmx.CacheJmxWrapper</literal>
+ . This is the
+ class JBoss Cache uses to handle JMX integration; the
+ <literal>Cache</literal>
+ itself does not expose an MBean
+ interface. See the
+ <link linkend="jmx.mbeans">JBoss Cache MBeans section</link>
+ for more on the
+ <literal>CacheJmxWrapper</literal>
+ .
+ </para>
- <para>
- Once your cache is deployed, in order to use it with an in-VM client
- such as a servlet, a JMX proxy can be used to get a reference to
- the cache:
- </para>
+ <para>
+ Once your cache is deployed, in order to use it with an in-VM client
+ such as a servlet, a JMX proxy can be used to get a reference to
+ the cache:
+ </para>
- <programlisting role="JAVA"><![CDATA[
+ <programlisting role="JAVA"><![CDATA[
MBeanServer server = MBeanServerLocator.locateJBoss();
ObjectName on = new ObjectName("jboss.cache:service=Cache");
CacheJmxWrapperMBean cacheWrapper =
@@ -116,82 +116,82 @@
Node root = cache.getRoot(); // etc etc
]]></programlisting>
- <para>The MBeanServerLocator class is a helper to find the (only) JBoss
- MBean server inside the current JVM. The
- <literal>javax.management.MBeanServerInvocationHandler</literal>
- class'
- <literal>newProxyInstance</literal>
- method creates a
- dynamic proxy implementing the given interface and uses JMX to
- dynamically dispatch methods invoked against the generated interface
- to the MBean. The name used to look up the MBean is the same as defined
- in the cache's configuration file.
- </para>
+ <para>The MBeanServerLocator class is a helper to find the (only) JBoss
+ MBean server inside the current JVM. The
+ <literal>javax.management.MBeanServerInvocationHandler</literal>
+ class'
+ <literal>newProxyInstance</literal>
+ method creates a
+ dynamic proxy implementing the given interface and uses JMX to
+ dynamically dispatch methods invoked against the generated interface
+ to the MBean. The name used to look up the MBean is the same as defined
+ in the cache's configuration file.
+ </para>
- <para>
- Once the proxy to the
- <literal>CacheJmxWrapper</literal>
- is obtained,
- the
- <literal>getCache()</literal>
- will return a reference to the
- <literal>Cache</literal>
- itself.
- </para>
+ <para>
+ Once the proxy to the
+ <literal>CacheJmxWrapper</literal>
+ is obtained,
+ the
+ <literal>getCache()</literal>
+ will return a reference to the
+ <literal>Cache</literal>
+ itself.
+ </para>
- </section>
+ </section>
- <section id="deployment.microcontainer">
- <title>Via JBoss Microcontainer (JBoss AS 5.x)</title>
+ <section id="deployment.microcontainer">
+ <title>Via JBoss Microcontainer (JBoss AS 5.x)</title>
- <para>
- Beginning with AS 5, JBoss AS also supports deployment of POJO services via
- deployment of a file whose name ends with
- <literal>-beans.xml</literal>
- .
- A POJO service is one whose implementation is via a "Plain Old Java Object",
- meaning a simple java bean that isn't required to implement any special
- interfaces or extend any particular superclass. A
- <literal>Cache</literal>
- is a POJO service, and all the components in a
- <literal>Configuration</literal>
- are also POJOS, so deploying a cache in this way is a natural step.
- </para>
- <para>
- Deployment of the cache is done using the JBoss Microcontainer that forms the
- core of JBoss AS. JBoss Microcontainer is a sophisticated IOC framework
- (similar to Spring). A
- <literal>-beans.xml</literal>
- file is basically
- a descriptor that tells the IOC framework how to assemble the various
- beans that make up a POJO service.
- </para>
- <para>
- For each configurable option exposed by the
- <literal>Configuration</literal>
- components, a getter/setter must be defined in the configuration class.
- This is required so that JBoss Microcontainer can, in typical IOC way,
- call these methods when the corresponding properties have been
- configured.
- </para>
- <para>
- The rules for how to deploy the file, how to package it, how to
- ensure the required jars are on the classpath, etc. are the same
- as for a
- <link linkend="deployment.microkernel">JMX-based deployment</link>
- .
- </para>
- <para>
- Following is an example
- <literal>-beans.xml</literal>
- file. If you
- look in the
- <literal>server/all/deploy</literal>
- directory of an AS 5
- installation, you can find several more examples.
- </para>
+ <para>
+ Beginning with AS 5, JBoss AS also supports deployment of POJO services via
+ deployment of a file whose name ends with
+ <literal>-beans.xml</literal>
+ .
+ A POJO service is one whose implementation is via a "Plain Old Java Object",
+ meaning a simple java bean that isn't required to implement any special
+ interfaces or extend any particular superclass. A
+ <literal>Cache</literal>
+ is a POJO service, and all the components in a
+ <literal>Configuration</literal>
+ are also POJOS, so deploying a cache in this way is a natural step.
+ </para>
+ <para>
+ Deployment of the cache is done using the JBoss Microcontainer that forms the
+ core of JBoss AS. JBoss Microcontainer is a sophisticated IOC framework
+ (similar to Spring). A
+ <literal>-beans.xml</literal>
+ file is basically
+ a descriptor that tells the IOC framework how to assemble the various
+ beans that make up a POJO service.
+ </para>
+ <para>
+ For each configurable option exposed by the
+ <literal>Configuration</literal>
+ components, a getter/setter must be defined in the configuration class.
+ This is required so that JBoss Microcontainer can, in typical IOC way,
+ call these methods when the corresponding properties have been
+ configured.
+ </para>
+ <para>
+ The rules for how to deploy the file, how to package it, how to
+ ensure the required jars are on the classpath, etc. are the same
+ as for a
+ <link linkend="deployment.microkernel">JMX-based deployment</link>
+ .
+ </para>
+ <para>
+ Following is an example
+ <literal>-beans.xml</literal>
+ file. If you
+ look in the
+ <literal>server/all/deploy</literal>
+ directory of an AS 5
+ installation, you can find several more examples.
+ </para>
- <programlisting role="XML"><![CDATA[
+ <programlisting role="XML"><![CDATA[<![CDATA[<![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns="urn:jboss:bean-deployer:2.0">
@@ -280,8 +280,8 @@
</bean>
<!-- Factory to build the Cache. -->
- <bean name="DefaultCacheFactory" class="org.jboss.cache.DefaultCacheFactory">
- <constructor factoryClass="org.jboss.cache.DefaultCacheFactory"
+ <bean name="DefaultCacheFactory" class="org.jboss.starobrno.factories.DefaultCacheFactory">
+ <conorg.jboss.starobrno.factories.DefaultCacheFactoryche.DefaultCacheFactory"
factoryMethod="getInstance"/>
</bean>
@@ -297,158 +297,160 @@
</bean>
</deployment>
- ]]></programlisting>
+ ]]>]]>]]>
+ </programlisting>
- <para>
- See the JBoss Microcontainer documentation
- <footnote>
- <para>http://labs.jboss.com/jbossmc/docs</para>
- </footnote>
- for details on the above syntax. Basically, each
- <literal>bean</literal>
- element represents an object; most going to create a
- <literal>Configuration</literal>
- and its
- <link linkend="configuration.elements">constituent parts</link>
- .
- </para>
- <para>
- An interesting thing to note in the above example is the use of the
- <literal>RuntimeConfig</literal>
- object. External resources like
- a
- <literal>TransactionManager</literal>
- and a JGroups
- <literal>ChannelFactory</literal>
- that are visible to the
- microcontainer are dependency injected into the
- <literal>RuntimeConfig</literal>
- .
- The assumption here is that in some other deployment descriptor in the AS,
- the referenced beans have been described.
- </para>
- </section>
-
- <section>
- <title>Binding to JNDI in JBoss AS</title>
- <para>
- With the 1.x JBoss Cache releases, a proxy to the cache could be bound
- into JBoss AS's JNDI tree using the AS's
- <literal>JRMPProxyFactory</literal>
- service. With JBoss Cache 2.x, this no longer works. An alternative
- way of doing a similar thing with a POJO (i.e. non-JMX-based) service
- like a
- <literal>Cache</literal>
- is under development by the JBoss AS
- team
- <footnote>
- <para>http://jira.jboss.com/jira/browse/JBAS-4456</para>
- </footnote>
- . That feature is not available as of the time of this writing,
- although it will be completed before AS 5.0.0.GA is released.
- We will add a wiki page describing how to use it once it becomes available.
- </para>
- </section>
-
- <section>
- <title>Runtime Management Information</title>
- <para>JBoss Cache includes JMX MBeans to expose cache functionality and provide statistics that can be
- used to analyze cache operations. JBoss Cache can also broadcast cache events as MBean notifications for
- handling
- via JMX monitoring tools.
- </para>
-
- <section id="jmx.mbeans">
- <title>JBoss Cache MBeans</title>
- <para>
- JBoss Cache provides an MBean that can be registered with your environments JMX server to allow access
- to the cache instance via JMX. This MBean is the
- <literal>org.jboss.cache.jmx.CacheJmxWrapper</literal>
+ <para>
+ See the JBoss Microcontainer documentation
+ <footnote>
+ <para>http://labs.jboss.com/jbossmc/docs</para>
+ </footnote>
+ for details on the above syntax. Basically, each
+ <literal>bean</literal>
+ element represents an object; most going to create a
+ <literal>Configuration</literal>
+ and its
+ <link linkend="configuration.elements">constituent parts</link>
.
- It is a StandardMBean, so it's MBean interface is
- <literal>org.jboss.cache.jmx.CacheJmxWrapperMBean</literal>
+ </para>
+ <para>
+ An interesting thing to note in the above example is the use of the
+ <literal>RuntimeConfig</literal>
+ object. External resources like
+ a
+ <literal>TransactionManager</literal>
+ and a JGroups
+ <literal>ChannelFactory</literal>
+ that are visible to the
+ microcontainer are dependency injected into the
+ <literal>RuntimeConfig</literal>
.
- This MBean can be used to:
- <itemizedlist>
- <listitem>Get a reference to the underlying
- <literal>Cache</literal>
- .
- </listitem>
- <listitem>Invoke create/start/stop/destroy lifecycle operations on
- the underlying
- <literal>Cache</literal>
- .
- </listitem>
- <listitem>Inspect various details about the cache's current state (number of nodes, lock information,
- etc.)
- </listitem>
- <listitem>See numerous details about the cache's configuration, and
- change those configuration items that can be changed when the
- cache has already been started.
- </listitem>
- </itemizedlist>
- See the
- <literal>CacheJmxWrapperMBean</literal>
- javadoc for more details.
- </para>
- <para>
- It is important to note a significant architectural difference between JBoss Cache 1.x and 2.x. In 1.x,
- the old
- <literal>TreeCache</literal>
- class was itself an MBean, and essentially exposed the cache's entire
- API via JMX. In 2.x, JMX has been returned to it's fundamental role as a management layer. The
+ The assumption here is that in some other deployment descriptor in the AS,
+ the referenced beans have been described.
+ </para>
+ </section>
+
+ <section>
+ <title>Binding to JNDI in JBoss AS</title>
+ <para>
+ With the 1.x JBoss Cache releases, a proxy to the cache could be bound
+ into JBoss AS's JNDI tree using the AS's
+ <literal>JRMPProxyFactory</literal>
+ service. With JBoss Cache 2.x, this no longer works. An alternative
+ way of doing a similar thing with a POJO (i.e. non-JMX-based) service
+ like a
<literal>Cache</literal>
- object itself is completely unaware of JMX; instead JMX functionality is added
- through a wrapper class designed for that purpose. Furthermore, the interface exposed through JMX
- has been limited to management functions; the general
- <literal>Cache</literal>
- API is no longer exposed
- through JMX. For example, it is no longer possible to invoke a cache
- <literal>put</literal>
- or
- <literal>get</literal>
- via the JMX interface.
- </para>
- <para>
- If a
- <literal>CacheJmxWrapper</literal>
- is registered, JBoss Cache also provides MBeans
- for each interceptor configured in the cache's interceptor stack. These
- MBeans are used to capture and expose statistics related to cache operations. They are hierarchically
- associated with the
- <literal>CacheJmxWrapper</literal>
- MBean and have service names that reflect this relationship. For
- example, a replication interceptor MBean for the
- <literal>jboss.cache:service=TomcatClusteringCache</literal>
- instance will be
- accessible through the service named
- <literal>jboss.cache:service=TomcatClusteringCache,cache-interceptor=ReplicationInterceptor</literal>
- .
- </para>
- </section>
+ is under development by the JBoss AS
+ team
+ <footnote>
+ <para>http://jira.jboss.com/jira/browse/JBAS-4456</para>
+ </footnote>
+ . That feature is not available as of the time of this writing,
+ although it will be completed before AS 5.0.0.GA is released.
+ We will add a wiki page describing how to use it once it becomes available.
+ </para>
+ </section>
- <section id="jmx.registration">
- <title>Registering the CacheJmxWrapper with the MBeanServer</title>
+ <section>
+ <title>Runtime Management Information</title>
+ <para>JBoss Cache includes JMX MBeans to expose cache functionality and provide statistics that can be
+ used to analyze cache operations. JBoss Cache can also broadcast cache events as MBean notifications for
+ handling
+ via JMX monitoring tools.
+ </para>
- <para>
- The best way to ensure the
- <literal>CacheJmxWrapper</literal>
- is registered
- in JMX depends on how you are deploying your cache:
- </para>
+ <section id="jmx.mbeans">
+ <title>JBoss Cache MBeans</title>
+ <para>
+ JBoss Cache provides an MBean that can be registered with your environments JMX server to allow access
+ to the cache instance via JMX. This MBean is the
+ <literal>org.jboss.cache.jmx.CacheJmxWrapper</literal>
+ .
+ It is a StandardMBean, so it's MBean interface is
+ <literal>org.jboss.cache.jmx.CacheJmxWrapperMBean</literal>
+ .
+ This MBean can be used to:
+ <itemizedlist>
+ <listitem>Get a reference to the underlying
+ <literal>Cache</literal>
+ .
+ </listitem>
+ <listitem>Invoke create/start/stop/destroy lifecycle operations on
+ the underlying
+ <literal>Cache</literal>
+ .
+ </listitem>
+ <listitem>Inspect various details about the cache's current state (number of nodes, lock
+ information,
+ etc.)
+ </listitem>
+ <listitem>See numerous details about the cache's configuration, and
+ change those configuration items that can be changed when the
+ cache has already been started.
+ </listitem>
+ </itemizedlist>
+ See the
+ <literal>CacheJmxWrapperMBean</literal>
+ javadoc for more details.
+ </para>
+ <para>
+ It is important to note a significant architectural difference between JBoss Cache 1.x and 2.x. In 1.x,
+ the old
+ <literal>TreeCache</literal>
+ class was itself an MBean, and essentially exposed the cache's entire
+ API via JMX. In 2.x, JMX has been returned to it's fundamental role as a management layer. The
+ <literal>Cache</literal>
+ object itself is completely unaware of JMX; instead JMX functionality is added
+ through a wrapper class designed for that purpose. Furthermore, the interface exposed through JMX
+ has been limited to management functions; the general
+ <literal>Cache</literal>
+ API is no longer exposed
+ through JMX. For example, it is no longer possible to invoke a cache
+ <literal>put</literal>
+ or
+ <literal>get</literal>
+ via the JMX interface.
+ </para>
+ <para>
+ If a
+ <literal>CacheJmxWrapper</literal>
+ is registered, JBoss Cache also provides MBeans
+ for each interceptor configured in the cache's interceptor stack. These
+ MBeans are used to capture and expose statistics related to cache operations. They are hierarchically
+ associated with the
+ <literal>CacheJmxWrapper</literal>
+ MBean and have service names that reflect this relationship. For
+ example, a replication interceptor MBean for the
+ <literal>jboss.cache:service=TomcatClusteringCache</literal>
+ instance will be
+ accessible through the service named
+ <literal>jboss.cache:service=TomcatClusteringCache,cache-interceptor=ReplicationInterceptor</literal>
+ .
+ </para>
+ </section>
- <section id="jmx.registration.programatic">
- <title>Programatic Registration</title>
+ <section id="jmx.registration">
+ <title>Registering the CacheJmxWrapper with the MBeanServer</title>
<para>
- Simplest way to do this is to create your
- <literal>Cache</literal>
- and pass it to the
- <literal>CacheJmxWrapper</literal>
- constructor.
+ The best way to ensure the
+ <literal>CacheJmxWrapper</literal>
+ is registered
+ in JMX depends on how you are deploying your cache:
</para>
- <programlisting role="JAVA"><![CDATA[
+ <section id="jmx.registration.programatic">
+ <title>Programatic Registration</title>
+
+ <para>
+ Simplest way to do this is to create your
+ <literal>Cache</literal>
+ and pass it to the
+ <literal>CacheJmxWrapper</literal>
+ constructor.
+ </para>
+
+ <programlisting role="JAVA"><![CDATA[
CacheFactory factory = new DefaultCacheFactory();
// Build but don't start the cache
// (although it would work OK if we started it)
@@ -474,19 +476,19 @@
wrapper.destroy();
]]></programlisting>
- <para>
- Alternatively, build a
- <literal>Configuration</literal>
- object
- and pass it to the
- <literal>CacheJmxWrapper</literal>
- . The wrapper
- will construct the
- <literal>Cache</literal>
- :
- </para>
+ <para>
+ Alternatively, build a
+ <literal>Configuration</literal>
+ object
+ and pass it to the
+ <literal>CacheJmxWrapper</literal>
+ . The wrapper
+ will construct the
+ <literal>Cache</literal>
+ :
+ </para>
- <programlisting role="JAVA"><![CDATA[
+ <programlisting role="JAVA"><![CDATA[
Configuration config = buildConfiguration(); // whatever it does
CacheJmxWrapperMBean wrapper = new CacheJmxWrapper(config);
@@ -508,43 +510,44 @@
wrapper.stop();
wrapper.destroy();
]]></programlisting>
- </section>
+ </section>
- <section>
- <title>JMX-Based Deployment in JBoss AS (JBoss AS 4.x and 5.x)</title>
+ <section>
+ <title>JMX-Based Deployment in JBoss AS (JBoss AS 4.x and 5.x)</title>
- <para>
- When you
- <link linkend="deployment.microkernel">deploy your cache in JBoss AS using a -service.xml file</link>
- ,
- a
- <literal>CacheJmxWrapper</literal>
- is automatically registered. There is no need
- to do anything further. The
- <literal>CacheJmxWrapper</literal>
- is accessible from an MBean server
- through the service name specified in the cache configuration file's
- <literal>mbean</literal>
- element.
- </para>
- </section>
+ <para>
+ When you
+ <link linkend="deployment.microkernel">deploy your cache in JBoss AS using a -service.xml file
+ </link>
+ ,
+ a
+ <literal>CacheJmxWrapper</literal>
+ is automatically registered. There is no need
+ to do anything further. The
+ <literal>CacheJmxWrapper</literal>
+ is accessible from an MBean server
+ through the service name specified in the cache configuration file's
+ <literal>mbean</literal>
+ element.
+ </para>
+ </section>
- <section>
- <title>Via JBoss Microcontainer (JBoss AS 5.x)</title>
+ <section>
+ <title>Via JBoss Microcontainer (JBoss AS 5.x)</title>
- <para>
- <literal>CacheJmxWrapper</literal>
- is a POJO, so the microcontainer
- has no problem creating one. The trick is
- getting it to register your bean in JMX. This can be done by
- specifying the
- <literal>org.jboss.aop.microcontainer.aspects.jmx.JMX</literal>
- annotation on the
- <literal>CacheJmxWrapper</literal>
- bean:
- </para>
+ <para>
+ <literal>CacheJmxWrapper</literal>
+ is a POJO, so the microcontainer
+ has no problem creating one. The trick is
+ getting it to register your bean in JMX. This can be done by
+ specifying the
+ <literal>org.jboss.aop.microcontainer.aspects.jmx.JMX</literal>
+ annotation on the
+ <literal>CacheJmxWrapper</literal>
+ bean:
+ </para>
- <programlisting role="XML"><![CDATA[
+ <programlisting role="XML"><![CDATA[<![CDATA[<![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns="urn:jboss:bean-deployer:2.0">
@@ -552,63 +555,64 @@
<!-- First we create a Configuration object for the cache -->
<bean name="ExampleCacheConfig"
class="org.jboss.cache.config.Configuration">
-
+
... build up the Configuration
-
+
</bean>
-
+
<!-- Factory to build the Cache. -->
- <bean name="DefaultCacheFactory" class="org.jboss.cache.DefaultCacheFactory">
- <constructor factoryClass="org.jboss.cache.DefaultCacheFactory"
+ <bean name="DefaultCacheFactoryorg.jboss.starobrno.factories.DefaultCacheFactoryheFactory">
+ <constructor factoryClass="org.jboss.starobrno.factories.DefaultCacheFactory"
factoryMethod="getInstance"/>
</bean>
-
+
<!-- The cache itself -->
<bean name="ExampleCache" class="org.jboss.cache.CacheImpl">
-
+
<constructor factoryMethod="createnewInstance">
<factory bean="DefaultCacheFactory"/>
<parameter><inject bean="ExampleCacheConfig"/></parameter>
<parameter>false</false>
</constructor>
-
+
</bean>
-
+
<!-- JMX Management -->
<bean name="ExampleCacheJmxWrapper" class="org.jboss.cache.jmx.CacheJmxWrapper">
-
- <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.cache:service=ExampleTreeCache",
- exposedInterface=org.jboss.cache.jmx.CacheJmxWrapperMBean.class,
+
+ <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.cache:service=ExampleTreeCache",
+ exposedInterface=org.jboss.cache.jmx.CacheJmxWrapperMBean.class,
registerDirectly=true)</annotation>
-
+
<constructor>
<parameter><inject bean="ExampleCache"/></parameter>
</constructor>
-
+
</bean>
-</deployment>
-]]></programlisting>
+</deployment>
+]]>]]>]]>
+ </programlisting>
- <para>
- As discussed in the
- <link linkend="jmx.registration.programatic">Programatic Registration</link>
- section,
- <literal>CacheJmxWrapper</literal>
- can do the work of building,
- creating and starting the
- <literal>Cache</literal>
- if it is provided
- with a
- <literal>Configuration</literal>
- . With the microcontainer,
- this is the preferred approach, as it saves the boilerplate XML
- needed to create the
- <literal>CacheFactory</literal>
- :
- </para>
+ <para>
+ As discussed in the
+ <link linkend="jmx.registration.programatic">Programatic Registration</link>
+ section,
+ <literal>CacheJmxWrapper</literal>
+ can do the work of building,
+ creating and starting the
+ <literal>Cache</literal>
+ if it is provided
+ with a
+ <literal>Configuration</literal>
+ . With the microcontainer,
+ this is the preferred approach, as it saves the boilerplate XML
+ needed to create the
+ <literal>CacheFactory</literal>
+ :
+ </para>
- <programlisting role="XML"><![CDATA[
+ <programlisting role="XML"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns="urn:jboss:bean-deployer:2.0">
@@ -635,133 +639,135 @@
</deployment>
]]></programlisting>
- </section>
+ </section>
- </section>
+ </section>
- <section id="jmx.statistics">
- <title>JBoss Cache Statistics</title>
- <para>
- JBoss Cache captures statistics in its interceptors and exposes the statistics through interceptor
- MBeans. Gathering of statistics is enabled by default; this can be disabled for a specific cache
- instance through the
- <literal>ExposeManagementStatistics</literal>
- configuration attribute. Note that
- the majority of the statistics are provided by the
- <literal>CacheMgmtInterceptor</literal>
- ,
- so this MBean is the most significant in this regard. If you want to disable all statistics for performance
- reasons, you set
- <literal>ExposeManagementStatistics</literal>
- to
- <literal>false</literal>
- as this will
- prevent the
- <literal>CacheMgmtInterceptor</literal>
- from being included in the cache's interceptor stack
- when the cache is started.
- </para>
- <para>
- If a
- <literal>CacheJmxWrapper</literal>
- is registered with JMX, the wrapper also ensures that
- an MBean is registered in JMX for each interceptor that exposes statistics
- <footnote>
- <para>
- Note that if the
- <literal>CacheJmxWrapper</literal>
- is not registered in JMX, the
- interceptor MBeans will not be registered either. The JBoss Cache 1.4 releases
- included code that would try to "discover" an
- <literal>MBeanServer</literal>
- and
- automatically register the interceptor MBeans with it. For JBoss Cache 2.x we decided
- that this sort of "discovery" of the JMX environment was beyond the proper scope of
- a caching library, so we removed this functionality.
- </para>
- </footnote>
- .
- Management tools can then access those MBeans to examine the statistics. See the section in the
- <link linkend="jmx_reference.statistics">JMX Reference chapter</link>
- pertaining to the
- statistics that are made available via JMX.
- </para>
- <para>
- The name under which the interceptor MBeans will be registered is derived by taking the
- <literal>ObjectName</literal>
- under which the
- <literal>CacheJmxWrapper</literal>
- is
- registered and adding a
- <literal>cache-interceptor</literal>
- attribute key whose value
- is the non-qualified name of the interceptor class. So, for example, if the
- <literal>CacheJmxWrapper</literal>
- were registered under
- <literal>jboss.cache:service=TreeCache</literal>
- , the name of the
- <literal>CacheMgmtInterceptor</literal>
- MBean would be
- <literal>jboss.cache:service=TreeCache,cache-interceptor=CacheMgmtInterceptor</literal>
- .
- </para>
- <para>
- Each interceptor's MBean exposes a
- <literal>StatisticsEnabled</literal>
- attribute that can be used to disable maintenance of statistics for
- that interceptor. In addition, each interceptor MBean provides the following common operations and
- attributes.
- <itemizedlist>
- <listitem>
- <literal>dumpStatistics</literal>
- - returns a
- <literal>Map</literal>
- containing the interceptor's attributes and values.
- </listitem>
- <listitem>
- <literal>resetStatistics</literal>
- - resets all statistics maintained by the interceptor.
- </listitem>
- <listitem>
- <literal>setStatisticsEnabled(boolean)</literal>
- - allows statistics to be disabled for a specific interceptor.
- </listitem>
- </itemizedlist>
- </para>
- <para>
- </para>
- </section>
+ <section id="jmx.statistics">
+ <title>JBoss Cache Statistics</title>
+ <para>
+ JBoss Cache captures statistics in its interceptors and exposes the statistics through interceptor
+ MBeans. Gathering of statistics is enabled by default; this can be disabled for a specific cache
+ instance through the
+ <literal>ExposeManagementStatistics</literal>
+ configuration attribute. Note that
+ the majority of the statistics are provided by the
+ <literal>CacheMgmtInterceptor</literal>
+ ,
+ so this MBean is the most significant in this regard. If you want to disable all statistics for
+ performance
+ reasons, you set
+ <literal>ExposeManagementStatistics</literal>
+ to
+ <literal>false</literal>
+ as this will
+ prevent the
+ <literal>CacheMgmtInterceptor</literal>
+ from being included in the cache's interceptor stack
+ when the cache is started.
+ </para>
+ <para>
+ If a
+ <literal>CacheJmxWrapper</literal>
+ is registered with JMX, the wrapper also ensures that
+ an MBean is registered in JMX for each interceptor that exposes statistics
+ <footnote>
+ <para>
+ Note that if the
+ <literal>CacheJmxWrapper</literal>
+ is not registered in JMX, the
+ interceptor MBeans will not be registered either. The JBoss Cache 1.4 releases
+ included code that would try to "discover" an
+ <literal>MBeanServer</literal>
+ and
+ automatically register the interceptor MBeans with it. For JBoss Cache 2.x we decided
+ that this sort of "discovery" of the JMX environment was beyond the proper scope of
+ a caching library, so we removed this functionality.
+ </para>
+ </footnote>
+ .
+ Management tools can then access those MBeans to examine the statistics. See the section in the
+ <link linkend="jmx_reference.statistics">JMX Reference chapter</link>
+ pertaining to the
+ statistics that are made available via JMX.
+ </para>
+ <para>
+ The name under which the interceptor MBeans will be registered is derived by taking the
+ <literal>ObjectName</literal>
+ under which the
+ <literal>CacheJmxWrapper</literal>
+ is
+ registered and adding a
+ <literal>cache-interceptor</literal>
+ attribute key whose value
+ is the non-qualified name of the interceptor class. So, for example, if the
+ <literal>CacheJmxWrapper</literal>
+ were registered under
+ <literal>jboss.cache:service=TreeCache</literal>
+ , the name of the
+ <literal>CacheMgmtInterceptor</literal>
+ MBean would be
+ <literal>jboss.cache:service=TreeCache,cache-interceptor=CacheMgmtInterceptor</literal>
+ .
+ </para>
+ <para>
+ Each interceptor's MBean exposes a
+ <literal>StatisticsEnabled</literal>
+ attribute that can be used to disable maintenance of statistics for
+ that interceptor. In addition, each interceptor MBean provides the following common operations and
+ attributes.
+ <itemizedlist>
+ <listitem>
+ <literal>dumpStatistics</literal>
+ - returns a
+ <literal>Map</literal>
+ containing the interceptor's attributes and values.
+ </listitem>
+ <listitem>
+ <literal>resetStatistics</literal>
+ - resets all statistics maintained by the interceptor.
+ </listitem>
+ <listitem>
+ <literal>setStatisticsEnabled(boolean)</literal>
+ - allows statistics to be disabled for a specific interceptor.
+ </listitem>
+ </itemizedlist>
+ </para>
+ <para>
+ </para>
+ </section>
- <section>
- <title>Receiving JMX Notifications</title>
- <para>
- JBoss Cache users can register a listener to receive cache events described earlier in the
- <link linkend="api.listener">User API</link>
- chapter. Users can alternatively utilize the cache's management information infrastructure to receive these
- events
- via JMX notifications. Cache events are accessible as notifications by registering a
- <literal>NotificationListener</literal>
- for the
- <literal>CacheJmxWrapper</literal>
- .
- </para>
+ <section>
+ <title>Receiving JMX Notifications</title>
+ <para>
+ JBoss Cache users can register a listener to receive cache events described earlier in the
+ <link linkend="api.listener">User API</link>
+ chapter. Users can alternatively utilize the cache's management information infrastructure to receive
+ these
+ events
+ via JMX notifications. Cache events are accessible as notifications by registering a
+ <literal>NotificationListener</literal>
+ for the
+ <literal>CacheJmxWrapper</literal>
+ .
+ </para>
- <para>
- See the section in the
- <link linkend="jmx_reference.notifications">JMX Reference chapter</link>
- pertaining
- to JMX notifications for a list of notifications that can be received through the
- <literal>CacheJmxWrapper</literal>
- .
- </para>
+ <para>
+ See the section in the
+ <link linkend="jmx_reference.notifications">JMX Reference chapter</link>
+ pertaining
+ to JMX notifications for a list of notifications that can be received through the
+ <literal>CacheJmxWrapper</literal>
+ .
+ </para>
- <para>
- The following is an example of how to programmatically receive cache notifications when running in a
- JBoss AS environment. In this example, the client uses a filter to specify which events are of interest.
- </para>
+ <para>
+ The following is an example of how to programmatically receive cache notifications when running in a
+ JBoss AS environment. In this example, the client uses a filter to specify which events are of interest.
+ </para>
- <programlisting role="JAVA"><![CDATA[
+ <programlisting role="JAVA"><![CDATA[
MyListener listener = new MyListener();
NotificationFilterSupport filter = null;
@@ -789,8 +795,8 @@
server.removeNotificationListener(mgmt_name, listener, filter, null);
]]></programlisting>
- <para>The following is the simple notification listener implementation used in the previous example.</para>
- <programlisting role="JAVA"><![CDATA[
+ <para>The following is the simple notification listener implementation used in the previous example.</para>
+ <programlisting role="JAVA"><![CDATA[
private class MyListener implements NotificationListener, Serializable
{
public void handleNotification(Notification notification, Object handback)
@@ -825,71 +831,73 @@
}
]]></programlisting>
- <para>Note that the JBoss Cache management implementation only listens to cache events after a client registers
- to receive MBean notifications. As soon as no clients are registered for notifications, the MBean will
- remove
- itself as a cache listener.
- </para>
+ <para>Note that the JBoss Cache management implementation only listens to cache events after a client
+ registers
+ to receive MBean notifications. As soon as no clients are registered for notifications, the MBean will
+ remove
+ itself as a cache listener.
+ </para>
- </section>
+ </section>
- <section>
- <title>Accessing Cache MBeans in a Standalone Environment</title>
- <para>
- JBoss Cache MBeans are easily accessed when running cache instances in an application server that
- provides an MBean server interface such as JBoss JMX Console. Refer to your server documentation
- for instructions on how to access MBeans running in a server's MBean container.
- </para>
- <para>
- In addition, though, JBoss Cache MBeans are also accessible when running in a non-server environment if the
- JVM is JDK 5.0 or later. When running a standalone cache in a JDK 5.0 environment, you can access the
- cache's MBeans as follows.
- </para>
- <para>
- <orderedlist>
- <listitem>
- Set the system property
- <literal>-Dcom.sun.management.jmxremote</literal>
- when starting the JVM
- where the cache will run.
- </listitem>
- <listitem>
- Once the JVM is running, start the JDK 5.0
- <literal>jconsole</literal>
- utility, located in your JDK's
- <literal>/bin</literal>
- directory.
- </listitem>
- <listitem>When the utility loads, you will be able to select your running JVM and connect to it. The
- JBoss Cache
- MBeans will be available on the MBeans panel.
- </listitem>
- </orderedlist>
- </para>
- <para>Note that the
- <literal>jconsole</literal>
- utility will automatically register as a listener for cache notifications when
- connected to a JVM running JBoss Cache instances.
- </para>
+ <section>
+ <title>Accessing Cache MBeans in a Standalone Environment</title>
+ <para>
+ JBoss Cache MBeans are easily accessed when running cache instances in an application server that
+ provides an MBean server interface such as JBoss JMX Console. Refer to your server documentation
+ for instructions on how to access MBeans running in a server's MBean container.
+ </para>
+ <para>
+ In addition, though, JBoss Cache MBeans are also accessible when running in a non-server environment if
+ the
+ JVM is JDK 5.0 or later. When running a standalone cache in a JDK 5.0 environment, you can access the
+ cache's MBeans as follows.
+ </para>
+ <para>
+ <orderedlist>
+ <listitem>
+ Set the system property
+ <literal>-Dcom.sun.management.jmxremote</literal>
+ when starting the JVM
+ where the cache will run.
+ </listitem>
+ <listitem>
+ Once the JVM is running, start the JDK 5.0
+ <literal>jconsole</literal>
+ utility, located in your JDK's
+ <literal>/bin</literal>
+ directory.
+ </listitem>
+ <listitem>When the utility loads, you will be able to select your running JVM and connect to it. The
+ JBoss Cache
+ MBeans will be available on the MBeans panel.
+ </listitem>
+ </orderedlist>
+ </para>
+ <para>Note that the
+ <literal>jconsole</literal>
+ utility will automatically register as a listener for cache notifications when
+ connected to a JVM running JBoss Cache instances.
+ </para>
- <para>The following figure shows cache interceptor MBeans in
- <literal>jconsole</literal>
- . Cache statistics are displayed
- for the
- <literal>CacheMgmtInterceptor</literal>
- :
- </para>
+ <para>The following figure shows cache interceptor MBeans in
+ <literal>jconsole</literal>
+ . Cache statistics are displayed
+ for the
+ <literal>CacheMgmtInterceptor</literal>
+ :
+ </para>
- <figure>
- <title>CacheMgmtInterceptor MBean in jconsole</title>
+ <figure>
+ <title>CacheMgmtInterceptor MBean in jconsole</title>
- <mediaobject>
- <imageobject>
- <imagedata fileref="CacheMgmtInterceptor.png"/>
- </imageobject>
- </mediaobject>
- </figure>
+ <mediaobject>
+ <imageobject>
+ <imagedata fileref="CacheMgmtInterceptor.png"/>
+ </imageobject>
+ </mediaobject>
+ </figure>
- </section>
- </section>
+ </section>
+ </section>
</chapter>
Modified: core/branches/flat/src/main/java/org/jboss/cache/CacheFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/CacheFactory.java 2009-01-14 16:55:34 UTC (rev 7473)
+++ core/branches/flat/src/main/java/org/jboss/cache/CacheFactory.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -47,7 +47,7 @@
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
* @see Cache_Legacy
- * @see org.jboss.cache.DefaultCacheFactory
+ * @see org.jboss.starobrno.factories.DefaultCacheFactory
* @since 2.0.0
*/
@ThreadSafe
Modified: core/branches/flat/src/main/java/org/jboss/cache/CacheManagerImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/CacheManagerImpl.java 2009-01-14 16:55:34 UTC (rev 7473)
+++ core/branches/flat/src/main/java/org/jboss/cache/CacheManagerImpl.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -135,7 +135,7 @@
/**
* Extension point for subclasses, where we actually use a
* {@link CacheFactory} to create a cache. This default implementation
- * uses {@link DefaultCacheFactory}.
+ * uses {@link org.jboss.starobrno.factories.DefaultCacheFactory}.
*
* @param config the Configuration for the cache
* @return the Cache
Deleted: core/branches/flat/src/main/java/org/jboss/cache/DefaultCacheFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/DefaultCacheFactory.java 2009-01-14 16:55:34 UTC (rev 7473)
+++ core/branches/flat/src/main/java/org/jboss/cache/DefaultCacheFactory.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -1,181 +0,0 @@
-/*
- * 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.annotations.Compat;
-import org.jboss.cache.jmx.PlatformMBeanServerRegistration;
-import org.jboss.starobrno.Cache;
-import org.jboss.starobrno.CacheDelegate;
-import org.jboss.starobrno.CacheSPI;
-import org.jboss.starobrno.config.Configuration;
-import org.jboss.starobrno.config.ConfigurationException;
-import org.jboss.starobrno.config.parsing.XmlConfigurationParserJBC3;
-import org.jboss.starobrno.factories.ComponentFactory;
-import org.jboss.starobrno.factories.ComponentRegistry;
-
-import java.io.InputStream;
-
-/**
- * Default implementation of the {@link org.jboss.cache.CacheFactory} interface.
- * <p/>
- * This is a special instance of a {@link ComponentFactory} which contains bootstrap information for the
- * {@link org.jboss.cache.factories.ComponentRegistry}.
- * <p/>
- *
- * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
- * @see org.jboss.cache.factories.ComponentFactory
- */
-public class DefaultCacheFactory<K, V> extends ComponentFactory implements CacheFactory<K, V>
-{
- private ClassLoader defaultClassLoader;
-
-
- /**
- * This is here for backward compatibility only. Use <tt>new DefaultCacheFactory()</tt> instead.
- *
- * @deprecated
- */
- @SuppressWarnings("unchecked")
- @Deprecated
- @Compat
- public static DefaultCacheFactory getInstance()
- {
- return new DefaultCacheFactory();
- }
-
- public org.jboss.starobrno.Cache<K, V> createCache() throws ConfigurationException
- {
- return createCache(true);
- }
-
- public org.jboss.starobrno.Cache<K, V> createCache(boolean start) throws ConfigurationException
- {
- return createCache(new Configuration(), start);
- }
-
- public org.jboss.starobrno.Cache<K, V> createCache(String configFileName) throws ConfigurationException
- {
- return createCache(configFileName, true);
- }
-
- public org.jboss.starobrno.Cache<K, V> createCache(String configFileName, boolean start) throws ConfigurationException
- {
- XmlConfigurationParserJBC3 parser = new XmlConfigurationParserJBC3();
- Configuration c;
- c = parser.parseFile(configFileName);
- return createCache(c, start);
- }
-
- /**
- * This implementation clones the configuration passed in before using it.
- *
- * @param configuration to use
- * @return a cache
- * @throws ConfigurationException if there are problems with the cfg
- */
- public org.jboss.starobrno.Cache<K, V> createCache(Configuration configuration) throws ConfigurationException
- {
- return createCache(configuration, true);
- }
-
- /**
- * This implementation clones the configuration passed in before using it.
- *
- * @param configuration to use
- * @param start whether to start the cache
- * @return a cache
- * @throws ConfigurationException if there are problems with the cfg
- */
- public org.jboss.starobrno.Cache<K, V> createCache(Configuration configuration, boolean start) throws ConfigurationException
- {
- try
- {
- CacheSPI<K, V> cache = createAndWire(configuration);
- if (start) cache.start();
- return cache;
- }
- catch (ConfigurationException ce)
- {
- throw ce;
- }
- catch (RuntimeException re)
- {
- throw re;
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
-
- protected org.jboss.starobrno.CacheSPI<K, V> createAndWire(Configuration configuration) throws Exception
- {
- CacheSPI<K, V> spi = new CacheDelegate<K, V>();
- bootstrap(spi, configuration);
- return spi;
- }
-
- /**
- * Bootstraps this factory with a Configuration and a ComponentRegistry.
- */
- private void bootstrap(CacheSPI spi, Configuration configuration)
- {
- // injection bootstrap stuff
- componentRegistry = new ComponentRegistry(configuration, spi);
- componentRegistry.registerDefaultClassLoader(defaultClassLoader);
- this.configuration = configuration;
-
- componentRegistry.registerComponent(spi, CacheSPI.class);
- componentRegistry.registerComponent(new PlatformMBeanServerRegistration(), PlatformMBeanServerRegistration.class);
- }
-
- /**
- * Allows users to specify a default class loader to use for both the construction and running of the cache.
- *
- * @param loader class loader to use as a default.
- */
- public void setDefaultClassLoader(ClassLoader loader)
- {
- this.defaultClassLoader = loader;
- }
-
- public Cache<K, V> createCache(InputStream is) throws ConfigurationException
- {
- XmlConfigurationParserJBC3 parser = new XmlConfigurationParserJBC3();
- Configuration c = null;
- c = parser.parseStream(is);
- return createCache(c);
- }
-
- public Cache<K, V> createCache(InputStream is, boolean start) throws ConfigurationException
- {
- XmlConfigurationParserJBC3 parser = new XmlConfigurationParserJBC3();
- Configuration c = parser.parseStream(is);
- return createCache(c, start);
- }
-
- @Override
- protected <T> T construct(Class<T> componentType)
- {
- throw new UnsupportedOperationException("Should never be invoked - this is a bootstrap factory.");
- }
-}
Modified: core/branches/flat/src/main/java/org/jboss/cache/jmx/CacheJmxWrapper.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/jmx/CacheJmxWrapper.java 2009-01-14 16:55:34 UTC (rev 7473)
+++ core/branches/flat/src/main/java/org/jboss/cache/jmx/CacheJmxWrapper.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -23,11 +23,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheFactory;
import org.jboss.cache.CacheSPI_Legacy;
import org.jboss.cache.CacheStatus;
import org.jboss.cache.Cache_Legacy;
-import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.util.CachePrinter;
import org.jboss.starobrno.CacheException;
import org.jboss.starobrno.config.BuddyReplicationConfig;
@@ -46,16 +44,7 @@
import org.jgroups.jmx.JChannelFactoryMBean;
import org.w3c.dom.Element;
-import javax.management.AttributeChangeNotification;
-import javax.management.ListenerNotFoundException;
-import javax.management.MBeanNotificationInfo;
-import javax.management.MBeanRegistration;
-import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
-import javax.management.NotificationBroadcasterSupport;
-import javax.management.NotificationFilter;
-import javax.management.NotificationListener;
-import javax.management.ObjectName;
+import javax.management.*;
import javax.transaction.TransactionManager;
import java.util.ArrayList;
import java.util.List;
@@ -935,7 +924,7 @@
protected void constructCache() throws ConfigurationException
{
log.debug("Constructing Cache");
- CacheFactory<K, V> cf = new DefaultCacheFactory<K, V>();
+ //CacheFactory<K, V> cf = new DefaultCacheFactory<K, V>();
throw new UnsupportedOperationException("Fix me to use a flat cache!!");
// setCache(cf.createCache(config, false));
// if (multiplexerService != null)
Modified: core/branches/flat/src/main/java/org/jboss/cache/loader/tcp/TcpCacheServer.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/loader/tcp/TcpCacheServer.java 2009-01-14 16:55:34 UTC (rev 7473)
+++ core/branches/flat/src/main/java/org/jboss/cache/loader/tcp/TcpCacheServer.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -23,14 +23,32 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.*;
+import org.jboss.cache.CacheSPI_Legacy;
+import org.jboss.cache.Cache_Legacy;
+import org.jboss.cache.Modification;
+import org.jboss.cache.Node;
+import org.jboss.cache.NodeSPI;
import org.jboss.cache.jmx.CacheJmxWrapperMBean;
import org.jboss.starobrno.CacheException;
import org.jboss.starobrno.tree.Fqn;
-import java.io.*;
-import java.net.*;
-import java.util.*;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
/**
* TCP-IP based CacheServer, setCache TcpDelegatingCacheLoader with host and port of this server
@@ -123,7 +141,8 @@
}
else if (config != null)
{
- cache = (CacheSPI_Legacy) new DefaultCacheFactory<Object, Object>().createCache(this.config);
+// cache = (CacheSPI_Legacy) new DefaultCacheFactory<Object, Object>().createCache(this.config, null);
+ throw new RuntimeException("FIX ME");
}
}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java 2009-01-14 16:55:34 UTC (rev 7473)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -34,7 +34,12 @@
import org.jboss.starobrno.commands.CommandsFactory;
import org.jboss.starobrno.commands.read.GetKeyValueCommand;
import org.jboss.starobrno.commands.read.SizeCommand;
-import org.jboss.starobrno.commands.write.*;
+import org.jboss.starobrno.commands.write.ClearCommand;
+import org.jboss.starobrno.commands.write.EvictCommand;
+import org.jboss.starobrno.commands.write.PutKeyValueCommand;
+import org.jboss.starobrno.commands.write.PutMapCommand;
+import org.jboss.starobrno.commands.write.RemoveCommand;
+import org.jboss.starobrno.commands.write.ReplaceCommand;
import org.jboss.starobrno.config.Configuration;
import org.jboss.starobrno.config.ConfigurationException;
import org.jboss.starobrno.container.DataContainer;
@@ -84,6 +89,10 @@
private LockManager lockManager;
private static final Log log = LogFactory.getLog(CacheDelegate.class);
+ public CacheDelegate(String name)
+ {
+ this.name = name;
+ }
@Inject
private void injectDependencies(EvictionManager evictionManager,
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/EvictionManager.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/EvictionManager.java 2009-01-14 16:55:34 UTC (rev 7473)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/EvictionManager.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -1,16 +1,17 @@
package org.jboss.starobrno;
+import net.jcip.annotations.ThreadSafe;
import org.jboss.starobrno.eviction.EvictionCacheManager;
import org.jboss.starobrno.factories.annotations.NonVolatile;
-import net.jcip.annotations.ThreadSafe;
+import org.jboss.starobrno.factories.scopes.Scope;
+import org.jboss.starobrno.factories.scopes.Scopes;
-import java.util.concurrent.ThreadFactory;
-
/**
* @author Mircea.Markus(a)jboss.com
*/
@ThreadSafe
@NonVolatile
+(a)Scope(Scopes.CACHE_ONLY)
public interface EvictionManager
{
/**
@@ -30,7 +31,8 @@
* If the given cache doesn't have eviction enabled this is an no-op.
* If this is the only cache that has eviction enabled, then the eviction thread will be stopped.
* After calling this method the given cache will be unregistered from eviction events.
- * @param chacheName
+ *
+ * @param cacheName
*/
public void cacheStopped(String cacheName);
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/CommandsFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/CommandsFactory.java 2009-01-14 16:55:34 UTC (rev 7473)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/CommandsFactory.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -23,11 +23,19 @@
import org.jboss.starobrno.commands.read.GetKeyValueCommand;
import org.jboss.starobrno.commands.read.SizeCommand;
+import org.jboss.starobrno.commands.remote.ReplicateCommand;
import org.jboss.starobrno.commands.tx.CommitCommand;
import org.jboss.starobrno.commands.tx.PrepareCommand;
import org.jboss.starobrno.commands.tx.RollbackCommand;
-import org.jboss.starobrno.commands.write.*;
-import org.jboss.starobrno.commands.remote.ReplicateCommand;
+import org.jboss.starobrno.commands.write.ClearCommand;
+import org.jboss.starobrno.commands.write.EvictCommand;
+import org.jboss.starobrno.commands.write.InvalidateCommand;
+import org.jboss.starobrno.commands.write.PutKeyValueCommand;
+import org.jboss.starobrno.commands.write.PutMapCommand;
+import org.jboss.starobrno.commands.write.RemoveCommand;
+import org.jboss.starobrno.commands.write.ReplaceCommand;
+import org.jboss.starobrno.factories.scopes.Scope;
+import org.jboss.starobrno.factories.scopes.Scopes;
import org.jboss.starobrno.transaction.GlobalTransaction;
import org.jgroups.Address;
@@ -37,6 +45,7 @@
/**
* @author Mircea.Markus(a)jboss.com
*/
+(a)Scope(Scopes.CACHE_ONLY)
public interface CommandsFactory
{
PutKeyValueCommand buildPutKeyValueCommand(Object key, Object value);
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/config/Configuration.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/Configuration.java 2009-01-14 16:55:34 UTC (rev 7473)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/Configuration.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -33,7 +33,11 @@
import org.w3c.dom.Element;
import java.net.URL;
-import java.util.*;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
/**
* Encapsulates the configuration of a Cache.
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/config/ConfigurationComponent.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/ConfigurationComponent.java 2009-01-14 16:55:34 UTC (rev 7473)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/ConfigurationComponent.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -28,8 +28,15 @@
import org.jboss.starobrno.factories.ComponentRegistry;
import org.jboss.starobrno.factories.annotations.Inject;
import org.jboss.starobrno.factories.annotations.Start;
+import org.jboss.starobrno.factories.scopes.Scope;
+import org.jboss.starobrno.factories.scopes.Scopes;
-import java.util.*;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
/**
* Base superclass of Cache configuration classes that expose some properties
@@ -39,6 +46,7 @@
* @version $Revision$
* @see #testImmutability(String)
*/
+(a)Scope(Scopes.CACHE_ONLY)
public abstract class ConfigurationComponent implements CloneableConfigurationComponent
{
private static final long serialVersionUID = 4879873994727821938L;
Added: core/branches/flat/src/main/java/org/jboss/starobrno/config/SharedConfiguration.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/SharedConfiguration.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/SharedConfiguration.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -0,0 +1,42 @@
+package org.jboss.starobrno.config;
+
+/**
+ * // TODO: Manik: Document this!
+ *
+ * @author Manik Surtani
+ */
+public class SharedConfiguration extends ConfigurationComponent
+{
+ /*
+ <asyncListenerExecutor factory="org.jboss.starobrno.executors.DefaultExecutorFactory">
+ <property name="maxThreads">5</property>
+ <property name="threadNamePrefix">AsyncListenerThread</property>
+ </asyncListenerExecutor>
+
+ <asyncSerializationExecutor factory="org.jboss.starobrno.executors.DefaultExecutorFactory">
+ <property name="maxThreads">25</property>
+ <property name="threadNamePrefix">AsyncSerializationThread</property>
+ </asyncSerializationExecutor>
+
+ <evictionScheduledExecutor factory="org.jboss.starobrno.executors.DefaultScheduledExecutorFactory">
+ <property name="threadNamePrefix">EvictionThread</property>
+ </evictionScheduledExecutor>
+
+ <replicationQueueScheduledExecutor factory="org.jboss.starobrno.executors.DefaultScheduledExecutorFactory">
+ <property name="threadNamePrefix">ReplicationQueueThread</property>
+ </replicationQueueScheduledExecutor>
+
+ <jgroupsConfig configFile="udp.xml"/>
+
+ <serialization marshallerClass="org.jboss.starobrno.marshall.CacheMarshallerStarobrno" version="1.0"
+ objectInputStreamPoolSize="100" objectOutputStreamPoolSize="100"/>
+ */
+ String asyncListenerExecutorFactoryClass;
+ String asyncSerializationExecutorFactoryClass;
+ String evictionScheduledExecutorFactoryClass;
+ String replicationQueueScheduledExecutorFactoryClass;
+ String marshallerClass;
+ String marshallVersion;
+ int objectInputStreamPoolSize;
+ int objectOutputStreamPoolSize;
+}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/container/DataContainer.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/container/DataContainer.java 2009-01-14 16:55:34 UTC (rev 7473)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/container/DataContainer.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -21,6 +21,9 @@
*/
package org.jboss.starobrno.container;
+import org.jboss.starobrno.factories.scopes.Scope;
+import org.jboss.starobrno.factories.scopes.Scopes;
+
import java.util.Set;
/**
@@ -29,6 +32,7 @@
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
* @since 3.0
*/
+(a)Scope(Scopes.CACHE_ONLY)
public interface DataContainer<K, V>
{
V get(K k);
Added: core/branches/flat/src/main/java/org/jboss/starobrno/executors/DefaultExecutorFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/executors/DefaultExecutorFactory.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/executors/DefaultExecutorFactory.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -0,0 +1,32 @@
+package org.jboss.starobrno.executors;
+
+import org.jboss.starobrno.util.TypedProperties;
+
+import java.util.Properties;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Default executor factory that creates executors using the JDK Executors service.
+ *
+ * @author Manik Surtani
+ */
+public class DefaultExecutorFactory implements ExecutorFactory
+{
+ public ExecutorService getExecutor(Properties p)
+ {
+ TypedProperties tp = new TypedProperties(p);
+ int maxThreads = tp.getIntProperty("maxThreads", 1);
+ final String threadNamePrefix = tp.getProperty("threadNamePrefix", "Thread");
+ final AtomicInteger counter = new AtomicInteger(0);
+ return Executors.newFixedThreadPool(maxThreads, new ThreadFactory()
+ {
+ public Thread newThread(Runnable r)
+ {
+ return new Thread(threadNamePrefix + "-" + counter.getAndIncrement());
+ }
+ });
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/executors/DefaultScheduledExecutorFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/executors/DefaultScheduledExecutorFactory.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/executors/DefaultScheduledExecutorFactory.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -0,0 +1,31 @@
+package org.jboss.starobrno.executors;
+
+import org.jboss.starobrno.util.TypedProperties;
+
+import java.util.Properties;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Creates scheduled executors using the JDK Executors service
+ *
+ * @author Manik Surtani
+ */
+public class DefaultScheduledExecutorFactory implements ScheduledExecutorFactory
+{
+ public ScheduledExecutorService getScheduledExecutor(Properties p)
+ {
+ TypedProperties tp = new TypedProperties(p);
+ final String threadNamePrefix = tp.getProperty("threadNamePrefix", "ScheduledThread");
+ final AtomicInteger counter = new AtomicInteger(0);
+ return Executors.newSingleThreadScheduledExecutor(new ThreadFactory()
+ {
+ public Thread newThread(Runnable r)
+ {
+ return new Thread(threadNamePrefix + "-" + counter.getAndIncrement());
+ }
+ });
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/executors/ExecutorFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/executors/ExecutorFactory.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/executors/ExecutorFactory.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -0,0 +1,14 @@
+package org.jboss.starobrno.executors;
+
+import java.util.Properties;
+import java.util.concurrent.ExecutorService;
+
+/**
+ * Used to configure and create executors
+ *
+ * @author Manik Surtani
+ */
+public interface ExecutorFactory
+{
+ ExecutorService getExecutor(Properties p);
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/executors/ScheduledExecutorFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/executors/ScheduledExecutorFactory.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/executors/ScheduledExecutorFactory.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -0,0 +1,14 @@
+package org.jboss.starobrno.executors;
+
+import java.util.Properties;
+import java.util.concurrent.ScheduledExecutorService;
+
+/**
+ * Used to configure and create scheduled executors
+ *
+ * @author Manik Surtani
+ */
+public interface ScheduledExecutorFactory
+{
+ ScheduledExecutorService getScheduledExecutor(Properties p);
+}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentFactory.java 2009-01-14 16:55:34 UTC (rev 7473)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentFactory.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -26,11 +26,13 @@
import org.jboss.starobrno.config.Configuration;
import org.jboss.starobrno.config.ConfigurationException;
import org.jboss.starobrno.factories.annotations.Inject;
+import org.jboss.starobrno.factories.scopes.Scope;
+import org.jboss.starobrno.factories.scopes.Scopes;
/**
* Factory that creates components used internally within JBoss Cache, and also wires dependencies into the components.
* <p/>
- * The {@link org.jboss.cache.DefaultCacheFactory} is a special subclass of this, which bootstraps the construction of
+ * The {@link DefaultCacheFactory} is a special subclass of this, which bootstraps the construction of
* other components. When this class is loaded, it maintains a static list of known default factories for known
* components, which it then delegates to, when actually performing the construction.
* <p/>
@@ -40,6 +42,7 @@
* @see ComponentRegistry
* @since 2.1.0
*/
+(a)Scope(Scopes.CACHE_ONLY)
public abstract class ComponentFactory
{
protected final Log log = LogFactory.getLog(getClass());
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentRegistry.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentRegistry.java 2009-01-14 16:55:34 UTC (rev 7473)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentRegistry.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -30,14 +30,27 @@
import org.jboss.starobrno.config.Configuration;
import org.jboss.starobrno.config.ConfigurationException;
import org.jboss.starobrno.config.RuntimeConfig;
-import org.jboss.starobrno.factories.annotations.*;
+import org.jboss.starobrno.factories.annotations.DefaultFactoryFor;
+import org.jboss.starobrno.factories.annotations.Destroy;
+import org.jboss.starobrno.factories.annotations.Inject;
+import org.jboss.starobrno.factories.annotations.NonVolatile;
+import org.jboss.starobrno.factories.annotations.Start;
+import org.jboss.starobrno.factories.annotations.Stop;
+import org.jboss.starobrno.factories.scopes.Scope;
+import org.jboss.starobrno.factories.scopes.Scopes;
import org.jboss.starobrno.lifecycle.Lifecycle;
import org.jboss.starobrno.util.BeanUtils;
import org.jboss.starobrno.util.ReflectionUtil;
import javax.management.MBeanServerFactory;
import java.lang.reflect.Method;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
/**
* A registry where components which have been created are stored. Components are stored as singletons, registered under
@@ -68,12 +81,13 @@
* @since 2.1.0
*/
@NonVolatile
+(a)Scope(Scopes.CACHE_ONLY)
public class ComponentRegistry implements Lifecycle
{
/**
* Contains class definitions of component factories that can be used to construct certain components
*/
- Map<Class, Class<? extends ComponentFactory>> defaultFactories = null;
+ private Map<Class, Class<? extends ComponentFactory>> defaultFactories = null;
private static final Log log = LogFactory.getLog(ComponentRegistry.class);
private static final boolean trace = log.isTraceEnabled();
@@ -328,8 +342,8 @@
*/
protected ComponentFactory getFactory(Class componentClass)
{
- if (defaultFactories == null) scanDefaultFactories();
- Class<? extends ComponentFactory> cfClass = defaultFactories.get(componentClass);
+ Map<Class, Class<? extends ComponentFactory>> defaultFactoryMap = getDefaultFactoryMap();
+ Class<? extends ComponentFactory> cfClass = defaultFactoryMap.get(componentClass);
if (cfClass == null)
throw new ConfigurationException("No registered default factory for component " + componentClass + " found!");
// a component factory is a component too! See if one has been created and exists in the registry
@@ -351,6 +365,12 @@
return cf;
}
+ protected Map<Class, Class<? extends ComponentFactory>> getDefaultFactoryMap()
+ {
+ if (defaultFactories == null) scanDefaultFactories();
+ return defaultFactories;
+ }
+
/**
* Scans the class path for classes annotated with {@link org.jboss.cache.factories.annotations.DefaultFactoryFor}, and
* analyses which components can be created by such factories.
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/factories/DefaultCacheFactory.java (from rev 7331, core/branches/flat/src/main/java/org/jboss/cache/DefaultCacheFactory.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/DefaultCacheFactory.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/DefaultCacheFactory.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -0,0 +1,122 @@
+/*
+ * 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.starobrno.factories;
+
+import org.jboss.cache.jmx.PlatformMBeanServerRegistration;
+import org.jboss.starobrno.Cache;
+import org.jboss.starobrno.CacheDelegate;
+import org.jboss.starobrno.CacheSPI;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.config.ConfigurationException;
+import org.jboss.starobrno.manager.CacheManager;
+
+/**
+ * Default implementation of the {@link org.jboss.cache.CacheFactory} interface.
+ * <p/>
+ * This is a special instance of a {@link ComponentFactory} which contains bootstrap information for the
+ * {@link org.jboss.cache.factories.ComponentRegistry}.
+ * <p/>
+ *
+ * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
+ * @see org.jboss.cache.factories.ComponentFactory
+ */
+public class DefaultCacheFactory<K, V> extends ComponentFactory// implements CacheFactory<K, V>
+{
+ private ClassLoader defaultClassLoader;
+
+ /**
+ * This implementation clones the configuration passed in before using it.
+ *
+ * @param configuration to use
+ * @param start whether to start the cache
+ * @return a cache
+ * @throws ConfigurationException if there are problems with the cfg
+ */
+ public Cache<K, V> createCache(Configuration configuration, ComponentRegistry parentComponentRegistry, String cacheName) throws ConfigurationException
+ {
+ try
+ {
+ CacheSPI<K, V> cache = createAndWire(configuration, parentComponentRegistry, cacheName);
+ cache.start();
+ return cache;
+ }
+ catch (ConfigurationException ce)
+ {
+ throw ce;
+ }
+ catch (RuntimeException re)
+ {
+ throw re;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public Cache<K, V> createDefaultCache(Configuration configuration) throws ConfigurationException
+ {
+ return createCache(configuration, null, CacheManager.DEFAULT_CACHE_NAME);
+ }
+
+ protected CacheSPI<K, V> createAndWire(Configuration configuration, ComponentRegistry parentComponentRegistry, String cacheName) throws Exception
+ {
+ CacheSPI<K, V> spi = new CacheDelegate<K, V>(cacheName);
+ bootstrap(spi, configuration, parentComponentRegistry);
+ return spi;
+ }
+
+ /**
+ * Bootstraps this factory with a Configuration and a ComponentRegistry.
+ */
+ private void bootstrap(CacheSPI spi, Configuration configuration, ComponentRegistry parentComponentRegistry)
+ {
+ // injection bootstrap stuff
+ componentRegistry = parentComponentRegistry == null ? new ComponentRegistry(configuration, spi) : new HierarchicalComponentRegistry(configuration, spi, parentComponentRegistry);
+ componentRegistry.registerDefaultClassLoader(defaultClassLoader);
+ this.configuration = configuration;
+
+ componentRegistry.registerComponent(spi, CacheSPI.class);
+ componentRegistry.registerComponent(new PlatformMBeanServerRegistration(), PlatformMBeanServerRegistration.class);
+ }
+
+ /**
+ * Allows users to specify a default class loader to use for both the construction and running of the cache.
+ *
+ * @param loader class loader to use as a default.
+ */
+ public void setDefaultClassLoader(ClassLoader loader)
+ {
+ this.defaultClassLoader = loader;
+ }
+
+ @Override
+ protected <T> T construct(Class<T> componentType)
+ {
+ throw new UnsupportedOperationException("Should never be invoked - this is a bootstrap factory.");
+ }
+
+// public Cache<K, V> createCache() throws ConfigurationException
+// {
+// throw new UnsupportedOperationException("Should never be invoked - this is a bootstrap factory.");
+// }
+}
Property changes on: core/branches/flat/src/main/java/org/jboss/starobrno/factories/DefaultCacheFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: core/branches/flat/src/main/java/org/jboss/starobrno/factories/HierarchicalComponentRegistry.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/HierarchicalComponentRegistry.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/HierarchicalComponentRegistry.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -0,0 +1,68 @@
+package org.jboss.starobrno.factories;
+
+import org.jboss.starobrno.CacheSPI;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.factories.scopes.ScopeDetector;
+import org.jboss.starobrno.factories.scopes.Scopes;
+
+import java.util.Map;
+
+/**
+ * // TODO: Manik: Document this!
+ *
+ * @author Manik Surtani
+ */
+public class HierarchicalComponentRegistry extends ComponentRegistry
+{
+ ComponentRegistry parent;
+
+ /**
+ * Creates an instance of the component registry. The configuration passed in is automatically registered.
+ *
+ * @param configuration configuration with which this is created
+ * @param cache cache
+ * @param parent parent Component Registry to delegate to
+ */
+ public HierarchicalComponentRegistry(Configuration configuration, CacheSPI cache, ComponentRegistry parent)
+ {
+ super(configuration, cache);
+ this.parent = parent;
+ }
+
+ @Override
+ public <T> T getComponent(Class<T> componentType)
+ {
+ // first try in the local registry
+ Scopes componentScope = ScopeDetector.detectScope(componentType);
+ switch (componentScope)
+ {
+ case CACHE_MANAGER_ONLY:
+ return parent.getComponent(componentType);
+ case CACHE_ONLY:
+ return super.getComponent(componentType);
+ case EITHER:
+ T t = super.getComponent(componentType);
+ if (t == null)
+ {
+ // delegate to parent
+ t = parent.getComponent(componentType);
+ }
+ return t;
+ default:
+ throw new IllegalArgumentException("Unknown component scope " + componentScope);
+ }
+ }
+
+ @Override
+ protected Map<Class, Class<? extends ComponentFactory>> getDefaultFactoryMap()
+ {
+ // delegate to parent. No sense maintaining multiple copies of this map.
+ return parent.getDefaultFactoryMap();
+ }
+
+ @Override
+ protected ComponentFactory getFactory(Class componentClass)
+ {
+ return super.getFactory(componentClass);
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/factories/scopes/Scope.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/scopes/Scope.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/scopes/Scope.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -0,0 +1,16 @@
+package org.jboss.starobrno.factories.scopes;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Defines the scope of a component in a cache system. If not specified, components default to the {@link Scopes#EITHER} scope.
+ *
+ * @author Manik Surtani
+ * @see Scopes
+ */
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface Scope
+{
+ Scopes value();
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/factories/scopes/ScopeDetector.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/scopes/ScopeDetector.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/scopes/ScopeDetector.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -0,0 +1,20 @@
+package org.jboss.starobrno.factories.scopes;
+
+import org.jboss.starobrno.util.ReflectionUtil;
+
+/**
+ * Retrieves the declated scope of a component
+ *
+ * @author Manik Surtani
+ */
+public class ScopeDetector
+{
+ public static Scopes detectScope(Class clazz)
+ {
+ Scope s = ReflectionUtil.getAnnotation(clazz, Scope.class);
+ if (s == null)
+ return Scopes.getDefaultScope();
+ else
+ return s.value();
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/factories/scopes/Scopes.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/scopes/Scopes.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/scopes/Scopes.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -0,0 +1,34 @@
+package org.jboss.starobrno.factories.scopes;
+
+/**
+ * The different scopes that can be declared for a component in the cache system. If components are not bounded to a
+ * specific scope explicity, then it defaults to the {@link #CACHE_ONLY} scope.
+ *
+ * @author Manik Surtani
+ * @see Scope
+ */
+public enum Scopes
+{
+ /**
+ * Components bounded to this scope can only be created by a {@link org.jboss.starobrno.manager.CacheManager} and exist in the
+ * {@link org.jboss.starobrno.manager.CacheManager}'s {@link org.jboss.starobrno.factories.ComponentRegistry}.
+ */
+ CACHE_MANAGER_ONLY,
+
+ /**
+ * Components bounded to this scope can only be created by a {@link org.jboss.starobrno.Cache} and exist in the
+ * {@link org.jboss.starobrno.Cache}'s {@link org.jboss.starobrno.factories.ComponentRegistry}.
+ */
+ CACHE_ONLY,
+
+ /**
+ * Components bounded to this scope could be created by either the CacheManager or the Cache, depending on where it is
+ * first configured and encountered.
+ */
+ EITHER;
+
+ public static Scopes getDefaultScope()
+ {
+ return CACHE_ONLY;
+ }
+}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/InterceptorChain.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/InterceptorChain.java 2009-01-14 16:55:34 UTC (rev 7473)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/InterceptorChain.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -28,6 +28,8 @@
import org.jboss.starobrno.context.InvocationContext;
import org.jboss.starobrno.factories.annotations.Inject;
import org.jboss.starobrno.factories.annotations.Start;
+import org.jboss.starobrno.factories.scopes.Scope;
+import org.jboss.starobrno.factories.scopes.Scopes;
import org.jboss.starobrno.interceptors.base.CommandInterceptor;
import org.jboss.starobrno.invocation.InvocationContextContainer;
@@ -44,6 +46,7 @@
* todo - if you add the same interceptor instance twice, things get really dirty.
* -- this should be treated as an missuse and an exception should be thrown
*/
+(a)Scope(Scopes.CACHE_ONLY)
public class InterceptorChain
{
/**
@@ -379,4 +382,15 @@
}
return false;
}
+
+ public boolean containsInterceptorType(Class<? extends CommandInterceptor> interceptorType)
+ {
+ CommandInterceptor it = firstInChain;
+ while (it != null)
+ {
+ if (it.getClass().equals(interceptorType)) return true;
+ it = it.getNext();
+ }
+ return false;
+ }
}
\ No newline at end of file
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/CommandInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/CommandInterceptor.java 2009-01-14 16:55:34 UTC (rev 7473)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/CommandInterceptor.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -28,6 +28,8 @@
import org.jboss.starobrno.config.Configuration;
import org.jboss.starobrno.context.InvocationContext;
import org.jboss.starobrno.factories.annotations.Inject;
+import org.jboss.starobrno.factories.scopes.Scope;
+import org.jboss.starobrno.factories.scopes.Scopes;
/**
* This is the base class for all interceptors to extend, and implements the {@link org.jboss.cache.commands.Visitor} interface
@@ -52,6 +54,7 @@
* @see org.jboss.cache.interceptors.InterceptorChain
* @since 2.2
*/
+(a)Scope(Scopes.CACHE_ONLY)
public class CommandInterceptor extends AbstractVisitor
{
private CommandInterceptor next;
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/invocation/InvocationContextContainer.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/invocation/InvocationContextContainer.java 2009-01-14 16:55:34 UTC (rev 7473)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/invocation/InvocationContextContainer.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -21,10 +21,12 @@
*/
package org.jboss.starobrno.invocation;
+import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.starobrno.factories.annotations.Inject;
import org.jboss.starobrno.factories.annotations.NonVolatile;
-import org.jboss.starobrno.factories.annotations.Inject;
import org.jboss.starobrno.factories.context.ContextFactory;
-import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.starobrno.factories.scopes.Scope;
+import org.jboss.starobrno.factories.scopes.Scopes;
/**
@@ -34,6 +36,7 @@
* @since 2.1.0
*/
@NonVolatile
+(a)Scope(Scopes.CACHE_ONLY)
public class InvocationContextContainer extends ThreadLocal<InvocationContext>
{
ContextFactory contextFactory;
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/loader/CacheLoader.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/loader/CacheLoader.java 2009-01-14 16:55:34 UTC (rev 7473)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/loader/CacheLoader.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -25,6 +25,8 @@
import org.jboss.cache.loader.AbstractCacheLoader;
import org.jboss.starobrno.CacheSPI;
import org.jboss.starobrno.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
+import org.jboss.starobrno.factories.scopes.Scope;
+import org.jboss.starobrno.factories.scopes.Scopes;
import org.jboss.starobrno.marshall.EntryData;
import java.io.ObjectInputStream;
@@ -60,6 +62,7 @@
* @since 2.0.0
*/
@ThreadSafe
+(a)Scope(Scopes.CACHE_ONLY)
public interface CacheLoader<K, V>
{
/**
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/manager/CacheManager.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/manager/CacheManager.java 2009-01-14 16:55:34 UTC (rev 7473)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/manager/CacheManager.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -21,16 +21,19 @@
*/
package org.jboss.starobrno.manager;
-import org.jboss.cache.DefaultCacheFactory;
import org.jboss.starobrno.Cache;
+import org.jboss.starobrno.CacheSPI;
import org.jboss.starobrno.config.Configuration;
import org.jboss.starobrno.config.ConfigurationException;
import org.jboss.starobrno.config.parsing.XmlConfigurationParser;
import org.jboss.starobrno.config.parsing.XmlConfigurationParserImpl;
+import org.jboss.starobrno.factories.ComponentRegistry;
+import org.jboss.starobrno.factories.DefaultCacheFactory;
import org.jboss.starobrno.lifecycle.Lifecycle;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -81,7 +84,9 @@
protected Configuration configuration;
private final ConcurrentMap<String, Cache> caches = new ConcurrentHashMap<String, Cache>();
private final ConcurrentMap<String, Configuration> configurationOverrides = new ConcurrentHashMap<String, Configuration>();
+ private ComponentRegistry sharedComponentRegistry;
+
/**
* Constructs and starts a default instance of the CacheManager, using configuration defaults.
*/
@@ -228,26 +233,21 @@
*/
public Cache getCache()
{
- try
- {
- return getCache(DEFAULT_CACHE_NAME);
- }
- catch (NamedCacheNotFoundException e)
- {
- throw new RuntimeException("Default cache not found; this should NEVER happen!", e);
- }
+ return getCache(DEFAULT_CACHE_NAME);
}
/**
- * Retrieves a named cache from the system. The named cache must have been defined previously using the {@link #defineCache(String, org.jboss.starobrno.config.Configuration)}
- * method or have been declared in the configuration file used by this <tt>CacheManager</tt>
- * instance, otherwise this method will throw a {@link org.jboss.starobrno.manager.NamedCacheNotFoundException}.
+ * Retrieves a named cache from the system. If the cache has been previously created with the same name, the running
+ * cache instance is returned. Otherwise, this method attempts to create the cache first.
+ * <p/>
+ * When creating a new cache, this method will use the configuration passed in to the CacheManager on construction,
+ * as a template, and then optionally apply any overrides previously defined for the named cache using the
+ * {@link #defineCache(String, org.jboss.starobrno.config.Configuration)} method, or declared in the configuration file.
*
* @param cacheName name of cache to retrieve
* @return a cache instance identified by cacheName
- * @throws NamedCacheNotFoundException if the named cache does not exist, or is not defined declaratively.
*/
- public Cache getCache(String cacheName) throws NamedCacheNotFoundException
+ public Cache getCache(String cacheName)
{
if (cacheName == null)
throw new NullPointerException("Null arguments not allowed");
@@ -255,9 +255,6 @@
if (caches.containsKey(cacheName))
return caches.get(cacheName);
- if (!cacheName.equals(DEFAULT_CACHE_NAME) && !configurationOverrides.containsKey(cacheName))
- throw new NamedCacheNotFoundException("No such cache named " + cacheName + " defined or declared with this CacheManager!");
-
return createCache(cacheName);
}
@@ -267,10 +264,10 @@
if (!cacheName.equals(DEFAULT_CACHE_NAME))
{
Configuration overrides = configurationOverrides.get(cacheName);
- c.applyOverrides(overrides);
+ if (overrides != null) c.applyOverrides(overrides);
}
- Cache cache = new DefaultCacheFactory().createCache(c, false);
+ Cache cache = new DefaultCacheFactory().createCache(c, sharedComponentRegistry, cacheName);
Cache other = caches.putIfAbsent(cacheName, cache);
if (other == null)
{
@@ -285,11 +282,27 @@
public void start()
{
- // todo
+ // get a hold of the "default" cache to start this?
+ CacheSPI defaultCache = (CacheSPI) getCache();
+ sharedComponentRegistry = defaultCache.getComponentRegistry();
}
public void stop()
{
- for (Cache cache : caches.values()) cache.stop();
+ // make sure we stop the default cache LAST!
+ Cache defaultCache = null;
+ for (Map.Entry<String, Cache> entry : caches.entrySet())
+ {
+ if (entry.getKey().equals(DEFAULT_CACHE_NAME))
+ {
+ defaultCache = entry.getValue();
+ }
+ else
+ {
+ entry.getValue().stop();
+ }
+ }
+
+ if (defaultCache != null) defaultCache.stop();
}
}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/notifications/NotifierImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/notifications/NotifierImpl.java 2009-01-14 16:55:34 UTC (rev 7473)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/notifications/NotifierImpl.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -29,7 +29,13 @@
import org.jboss.starobrno.CacheSPI;
import org.jboss.starobrno.config.Configuration;
import org.jboss.starobrno.context.InvocationContext;
-import org.jboss.starobrno.factories.annotations.*;
+import org.jboss.starobrno.factories.annotations.Destroy;
+import org.jboss.starobrno.factories.annotations.Inject;
+import org.jboss.starobrno.factories.annotations.NonVolatile;
+import org.jboss.starobrno.factories.annotations.Start;
+import org.jboss.starobrno.factories.annotations.Stop;
+import org.jboss.starobrno.factories.scopes.Scope;
+import org.jboss.starobrno.factories.scopes.Scopes;
import org.jboss.starobrno.notifications.annotation.*;
import org.jboss.starobrno.notifications.event.*;
import static org.jboss.starobrno.notifications.event.Event.Type.*;
@@ -42,7 +48,12 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.util.*;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadFactory;
@@ -54,6 +65,7 @@
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
*/
@NonVolatile
+(a)Scope(Scopes.CACHE_ONLY)
public class NotifierImpl implements Notifier
{
private static final Log log = LogFactory.getLog(NotifierImpl.class);
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/remoting/RPCManager.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/remoting/RPCManager.java 2009-01-14 16:55:34 UTC (rev 7473)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/remoting/RPCManager.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -22,6 +22,8 @@
package org.jboss.starobrno.remoting;
import org.jboss.starobrno.commands.ReplicableCommand;
+import org.jboss.starobrno.factories.scopes.Scope;
+import org.jboss.starobrno.factories.scopes.Scopes;
import org.jgroups.Address;
import org.jgroups.Channel;
import org.jgroups.blocks.RspFilter;
@@ -43,6 +45,7 @@
* @author Manik Surtani
* @since 2.1.0
*/
+(a)Scope(Scopes.CACHE_MANAGER_ONLY)
public interface RPCManager
{
/**
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/util/ReflectionUtil.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/util/ReflectionUtil.java 2009-01-14 16:55:34 UTC (rev 7473)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/util/ReflectionUtil.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -170,4 +170,38 @@
throw new CacheException("Cannot access field " + f, iae);
}
}
+
+ /**
+ * Inspects the class passed in for the class level annotation specified. If the annotation is not available, this
+ * method recursively inspects superclasses and interfaces until it finds the required annotation.
+ * <p/>
+ * Returns null if the annotation cannot be found.
+ *
+ * @param clazz class to inspect
+ * @param ann annotation to search for. Must be a class-level annotation.
+ * @return the annotation instance, or null
+ */
+ @SuppressWarnings("unchecked")
+ public static <T extends Annotation> T getAnnotation(Class clazz, Class<T> ann)
+ {
+ // first check class
+ T a = (T) clazz.getAnnotation(ann);
+ if (a != null) return a;
+
+ // check interfaces
+ if (!clazz.isInterface())
+ {
+ Class[] interfaces = clazz.getInterfaces();
+ for (Class inter : interfaces)
+ {
+ a = getAnnotation(inter, ann);
+ if (a != null) return a;
+ }
+ }
+
+ // check superclasses
+ Class superclass = clazz.getSuperclass();
+ if (superclass == null) return null; // no where else to look
+ return getAnnotation(superclass, ann);
+ }
}
Modified: core/branches/flat/src/main/resources/schema/starobrno-config-1.0.xsd
===================================================================
--- core/branches/flat/src/main/resources/schema/starobrno-config-1.0.xsd 2009-01-14 16:55:34 UTC (rev 7473)
+++ core/branches/flat/src/main/resources/schema/starobrno-config-1.0.xsd 2009-01-14 17:00:40 UTC (rev 7474)
@@ -3,10 +3,46 @@
xmlns:tns="urn:jboss:starobrno-core:config:1.0" targetNamespace="urn:jboss:starobrno-core:config:1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0">
- <xs:element name="jbosscache" type="tns:cacheConfigurationType"/>
+ <xs:element name="jbosscache" type="tns:cacheManagerConfigurationType"/>
- <xs:complexType name="cacheConfigurationType">
+ <xs:complexType name="cacheManagerConfigurationType">
+ <xs:sequence>
+ <xs:element name="global" type="tns:globalCacheConfigurationType" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="default" type="tns:defaultCacheConfigurationType" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="namedCache" type="tns:namedCacheConfigurationType" maxOccurs="unbounded"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:complexType name="globalCacheConfigurationType">
<xs:all>
+ <xs:element name="serialization" type="tns:sharedSerializationType" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="jgroupsConfig" type="tns:jgroupsConfigType" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="asyncListenerExecutor" type="tns:executorConfigurationType" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="asyncSerializationExecutor" type="tns:executorConfigurationType" minOccurs="0"
+ maxOccurs="1"/>
+ <xs:element name="evictionScheduledExecutor" type="tns:executorConfigurationType" minOccurs="0"
+ maxOccurs="1"/>
+ <xs:element name="replicationQueueScheduledExecutor" type="tns:executorConfigurationType" minOccurs="0"
+ maxOccurs="1"/>
+ </xs:all>
+ </xs:complexType>
+
+ <xs:complexType name="sharedSerializationType">
+ <xs:attribute name="objectInputStreamPoolSize" type="tns:positiveInteger"/>
+ <xs:attribute name="objectOutputStreamPoolSize" type="tns:positiveInteger"/>
+ <xs:attribute name="version" type="xs:string"/>
+ <xs:attribute name="marshallerClass" type="xs:string"/>
+ </xs:complexType>
+
+ <xs:complexType name="executorConfigurationType">
+ <xs:sequence>
+ <xs:element name="property" minOccurs="0" maxOccurs="unbounded" type="tns:propertyType"/>
+ </xs:sequence>
+ <xs:attribute name="factory" type="xs:string"/>
+ </xs:complexType>
+
+ <xs:complexType name="defaultCacheConfigurationType">
+ <xs:all>
<xs:element name="locking" type="tns:lockingType" minOccurs="0" maxOccurs="1"/>
<xs:element name="transaction" type="tns:transactionType" minOccurs="0" maxOccurs="1"/>
<xs:element name="startup" type="tns:startupType" minOccurs="0" maxOccurs="1"/>
@@ -22,6 +58,24 @@
</xs:all>
</xs:complexType>
+ <xs:complexType name="namedCacheConfigurationType">
+ <xs:all>
+ <xs:element name="locking" type="tns:lockingType" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="transaction" type="tns:transactionType" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="startup" type="tns:startupType" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="shutdown" type="tns:shutdownType" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="serialization" type="tns:serializationType" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="jmxStatistics" type="tns:jmxStatisticsType" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="listeners" type="tns:listenersType" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="invocationBatching" type="tns:invocationBatchingType" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="eviction" type="tns:evictionType" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="loaders" type="tns:loadersType" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="customInterceptors" type="tns:customInterceptorsType" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="clustering" type="tns:clusteringType" minOccurs="0" maxOccurs="1"/>
+ </xs:all>
+ <xs:attribute name="name" type="xs:string"/>
+ </xs:complexType>
+
<xs:complexType name="clusteringType">
<xs:all>
<xs:element name="sync" type="tns:syncType" minOccurs="0" maxOccurs="1"/>
@@ -51,7 +105,6 @@
<xs:attribute name="communicationTimeout" type="xs:integer"/>
</xs:complexType>
</xs:element>
- <xs:element name="jgroupsConfig" type="tns:jgroupsConfigType" minOccurs="0" maxOccurs="1"/>
</xs:all>
<xs:attribute name="mode">
<xs:simpleType>
@@ -108,12 +161,7 @@
</xs:complexType>
<xs:complexType name="serializationType">
- <xs:attribute name="objectInputStreamPoolSize" type="tns:positiveInteger"/>
- <xs:attribute name="objectOutputStreamPoolSize" type="tns:positiveInteger"/>
- <xs:attribute name="version" type="xs:string"/>
- <xs:attribute name="marshallerClass" type="xs:string"/>
<xs:attribute name="useLazyDeserialization" type="tns:booleanType"/>
- <xs:attribute name="useRegionBasedMarshalling" type="tns:booleanType"/>
</xs:complexType>
<xs:simpleType name="booleanType">
Modified: core/branches/flat/src/test/java/org/jboss/starobrno/UnitTestCacheFactory.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/UnitTestCacheFactory.java 2009-01-14 16:55:34 UTC (rev 7473)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/UnitTestCacheFactory.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -9,10 +9,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheFactory;
-import org.jboss.cache.DefaultCacheFactory;
import org.jboss.starobrno.config.Configuration;
import org.jboss.starobrno.config.ConfigurationException;
import org.jboss.starobrno.config.parsing.XmlConfigurationParserJBC3;
+import org.jboss.starobrno.manager.CacheManager;
import org.jboss.starobrno.util.TestingUtil;
import org.jgroups.conf.XmlConfigurator;
@@ -149,7 +149,9 @@
log.info("Unknown cache mode!");
}
- Cache<K, V> cache = new DefaultCacheFactory<K, V>().createCache(configuration, start);
+// Cache<K, V> cache = new DefaultCacheFactory<K, V>().createCache(configuration, start);
+ CacheManager cm = new CacheManager(configuration);
+ Cache<K, V> cache = cm.getCache();
List<Cache> caches = threadCaches.get();
caches.add(cache);
Modified: core/branches/flat/src/test/java/org/jboss/starobrno/atomic/APITest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/atomic/APITest.java 2009-01-14 16:55:34 UTC (rev 7473)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/atomic/APITest.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -21,9 +21,9 @@
*/
package org.jboss.starobrno.atomic;
-import org.jboss.cache.DefaultCacheFactory;
import org.jboss.starobrno.config.Configuration;
import org.jboss.starobrno.config.Configuration.CacheMode;
+import org.jboss.starobrno.manager.CacheManager;
import org.jboss.starobrno.transaction.DummyTransactionManager;
import org.jboss.starobrno.transaction.DummyTransactionManagerLookup;
import org.jboss.starobrno.util.TestingUtil;
@@ -52,7 +52,7 @@
{
Configuration c = new Configuration();
c.setInvocationBatchingEnabled(true);
- AtomicMapCache cache = (AtomicMapCache) new DefaultCacheFactory().createCache(c);
+ AtomicMapCache cache = (AtomicMapCache) new CacheManager(c).getCache();
try
{
AtomicMap map = cache.getAtomicMap("map");
@@ -82,7 +82,7 @@
Configuration c = new Configuration();
c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
c.setInvocationBatchingEnabled(true);
- AtomicMapCache cache = (AtomicMapCache) new DefaultCacheFactory().createCache(c);
+ AtomicMapCache cache = (AtomicMapCache) new CacheManager(c).getCache();
try
{
AtomicMap map = cache.getAtomicMap("map");
@@ -123,7 +123,7 @@
Configuration c = new Configuration();
c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
c.setInvocationBatchingEnabled(true);
- AtomicMapCache cache = (AtomicMapCache) new DefaultCacheFactory().createCache(c);
+ AtomicMapCache cache = (AtomicMapCache) new CacheManager(c).getCache();
try
{
AtomicMap map = cache.getAtomicMap("map");
@@ -161,7 +161,7 @@
Configuration c = new Configuration();
c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
c.setInvocationBatchingEnabled(true);
- AtomicMapCache cache = (AtomicMapCache) new DefaultCacheFactory().createCache(c);
+ AtomicMapCache cache = (AtomicMapCache) new CacheManager(c).getCache();
try
{
AtomicMap map = cache.getAtomicMap("map");
@@ -194,8 +194,8 @@
c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
c.setCacheMode(CacheMode.REPL_SYNC);
c.setInvocationBatchingEnabled(true);
- AtomicMapCache cache1 = (AtomicMapCache) new DefaultCacheFactory().createCache(c.clone());
- AtomicMapCache cache2 = (AtomicMapCache) new DefaultCacheFactory().createCache(c.clone());
+ AtomicMapCache cache1 = (AtomicMapCache) new CacheManager(c).getCache();
+ AtomicMapCache cache2 = (AtomicMapCache) new CacheManager(c).getCache();
try
{
@@ -229,8 +229,8 @@
c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
c.setCacheMode(CacheMode.REPL_SYNC);
c.setInvocationBatchingEnabled(true);
- AtomicMapCache cache1 = (AtomicMapCache) new DefaultCacheFactory().createCache(c.clone());
- AtomicMapCache cache2 = (AtomicMapCache) new DefaultCacheFactory().createCache(c.clone());
+ AtomicMapCache cache1 = (AtomicMapCache) new CacheManager(c).getCache();
+ AtomicMapCache cache2 = (AtomicMapCache) new CacheManager(c).getCache();
try
{
Added: core/branches/flat/src/test/java/org/jboss/starobrno/factories/scopes/ScopeDetectorTest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/factories/scopes/ScopeDetectorTest.java (rev 0)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/factories/scopes/ScopeDetectorTest.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -0,0 +1,101 @@
+package org.jboss.starobrno.factories.scopes;
+
+import org.testng.annotations.Test;
+
+/**
+ * @author Manik Surtani
+ */
+@Test(groups = "unit")
+public class ScopeDetectorTest
+{
+ public void testScopeOnClass()
+ {
+ testScopes(Test1.class, Scopes.CACHE_MANAGER_ONLY);
+
+ }
+
+ public void testScopeOnInterface()
+ {
+ testScopes(Test2.class, Scopes.CACHE_MANAGER_ONLY);
+ }
+
+ public void testScopeOnSuperClass()
+ {
+ testScopes(Test3.class, Scopes.CACHE_MANAGER_ONLY);
+ }
+
+ public void testScopeOnSuperInterface()
+ {
+ testScopes(Test4.class, Scopes.CACHE_MANAGER_ONLY);
+ }
+
+ public void testMultipleScopes()
+ {
+ testScopes(Test5.class, Scopes.EITHER);
+ }
+
+ public void testNoScopes()
+ {
+ testScopes(Test6.class, Scopes.CACHE_ONLY);
+ }
+
+ private void testScopes(Class clazz, Scopes expected)
+ {
+ Scopes detected = ScopeDetector.detectScope(clazz);
+ assert detected == expected : "Expected " + expected + " but was " + detected;
+ }
+
+ public static interface Unscoped
+ {
+
+ }
+
+ @Scope(Scopes.CACHE_MANAGER_ONLY)
+ public static interface Scoped
+ {
+
+ }
+
+ @Scope(Scopes.CACHE_MANAGER_ONLY)
+ public static class SuperScoped
+ {
+
+ }
+
+ public static class SuperUnScoped
+ {
+
+ }
+
+ @Scope(Scopes.CACHE_MANAGER_ONLY)
+ public static class Test1
+ {
+
+ }
+
+ public static class Test2 implements Scoped
+ {
+
+ }
+
+ public static class Test3 extends SuperScoped
+ {
+
+ }
+
+ public static class Test4 extends Test2
+ {
+
+ }
+
+ @Scope(Scopes.EITHER)
+ public static class Test5 implements Scoped
+ {
+
+ }
+
+ public static class Test6 extends SuperUnScoped implements Unscoped
+ {
+
+ }
+}
Added: core/branches/flat/src/test/java/org/jboss/starobrno/manager/CacheManagerComponentRegistryTest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/manager/CacheManagerComponentRegistryTest.java (rev 0)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/manager/CacheManagerComponentRegistryTest.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -0,0 +1,102 @@
+package org.jboss.starobrno.manager;
+
+import org.jboss.starobrno.Cache;
+import org.jboss.starobrno.config.CacheLoaderConfig;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.interceptors.BatchingInterceptor;
+import org.jboss.starobrno.interceptors.InterceptorChain;
+import org.jboss.starobrno.loader.CacheLoaderManager;
+import org.jboss.starobrno.loader.FileCacheLoaderConfig;
+import org.jboss.starobrno.remoting.RPCManager;
+import org.jboss.starobrno.transaction.DummyTransactionManager;
+import org.jboss.starobrno.transaction.DummyTransactionManagerLookup;
+import org.jboss.starobrno.util.TestingUtil;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.Test;
+
+import javax.transaction.TransactionManager;
+
+/**
+ * @author Manik Surtani
+ */
+@Test(groups = "functional", sequential = true)
+public class CacheManagerComponentRegistryTest
+{
+ CacheManager cm;
+
+ @AfterMethod
+ public void tearDown()
+ {
+ if (cm != null) cm.stop();
+ }
+
+ public void testForceSharedComponents() throws CacheNameExistsException, NamedCacheNotFoundException
+ {
+ Configuration defaultCfg = new Configuration();
+ defaultCfg.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ // cache manager with default configuration
+ cm = new CacheManager(defaultCfg);
+
+ // default cache with no overrides
+ Cache c = cm.getCache();
+
+ Configuration overrides = new Configuration();
+ overrides.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ cm.defineCache("transactional", overrides);
+ Cache transactional = cm.getCache("transactional");
+
+ // assert components.
+ assert TestingUtil.extractComponent(c, TransactionManager.class) == null;
+ assert TestingUtil.extractComponent(transactional, TransactionManager.class) instanceof DummyTransactionManager;
+
+ // assert force-shared components
+ assert TestingUtil.extractComponent(c, RPCManager.class) != null;
+ assert TestingUtil.extractComponent(transactional, RPCManager.class) != null;
+ assert TestingUtil.extractComponent(c, RPCManager.class) == TestingUtil.extractComponent(transactional, RPCManager.class);
+ }
+
+ public void testForceUnsharedComponents() throws CacheNameExistsException, NamedCacheNotFoundException
+ {
+ CacheLoaderConfig clc = new CacheLoaderConfig();
+ FileCacheLoaderConfig fc = new FileCacheLoaderConfig();
+ fc.setLocation("/tmp");
+ clc.addIndividualCacheLoaderConfig(fc);
+
+ Configuration defaultCfg = new Configuration();
+ defaultCfg.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ defaultCfg.setCacheLoaderConfig(clc);
+ // cache manager with default configuration
+ cm = new CacheManager(defaultCfg);
+
+ // default cache with no overrides
+ Cache c = cm.getCache();
+
+ Configuration overrides = new Configuration();
+ overrides.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ cm.defineCache("transactional", overrides);
+ Cache transactional = cm.getCache("transactional");
+
+ // assert components.
+ assert TestingUtil.extractComponent(c, CacheLoaderManager.class) != null;
+ assert TestingUtil.extractComponent(transactional, CacheLoaderManager.class) != null;
+ assert TestingUtil.extractComponent(c, CacheLoaderManager.class) != TestingUtil.extractComponent(transactional, CacheLoaderManager.class);
+ }
+
+ public void testOverridingComponents() throws CacheNameExistsException, NamedCacheNotFoundException
+ {
+ Configuration defaultCfg = new Configuration();
+ cm = new CacheManager(defaultCfg);
+
+ // default cache with no overrides
+ Cache c = cm.getCache();
+
+ Configuration overrides = new Configuration();
+ overrides.setInvocationBatchingEnabled(true);
+ cm.defineCache("overridden", overrides);
+ Cache overridden = cm.getCache("overridden");
+
+ // assert components.
+ assert !TestingUtil.extractComponent(c, InterceptorChain.class).containsInterceptorType(BatchingInterceptor.class);
+ assert TestingUtil.extractComponent(overridden, InterceptorChain.class).containsInterceptorType(BatchingInterceptor.class);
+ }
+}
Added: core/branches/flat/src/test/java/org/jboss/starobrno/manager/CacheManagerTest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/manager/CacheManagerTest.java (rev 0)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/manager/CacheManagerTest.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -0,0 +1,68 @@
+package org.jboss.starobrno.manager;
+
+import org.jboss.cache.CacheStatus;
+import org.jboss.starobrno.Cache;
+import org.jboss.starobrno.config.Configuration;
+import org.testng.annotations.Test;
+
+/**
+ * @author Manik Surtani
+ */
+@Test(groups = "functional")
+public class CacheManagerTest
+{
+ public void testDefaultCache() throws CacheNameExistsException
+ {
+ CacheManager cm = new CacheManager();
+
+ assert cm.getCache().getCacheStatus() == CacheStatus.STARTED;
+ assert cm.getCache().getName().equals(CacheManager.DEFAULT_CACHE_NAME);
+
+ try
+ {
+ cm.defineCache(CacheManager.DEFAULT_CACHE_NAME, new Configuration());
+ assert false : "Should fail";
+ }
+ catch (IllegalArgumentException e)
+ {
+ // ok
+ assert true : "Allowed";
+ }
+ }
+
+ public void testClashingNames() throws CacheNameExistsException
+ {
+ CacheManager cm = new CacheManager();
+ Configuration c = new Configuration();
+
+ cm.defineCache("aCache", c);
+ try
+ {
+ cm.defineCache("aCache", c);
+ assert false : "Should fail";
+ }
+ catch (CacheNameExistsException cnee)
+ {
+ // expected
+ assert true : "Expected";
+ }
+ }
+
+ public void testStartAndStop()
+ {
+ CacheManager cm = new CacheManager();
+ Cache c1 = cm.getCache("cache1");
+ Cache c2 = cm.getCache("cache2");
+ Cache c3 = cm.getCache("cache3");
+
+ assert c1.getCacheStatus() == CacheStatus.STARTED;
+ assert c2.getCacheStatus() == CacheStatus.STARTED;
+ assert c3.getCacheStatus() == CacheStatus.STARTED;
+
+ cm.stop();
+
+ assert c1.getCacheStatus() == CacheStatus.STOPPED;
+ assert c2.getCacheStatus() == CacheStatus.STOPPED;
+ assert c3.getCacheStatus() == CacheStatus.STOPPED;
+ }
+}
Added: core/branches/flat/src/test/java/org/jboss/starobrno/manager/CacheManagerXmlConfigurationTest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/manager/CacheManagerXmlConfigurationTest.java (rev 0)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/manager/CacheManagerXmlConfigurationTest.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -0,0 +1,157 @@
+package org.jboss.starobrno.manager;
+
+import org.jboss.starobrno.Cache;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.config.ConfigurationException;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+/**
+ * @author Manik Surtani
+ */
+@Test(groups = "functional", sequential = true)
+public class CacheManagerXmlConfigurationTest
+{
+ CacheManager cm;
+
+ @AfterMethod
+ public void tearDown()
+ {
+ if (cm != null) cm.stop();
+ }
+
+ public void testNamedCacheXML() throws IOException
+ {
+ String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+ "<jbosscache xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:jboss:starobrno-core:config:1.0\">\n" +
+ "\n" +
+ " <default>\n" +
+ " <locking concurrencyLevel=\"100\" lockAcquisitionTimeout=\"1000\" />\n" +
+ " </default>\n" +
+ "\n" +
+ " <namedCache name=\"transactional\">\n" +
+ " <transaction transactionManagerLookupClass=\"org.jboss.starobrno.transaction.GenericTransactionManagerLookup\"/>\n" +
+ " </namedCache>\n" +
+ "\n" +
+ " <namedCache name=\"syncRepl\">\n" +
+ " <clustering>\n" +
+ " <stateRetrieval fetchInMemoryState=\"true\" timeout=\"15000\"/>\n" +
+ " <jgroupsConfig configFile=\"udp.xml\"/>\n" +
+ " <sync replTimeout=\"15000\"/>\n" +
+ " </clustering>\n" +
+ " </namedCache>\n" +
+ "\n" +
+ " <namedCache name=\"txSyncRepl\">\n" +
+ " <transaction transactionManagerLookupClass=\"org.jboss.starobrno.transaction.GenericTransactionManagerLookup\"/>\n" +
+ " <clustering>\n" +
+ " <stateRetrieval fetchInMemoryState=\"true\" timeout=\"15000\"/>\n" +
+ " <jgroupsConfig configFile=\"udp.xml\"/>\n" +
+ " <sync replTimeout=\"15000\"/>\n" +
+ " </clustering>\n" +
+ " </namedCache>\n" +
+ " \n" +
+ "</jbosscache>";
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
+ cm = new CacheManager(bais);
+
+ // test default cache
+ Cache c = cm.getCache();
+ assert c.getConfiguration().getConcurrencyLevel() == 100;
+ assert c.getConfiguration().getLockAcquisitionTimeout() == 1000;
+ assert c.getConfiguration().getRuntimeConfig().getTransactionManager() == null;
+ assert c.getConfiguration().getRuntimeConfig().getRPCManager() == null;
+
+ // test the "transactional" cache
+ c = cm.getCache("transactional");
+ assert c.getConfiguration().getConcurrencyLevel() == 100;
+ assert c.getConfiguration().getLockAcquisitionTimeout() == 1000;
+ assert c.getConfiguration().getRuntimeConfig().getTransactionManager() != null;
+ assert c.getConfiguration().getRuntimeConfig().getRPCManager() == null;
+
+ // test the "replicated" cache
+ c = cm.getCache("syncRepl");
+ assert c.getConfiguration().getConcurrencyLevel() == 100;
+ assert c.getConfiguration().getLockAcquisitionTimeout() == 1000;
+ assert c.getConfiguration().getRuntimeConfig().getTransactionManager() == null;
+ assert c.getConfiguration().getRuntimeConfig().getRPCManager() != null;
+
+ // test the "txSyncRepl" cache
+ c = cm.getCache("txSyncRepl");
+ assert c.getConfiguration().getConcurrencyLevel() == 100;
+ assert c.getConfiguration().getLockAcquisitionTimeout() == 1000;
+ assert c.getConfiguration().getRuntimeConfig().getTransactionManager() != null;
+ assert c.getConfiguration().getRuntimeConfig().getRPCManager() != null;
+ }
+
+ public void testNamedCacheXMLClashingNames() throws IOException
+ {
+ String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+ "<jbosscache xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:jboss:starobrno-core:config:1.0\">\n" +
+ "\n" +
+ " <default>\n" +
+ " <locking concurrencyLevel=\"100\" lockAcquisitionTimeout=\"1000\" />\n" +
+ " </default>\n" +
+ "\n" +
+ " <namedCache name=\"c1\">\n" +
+ " <transaction transactionManagerLookupClass=\"org.jboss.starobrno.transaction.GenericTransactionManagerLookup\"/>\n" +
+ " </namedCache>\n" +
+ "\n" +
+ " <namedCache name=\"c1\">\n" +
+ " <clustering>\n" +
+ " <stateRetrieval fetchInMemoryState=\"true\" timeout=\"15000\"/>\n" +
+ " <jgroupsConfig configFile=\"udp.xml\"/>\n" +
+ " <sync replTimeout=\"15000\"/>\n" +
+ " </clustering>\n" +
+ " </namedCache>\n" +
+ " \n" +
+ "</jbosscache>";
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
+ try
+ {
+ cm = new CacheManager(bais);
+ assert false : "Should fail";
+ }
+ catch (ConfigurationException expected)
+ {
+
+ }
+ }
+
+ public void testNamedCacheXMLClashingNamesProgrammatic() throws IOException
+ {
+ String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+ "<jbosscache xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:jboss:starobrno-core:config:1.0\">\n" +
+ "\n" +
+ " <default>\n" +
+ " <locking concurrencyLevel=\"100\" lockAcquisitionTimeout=\"1000\" />\n" +
+ " </default>\n" +
+ "\n" +
+ " <namedCache name=\"c1\">\n" +
+ " <transaction transactionManagerLookupClass=\"org.jboss.starobrno.transaction.GenericTransactionManagerLookup\"/>\n" +
+ " </namedCache>\n" +
+ "\n" +
+ "</jbosscache>";
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
+ cm = new CacheManager(bais);
+
+ assert cm.getCache() != null;
+ assert cm.getCache("c1") != null;
+ try
+ {
+ cm.defineCache("c1", new Configuration());
+ assert false : "Should fail";
+ }
+ catch (CacheNameExistsException expected)
+ {
+
+ }
+ }
+}
+
+
Modified: core/branches/flat/src/test/java/org/jboss/starobrno/profiling/MemConsumptionTest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/profiling/MemConsumptionTest.java 2009-01-14 16:55:34 UTC (rev 7473)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/profiling/MemConsumptionTest.java 2009-01-14 17:00:40 UTC (rev 7474)
@@ -21,9 +21,9 @@
*/
package org.jboss.starobrno.profiling;
-import org.jboss.cache.DefaultCacheFactory;
import org.jboss.starobrno.Cache;
import org.jboss.starobrno.CacheException;
+import org.jboss.starobrno.manager.CacheManager;
import org.jboss.starobrno.util.TestingUtil;
import org.testng.annotations.Test;
@@ -55,8 +55,7 @@
int kBytesCached = (bytesPerCharacter * numEntries * (payloadSize + keySize)) / 1024;
System.out.println("Bytes to be cached: " + NumberFormat.getIntegerInstance().format(kBytesCached) + " kb");
-// Cache c = new UnitTestCacheFactory().createCache(false); // default LOCAL cache
- Cache c = new DefaultCacheFactory().createCache();
+ Cache c = new CacheManager().getCache();
for (int i = 0; i < numEntries; i++)
{
switch (payloadType)
Copied: core/branches/flat/src/test/resources/configs/named-cache-test.xml (from rev 7331, core/branches/flat/src/test/resources/configs/replSync.xml)
===================================================================
--- core/branches/flat/src/test/resources/configs/named-cache-test.xml (rev 0)
+++ core/branches/flat/src/test/resources/configs/named-cache-test.xml 2009-01-14 17:00:40 UTC (rev 7474)
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:jboss:starobrno-core:config:1.0">
+
+ <global>
+
+ <asyncListenerExecutor factory="org.jboss.starobrno.executors.DefaultExecutorFactory">
+ <property name="maxThreads">5</property>
+ <property name="threadNamePrefix">AsyncListenerThread</property>
+ </asyncListenerExecutor>
+
+ <asyncSerializationExecutor factory="org.jboss.starobrno.executors.DefaultExecutorFactory">
+ <property name="maxThreads">25</property>
+ <property name="threadNamePrefix">AsyncSerializationThread</property>
+ </asyncSerializationExecutor>
+
+ <evictionScheduledExecutor factory="org.jboss.starobrno.executors.DefaultScheduledExecutorFactory">
+ <property name="threadNamePrefix">EvictionThread</property>
+ </evictionScheduledExecutor>
+
+ <replicationQueueScheduledExecutor factory="org.jboss.starobrno.executors.DefaultScheduledExecutorFactory">
+ <property name="threadNamePrefix">ReplicationQueueThread</property>
+ </replicationQueueScheduledExecutor>
+
+ <jgroupsConfig configFile="udp.xml"/>
+
+ <serialization marshallerClass="org.jboss.starobrno.marshall.CacheMarshallerStarobrno" version="1.0"
+ objectInputStreamPoolSize="100" objectOutputStreamPoolSize="100"/>
+
+ </global>
+
+ <default>
+ <locking concurrencyLevel="100" lockAcquisitionTimeout="1000"/>
+ </default>
+
+ <namedCache name="transactional">
+ <transaction transactionManagerLookupClass="org.jboss.starobrno.transaction.GenericTransactionManagerLookup"/>
+ </namedCache>
+
+ <namedCache name="syncRepl">
+
+ <clustering>
+ <stateRetrieval fetchInMemoryState="true" timeout="15000"/>
+ <sync replTimeout="15000"/>
+ </clustering>
+ </namedCache>
+
+ <namedCache name="txSyncRepl">
+ <transaction transactionManagerLookupClass="org.jboss.starobrno.transaction.GenericTransactionManagerLookup"/>
+ <clustering>
+ <stateRetrieval fetchInMemoryState="true" timeout="15000"/>
+ <sync replTimeout="15000"/>
+ </clustering>
+ </namedCache>
+
+</jbosscache>
Property changes on: core/branches/flat/src/test/resources/configs/named-cache-test.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ LF
17 years, 2 months
JBoss Cache SVN: r7473 - core/branches/flat/src/main/java/org/jboss/starobrno/util.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-01-14 11:55:34 -0500 (Wed, 14 Jan 2009)
New Revision: 7473
Added:
core/branches/flat/src/main/java/org/jboss/starobrno/util/TypedProperties.java
Log:
Utility to read typed properties
Added: core/branches/flat/src/main/java/org/jboss/starobrno/util/TypedProperties.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/util/TypedProperties.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/util/TypedProperties.java 2009-01-14 16:55:34 UTC (rev 7473)
@@ -0,0 +1,76 @@
+package org.jboss.starobrno.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Properties;
+
+/**
+ * Type-aware properties. Extends the JDK {@link Properties} class to provide accessors that convert values to certain
+ * types, using default values if a conversion is not possible.
+ *
+ * @author Manik Surtani
+ */
+public class TypedProperties extends Properties
+{
+ private static final Log log = LogFactory.getLog(TypedProperties.class);
+
+ public TypedProperties(Properties p)
+ {
+ if (p != null) putAll(p);
+ }
+
+ public int getIntProperty(String key, int defaultValue)
+ {
+ String value = getProperty(key);
+ if (value == null) return defaultValue;
+ value = value.trim();
+ if (value.length() == 0) return defaultValue;
+
+ try
+ {
+ return Integer.parseInt(value);
+ }
+ catch (NumberFormatException nfe)
+ {
+ log.warn("Unable to convert string property [" + value + "] to an int! Using default value of " + defaultValue);
+ return defaultValue;
+ }
+ }
+
+ public long getLongProperty(String key, long defaultValue)
+ {
+ String value = getProperty(key);
+ if (value == null) return defaultValue;
+ value = value.trim();
+ if (value.length() == 0) return defaultValue;
+
+ try
+ {
+ return Long.parseLong(value);
+ }
+ catch (NumberFormatException nfe)
+ {
+ log.warn("Unable to convert string property [" + value + "] to a long! Using default value of " + defaultValue);
+ return defaultValue;
+ }
+ }
+
+ public boolean getBooleanProperty(String key, boolean defaultValue)
+ {
+ String value = getProperty(key);
+ if (value == null) return defaultValue;
+ value = value.trim();
+ if (value.length() == 0) return defaultValue;
+
+ try
+ {
+ return Boolean.parseBoolean(value);
+ }
+ catch (Exception e)
+ {
+ log.warn("Unable to convert string property [" + value + "] to a boolean! Using default value of " + defaultValue);
+ return defaultValue;
+ }
+ }
+}
17 years, 2 months
JBoss Cache SVN: r7472 - core/trunk/src/test/java/org/jboss/cache.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-01-14 11:50:49 -0500 (Wed, 14 Jan 2009)
New Revision: 7472
Modified:
core/trunk/src/test/java/org/jboss/cache/ResourceCleanupTest.java
Log:
Extra info
Modified: core/trunk/src/test/java/org/jboss/cache/ResourceCleanupTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/ResourceCleanupTest.java 2009-01-14 16:45:03 UTC (rev 7471)
+++ core/trunk/src/test/java/org/jboss/cache/ResourceCleanupTest.java 2009-01-14 16:50:49 UTC (rev 7472)
@@ -43,9 +43,11 @@
System.setProperty("bind.address","127.0.0.1");
}
System.out.println("java.vm.version = " + System.getProperty("java.vm.version"));
+ System.out.println("java.vm.vendor = " + System.getProperty("java.vm.vendor"));
System.out.println("os.name = " + System.getProperty("os.name"));
System.out.println("os.version = " + System.getProperty("os.version"));
System.out.println("sun.arch.data.model = " + System.getProperty("sun.arch.data.model"));
+ System.out.println("sun.cpu.endian = " + System.getProperty("sun.cpu.endian"));
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~ ENVIRONMENT INFO ~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
17 years, 2 months