[jbosscache-commits] JBoss Cache SVN: r7537 - in core/branches/flat/src: main/java/org/horizon/config and 11 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Tue Jan 20 11:51:26 EST 2009


Author: manik.surtani at jboss.com
Date: 2009-01-20 11:51:26 -0500 (Tue, 20 Jan 2009)
New Revision: 7537

Added:
   core/branches/flat/src/main/java/org/horizon/ComponentStatus.java
   core/branches/flat/src/main/java/org/horizon/config/AbstractConfigurationBean.java
   core/branches/flat/src/main/java/org/horizon/config/AbstractNamedCacheConfigurationBean.java
   core/branches/flat/src/main/java/org/horizon/factories/AutoInstantiableFactory.java
   core/branches/flat/src/main/java/org/horizon/factories/NamedComponentFactory.java
   core/branches/flat/src/main/java/org/horizon/factories/NamedExecutorsFactory.java
   core/branches/flat/src/main/java/org/horizon/factories/TransportFactory.java
Removed:
   core/branches/flat/src/main/java/org/horizon/CacheStatus.java
   core/branches/flat/src/main/java/org/horizon/config/ConfigurationComponent.java
Modified:
   core/branches/flat/src/main/java/org/horizon/Cache.java
   core/branches/flat/src/main/java/org/horizon/CacheDelegate.java
   core/branches/flat/src/main/java/org/horizon/config/CacheLoaderConfig.java
   core/branches/flat/src/main/java/org/horizon/config/Configuration.java
   core/branches/flat/src/main/java/org/horizon/config/CustomInterceptorConfig.java
   core/branches/flat/src/main/java/org/horizon/config/EvictionCacheConfig.java
   core/branches/flat/src/main/java/org/horizon/config/EvictionConfig.java
   core/branches/flat/src/main/java/org/horizon/config/GlobalConfiguration.java
   core/branches/flat/src/main/java/org/horizon/config/PluggableConfigurationComponent.java
   core/branches/flat/src/main/java/org/horizon/config/RuntimeConfig.java
   core/branches/flat/src/main/java/org/horizon/eviction/EvictionAlgorithmConfigBase.java
   core/branches/flat/src/main/java/org/horizon/eviction/algorithms/NULL/NullEvictionAlgorithmConfig.java
   core/branches/flat/src/main/java/org/horizon/factories/AbstractComponentRegistry.java
   core/branches/flat/src/main/java/org/horizon/factories/BootstrapFactory.java
   core/branches/flat/src/main/java/org/horizon/factories/ComponentFactory.java
   core/branches/flat/src/main/java/org/horizon/factories/ComponentRegistry.java
   core/branches/flat/src/main/java/org/horizon/factories/DataContainerFactory.java
   core/branches/flat/src/main/java/org/horizon/factories/DefaultCacheFactory.java
   core/branches/flat/src/main/java/org/horizon/factories/EmptyConstructorFactory.java
   core/branches/flat/src/main/java/org/horizon/factories/EvictionManagerFactory.java
   core/branches/flat/src/main/java/org/horizon/factories/GlobalComponentRegistry.java
   core/branches/flat/src/main/java/org/horizon/factories/InterceptorChainFactory.java
   core/branches/flat/src/main/java/org/horizon/factories/LockManagerFactory.java
   core/branches/flat/src/main/java/org/horizon/factories/ReplicationQueueFactory.java
   core/branches/flat/src/main/java/org/horizon/factories/RuntimeConfigAwareFactory.java
   core/branches/flat/src/main/java/org/horizon/factories/StateTransferFactory.java
   core/branches/flat/src/main/java/org/horizon/factories/StateTransferManagerFactory.java
   core/branches/flat/src/main/java/org/horizon/factories/TransactionManagerFactory.java
   core/branches/flat/src/main/java/org/horizon/loader/ClusteredCacheLoader.java
   core/branches/flat/src/main/java/org/horizon/manager/CacheManager.java
   core/branches/flat/src/main/java/org/horizon/manager/DefaultCacheManager.java
   core/branches/flat/src/main/java/org/horizon/remoting/RPCManagerImpl.java
   core/branches/flat/src/main/java/org/horizon/tree/TreeCache.java
   core/branches/flat/src/main/java/org/horizon/tree/TreeCacheImpl.java
   core/branches/flat/src/main/java/org/horizon/util/TestingUtil.java
   core/branches/flat/src/test/java/org/horizon/UnitTestCacheManager.java
   core/branches/flat/src/test/java/org/horizon/manager/CacheManagerTest.java
   core/branches/flat/src/test/resources/log4j.xml
Log:
Component registry fixes

Modified: core/branches/flat/src/main/java/org/horizon/Cache.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/Cache.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/Cache.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -56,7 +56,7 @@
     *
     * @param key   key with which the specified value is to be associated.
     * @param value value to be associated with the specified key.
-    * @throws IllegalStateException if {@link #getCacheStatus()} would not return {@link CacheStatus#STARTED}.
+    * @throws IllegalStateException if {@link #getCacheStatus()} would not return {@link ComponentStatus#STARTED}.
     */
    void putForExternalRead(K key, V value);
 
@@ -68,7 +68,7 @@
 
    void setInvocationContext(InvocationContext ctx);
 
-   CacheStatus getCacheStatus();
+   ComponentStatus getCacheStatus();
 
    /**
     * @return true if a batch was successfully started; false if one was available and already running.

Modified: core/branches/flat/src/main/java/org/horizon/CacheDelegate.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/CacheDelegate.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/CacheDelegate.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -336,7 +336,7 @@
       return componentRegistry;
    }
 
-   public CacheStatus getCacheStatus() {
+   public ComponentStatus getCacheStatus() {
       return componentRegistry.getState();
    }
 

Deleted: core/branches/flat/src/main/java/org/horizon/CacheStatus.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/CacheStatus.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/CacheStatus.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -1,191 +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.horizon;
-
-import org.horizon.logging.Log;
-import org.horizon.logging.LogFactory;
-
-/**
- * Various states that an object that has a four stage lifecycle (i.e. <code>create()</code>, <code>start()</code>,
- * <code>stop()</code> and <code>destroy()</code>) might be in.
- *
- * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
- * @since 1.0
- */
-public enum CacheStatus {
-   /**
-    * Object has been instantiated, but create() has not been called.
-    */
-   INSTANTIATED,
-   /**
-    * The <code>create()</code> method has been called but not yet completed.
-    */
-   CREATING,
-   /**
-    * The <code>create()</code> method has been completed but <code>start()</code> has not been called.
-    */
-   CREATED,
-   /**
-    * The <code>start()</code> method has been called but has not yet completed.
-    */
-   STARTING,
-   /**
-    * The <code>start()</code> method has completed.
-    */
-   STARTED,
-   /**
-    * The <code>stop()</code> method has been called but has not yet completed.
-    */
-   STOPPING,
-   /**
-    * The <code>stop()</code> method has completed but <code>destroy()</code> has not yet been called. Conceptually
-    * equivalent to {@link #CREATED}.
-    */
-   STOPPED,
-   /**
-    * The <code>destroy()</code> method has been called but has not yet completed.
-    */
-   DESTROYING,
-   /**
-    * The <code>destroy()</code> method has completed. Conceptually equivalent to {@link #INSTANTIATED}.
-    */
-   DESTROYED,
-   /**
-    * A failure occurred during the execution of <code>create()</code>, <code>start()</code>, <code>stop()</code> or
-    * <code>destroy()</code>. The next logical transition is to call <code>destroy()</code>.
-    */
-   FAILED;
-
-   private static final Log log = LogFactory.getLog(CacheStatus.class);
-
-   public boolean createAllowed() {
-      switch (this) {
-         case CREATING:
-         case CREATED:
-         case STARTING:
-         case STARTED:
-         case STOPPED:
-         case FAILED:
-         case STOPPING:
-         case DESTROYING:
-            return false;
-         default:
-            return true;
-      }
-   }
-
-   public boolean needToDestroyFailedCache() {
-      if (this == CacheStatus.FAILED) {
-         log.debug("need to call destroy() since current state is " +
-               this);
-         return true;
-      }
-
-      return false;
-   }
-
-   public boolean startAllowed() {
-      switch (this) {
-         case INSTANTIATED:
-         case DESTROYED:
-         case STARTING:
-         case STARTED:
-         case FAILED:
-         case STOPPING:
-         case DESTROYING:
-            return false;
-         default:
-            return true;
-      }
-   }
-
-   public boolean needCreateBeforeStart() {
-      switch (this) {
-         case INSTANTIATED:
-         case DESTROYED:
-            log.debug("start() called while current state is " +
-                  this + " -- call create() first");
-            return true;
-         default:
-            return false;
-      }
-   }
-
-   public boolean stopAllowed() {
-      switch (this) {
-         case INSTANTIATED:
-         case CREATED:
-         case STOPPED:
-         case DESTROYED:
-            log.debug("Ignoring call to stop() as current state is " + this);
-            return false;
-         case CREATING:
-         case STARTING:
-         case STOPPING:
-         case DESTROYING:
-            log.warn("Ignoring call to stop() as current state is " + this);
-            return false;
-         case FAILED:
-         case STARTED:
-         default:
-            return true;
-      }
-
-   }
-
-   public boolean destroyAllowed() {
-      switch (this) {
-         case INSTANTIATED:
-         case DESTROYED:
-            log.debug("Ignoring call to destroy() as current state is " + this);
-            return false;
-         case CREATING:
-         case STARTING:
-         case STOPPING:
-         case DESTROYING:
-            log.warn("Ignoring call to destroy() as current state iswhile cache is " + this);
-            return false;
-         case STARTED:
-            // stop first
-            return false;
-         case CREATED:
-         case STOPPED:
-         case FAILED:
-         default:
-            return true;
-      }
-   }
-
-   public boolean needStopBeforeDestroy() {
-      if (this == CacheStatus.STARTED) {
-         log.warn("destroy() called while current state is " +
-               this + " -- call stop() first");
-         return true;
-      }
-
-      return false;
-   }
-
-   public boolean allowInvocations() {
-      return (this == CacheStatus.STARTED);
-   }
-}

Copied: core/branches/flat/src/main/java/org/horizon/ComponentStatus.java (from rev 7526, core/branches/flat/src/main/java/org/horizon/CacheStatus.java)
===================================================================
--- core/branches/flat/src/main/java/org/horizon/ComponentStatus.java	                        (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/ComponentStatus.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -0,0 +1,191 @@
+/*
+ * 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.horizon;
+
+import org.horizon.logging.Log;
+import org.horizon.logging.LogFactory;
+
+/**
+ * Various states that an object that has a four stage lifecycle (i.e. <code>create()</code>, <code>start()</code>,
+ * <code>stop()</code> and <code>destroy()</code>) might be in.
+ *
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @since 1.0
+ */
+public enum ComponentStatus {
+   /**
+    * Object has been instantiated, but create() has not been called.
+    */
+   INSTANTIATED,
+   /**
+    * The <code>create()</code> method has been called but not yet completed.
+    */
+   CREATING,
+   /**
+    * The <code>create()</code> method has been completed but <code>start()</code> has not been called.
+    */
+   CREATED,
+   /**
+    * The <code>start()</code> method has been called but has not yet completed.
+    */
+   STARTING,
+   /**
+    * The <code>start()</code> method has completed.
+    */
+   STARTED,
+   /**
+    * The <code>stop()</code> method has been called but has not yet completed.
+    */
+   STOPPING,
+   /**
+    * The <code>stop()</code> method has completed but <code>destroy()</code> has not yet been called. Conceptually
+    * equivalent to {@link #CREATED}.
+    */
+   STOPPED,
+   /**
+    * The <code>destroy()</code> method has been called but has not yet completed.
+    */
+   DESTROYING,
+   /**
+    * The <code>destroy()</code> method has completed. Conceptually equivalent to {@link #INSTANTIATED}.
+    */
+   DESTROYED,
+   /**
+    * A failure occurred during the execution of <code>create()</code>, <code>start()</code>, <code>stop()</code> or
+    * <code>destroy()</code>. The next logical transition is to call <code>destroy()</code>.
+    */
+   FAILED;
+
+   private static final Log log = LogFactory.getLog(ComponentStatus.class);
+
+   public boolean createAllowed() {
+      switch (this) {
+         case CREATING:
+         case CREATED:
+         case STARTING:
+         case STARTED:
+         case STOPPED:
+         case FAILED:
+         case STOPPING:
+         case DESTROYING:
+            return false;
+         default:
+            return true;
+      }
+   }
+
+   public boolean needToDestroyFailedCache() {
+      if (this == ComponentStatus.FAILED) {
+         log.debug("need to call destroy() since current state is " +
+               this);
+         return true;
+      }
+
+      return false;
+   }
+
+   public boolean startAllowed() {
+      switch (this) {
+         case INSTANTIATED:
+         case DESTROYED:
+         case STARTING:
+         case STARTED:
+         case FAILED:
+         case STOPPING:
+         case DESTROYING:
+            return false;
+         default:
+            return true;
+      }
+   }
+
+   public boolean needCreateBeforeStart() {
+      switch (this) {
+         case INSTANTIATED:
+         case DESTROYED:
+            log.debug("start() called while current state is " +
+                  this + " -- call create() first");
+            return true;
+         default:
+            return false;
+      }
+   }
+
+   public boolean stopAllowed() {
+      switch (this) {
+         case INSTANTIATED:
+         case CREATED:
+         case STOPPED:
+         case DESTROYED:
+            log.debug("Ignoring call to stop() as current state is " + this);
+            return false;
+         case CREATING:
+         case STARTING:
+         case STOPPING:
+         case DESTROYING:
+            log.warn("Ignoring call to stop() as current state is " + this);
+            return false;
+         case FAILED:
+         case STARTED:
+         default:
+            return true;
+      }
+
+   }
+
+   public boolean destroyAllowed() {
+      switch (this) {
+         case INSTANTIATED:
+         case DESTROYED:
+            log.debug("Ignoring call to destroy() as current state is " + this);
+            return false;
+         case CREATING:
+         case STARTING:
+         case STOPPING:
+         case DESTROYING:
+            log.warn("Ignoring call to destroy() as current state iswhile cache is " + this);
+            return false;
+         case STARTED:
+            // stop first
+            return false;
+         case CREATED:
+         case STOPPED:
+         case FAILED:
+         default:
+            return true;
+      }
+   }
+
+   public boolean needStopBeforeDestroy() {
+      if (this == ComponentStatus.STARTED) {
+         log.warn("destroy() called while current state is " +
+               this + " -- call stop() first");
+         return true;
+      }
+
+      return false;
+   }
+
+   public boolean allowInvocations() {
+      return (this == ComponentStatus.STARTED);
+   }
+}


Property changes on: core/branches/flat/src/main/java/org/horizon/ComponentStatus.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Copied: core/branches/flat/src/main/java/org/horizon/config/AbstractConfigurationBean.java (from rev 7526, core/branches/flat/src/main/java/org/horizon/config/ConfigurationComponent.java)
===================================================================
--- core/branches/flat/src/main/java/org/horizon/config/AbstractConfigurationBean.java	                        (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/config/AbstractConfigurationBean.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -0,0 +1,185 @@
+/*
+ * 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.horizon.config;
+
+import org.horizon.factories.scopes.Scope;
+import org.horizon.factories.scopes.Scopes;
+import org.horizon.logging.Log;
+import org.horizon.logging.LogFactory;
+import org.horizon.util.TypedProperties;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Properties;
+
+/**
+ * Base superclass of Cache configuration classes that expose some properties that can be changed after the cache is
+ * started.
+ *
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @see #testImmutability(String)
+ * @since 1.0
+ */
+ at Scope(Scopes.NAMED_CACHE)
+public abstract class AbstractConfigurationBean implements CloneableConfigurationComponent {
+   private static final long serialVersionUID = 4879873994727821938L;
+
+   protected transient Log log = LogFactory.getLog(getClass());
+//   private transient CacheSPI cache; // back-reference to test whether the cache is running.
+   //   private transient ComponentRegistry cr;
+   // a workaround to get over immutability checks
+   private boolean accessible;
+   protected List<String> overriddenConfigurationElements = new LinkedList<String>();
+
+   protected AbstractConfigurationBean() {
+   }
+
+//   public void passCacheToChildConfig(AbstractConfigurationBean child) {
+//      if (child != null) {
+//         child.setCache(cache);
+//      }
+//   }
+
+//   protected void addChildConfig(AbstractConfigurationBean child) {
+//      if (child != null) children.add(child);
+//      if (child != null && children.add(child))
+//         child.setCache(cache);
+//   }
+
+//   protected void addChildConfigs(Collection<? extends AbstractConfigurationBean> toAdd) {
+//      if (toAdd != null) {
+//         for (AbstractConfigurationBean child : toAdd)
+//            addChildConfig(child);
+//      }
+//   }
+//
+//   protected void removeChildConfig(AbstractConfigurationBean child) {
+//      children.remove(child);
+//   }
+
+//   protected void removeChildConfigs(Collection<? extends AbstractConfigurationBean> toRemove) {
+//      if (toRemove != null) {
+//         for (AbstractConfigurationBean child : toRemove)
+//            removeChildConfig(child);
+//      }
+//   }
+//
+//   protected void replaceChildConfig(AbstractConfigurationBean oldConfig, AbstractConfigurationBean newConfig) {
+//      removeChildConfig(oldConfig);
+//      addChildConfig(newConfig);
+//   }
+
+//   protected void replaceChildConfigs(Collection<? extends AbstractConfigurationBean> oldConfigs,
+//                                      Collection<? extends AbstractConfigurationBean> newConfigs) {
+//      synchronized (children) {
+//         removeChildConfigs(oldConfigs);
+//         addChildConfigs(newConfigs);
+//      }
+//   }
+
+   /**
+    * Safely converts a String to upper case.
+    *
+    * @param s string to convert
+    * @return the string in upper case, or null if s is null.
+    */
+   protected String uc(String s) {
+      return s == null ? null : s.toUpperCase(Locale.ENGLISH);
+   }
+
+   /**
+    * Converts a given {@link Properties} instance to an instance of {@link TypedProperties}
+    *
+    * @param p properties to convert
+    * @return TypedProperties instance
+    */
+   protected TypedProperties toTypedProperties(Properties p) {
+      return TypedProperties.toTypedProperties(p);
+   }
+
+   protected TypedProperties toTypedProperties(String s) {
+      TypedProperties tp = new TypedProperties();
+      if (s != null && s.trim().length() > 0) {
+         InputStream stream = new ByteArrayInputStream(s.getBytes());
+         try {
+            tp.load(stream);
+         } catch (IOException e) {
+            throw new ConfigurationException("Unable to parse properties string " + s, e);
+         }
+      }
+      return tp;
+   }
+
+   /**
+    * Tests whether the component this configuration bean intents to configure has already started.
+    *
+    * @return true if the component has started; false otherwise.
+    */
+   protected abstract boolean hasComponentStarted();
+
+   /**
+    * Checks field modifications via setters
+    *
+    * @param fieldName
+    */
+   protected void testImmutability(String fieldName) {
+      try {
+         if (!accessible && hasComponentStarted() && !getClass().getDeclaredField(fieldName).isAnnotationPresent(Dynamic.class)) {
+            throw new ConfigurationException("Attempted to modify a non-Dynamic configuration element [" + fieldName + "] after the component has started!");
+         }
+      }
+      catch (NoSuchFieldException e) {
+         log.warn("Field " + fieldName + " not found!!");
+      }
+      finally {
+         accessible = false;
+      }
+
+      // now mark this as overridden
+      overriddenConfigurationElements.add(fieldName);
+   }
+
+//   public void setCache(CacheSPI cache) {
+//      this.cache = cache;
+//      synchronized (children) {
+//         for (AbstractConfigurationBean child : children) {
+//            child.setCache(cache);
+//         }
+//      }
+//   }
+
+//   @Start
+//   private void start() {
+//      setCache(cr.getComponent(CacheSPI.class));
+//   }
+
+   @Override
+   public CloneableConfigurationComponent clone() throws CloneNotSupportedException {
+      AbstractConfigurationBean c = (AbstractConfigurationBean) super.clone();
+//      c.setCache(null);
+      return c;
+   }
+}


Property changes on: core/branches/flat/src/main/java/org/horizon/config/AbstractConfigurationBean.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: core/branches/flat/src/main/java/org/horizon/config/AbstractNamedCacheConfigurationBean.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/config/AbstractNamedCacheConfigurationBean.java	                        (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/config/AbstractNamedCacheConfigurationBean.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -0,0 +1,28 @@
+package org.horizon.config;
+
+import org.horizon.ComponentStatus;
+import org.horizon.factories.ComponentRegistry;
+import org.horizon.factories.annotations.Inject;
+import org.horizon.factories.scopes.Scope;
+import org.horizon.factories.scopes.Scopes;
+
+/**
+ * Adds named cache specific features to the {@link org.horizon.config.AbstractConfigurationBean}.
+ *
+ * @author Manik Surtani
+ * @since 1.0
+ */
+ at Scope(Scopes.NAMED_CACHE)
+public abstract class AbstractNamedCacheConfigurationBean extends AbstractConfigurationBean {
+
+   protected ComponentRegistry cr;
+
+   @Inject
+   private void inject(ComponentRegistry cr) {
+      this.cr = cr;
+   }
+
+   protected boolean hasComponentStarted() {
+      return cr != null && cr.getState() != null && cr.getState() == ComponentStatus.STARTED;
+   }
+}

Modified: core/branches/flat/src/main/java/org/horizon/config/CacheLoaderConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/config/CacheLoaderConfig.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/config/CacheLoaderConfig.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -38,7 +38,7 @@
  * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
  * @since 1.0
  */
-public class CacheLoaderConfig extends ConfigurationComponent {
+public class CacheLoaderConfig extends AbstractNamedCacheConfigurationBean {
    private static final long serialVersionUID = 2210349340378984424L;
 
    private boolean passivation;
@@ -68,8 +68,6 @@
    public void addIndividualCacheLoaderConfig(IndividualCacheLoaderConfig clc) {
       testImmutability("cacheLoaderConfigs");
       cacheLoaderConfigs.add(clc);
-      // Ensure this config gets our back ref to the cache
-      addChildConfig(clc);
    }
 
    public List<IndividualCacheLoaderConfig> getIndividualCacheLoaderConfigs() {
@@ -78,8 +76,6 @@
 
    public void setIndividualCacheLoaderConfigs(List<IndividualCacheLoaderConfig> configs) {
       testImmutability("cacheLoaderConfigs");
-      // Ensure these configs get our back ref to the cache
-      replaceChildConfigs(this.cacheLoaderConfigs, configs);
       this.cacheLoaderConfigs = configs == null ? new ArrayList<IndividualCacheLoaderConfig>() : configs;
    }
 
@@ -227,7 +223,6 @@
 
       public void setSingletonStoreConfig(SingletonStoreConfig singletonStoreConfig) {
          testImmutability("singletonStoreConfig");
-         replaceChildConfig(this.singletonStoreConfig, singletonStoreConfig);
          this.singletonStoreConfig = singletonStoreConfig;
       }
 

Modified: core/branches/flat/src/main/java/org/horizon/config/Configuration.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/config/Configuration.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/config/Configuration.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -21,6 +21,7 @@
  */
 package org.horizon.config;
 
+import org.horizon.factories.annotations.Inject;
 import org.horizon.factories.annotations.NonVolatile;
 import org.horizon.factories.annotations.Start;
 import org.horizon.lock.IsolationLevel;
@@ -38,11 +39,12 @@
  * @since 1.0
  */
 @NonVolatile
-public class Configuration extends ConfigurationComponent {
+public class Configuration extends AbstractNamedCacheConfigurationBean {
    private static final long serialVersionUID = 5553791890144997466L;
    private boolean invocationBatchingEnabled;
 
    private Map<String, EvictionCacheConfig> evictionCacheConfigs = new HashMap<String, EvictionCacheConfig>(4);
+   private GlobalConfiguration globalConfiguration;
 
    public EvictionCacheConfig getEvictionCacheConfig(String cacheName) {
       return evictionCacheConfigs.values().iterator().next();
@@ -52,6 +54,15 @@
       evictionCacheConfigs.put(cacheName, ecc);
    }
 
+   public GlobalConfiguration getGlobalConfiguration() {
+      return globalConfiguration;
+   }
+
+   @Inject
+   private void injectGlobalConfiguration(GlobalConfiguration globalConfiguration) {
+      this.globalConfiguration = globalConfiguration;
+   }
+
    /**
     * Cache replication mode.
     */
@@ -255,7 +266,6 @@
 
    public void setCacheLoaderConfig(CacheLoaderConfig config) {
       testImmutability("cacheLoaderConfig");
-      replaceChildConfig(this.cacheLoaderConfig, config);
       this.cacheLoaderConfig = config;
    }
 

Deleted: core/branches/flat/src/main/java/org/horizon/config/ConfigurationComponent.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/config/ConfigurationComponent.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/config/ConfigurationComponent.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -1,192 +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.horizon.config;
-
-import org.horizon.CacheSPI;
-import org.horizon.CacheStatus;
-import org.horizon.factories.ComponentRegistry;
-import org.horizon.factories.annotations.Inject;
-import org.horizon.factories.annotations.Start;
-import org.horizon.factories.scopes.Scope;
-import org.horizon.factories.scopes.Scopes;
-import org.horizon.logging.Log;
-import org.horizon.logging.LogFactory;
-import org.horizon.util.TypedProperties;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Locale;
-import java.util.Properties;
-import java.util.Set;
-
-/**
- * Base superclass of Cache configuration classes that expose some properties that can be changed after the cache is
- * started.
- *
- * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
- * @see #testImmutability(String)
- * @since 1.0
- */
- at Scope(Scopes.NAMED_CACHE)
-public abstract class ConfigurationComponent implements CloneableConfigurationComponent {
-   private static final long serialVersionUID = 4879873994727821938L;
-
-   protected transient Log log = LogFactory.getLog(getClass());
-   private transient CacheSPI cache; // back-reference to test whether the cache is running.
-   private final Set<ConfigurationComponent> children = Collections.synchronizedSet(new HashSet<ConfigurationComponent>());
-   private transient ComponentRegistry cr;
-   // a workaround to get over immutability checks
-   private boolean accessible;
-   protected List<String> overriddenConfigurationElements = new LinkedList<String>();
-
-   protected ConfigurationComponent() {
-   }
-
-   public void passCacheToChildConfig(ConfigurationComponent child) {
-      if (child != null) {
-         child.setCache(cache);
-      }
-   }
-
-   protected void addChildConfig(ConfigurationComponent child) {
-      if (child != null && children.add(child))
-         child.setCache(cache);
-   }
-
-   protected void addChildConfigs(Collection<? extends ConfigurationComponent> toAdd) {
-      if (toAdd != null) {
-         for (ConfigurationComponent child : toAdd)
-            addChildConfig(child);
-      }
-   }
-
-   protected void removeChildConfig(ConfigurationComponent child) {
-      children.remove(child);
-   }
-
-   protected void removeChildConfigs(Collection<? extends ConfigurationComponent> toRemove) {
-      if (toRemove != null) {
-         for (ConfigurationComponent child : toRemove)
-            removeChildConfig(child);
-      }
-   }
-
-   protected void replaceChildConfig(ConfigurationComponent oldConfig, ConfigurationComponent newConfig) {
-      removeChildConfig(oldConfig);
-      addChildConfig(newConfig);
-   }
-
-   protected void replaceChildConfigs(Collection<? extends ConfigurationComponent> oldConfigs,
-                                      Collection<? extends ConfigurationComponent> newConfigs) {
-      synchronized (children) {
-         removeChildConfigs(oldConfigs);
-         addChildConfigs(newConfigs);
-      }
-   }
-
-   /**
-    * Safely converts a String to upper case.
-    *
-    * @param s string to convert
-    * @return the string in upper case, or null if s is null.
-    */
-   protected String uc(String s) {
-      return s == null ? null : s.toUpperCase(Locale.ENGLISH);
-   }
-
-   /**
-    * Converts a given {@link Properties} instance to an instance of {@link TypedProperties}
-    *
-    * @param p properties to convert
-    * @return TypedProperties instance
-    */
-   protected TypedProperties toTypedProperties(Properties p) {
-      return TypedProperties.toTypedProperties(p);
-   }
-
-   protected TypedProperties toTypedProperties(String s) {
-      TypedProperties tp = new TypedProperties();
-      if (s != null && s.trim().length() > 0) {
-         InputStream stream = new ByteArrayInputStream(s.getBytes());
-         try {
-            tp.load(stream);
-         } catch (IOException e) {
-            throw new ConfigurationException("Unable to parse properties string " + s, e);
-         }
-      }
-      return tp;
-   }
-
-   /**
-    * Checks field modifications via setters
-    *
-    * @param fieldName
-    */
-   protected void testImmutability(String fieldName) {
-      try {
-         if (!accessible && cache != null && cache.getCacheStatus() != null && cache.getCacheStatus() == CacheStatus.STARTED && !getClass().getDeclaredField(fieldName).isAnnotationPresent(Dynamic.class)) {
-            throw new ConfigurationException("Attempted to modify a non-Dynamic configuration element [" + fieldName + "] after the cache has started!");
-         }
-      }
-      catch (NoSuchFieldException e) {
-         log.warn("Field " + fieldName + " not found!!");
-      }
-      finally {
-         accessible = false;
-      }
-
-      // now mark this as overridden
-      overriddenConfigurationElements.add(fieldName);
-   }
-
-   public void setCache(CacheSPI cache) {
-      this.cache = cache;
-      synchronized (children) {
-         for (ConfigurationComponent child : children) {
-            child.setCache(cache);
-         }
-      }
-   }
-
-   @Inject
-   private void injectDependencies(ComponentRegistry cr) {
-      this.cr = cr;
-   }
-
-   @Start
-   private void start() {
-      setCache(cr.getComponent(CacheSPI.class));
-   }
-
-   @Override
-   public CloneableConfigurationComponent clone() throws CloneNotSupportedException {
-      ConfigurationComponent c = (ConfigurationComponent) super.clone();
-      c.setCache(null);
-      return c;
-   }
-}

Modified: core/branches/flat/src/main/java/org/horizon/config/CustomInterceptorConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/config/CustomInterceptorConfig.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/config/CustomInterceptorConfig.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -31,7 +31,7 @@
  * @since 1.0
  */
 @Immutable
-public class CustomInterceptorConfig extends ConfigurationComponent {
+public class CustomInterceptorConfig extends AbstractNamedCacheConfigurationBean {
    private CommandInterceptor interceptor;
    private boolean isFirst;
    private boolean isLast;

Modified: core/branches/flat/src/main/java/org/horizon/config/EvictionCacheConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/config/EvictionCacheConfig.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/config/EvictionCacheConfig.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -23,7 +23,7 @@
 
 import org.horizon.logging.LogFactory;
 
-public class EvictionCacheConfig extends ConfigurationComponent {
+public class EvictionCacheConfig extends AbstractNamedCacheConfigurationBean {
    /**
     * The serialVersionUID
     */

Modified: core/branches/flat/src/main/java/org/horizon/config/EvictionConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/config/EvictionConfig.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/config/EvictionConfig.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -27,7 +27,7 @@
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 
-public class EvictionConfig extends ConfigurationComponent {
+public class EvictionConfig extends AbstractNamedCacheConfigurationBean {
    /**
     * The serialVersionUID
     */

Modified: core/branches/flat/src/main/java/org/horizon/config/GlobalConfiguration.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/config/GlobalConfiguration.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/config/GlobalConfiguration.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -1,7 +1,16 @@
 package org.horizon.config;
 
 import org.horizon.CacheException;
+import org.horizon.ComponentStatus;
 import org.horizon.Version;
+import org.horizon.executors.DefaultExecutorFactory;
+import org.horizon.executors.DefaultScheduledExecutorFactory;
+import org.horizon.factories.GlobalComponentRegistry;
+import org.horizon.factories.annotations.Inject;
+import org.horizon.factories.annotations.NonVolatile;
+import org.horizon.factories.scopes.Scope;
+import org.horizon.factories.scopes.Scopes;
+import org.horizon.remoting.transport.jgroups.JGroupsTransport;
 import org.horizon.util.TypedProperties;
 
 import java.util.Properties;
@@ -12,32 +21,35 @@
  * @author Manik Surtani
  * @since 1.0
  */
-public class GlobalConfiguration extends ConfigurationComponent {
+ at NonVolatile
+ at Scope(Scopes.GLOBAL)
+public class GlobalConfiguration extends AbstractConfigurationBean {
 
    /**
     * Default replication version, from {@link org.horizon.Version#getVersionShort}.
     */
    public static final short DEFAULT_REPLICATION_VERSION = Version.getVersionShort();
 
-   String asyncListenerExecutorFactoryClass;
+   String asyncListenerExecutorFactoryClass = DefaultExecutorFactory.class.getName();
    TypedProperties asyncListenerExecutorProperties;
-   String asyncSerializationExecutorFactoryClass;
+   String asyncSerializationExecutorFactoryClass = DefaultExecutorFactory.class.getName();
    TypedProperties asyncSerializationExecutorProperties;
-   String evictionScheduledExecutorFactoryClass;
+   String evictionScheduledExecutorFactoryClass = DefaultScheduledExecutorFactory.class.getName();
    TypedProperties evictionScheduledExecutorProperties;
-   String replicationQueueScheduledExecutorFactoryClass;
+   String replicationQueueScheduledExecutorFactoryClass = DefaultScheduledExecutorFactory.class.getName();
    TypedProperties replicationQueueScheduledExecutorProperties;
    String marshallerClass;
    String marshallVersion;
    int objectInputStreamPoolSize;
    int objectOutputStreamPoolSize;
-   String transportClass;
+   String transportClass = JGroupsTransport.class.getName();
    TypedProperties transportProperties;
    Configuration defaultConfiguration;
    String clusterName = "Horizon-Cluster";
    ShutdownHookBehavior shutdownHookBehavior = ShutdownHookBehavior.DEFAULT;
    short replicationVersion = DEFAULT_REPLICATION_VERSION;
 
+   private GlobalComponentRegistry gcr;
 
    /**
     * Behavior of the JVM shutdown hook registered by the cache
@@ -57,7 +69,15 @@
       DONT_REGISTER
    }
 
+   @Inject
+   private void injectDependencies(GlobalComponentRegistry gcr) {
+      this.gcr = gcr;
+   }
 
+   protected boolean hasComponentStarted() {
+      return gcr != null && gcr.getState() != null && gcr.getState() == ComponentStatus.STARTED;
+   }
+
    public String getAsyncListenerExecutorFactoryClass() {
       return asyncListenerExecutorFactoryClass;
    }

Modified: core/branches/flat/src/main/java/org/horizon/config/PluggableConfigurationComponent.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/config/PluggableConfigurationComponent.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/config/PluggableConfigurationComponent.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -33,7 +33,7 @@
  * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
  * @since 1.0
  */
-public abstract class PluggableConfigurationComponent extends ConfigurationComponent {
+public abstract class PluggableConfigurationComponent extends AbstractNamedCacheConfigurationBean {
    protected String className;
    protected Properties properties;
 

Modified: core/branches/flat/src/main/java/org/horizon/config/RuntimeConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/config/RuntimeConfig.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/config/RuntimeConfig.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -27,7 +27,7 @@
 import javax.transaction.TransactionManager;
 import java.util.concurrent.ExecutorService;
 
-public class RuntimeConfig extends ConfigurationComponent {
+public class RuntimeConfig extends AbstractNamedCacheConfigurationBean {
    /**
     * The serialVersionUID
     */

Modified: core/branches/flat/src/main/java/org/horizon/eviction/EvictionAlgorithmConfigBase.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/eviction/EvictionAlgorithmConfigBase.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/eviction/EvictionAlgorithmConfigBase.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -21,7 +21,7 @@
  */
 package org.horizon.eviction;
 
-import org.horizon.config.ConfigurationComponent;
+import org.horizon.config.AbstractNamedCacheConfigurationBean;
 import org.horizon.config.ConfigurationException;
 import org.horizon.config.Dynamic;
 import org.horizon.config.EvictionAlgorithmConfig;
@@ -34,7 +34,7 @@
  * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
  * @since 1.0
  */
-public abstract class EvictionAlgorithmConfigBase extends ConfigurationComponent implements EvictionAlgorithmConfig {
+public abstract class EvictionAlgorithmConfigBase extends AbstractNamedCacheConfigurationBean implements EvictionAlgorithmConfig {
    private static final long serialVersionUID = 4591691674370188932L;
 
    protected String evictionAlgorithmClassName;

Modified: core/branches/flat/src/main/java/org/horizon/eviction/algorithms/NULL/NullEvictionAlgorithmConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/eviction/algorithms/NULL/NullEvictionAlgorithmConfig.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/eviction/algorithms/NULL/NullEvictionAlgorithmConfig.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -21,7 +21,7 @@
  */
 package org.horizon.eviction.algorithms.NULL;
 
-import org.horizon.config.ConfigurationComponent;
+import org.horizon.config.AbstractNamedCacheConfigurationBean;
 import org.horizon.config.ConfigurationException;
 import org.horizon.config.EvictionAlgorithmConfig;
 
@@ -31,7 +31,7 @@
  * @author Manik Surtani
  * @since 1.0
  */
-public class NullEvictionAlgorithmConfig extends ConfigurationComponent implements EvictionAlgorithmConfig {
+public class NullEvictionAlgorithmConfig extends AbstractNamedCacheConfigurationBean implements EvictionAlgorithmConfig {
    private static final long serialVersionUID = -6591180473728241737L;
 
    /**

Modified: core/branches/flat/src/main/java/org/horizon/factories/AbstractComponentRegistry.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/AbstractComponentRegistry.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/factories/AbstractComponentRegistry.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -22,11 +22,12 @@
 package org.horizon.factories;
 
 import org.horizon.CacheException;
-import org.horizon.CacheStatus;
+import org.horizon.ComponentStatus;
 import org.horizon.Version;
 import org.horizon.config.Configuration;
 import org.horizon.config.ConfigurationException;
 import org.horizon.config.RuntimeConfig;
+import org.horizon.factories.annotations.ComponentName;
 import org.horizon.factories.annotations.DefaultFactoryFor;
 import org.horizon.factories.annotations.Destroy;
 import org.horizon.factories.annotations.Inject;
@@ -40,6 +41,7 @@
 import org.horizon.util.BeanUtils;
 import org.horizon.util.ReflectionUtil;
 
+import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -48,6 +50,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.Stack;
 
 /**
  * A registry where components which have been created are stored.  Components are stored as singletons, registered
@@ -62,13 +65,13 @@
  * <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>STARTED - when {@link org.horizon.Cache#start()} is called</li>
- * <li>STOPPED - when {@link org.horizon.Cache#stop()} is called</li> </ul>
+ * The registry can exist in one of several states, as defined by the {@link org.horizon.ComponentStatus} 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>STARTED - when {@link
+ * org.horizon.Cache#start()} is called</li> <li>STOPPED - when {@link org.horizon.Cache#stop()} 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.horizon.CacheStatus#STARTED} state.
+ * org.horizon.ComponentStatus#STARTED} state.
  *
  * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
  * @since 1.0
@@ -76,6 +79,10 @@
 @NonVolatile
 @Scope(Scopes.NAMED_CACHE)
 public abstract class AbstractComponentRegistry implements Lifecycle {
+
+   private static final boolean DEBUG_DEPENDENCIES = true;
+   private Stack<String> debugStack = DEBUG_DEPENDENCIES ? new Stack<String>() : null;
+
    /**
     * Contains class definitions of component factories that can be used to construct certain components
     */
@@ -86,14 +93,14 @@
    // component and method containers
    final Map<String, Component> componentLookup = new HashMap<String, Component>();
 
-   CacheStatus state = CacheStatus.INSTANTIATED;
+   ComponentStatus state = ComponentStatus.INSTANTIATED;
 
    /**
     * Retrieves the state of the registry
     *
     * @return state of the registry
     */
-   public CacheStatus getState() {
+   public ComponentStatus getState() {
       return state;
    }
 
@@ -144,6 +151,8 @@
       s.add(LockManagerFactory.class);
       s.add(DataContainerFactory.class);
       s.add(EvictionManagerFactory.class);
+      s.add(NamedExecutorsFactory.class);
+      s.add(TransportFactory.class);
       return s;
    }
 
@@ -159,6 +168,8 @@
    }
 
    public void registerComponent(Object component, String name) {
+      if (component == null)
+         throw new NullPointerException("Cannot register a null component under name [" + name + "]");
       Component old = componentLookup.get(name);
 
       if (old != null) {
@@ -176,7 +187,7 @@
          old.methodsScanned = false;
          c = old;
 
-         if (state == CacheStatus.STARTED) populateLifecycleMethods();
+         if (state == ComponentStatus.STARTED) populateLifecycleMethods();
       } else {
          c = new Component();
          c.name = name;
@@ -205,15 +216,36 @@
    @SuppressWarnings("unchecked")
    protected void invokeInjectionMethod(Object o, Method m) {
       Class[] dependencies = m.getParameterTypes();
+      Annotation[][] parameterAnnotations = m.getParameterAnnotations();
       Object[] params = new Object[dependencies.length];
 
       for (int i = 0; i < dependencies.length; i++) {
-         params[i] = getOrCreateComponent(dependencies[i]);
+         params[i] = getOrCreateComponent(dependencies[i], getComponentName(dependencies[i], parameterAnnotations, i));
       }
 
       ReflectionUtil.invokeAccessibly(o, m, params);
    }
 
+   private String getComponentName(Class component, Annotation[][] annotations, int paramNumber) {
+      String name;
+      if (annotations == null ||
+            annotations.length <= paramNumber ||
+            (name = findComponentName(annotations[paramNumber])) == null) return component.getName();
+
+      return name;
+   }
+
+   private String findComponentName(Annotation[] anns) {
+      if (anns != null && anns.length > 0) {
+         for (Annotation a : anns) {
+            if (a instanceof ComponentName) {
+               return ((ComponentName) a).value();
+            }
+         }
+      }
+      return null;
+   }
+
    /**
     * 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
@@ -234,9 +266,14 @@
     * @throws ConfigurationException if there is a problem with consructing or wiring the instance.
     */
    protected <T> T getOrCreateComponent(Class<T> componentClass) {
+      return getOrCreateComponent(componentClass, componentClass.getName());
+   }
 
-      T component = getComponent(componentClass);
+   protected <T> T getOrCreateComponent(Class<T> componentClass, String name) {
+      if (DEBUG_DEPENDENCIES) debugStack.push(name);
 
+      T component = getComponent(componentClass, name);
+
       if (component == null) {
          // first see if this has been injected externally.
          component = getFromConfiguration(componentClass);
@@ -245,7 +282,9 @@
          if (component == null) {
             // create this component and add it to the registry
             ComponentFactory factory = getFactory(componentClass);
-            component = factory.construct(componentClass);
+            component = factory instanceof NamedComponentFactory ?
+                  ((NamedComponentFactory) factory).construct(componentClass, name)
+                  : factory.construct(componentClass);
             attemptedFactoryConstruction = true;
 
          }
@@ -259,6 +298,7 @@
          }
       }
 
+      if (DEBUG_DEPENDENCIES) debugStack.pop();
       return component;
    }
 
@@ -273,14 +313,14 @@
       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!");
+         throw new ConfigurationException("No registered default factory for component " + componentClass + " found! Debug stack: " + debugStack);
       // 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);
+            throw new ConfigurationException("Unable to locate component factory for component " + componentClass + "  Debug stack: " + debugStack);
          // we simply register this factory.  Registration will take care of constructing any dependencies.
          registerComponent(cf, cfClass);
       }
@@ -288,7 +328,7 @@
       // 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!");
+         throw new ConfigurationException("Component factory " + cfClass + " incorrectly registered! Debug stack: " + debugStack);
       return cf;
    }
 
@@ -302,14 +342,30 @@
     * created by such factories.
     */
    void scanDefaultFactories() {
-      defaultFactories = new HashMap<Class, Class<? extends ComponentFactory>>();
-
+      Map<Class, Class<? extends ComponentFactory>> temp = new HashMap<Class, Class<? extends ComponentFactory>>();
       Set<Class<? extends ComponentFactory>> factories = getHardcodedFactories();
 
       for (Class<? extends ComponentFactory> factory : factories) {
+         // check if this implements auto-instantiable.  If it doesn't have a no-arg constructor throw an exception
+         boolean factoryValid = true;
+         try {
+            if (AutoInstantiableFactory.class.isAssignableFrom(factory) && factory.getConstructor() == null) {
+               factoryValid = false;
+            }
+         } catch (Exception e) {
+            factoryValid = false;
+         }
+
+         if (!factoryValid)
+            throw new RuntimeException("Factory class " + factory + " implements AutoInstantiableFactory but does not expose a public, no-arg constructor!  Debug stack: " + debugStack);
+
          DefaultFactoryFor dFFAnnotation = factory.getAnnotation(DefaultFactoryFor.class);
-         for (Class targetClass : dFFAnnotation.classes()) defaultFactories.put(targetClass, factory);
+         if (dFFAnnotation != null) {
+            for (Class targetClass : dFFAnnotation.classes()) temp.put(targetClass, factory);
+         }
       }
+
+      defaultFactories = temp;
    }
 
    /**
@@ -320,13 +376,17 @@
     * @return factory instance
     */
    ComponentFactory instantiateFactory(Class<? extends ComponentFactory> factory) {
-      try {
-         return factory.newInstance();
+      if (AutoInstantiableFactory.class.isAssignableFrom(factory)) {
+         try {
+            return factory.newInstance();
+         }
+         catch (Exception e) {
+            // unable to get a hold of an instance!!
+            throw new ConfigurationException("Unable to instantiate factory " + factory + "  Debug stack: " + debugStack, e);
+         }
+      } else {
+         throw new ConfigurationException("Cannot auto-instantiate factory " + factory + " as it doesn't implement " + AutoInstantiableFactory.class.getSimpleName() + "!  Debug stack: " + debugStack);
       }
-      catch (Exception e) {
-         // unable to get a hold of an instance!!
-         throw new ConfigurationException("Unable to instantiate factory " + factory, e);
-      }
    }
 
    /**
@@ -390,9 +450,13 @@
     * @param type type to find
     * @return component, or null
     */
+   public <T> T getComponent(Class<T> type) {
+      return getComponent(type, type.getName());
+   }
+
    @SuppressWarnings("unchecked")
-   public <T> T getComponent(Class<T> type) {
-      Component wrapper = componentLookup.get(type.getName());
+   public <T> T getComponent(Class<T> type, String name) {
+      Component wrapper = componentLookup.get(name);
       if (wrapper == null) return null;
 
       return (T) (wrapper.instance == NULL_COMPONENT ? null : wrapper.instance);
@@ -472,7 +536,7 @@
 
    /**
     * Creates the components needed by a cache instance and sets the cache status to {@link
-    * org.horizon.CacheStatus#CREATED} when it is done.
+    * org.horizon.ComponentStatus#CREATED} when it is done.
     */
    public void create() {
       if (!state.createAllowed()) {
@@ -492,7 +556,7 @@
 
    /**
     * This starts the components in the cache, connecting to channels, starting service threads, etc.  If the cache is
-    * not in the {@link org.horizon.CacheStatus#CREATED} state, {@link #create()} will be invoked first.
+    * not in the {@link org.horizon.ComponentStatus#CREATED} state, {@link #create()} will be invoked first.
     */
    public void start() {
       boolean createdInStart = false;
@@ -516,8 +580,8 @@
    }
 
    /**
-    * Stops the cache and sets the cache status to {@link org.horizon.CacheStatus#STOPPED} once it is done.  If the
-    * cache is not in the {@link org.horizon.CacheStatus#STARTED} state, this is a no-op.
+    * Stops the cache and sets the cache status to {@link org.horizon.ComponentStatus#STOPPED} once it is done.  If the
+    * cache is not in the {@link org.horizon.ComponentStatus#STARTED} state, this is a no-op.
     */
    public void stop() {
       if (!state.stopAllowed()) {
@@ -525,7 +589,7 @@
       }
 
       // Trying to stop() from FAILED is valid, but may not work
-      boolean failed = state == CacheStatus.FAILED;
+      boolean failed = state == ComponentStatus.FAILED;
 
       try {
          internalStop();
@@ -538,16 +602,16 @@
          handleLifecycleTransitionFailure(t);
       }
       finally {
-         if (!failed) state = CacheStatus.STOPPED;
+         if (!failed) state = ComponentStatus.STOPPED;
       }
    }
 
    /**
-    * Destroys the cache and frees up any resources.  Sets the cache status to {@link CacheStatus#DESTROYED} when it is
-    * done.
+    * Destroys the cache and frees up any resources.  Sets the cache status to {@link
+    * org.horizon.ComponentStatus#DESTROYED} when it is done.
     * <p/>
-    * If the cache is in {@link org.horizon.CacheStatus#STARTED} when this method is called, it will first call {@link
-    * #stop()} to stop the cache.
+    * If the cache is in {@link org.horizon.ComponentStatus#STARTED} when this method is called, it will first call
+    * {@link #stop()} to stop the cache.
     */
    public void destroy() {
       if (!state.destroyAllowed()) {
@@ -567,7 +631,7 @@
       }
       finally {
          // We always progress to destroyed
-         state = CacheStatus.DESTROYED;
+         state = ComponentStatus.DESTROYED;
       }
    }
    // ------------------------------ END: Publicly available lifecycle methods -----------------------------
@@ -581,7 +645,7 @@
     * @param t throwable thrown during failure
     */
    private void handleLifecycleTransitionFailure(Throwable t) {
-      state = CacheStatus.FAILED;
+      state = ComponentStatus.FAILED;
       if (t instanceof CacheException)
          throw (CacheException) t;
       else if (t instanceof RuntimeException)
@@ -596,10 +660,10 @@
     * The actual create implementation.
     */
    private void internalCreate() {
-      state = CacheStatus.CREATING;
+      state = ComponentStatus.CREATING;
       resetNonVolatile();
       rewire();
-      state = CacheStatus.CREATED;
+      state = ComponentStatus.CREATED;
    }
 
    private void internalStart(boolean createdInStart) throws CacheException, IllegalArgumentException {
@@ -610,7 +674,7 @@
          rewire();
       }
 
-      state = CacheStatus.STARTING;
+      state = ComponentStatus.STARTING;
 
       // start all internal components
       // first cache all start, stop and destroy methods.
@@ -630,7 +694,7 @@
       addShutdownHook();
 
       getLog().info("JBoss Cache version: " + Version.printVersion());
-      state = CacheStatus.STARTED;
+      state = ComponentStatus.STARTED;
    }
 
    protected void addShutdownHook() {
@@ -645,7 +709,7 @@
     * Actual stop
     */
    private void internalStop() {
-      state = CacheStatus.STOPPING;
+      state = ComponentStatus.STOPPING;
       removeShutdownHook();
 
       List<PrioritizedMethod> stopMethods = new ArrayList<PrioritizedMethod>(componentLookup.size());
@@ -656,7 +720,7 @@
       // fire all STOP methods according to priority
       for (PrioritizedMethod em : stopMethods) em.invoke();
 
-      state = CacheStatus.STOPPED;
+      state = ComponentStatus.STOPPED;
    }
 
    /**
@@ -664,7 +728,7 @@
     */
    private void internalDestroy() {
 
-      state = CacheStatus.DESTROYING;
+      state = ComponentStatus.DESTROYING;
 
       resetNonVolatile();
 
@@ -676,7 +740,7 @@
       // fire all DESTROY methods according to priority
       for (PrioritizedMethod em : destroyMethods) em.invoke();
 
-      state = CacheStatus.DESTROYED;
+      state = ComponentStatus.DESTROYED;
    }
 
    // ------------------------------ END: Actual internal lifecycle methods --------------------------------
@@ -684,8 +748,8 @@
    /**
     * 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.horizon.CacheStatus#STARTING}, this method will block for up to {@link Configuration#getStateRetrievalTimeout()}
-    * millis, checking for a valid state.
+    * org.horizon.ComponentStatus#STARTING}, this method will block for up to {@link
+    * Configuration#getStateRetrievalTimeout()} millis, checking for a valid state.
     *
     * @param originLocal true if the call originates locally (i.e., from the {@link org.horizon.CacheDelegate} or false
     *                    if it originates remotely, i.e., from the {@link org.horizon.marshall.CommandAwareRpcDispatcher}.
@@ -701,7 +765,7 @@
       getLog().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) {
+      if (state == ComponentStatus.STARTING) {
          getLog().trace("Cache is starting; block.");
          try {
             blockUntilCacheStarts();
@@ -717,9 +781,9 @@
    }
 
    /**
-    * Blocks until the current cache instance is in its {@link org.horizon.CacheStatus#STARTED started} phase.  Blocks
-    * for up to {@link Configuration#getStateRetrievalTimeout()} milliseconds, throwing an IllegalStateException if the
-    * cache doesn't reach this state even after this maximum wait time.
+    * Blocks until the current cache instance is in its {@link org.horizon.ComponentStatus#STARTED started} phase.
+    * Blocks for up to {@link 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.

Added: core/branches/flat/src/main/java/org/horizon/factories/AutoInstantiableFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/AutoInstantiableFactory.java	                        (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/factories/AutoInstantiableFactory.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -0,0 +1,15 @@
+package org.horizon.factories;
+
+/**
+ * Component factories that implement this interface can be instantiated automatically by component registries when
+ * looking up components.  Typically, most component factories will implement this.  One known exception is the {@link
+ * org.horizon.factories.BootstrapFactory}.
+ * <p/>
+ * Anything implementing this interface should expose a public, no-arg constructor.
+ * <p/>
+ *
+ * @author Manik Surtani
+ * @since 1.0
+ */
+public interface AutoInstantiableFactory {
+}

Modified: core/branches/flat/src/main/java/org/horizon/factories/BootstrapFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/BootstrapFactory.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/factories/BootstrapFactory.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -44,13 +44,21 @@
    }
 
    @Override
-   protected <T> T construct(Class<T> componentType) {
-      if (componentType.isAssignableFrom(CacheSPI.class) ||
-            componentType.isAssignableFrom(Configuration.class) ||
-            componentType.isAssignableFrom(ComponentRegistry.class)) {
-         return componentType.cast(cacheSPI);
+   public <T> T construct(Class<T> componentType) {
+      Object comp = null;
+      if (componentType.isAssignableFrom(CacheSPI.class)) {
+         comp = cacheSPI;
+      } else if (componentType.isAssignableFrom(Configuration.class)) {
+         comp = configuration;
+      } else if (componentType.isAssignableFrom(ComponentRegistry.class)) {
+         comp = componentRegistry;
       }
+      if (comp == null) throw new CacheException("Don't know how to handle type " + componentType);
 
-      throw new CacheException("Don't know how to handle type " + componentType);
+      try {
+         return componentType.cast(comp);
+      } catch (Exception e) {
+         throw new CacheException("Problems casting bootstrap component " + comp.getClass() + " to type " + componentType, e);
+      }
    }
 }

Modified: core/branches/flat/src/main/java/org/horizon/factories/ComponentFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/ComponentFactory.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/factories/ComponentFactory.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -74,7 +74,7 @@
     * @param componentType type of component
     * @return a component
     */
-   protected abstract <T> T construct(Class<T> componentType);
+   public abstract <T> T construct(Class<T> componentType);
 
    protected void assertTypeConstructable(Class requestedType, Class... ableToConstruct) {
       boolean canConstruct = false;

Modified: core/branches/flat/src/main/java/org/horizon/factories/ComponentRegistry.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/ComponentRegistry.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/factories/ComponentRegistry.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -3,6 +3,7 @@
 import org.horizon.CacheException;
 import org.horizon.CacheSPI;
 import org.horizon.config.Configuration;
+import org.horizon.config.ConfigurationException;
 import org.horizon.factories.scopes.ScopeDetector;
 import org.horizon.factories.scopes.Scopes;
 import org.horizon.logging.Log;
@@ -33,13 +34,16 @@
 
       try {
          this.cacheName = cacheName;
-         this.log = LogFactory.getLog(ComponentRegistry.class.getName() + ":" + cacheName);
+         if (cacheName == null) throw new ConfigurationException("Cache name cannot be null!");
+         StringBuilder sb = new StringBuilder(ComponentRegistry.class.getName()).append(cacheName);
+         this.log = LogFactory.getLog(sb.toString());
+         if (globalComponents == null) throw new NullPointerException("GlobalComponentRegistry cannot be null!");
+         this.globalComponents = globalComponents;
+
          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);
@@ -66,16 +70,16 @@
 
 
    @Override
-   public <T> T getComponent(Class<T> componentType) {
+   public <T> T getComponent(Class<T> componentType, String name) {
       // first try in the local registry
       Scopes componentScope = ScopeDetector.detectScope(componentType);
       switch (componentScope) {
          case GLOBAL:
-            return globalComponents.getComponent(componentType);
+            return globalComponents.getComponent(componentType, name);
          case NAMED_CACHE:
-            return super.getComponent(componentType);
+            return super.getComponent(componentType, name);
          default:
-            throw new IllegalArgumentException("Unknown component scope " + componentScope);
+            throw new IllegalArgumentException("Unknown component scope " + componentScope + " for component type " + componentType);
       }
    }
 

Modified: core/branches/flat/src/main/java/org/horizon/factories/DataContainerFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/DataContainerFactory.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/factories/DataContainerFactory.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -32,8 +32,8 @@
  * @since 1.0
  */
 @DefaultFactoryFor(classes = DataContainer.class)
-public class DataContainerFactory extends ComponentFactory {
-   protected <T> T construct(Class<T> componentType) {
+public class DataContainerFactory extends ComponentFactory implements AutoInstantiableFactory {
+   public <T> T construct(Class<T> componentType) {
       return (T) new UnsortedDataContainer();
    }
 }

Modified: core/branches/flat/src/main/java/org/horizon/factories/DefaultCacheFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/DefaultCacheFactory.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/factories/DefaultCacheFactory.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -102,7 +102,7 @@
    }
 
    @Override
-   protected <T> T construct(Class<T> componentType) {
+   public <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/horizon/factories/EmptyConstructorFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/EmptyConstructorFactory.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/factories/EmptyConstructorFactory.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -31,7 +31,9 @@
 import org.horizon.loader.CacheLoaderManager;
 import org.horizon.marshall.Marshaller;
 import org.horizon.marshall.VersionAwareMarshaller;
+import org.horizon.notifications.CacheManagerNotifier;
 import org.horizon.notifications.CacheNotifier;
+import org.horizon.remoting.InboundInvocationHandler;
 import org.horizon.transaction.TransactionTable;
 
 /**
@@ -40,12 +42,12 @@
  * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
  * @since 1.0
  */
- at DefaultFactoryFor(classes = {CacheNotifier.class,
+ at DefaultFactoryFor(classes = {CacheNotifier.class, CacheManagerNotifier.class, InboundInvocationHandler.class,
                               CacheLoaderManager.class, Marshaller.class, InvocationContextContainer.class,
                               TransactionTable.class, BatchContainer.class, ContextFactory.class, EntryFactory.class, CommandsFactory.class})
-public class EmptyConstructorFactory extends ComponentFactory {
+public class EmptyConstructorFactory extends ComponentFactory implements AutoInstantiableFactory {
    @Override
-   protected <T> T construct(Class<T> componentType) {
+   public <T> T construct(Class<T> componentType) {
       try {
          if (componentType.isInterface()) {
             Class componentImpl;

Modified: core/branches/flat/src/main/java/org/horizon/factories/EvictionManagerFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/EvictionManagerFactory.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/factories/EvictionManagerFactory.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -9,8 +9,8 @@
  * @since 1.0
  */
 @DefaultFactoryFor(classes = {EvictionManager.class})
-public class EvictionManagerFactory extends ComponentFactory {
-   protected <T> T construct(Class<T> componentType) {
+public class EvictionManagerFactory extends ComponentFactory implements AutoInstantiableFactory {
+   public <T> T construct(Class<T> componentType) {
       if (componentType != EvictionManager.class) {
          throw new IllegalStateException();
       }

Modified: core/branches/flat/src/main/java/org/horizon/factories/GlobalComponentRegistry.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/GlobalComponentRegistry.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/factories/GlobalComponentRegistry.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -4,8 +4,11 @@
 import org.horizon.config.GlobalConfiguration;
 import static org.horizon.config.GlobalConfiguration.ShutdownHookBehavior.DEFAULT;
 import static org.horizon.config.GlobalConfiguration.ShutdownHookBehavior.REGISTER;
+import org.horizon.factories.scopes.Scope;
+import org.horizon.factories.scopes.Scopes;
 import org.horizon.logging.Log;
 import org.horizon.logging.LogFactory;
+import org.horizon.manager.CacheManager;
 
 import javax.management.MBeanServerFactory;
 import java.util.ArrayList;
@@ -16,6 +19,7 @@
  * @author Manik Surtani
  * @since 1.0
  */
+ at Scope(Scopes.GLOBAL)
 public class GlobalComponentRegistry extends AbstractComponentRegistry {
 
    private Log log = LogFactory.getLog(GlobalComponentRegistry.class);
@@ -36,11 +40,14 @@
     *
     * @param configuration configuration with which this is created
     */
-   public GlobalComponentRegistry(GlobalConfiguration configuration) {
+   public GlobalComponentRegistry(GlobalConfiguration configuration, CacheManager cacheManager) {
+      if (configuration == null) throw new NullPointerException("GlobalConfiguration cannot be null!");
       try {
+         // this order is important ... 
          globalConfiguration = configuration;
+         registerComponent(this, GlobalComponentRegistry.class);
+         registerComponent(cacheManager, CacheManager.class);
          registerComponent(configuration, GlobalConfiguration.class);
-         registerComponent(this, GlobalComponentRegistry.class);
       }
       catch (Exception e) {
          throw new CacheException("Unable to construct a GlobalComponentRegistry!", e);

Modified: core/branches/flat/src/main/java/org/horizon/factories/InterceptorChainFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/InterceptorChainFactory.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/factories/InterceptorChainFactory.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -43,7 +43,7 @@
  * @since 1.0
  */
 @DefaultFactoryFor(classes = InterceptorChain.class)
-public class InterceptorChainFactory extends ComponentFactory {
+public class InterceptorChainFactory extends ComponentFactory implements AutoInstantiableFactory {
    private CommandInterceptor createInterceptor(Class<? extends CommandInterceptor> clazz) throws IllegalAccessException, InstantiationException {
       CommandInterceptor chainedInterceptor = componentRegistry.getComponent(clazz);
       if (chainedInterceptor == null) {
@@ -185,7 +185,7 @@
    }
 
    @Override
-   protected <T> T construct(Class<T> componentType) {
+   public <T> T construct(Class<T> componentType) {
       try {
          return componentType.cast(buildInterceptorChain());
       }

Modified: core/branches/flat/src/main/java/org/horizon/factories/LockManagerFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/LockManagerFactory.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/factories/LockManagerFactory.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -32,8 +32,8 @@
  * @since 1.0
  */
 @DefaultFactoryFor(classes = LockManager.class)
-public class LockManagerFactory extends ComponentFactory {
-   protected <T> T construct(Class<T> componentType) {
+public class LockManagerFactory extends ComponentFactory implements AutoInstantiableFactory {
+   public <T> T construct(Class<T> componentType) {
       return (T) new StripedLockManager();
    }
 }

Added: core/branches/flat/src/main/java/org/horizon/factories/NamedComponentFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/NamedComponentFactory.java	                        (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/factories/NamedComponentFactory.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -0,0 +1,26 @@
+package org.horizon.factories;
+
+/**
+ * A specialized type of component factory that knows how to create named components, identified with the {@link
+ * org.horizon.factories.annotations.ComponentName} annotation on the classes requested in {@link
+ * org.horizon.factories.annotations.Inject} annotated methods.
+ *
+ * @author Manik Surtani
+ * @since 1.0
+ */
+public abstract class NamedComponentFactory extends ComponentFactory {
+
+   public <T> T construct(Class<T> componentType) {
+
+      // by default, use the FQCN of the component type.
+      return construct(componentType, componentType.getName());
+   }
+
+   /**
+    * Constructs a component.
+    *
+    * @param componentType type of component
+    * @return a component
+    */
+   public abstract <T> T construct(Class<T> componentType, String componentName);
+}

Added: core/branches/flat/src/main/java/org/horizon/factories/NamedExecutorsFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/NamedExecutorsFactory.java	                        (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/factories/NamedExecutorsFactory.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -0,0 +1,46 @@
+package org.horizon.factories;
+
+import org.horizon.config.ConfigurationException;
+import org.horizon.executors.ExecutorFactory;
+import org.horizon.factories.annotations.DefaultFactoryFor;
+import org.horizon.factories.scopes.Scope;
+import org.horizon.factories.scopes.Scopes;
+import org.horizon.util.Util;
+
+import java.util.Properties;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ScheduledExecutorService;
+
+/**
+ * A factory that specifically knows how to create named executors.
+ *
+ * @author Manik Surtani
+ * @since 1.0
+ */
+ at DefaultFactoryFor(classes = {ExecutorService.class, Executor.class, ScheduledExecutorService.class})
+ at Scope(Scopes.GLOBAL)
+public class NamedExecutorsFactory extends NamedComponentFactory implements AutoInstantiableFactory {
+
+   @SuppressWarnings("unchecked")
+   public <T> T construct(Class<T> componentType, String componentName) {
+      ExecutorFactory ef;
+      Properties props;
+      try {
+         if (componentName.equals(KnownComponentNames.ASYNC_NOTIFICATION_EXECUTOR)) {
+            ef = (ExecutorFactory) Util.getInstance(configuration.getGlobalConfiguration().getAsyncListenerExecutorFactoryClass());
+            props = configuration.getGlobalConfiguration().getAsyncListenerExecutorProperties();
+         } else if (componentName.equals(KnownComponentNames.ASYNC_SERIALIZATION_EXECUTOR)) {
+            ef = (ExecutorFactory) Util.getInstance(configuration.getGlobalConfiguration().getAsyncSerializationExecutorFactoryClass());
+            props = configuration.getGlobalConfiguration().getAsyncSerializationExecutorProperties();
+         } else {
+            throw new ConfigurationException("Unknown named executor " + componentName);
+         }
+      } catch (ConfigurationException ce) {
+         throw ce;
+      } catch (Exception e) {
+         throw new ConfigurationException("Unable to instantiate ExecutorFactory for named component " + componentName, e);
+      }
+      return (T) ef.getExecutor(props);
+   }
+}

Modified: core/branches/flat/src/main/java/org/horizon/factories/ReplicationQueueFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/ReplicationQueueFactory.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/factories/ReplicationQueueFactory.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -32,7 +32,7 @@
  * @since 1.0
  */
 @DefaultFactoryFor(classes = ReplicationQueue.class)
-public class ReplicationQueueFactory extends EmptyConstructorFactory {
+public class ReplicationQueueFactory extends EmptyConstructorFactory implements AutoInstantiableFactory {
    @Override
    public <T> T construct(Class<T> componentType) {
       if ((configuration.getCacheMode() == Configuration.CacheMode.REPL_ASYNC || configuration.getCacheMode() == Configuration.CacheMode.INVALIDATION_ASYNC)

Modified: core/branches/flat/src/main/java/org/horizon/factories/RuntimeConfigAwareFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/RuntimeConfigAwareFactory.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/factories/RuntimeConfigAwareFactory.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -36,9 +36,9 @@
  * @since 1.0
  */
 @DefaultFactoryFor(classes = RPCManager.class)
-public class RuntimeConfigAwareFactory extends EmptyConstructorFactory {
+public class RuntimeConfigAwareFactory extends EmptyConstructorFactory implements AutoInstantiableFactory {
    @Override
-   protected <T> T construct(Class<T> componentType) {
+   public <T> T construct(Class<T> componentType) {
       T component = super.construct(componentType);
 
       Method setter = BeanUtils.setterMethod(RuntimeConfig.class, componentType);

Modified: core/branches/flat/src/main/java/org/horizon/factories/StateTransferFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/StateTransferFactory.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/factories/StateTransferFactory.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -33,9 +33,9 @@
  */
 // TODO: Implement me
 //@DefaultFactoryFor(classes = {StateTransferGenerator.class, StateTransferIntegrator.class})
-public class StateTransferFactory extends ComponentFactory {
+public class StateTransferFactory extends ComponentFactory implements AutoInstantiableFactory {
    @SuppressWarnings("deprecation")
-   protected <T> T construct(Class<T> componentType) {
+   public <T> T construct(Class<T> componentType) {
       return null;
 //      if (componentType.equals(StateTransferIntegrator.class))
 //      {

Modified: core/branches/flat/src/main/java/org/horizon/factories/StateTransferManagerFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/StateTransferManagerFactory.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/factories/StateTransferManagerFactory.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -32,9 +32,9 @@
  * @since 1.0
  */
 @DefaultFactoryFor(classes = StateTransferManager.class)
-public class StateTransferManagerFactory extends ComponentFactory {
+public class StateTransferManagerFactory extends ComponentFactory implements AutoInstantiableFactory {
    @SuppressWarnings("deprecation")
-   protected <T> T construct(Class<T> componentType) {
+   public <T> T construct(Class<T> componentType) {
       return componentType.cast(new DefaultStateTransferManager());
    }
 }

Modified: core/branches/flat/src/main/java/org/horizon/factories/TransactionManagerFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/TransactionManagerFactory.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/factories/TransactionManagerFactory.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -35,8 +35,8 @@
  * @since 1.0
  */
 @DefaultFactoryFor(classes = {TransactionManager.class})
-public class TransactionManagerFactory extends ComponentFactory {
-   protected <T> T construct(Class<T> componentType) {
+public class TransactionManagerFactory extends ComponentFactory implements AutoInstantiableFactory {
+   public <T> T construct(Class<T> componentType) {
       // See if we had a TransactionManager injected into our config
       TransactionManager transactionManager = configuration.getRuntimeConfig().getTransactionManager();
       TransactionManagerLookup lookup = null;

Added: core/branches/flat/src/main/java/org/horizon/factories/TransportFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/TransportFactory.java	                        (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/factories/TransportFactory.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -0,0 +1,29 @@
+package org.horizon.factories;
+
+import org.horizon.CacheException;
+import org.horizon.factories.annotations.DefaultFactoryFor;
+import org.horizon.factories.scopes.Scope;
+import org.horizon.factories.scopes.Scopes;
+import org.horizon.remoting.transport.Transport;
+import org.horizon.util.Util;
+
+/**
+ * Factory for Transport implementations
+ *
+ * @author Manik Surtani
+ * @since 1.0
+ */
+ at DefaultFactoryFor(classes = Transport.class)
+ at Scope(Scopes.GLOBAL)
+public class TransportFactory extends ComponentFactory implements AutoInstantiableFactory {
+
+   @SuppressWarnings("unchecked")
+   public <T> T construct(Class<T> componentType) {
+      String transportClass = configuration.getGlobalConfiguration().getTransportClass();
+      try {
+         return (T) Util.getInstance(transportClass);
+      } catch (Exception e) {
+         throw new CacheException("Unable to create transport of type " + transportClass, e);
+      }
+   }
+}

Modified: core/branches/flat/src/main/java/org/horizon/loader/ClusteredCacheLoader.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/ClusteredCacheLoader.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/loader/ClusteredCacheLoader.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -22,7 +22,7 @@
 package org.horizon.loader;
 
 import net.jcip.annotations.ThreadSafe;
-import org.horizon.CacheStatus;
+import org.horizon.ComponentStatus;
 import org.horizon.commands.CommandsFactory;
 import org.horizon.commands.DataCommand;
 import org.horizon.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
@@ -65,7 +65,7 @@
     * @return true if the cache is in its STARTED state.
     */
    protected boolean isCacheReady() {
-      return cache.getCacheStatus() == CacheStatus.STARTED;
+      return cache.getCacheStatus() == ComponentStatus.STARTED;
    }
 
    @Inject

Modified: core/branches/flat/src/main/java/org/horizon/manager/CacheManager.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/manager/CacheManager.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/manager/CacheManager.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -2,6 +2,8 @@
 
 import org.horizon.Cache;
 import org.horizon.config.Configuration;
+import org.horizon.factories.scopes.Scope;
+import org.horizon.factories.scopes.Scopes;
 import org.horizon.lifecycle.Lifecycle;
 import org.horizon.notifications.Listenable;
 import org.horizon.remoting.transport.Address;
@@ -45,6 +47,7 @@
  * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
  * @since 1.0
  */
+ at Scope(Scopes.GLOBAL)
 public interface CacheManager extends Lifecycle, Listenable {
    /**
     * Defines a named cache.  Named caches can be defined by using this method, in which case the configuration passed

Modified: core/branches/flat/src/main/java/org/horizon/manager/DefaultCacheManager.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/manager/DefaultCacheManager.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/manager/DefaultCacheManager.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -157,7 +157,7 @@
    public DefaultCacheManager(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);
+      globalComponentRegistry = new GlobalComponentRegistry(this.globalConfiguration, this);
       if (start) start();
    }
 

Modified: core/branches/flat/src/main/java/org/horizon/remoting/RPCManagerImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/remoting/RPCManagerImpl.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/remoting/RPCManagerImpl.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -7,6 +7,7 @@
 import org.horizon.config.GlobalConfiguration;
 import org.horizon.factories.KnownComponentNames;
 import org.horizon.factories.annotations.ComponentName;
+import org.horizon.factories.annotations.Inject;
 import org.horizon.factories.annotations.Start;
 import org.horizon.factories.annotations.Stop;
 import org.horizon.marshall.Marshaller;
@@ -34,6 +35,7 @@
    AtomicLong replicationFailures = new AtomicLong(0);
    boolean statisticsEnabled = false; // by default, don't gather statistics.
 
+   @Inject
    public void injectDependencies(GlobalConfiguration globalConfiguration, Transport t, InboundInvocationHandler handler,
                                   Marshaller marshaller,
                                   @ComponentName(KnownComponentNames.ASYNC_SERIALIZATION_EXECUTOR) ExecutorService e,

Modified: core/branches/flat/src/main/java/org/horizon/tree/TreeCache.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/tree/TreeCache.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/tree/TreeCache.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -23,7 +23,7 @@
 
 import org.horizon.Cache;
 import org.horizon.CacheException;
-import org.horizon.CacheStatus;
+import org.horizon.ComponentStatus;
 import org.horizon.config.Configuration;
 import org.horizon.context.InvocationContext;
 import org.horizon.interceptors.base.CommandInterceptor;
@@ -114,7 +114,7 @@
     * @param fqn   <b><i>absolute</i></b> {@link Fqn} to the {@link Node} to be accessed.
     * @param key   key with which the specified value is to be associated.
     * @param value value to be associated with the specified key.
-    * @throws IllegalStateException if {@link #getCacheStatus()} would not return {@link org.horizon.CacheStatus#STARTED}.
+    * @throws IllegalStateException if {@link #getCacheStatus()} would not return {@link org.horizon.ComponentStatus#STARTED}.
     */
    void putForExternalRead(Fqn fqn, K key, V value);
 
@@ -240,7 +240,7 @@
     *
     * @return the CacheStatus. Will not return <code>null</code>.
     */
-   CacheStatus getCacheStatus();
+   ComponentStatus getCacheStatus();
 
    /**
     * @return the current invocation context for the current invocation and cache instance.
@@ -322,14 +322,14 @@
     * @param newParent  new location under which to attach the node being moved.
     * @throws NodeNotExistsException may throw one of these if the target node does not exist or if a different thread
     *                                has moved this node elsewhere already.
-    * @throws IllegalStateException  if {@link #getCacheStatus()} would not return {@link org.horizon.CacheStatus#STARTED}.
+    * @throws IllegalStateException  if {@link #getCacheStatus()} would not return {@link org.horizon.ComponentStatus#STARTED}.
     */
    void move(Fqn nodeToMove, Fqn newParent) throws NodeNotExistsException;
 
    /**
     * Convenience method that takes in string representations of Fqns.  Otherwise identical to {@link #move(Fqn, Fqn)}
     *
-    * @throws IllegalStateException if {@link #getCacheStatus()} would not return {@link org.horizon.CacheStatus#STARTED}.
+    * @throws IllegalStateException if {@link #getCacheStatus()} would not return {@link org.horizon.ComponentStatus#STARTED}.
     */
    void move(String nodeToMove, String newParent) throws NodeNotExistsException;
 
@@ -340,7 +340,7 @@
     * @param fqn
     * @return map of data, or an empty map
     * @throws CacheException
-    * @throws IllegalStateException if {@link #getCacheStatus()} would not return {@link org.horizon.CacheStatus#STARTED}.
+    * @throws IllegalStateException if {@link #getCacheStatus()} would not return {@link org.horizon.ComponentStatus#STARTED}.
     */
    Map<K, V> getData(Fqn fqn);
 
@@ -357,7 +357,7 @@
     * A convenience method to retrieving a node and getting keys from the node directly.
     *
     * @param fqn name of the node
-    * @throws IllegalStateException if {@link #getCacheStatus()} would not return {@link org.horizon.CacheStatus#STARTED}.
+    * @throws IllegalStateException if {@link #getCacheStatus()} would not return {@link org.horizon.ComponentStatus#STARTED}.
     */
    Set<K> getKeys(Fqn fqn);
 
@@ -365,7 +365,7 @@
     * Convenience method that takes in a String represenation of the Fqn.  Otherwise identical to {@link
     * #clearData(Fqn)}.
     *
-    * @throws IllegalStateException if {@link #getCacheStatus()} would not return {@link CacheStatus#STARTED}.
+    * @throws IllegalStateException if {@link #getCacheStatus()} would not return {@link org.horizon.ComponentStatus#STARTED}.
     */
    void clearData(String fqn);
 
@@ -375,7 +375,7 @@
     * A convenience method to retrieving a node and getting keys from the node directly.
     *
     * @param fqn name of the node
-    * @throws IllegalStateException if {@link #getCacheStatus()} would not return {@link org.horizon.CacheStatus#STARTED}.
+    * @throws IllegalStateException if {@link #getCacheStatus()} would not return {@link org.horizon.ComponentStatus#STARTED}.
     */
    void clearData(Fqn fqn);
 

Modified: core/branches/flat/src/main/java/org/horizon/tree/TreeCacheImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/tree/TreeCacheImpl.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/tree/TreeCacheImpl.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -23,7 +23,7 @@
 
 import org.horizon.Cache;
 import org.horizon.CacheException;
-import org.horizon.CacheStatus;
+import org.horizon.ComponentStatus;
 import org.horizon.atomic.AtomicMap;
 import org.horizon.config.Configuration;
 import org.horizon.context.InvocationContext;
@@ -331,7 +331,7 @@
       return cache;
    }
 
-   public CacheStatus getCacheStatus() {
+   public ComponentStatus getCacheStatus() {
       return cache.getCacheStatus();
    }
 

Modified: core/branches/flat/src/main/java/org/horizon/util/TestingUtil.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/util/TestingUtil.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/main/java/org/horizon/util/TestingUtil.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -10,13 +10,14 @@
 import org.horizon.Cache;
 import org.horizon.CacheDelegate;
 import org.horizon.CacheSPI;
-import org.horizon.CacheStatus;
+import org.horizon.ComponentStatus;
 import org.horizon.commands.CommandsFactory;
 import org.horizon.commands.VisitableCommand;
 import org.horizon.factories.ComponentRegistry;
 import org.horizon.interceptors.InterceptorChain;
 import org.horizon.interceptors.base.CommandInterceptor;
 import org.horizon.lock.LockManager;
+import org.horizon.manager.CacheManager;
 import org.horizon.tree.TreeCache;
 
 import javax.transaction.TransactionManager;
@@ -364,13 +365,21 @@
       }
    }
 
+   public static void killCacheManagers(CacheManager... cacheManagers) {
+      if (cacheManagers != null) {
+         for (CacheManager cm : cacheManagers) {
+            if (cm != null) cm.stop();
+         }
+      }
+   }
+
    /**
     * Kills a cache - stops it, clears any data in any cache loaders, and rolls back any associated txs
     */
    public static void killCaches(Cache... caches) {
       for (Cache c : caches) {
          try {
-            if (c != null && c.getCacheStatus() == CacheStatus.STARTED) {
+            if (c != null && c.getCacheStatus() == ComponentStatus.STARTED) {
                CacheSPI spi = (CacheSPI) c;
                if (spi.getTransactionManager() != null) {
                   try {
@@ -429,7 +438,7 @@
     */
    public static void killTransactions(Cache... caches) {
       for (Cache c : caches) {
-         if (c != null && c.getCacheStatus() == CacheStatus.STARTED) {
+         if (c != null && c.getCacheStatus() == ComponentStatus.STARTED) {
             CacheSPI ci = (CacheSPI) c;
             if (ci.getTransactionManager() != null) {
                try {
@@ -507,7 +516,7 @@
     * @param cacheStatus status to wait for
     * @param timeout     timeout to wait for
     */
-   public static void blockUntilCacheStatusAchieved(Cache cache, CacheStatus cacheStatus, long timeout) {
+   public static void blockUntilCacheStatusAchieved(Cache cache, ComponentStatus cacheStatus, long timeout) {
       CacheSPI spi = (CacheSPI) cache;
       long killTime = System.currentTimeMillis() + timeout;
       while (System.currentTimeMillis() < killTime) {

Modified: core/branches/flat/src/test/java/org/horizon/UnitTestCacheManager.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/UnitTestCacheManager.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/test/java/org/horizon/UnitTestCacheManager.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -8,6 +8,8 @@
 import org.horizon.config.Configuration;
 
 /**
+ * Always use this cache manager when writing unit tests.  This allows for parallel tests to run.
+ *
  * @author dpospisi
  */
 public class UnitTestCacheManager {

Modified: core/branches/flat/src/test/java/org/horizon/manager/CacheManagerTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/manager/CacheManagerTest.java	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/test/java/org/horizon/manager/CacheManagerTest.java	2009-01-20 16:51:26 UTC (rev 7537)
@@ -1,8 +1,9 @@
 package org.horizon.manager;
 
 import org.horizon.Cache;
-import org.horizon.CacheStatus;
+import org.horizon.ComponentStatus;
 import org.horizon.config.Configuration;
+import org.horizon.util.TestingUtil;
 import org.testng.annotations.Test;
 
 /**
@@ -12,50 +13,62 @@
 @Test(groups = "functional")
 public class CacheManagerTest {
    public void testDefaultCache() throws CacheNameExistsException {
-      DefaultCacheManager cm = new DefaultCacheManager();
+      CacheManager cm = new DefaultCacheManager();
 
-      assert cm.getCache().getCacheStatus() == CacheStatus.STARTED;
-      assert cm.getCache().getName().equals(DefaultCacheManager.DEFAULT_CACHE_NAME);
+      try {
+         assert cm.getCache().getCacheStatus() == ComponentStatus.STARTED;
+         assert cm.getCache().getName().equals(DefaultCacheManager.DEFAULT_CACHE_NAME);
 
-      try {
-         cm.defineCache(DefaultCacheManager.DEFAULT_CACHE_NAME, new Configuration());
-         assert false : "Should fail";
+         try {
+            cm.defineCache(DefaultCacheManager.DEFAULT_CACHE_NAME, new Configuration());
+            assert false : "Should fail";
+         }
+         catch (IllegalArgumentException e) {
+            // ok
+            assert true : "Allowed";
+         }
+      } finally {
+         TestingUtil.killCacheManagers(cm);
       }
-      catch (IllegalArgumentException e) {
-         // ok
-         assert true : "Allowed";
-      }
    }
 
    public void testClashingNames() throws CacheNameExistsException {
-      DefaultCacheManager cm = new DefaultCacheManager();
-      Configuration c = new Configuration();
+      CacheManager cm = new DefaultCacheManager();
+      try {
+         Configuration c = new Configuration();
 
-      cm.defineCache("aCache", c);
-      try {
          cm.defineCache("aCache", c);
-         assert false : "Should fail";
+         try {
+            cm.defineCache("aCache", c);
+            assert false : "Should fail";
+         }
+         catch (CacheNameExistsException cnee) {
+            // expected
+            assert true : "Expected";
+         }
+      } finally {
+         TestingUtil.killCacheManagers(cm);
       }
-      catch (CacheNameExistsException cnee) {
-         // expected
-         assert true : "Expected";
-      }
    }
 
    public void testStartAndStop() {
       DefaultCacheManager cm = new DefaultCacheManager();
-      Cache c1 = cm.getCache("cache1");
-      Cache c2 = cm.getCache("cache2");
-      Cache c3 = cm.getCache("cache3");
+      try {
+         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;
+         assert c1.getCacheStatus() == ComponentStatus.STARTED;
+         assert c2.getCacheStatus() == ComponentStatus.STARTED;
+         assert c3.getCacheStatus() == ComponentStatus.STARTED;
 
-      cm.stop();
+         cm.stop();
 
-      assert c1.getCacheStatus() == CacheStatus.STOPPED;
-      assert c2.getCacheStatus() == CacheStatus.STOPPED;
-      assert c3.getCacheStatus() == CacheStatus.STOPPED;
+         assert c1.getCacheStatus() == ComponentStatus.STOPPED;
+         assert c2.getCacheStatus() == ComponentStatus.STOPPED;
+         assert c3.getCacheStatus() == ComponentStatus.STOPPED;
+      } finally {
+         TestingUtil.killCacheManagers(cm);
+      }
    }
 }

Modified: core/branches/flat/src/test/resources/log4j.xml
===================================================================
--- core/branches/flat/src/test/resources/log4j.xml	2009-01-20 16:12:13 UTC (rev 7536)
+++ core/branches/flat/src/test/resources/log4j.xml	2009-01-20 16:51:26 UTC (rev 7537)
@@ -45,15 +45,15 @@
    <!-- ================ -->
 
    <category name="org.horizon">
-      <priority value="WARN"/>
+      <priority value="TRACE"/>
    </category>
 
-    <category name="org.horizon.profiling">
+   <category name="org.horizon.profiling">
       <priority value="WARN"/>
    </category>
 
    <category name="org.horizon.factories">
-      <priority value="WARN"/>
+      <priority value="TRACE"/>
    </category>
 
    <!-- ======================= -->




More information about the jbosscache-commits mailing list