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

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Tue Jan 20 14:24:46 EST 2009


Author: manik.surtani at jboss.com
Date: 2009-01-20 14:24:46 -0500 (Tue, 20 Jan 2009)
New Revision: 7546

Added:
   core/branches/flat/src/main/java/org/horizon/commands/RemoteCommandFactory.java
   core/branches/flat/src/main/java/org/horizon/factories/AbstractComponentFactory.java
   core/branches/flat/src/main/java/org/horizon/factories/AbstractNamedCacheComponentFactory.java
   core/branches/flat/src/main/java/org/horizon/factories/EmptyConstructorFactory.java
   core/branches/flat/src/main/java/org/horizon/factories/EmptyConstructorNamedCacheFactory.java
Removed:
   core/branches/flat/src/main/java/org/horizon/factories/ComponentFactory.java
   core/branches/flat/src/main/java/org/horizon/factories/EmptyConstructorFactory.java
Modified:
   core/branches/flat/src/main/java/org/horizon/commands/CommandsFactory.java
   core/branches/flat/src/main/java/org/horizon/commands/CommandsFactoryImpl.java
   core/branches/flat/src/main/java/org/horizon/config/GlobalConfiguration.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/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/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/NamedComponentFactory.java
   core/branches/flat/src/main/java/org/horizon/factories/NamedExecutorsFactory.java
   core/branches/flat/src/main/java/org/horizon/factories/RPCManagerFactory.java
   core/branches/flat/src/main/java/org/horizon/factories/ReplicationQueueFactory.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/factories/TransportFactory.java
   core/branches/flat/src/main/java/org/horizon/jmx/JmxRegistrationManager.java
   core/branches/flat/src/main/java/org/horizon/manager/DefaultCacheManager.java
   core/branches/flat/src/main/java/org/horizon/marshall/CacheMarshallerStarobrno.java
   core/branches/flat/src/main/java/org/horizon/marshall/Marshaller.java
   core/branches/flat/src/main/java/org/horizon/marshall/VersionAwareMarshaller.java
   core/branches/flat/src/main/java/org/horizon/remoting/InboundInvocationHandler.java
   core/branches/flat/src/main/java/org/horizon/remoting/InboundInvocationHandlerImpl.java
   core/branches/flat/src/test/java/org/horizon/manager/CacheManagerComponentRegistryTest.java
Log:
More construction stuff

Modified: core/branches/flat/src/main/java/org/horizon/commands/CommandsFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/commands/CommandsFactory.java	2009-01-20 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/commands/CommandsFactory.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -70,7 +70,17 @@
 
    RollbackCommand buildRollbackCommand(GlobalTransaction gtx);
 
-   ReplicableCommand fromStream(byte methodId, Object[] args);
+   /**
+    * Initializes a {@link org.horizon.commands.ReplicableCommand} read from a data stream with components specific to
+    * the target cache instance.
+    * <p/>
+    * Implementations should also be deep, in that if the command contains other commands, these should be recursed
+    * into.
+    * <p/>
+    *
+    * @param command command to initialize.  Cannot be null.
+    */
+   void initializeReplicableCommand(ReplicableCommand command);
 
    ReplicateCommand buildReplicateCommand(List<ReplicableCommand> toReplicate);
 

Modified: core/branches/flat/src/main/java/org/horizon/commands/CommandsFactoryImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/commands/CommandsFactoryImpl.java	2009-01-20 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/commands/CommandsFactoryImpl.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -21,7 +21,6 @@
  */
 package org.horizon.commands;
 
-import org.horizon.CacheException;
 import org.horizon.commands.read.GetKeyValueCommand;
 import org.horizon.commands.read.SizeCommand;
 import org.horizon.commands.remote.ReplicateCommand;
@@ -115,70 +114,32 @@
       return new ReplicateCommand(call);
    }
 
-   public ReplicableCommand fromStream(byte id, Object[] parameters) {
-      ReplicableCommand command;
-      switch (id) {
-         case PutKeyValueCommand.METHOD_ID: {
-            PutKeyValueCommand c = new PutKeyValueCommand();
-            c.init(notifier);
-            command = c;
+   public void initializeReplicableCommand(ReplicableCommand c) {
+      if (c == null) return;
+      switch (c.getCommandId()) {
+         case PutKeyValueCommand.METHOD_ID:
+            ((PutKeyValueCommand) c).init(notifier);
             break;
-         }
-         case PutMapCommand.METHOD_ID: {
-            PutMapCommand c = new PutMapCommand();
-            c.init(notifier);
-            command = c;
+         case PutMapCommand.METHOD_ID:
+            ((PutMapCommand) c).init(notifier);
             break;
-         }
-         case RemoveCommand.METHOD_ID: {
-            RemoveCommand c = new RemoveCommand();
-            c.init(notifier);
-            command = c;
+         case RemoveCommand.METHOD_ID:
+            ((RemoveCommand) c).init(notifier);
             break;
-         }
-         case ReplaceCommand.METHOD_ID: {
-            ReplaceCommand c = new ReplaceCommand();
-            command = c;
-            break;
-         }
-         case GetKeyValueCommand.METHOD_ID: {
-            GetKeyValueCommand c = new GetKeyValueCommand();
-            command = c;
-            break;
-         }
-         case ClearCommand.METHOD_ID: {
-            ClearCommand c = new ClearCommand();
-            command = c;
-            break;
-         }
-         case PrepareCommand.METHOD_ID: {
-            PrepareCommand c = new PrepareCommand();
-            command = c;
-            break;
-         }
-         case CommitCommand.METHOD_ID: {
-            CommitCommand c = new CommitCommand();
-            command = c;
-            break;
-         }
-         case RollbackCommand.METHOD_ID: {
-            RollbackCommand c = new RollbackCommand();
-            command = c;
-            break;
-         }
          case ReplicateCommand.MULTIPLE_METHOD_ID:
-         case ReplicateCommand.SINGLE_METHOD_ID: {
-            ReplicateCommand c = new ReplicateCommand();
-            c.initialize(interceptorChain);
-            command = c;
+         case ReplicateCommand.SINGLE_METHOD_ID:
+            ReplicateCommand rc = (ReplicateCommand) c;
+            if (rc.getModifications() != null)
+               for (ReplicableCommand nested : rc.getModifications()) initializeReplicableCommand(nested);
+            initializeReplicableCommand(rc.getSingleModification());
+            rc.initialize(interceptorChain);
             break;
-         }
-
-         default:
-            throw new CacheException("Unknown command id " + id + "!");
+         case PrepareCommand.METHOD_ID:
+            PrepareCommand pc = (PrepareCommand) c;
+            if (pc.getModifications() != null)
+               for (ReplicableCommand nested : pc.getModifications()) initializeReplicableCommand(nested);
+            break;
       }
-      command.setParameters(id, parameters);
-      return command;
    }
 
    public InvalidateCommand buildInvalidateCommand(Object fqn) {

Added: core/branches/flat/src/main/java/org/horizon/commands/RemoteCommandFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/commands/RemoteCommandFactory.java	                        (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/commands/RemoteCommandFactory.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -0,0 +1,75 @@
+package org.horizon.commands;
+
+import org.horizon.CacheException;
+import org.horizon.commands.read.GetKeyValueCommand;
+import org.horizon.commands.remote.ReplicateCommand;
+import org.horizon.commands.tx.CommitCommand;
+import org.horizon.commands.tx.PrepareCommand;
+import org.horizon.commands.tx.RollbackCommand;
+import org.horizon.commands.write.ClearCommand;
+import org.horizon.commands.write.PutKeyValueCommand;
+import org.horizon.commands.write.PutMapCommand;
+import org.horizon.commands.write.RemoveCommand;
+import org.horizon.commands.write.ReplaceCommand;
+
+/**
+ * Specifically used to create un-initialized {@link org.horizon.commands.ReplicableCommand}s from a byte stream.
+ *
+ * @author Manik Surtani
+ * @since 1.0
+ */
+public class RemoteCommandFactory {
+
+   /**
+    * Creates an un-initialized command.  Un-initialized in the sense that parameters will be set, but any components
+    * specific to the cache in question will not be set.
+    * <p/>
+    * You would typically set these parameters using {@link org.horizon.commands.CommandsFactory#initializeReplicableCommand(ReplicableCommand)}
+    * <p/>
+    *
+    * @param id         id of the command
+    * @param parameters parameters to set
+    * @return a replicable command
+    */
+   public ReplicableCommand fromStream(byte id, Object[] parameters) {
+      ReplicableCommand command;
+      switch (id) {
+         case PutKeyValueCommand.METHOD_ID:
+            command = new PutKeyValueCommand();
+            break;
+         case PutMapCommand.METHOD_ID:
+            command = new PutMapCommand();
+            break;
+         case RemoveCommand.METHOD_ID:
+            command = new RemoveCommand();
+            break;
+         case ReplaceCommand.METHOD_ID:
+            command = new ReplaceCommand();
+            break;
+         case GetKeyValueCommand.METHOD_ID:
+            command = new GetKeyValueCommand();
+            break;
+         case ClearCommand.METHOD_ID:
+            command = new ClearCommand();
+            break;
+         case PrepareCommand.METHOD_ID:
+            command = new PrepareCommand();
+            break;
+         case CommitCommand.METHOD_ID:
+            command = new CommitCommand();
+            break;
+         case RollbackCommand.METHOD_ID:
+            command = new RollbackCommand();
+            break;
+         case ReplicateCommand.MULTIPLE_METHOD_ID:
+         case ReplicateCommand.SINGLE_METHOD_ID:
+            command = new ReplicateCommand();
+            break;
+
+         default:
+            throw new CacheException("Unknown command id " + id + "!");
+      }
+      command.setParameters(id, parameters);
+      return command;
+   }
+}

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 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/config/GlobalConfiguration.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -10,6 +10,7 @@
 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;
@@ -358,4 +359,31 @@
          throw new CacheException("Problems cloning configuration component!", e);
       }
    }
+
+   /**
+    * Helper method that gets you a default constructed GlobalConfiguration, preconfigured to use the default clustering
+    * stack
+    *
+    * @return a new global configuration
+    */
+   public static GlobalConfiguration getClusteredDefault() {
+      GlobalConfiguration gc = new GlobalConfiguration();
+      gc.setTransportClass(JGroupsTransport.class.getName());
+      gc.setTransportProperties((Properties) null);
+      return gc;
+   }
+
+   /**
+    * Helper method that gets you a default constructed GlobalConfiguration, preconfigured for use in LOCAL mode
+    *
+    * @return a new global configuration
+    */
+   public static GlobalConfiguration getNonClusteredDefault() {
+      GlobalConfiguration gc = new GlobalConfiguration();
+      gc.setTransportClass(null);
+      gc.setTransportProperties((Properties) null);
+      return gc;
+   }
+
+
 }

Copied: core/branches/flat/src/main/java/org/horizon/factories/AbstractComponentFactory.java (from rev 7537, core/branches/flat/src/main/java/org/horizon/factories/ComponentFactory.java)
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/AbstractComponentFactory.java	                        (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/factories/AbstractComponentFactory.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -0,0 +1,79 @@
+/*
+ * 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.factories;
+
+import org.horizon.config.ConfigurationException;
+import org.horizon.config.GlobalConfiguration;
+import org.horizon.factories.annotations.Inject;
+import org.horizon.factories.scopes.Scope;
+import org.horizon.factories.scopes.Scopes;
+import org.horizon.logging.Log;
+import org.horizon.logging.LogFactory;
+
+/**
+ * Factory that creates components used internally within JBoss Cache, and also wires dependencies into the components.
+ * <p/>
+ * The {@link DefaultCacheFactory} is a special subclass of this, which bootstraps the construction of other components.
+ * When this class is loaded, it maintains a static list of known default factories for known components, which it then
+ * delegates to, when actually performing the construction.
+ * <p/>
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @see Inject
+ * @see ComponentRegistry
+ * @since 1.0
+ */
+ at Scope(Scopes.GLOBAL)
+public abstract class AbstractComponentFactory {
+   protected final Log log = LogFactory.getLog(getClass());
+   protected GlobalComponentRegistry globalComponentRegistry;
+   protected GlobalConfiguration globalConfiguration;
+
+   /**
+    * Constructs a new ComponentFactory.
+    */
+   public AbstractComponentFactory() {
+   }
+
+   @Inject
+   private void injectGlobalDependencies(GlobalConfiguration globalConfiguration, GlobalComponentRegistry globalComponentRegistry) {
+      this.globalComponentRegistry = globalComponentRegistry;
+      this.globalConfiguration = globalConfiguration;
+   }
+
+   /**
+    * Constructs a component.
+    *
+    * @param componentType type of component
+    * @return a component
+    */
+   public abstract <T> T construct(Class<T> componentType);
+
+   protected void assertTypeConstructable(Class requestedType, Class... ableToConstruct) {
+      boolean canConstruct = false;
+      for (Class c : ableToConstruct) {
+         canConstruct = canConstruct || requestedType.isAssignableFrom(c);
+      }
+      if (!canConstruct) throw new ConfigurationException("Don't know how to construct " + requestedType);
+   }
+
+}


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

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 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/factories/AbstractComponentRegistry.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -81,13 +81,13 @@
 public abstract class AbstractComponentRegistry implements Lifecycle {
 
    // Be careful when changing this to 'true'.  It should *never* go into the code repo with this flag set to 'true'!
-   private static final boolean DEBUG_DEPENDENCIES = false;
+   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
     */
-   private Map<Class, Class<? extends ComponentFactory>> defaultFactories = null;
+   private Map<Class, Class<? extends AbstractComponentFactory>> defaultFactories = null;
 
    protected static final Object NULL_COMPONENT = new Object();
 
@@ -139,9 +139,10 @@
     *
     * @return set of known factory types.
     */
-   private Set<Class<? extends ComponentFactory>> getHardcodedFactories() {
-      Set<Class<? extends ComponentFactory>> s = new HashSet<Class<? extends ComponentFactory>>();
+   private Set<Class<? extends AbstractComponentFactory>> getHardcodedFactories() {
+      Set<Class<? extends AbstractComponentFactory>> s = new HashSet<Class<? extends AbstractComponentFactory>>();
       s.add(BootstrapFactory.class);
+      s.add(EmptyConstructorNamedCacheFactory.class);
       s.add(EmptyConstructorFactory.class);
       s.add(InterceptorChainFactory.class);
       s.add(RPCManagerFactory.class);
@@ -282,7 +283,7 @@
 
          if (component == null) {
             // create this component and add it to the registry
-            ComponentFactory factory = getFactory(componentClass);
+            AbstractComponentFactory factory = getFactory(componentClass);
             component = factory instanceof NamedComponentFactory ?
                   ((NamedComponentFactory) factory).construct(componentClass, name)
                   : factory.construct(componentClass);
@@ -310,13 +311,13 @@
     * @param componentClass type of component to construct
     * @return component factory capable of constructing such components
     */
-   protected ComponentFactory getFactory(Class componentClass) {
-      Map<Class, Class<? extends ComponentFactory>> defaultFactoryMap = getDefaultFactoryMap();
-      Class<? extends ComponentFactory> cfClass = defaultFactoryMap.get(componentClass);
+   protected AbstractComponentFactory getFactory(Class componentClass) {
+      Map<Class, Class<? extends AbstractComponentFactory>> defaultFactoryMap = getDefaultFactoryMap();
+      Class<? extends AbstractComponentFactory> cfClass = defaultFactoryMap.get(componentClass);
       if (cfClass == null)
          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);
+      AbstractComponentFactory cf = getComponent(cfClass);
       if (cf == null) {
          // hasn't yet been created.  Create and put in registry
          cf = instantiateFactory(cfClass);
@@ -327,13 +328,17 @@
       }
 
       // ensure the component factory is in the STARTED state!
-      Component c = componentLookup.get(cfClass.getName());
+      Component c = lookupComponent(cfClass, cfClass.getName());
       if (c.instance != cf)
          throw new ConfigurationException("Component factory " + cfClass + " incorrectly registered! Debug stack: " + debugStack);
       return cf;
    }
 
-   protected Map<Class, Class<? extends ComponentFactory>> getDefaultFactoryMap() {
+   protected Component lookupComponent(Class type, String componentName) {
+      return componentLookup.get(componentName);
+   }
+
+   protected Map<Class, Class<? extends AbstractComponentFactory>> getDefaultFactoryMap() {
       if (defaultFactories == null) scanDefaultFactories();
       return defaultFactories;
    }
@@ -343,10 +348,10 @@
     * created by such factories.
     */
    void scanDefaultFactories() {
-      Map<Class, Class<? extends ComponentFactory>> temp = new HashMap<Class, Class<? extends ComponentFactory>>();
-      Set<Class<? extends ComponentFactory>> factories = getHardcodedFactories();
+      Map<Class, Class<? extends AbstractComponentFactory>> temp = new HashMap<Class, Class<? extends AbstractComponentFactory>>();
+      Set<Class<? extends AbstractComponentFactory>> factories = getHardcodedFactories();
 
-      for (Class<? extends ComponentFactory> factory : factories) {
+      for (Class<? extends AbstractComponentFactory> factory : factories) {
          // check if this implements auto-instantiable.  If it doesn't have a no-arg constructor throw an exception
          boolean factoryValid = true;
          try {
@@ -376,7 +381,7 @@
     * @param factory class of factory to be created
     * @return factory instance
     */
-   ComponentFactory instantiateFactory(Class<? extends ComponentFactory> factory) {
+   AbstractComponentFactory instantiateFactory(Class<? extends AbstractComponentFactory> factory) {
       if (AutoInstantiableFactory.class.isAssignableFrom(factory)) {
          try {
             return factory.newInstance();
@@ -457,13 +462,27 @@
 
    @SuppressWarnings("unchecked")
    public <T> T getComponent(Class<T> type, String name) {
-      Component wrapper = componentLookup.get(name);
+      Component wrapper = lookupComponent(type, name);
       if (wrapper == null) return null;
 
       return (T) (wrapper.instance == NULL_COMPONENT ? null : wrapper.instance);
    }
 
    /**
+    * Registers the default class loader.  This method *must* be called before any other components are registered,
+    * typically called by bootstrap code.  Defensively, it is called in the constructor of ComponentRegistry with a null
+    * parameter.
+    *
+    * @param loader a class loader to use by default.  If this is null, the class loader used to load this instance of
+    *               ComponentRegistry is used.
+    */
+   public void registerDefaultClassLoader(ClassLoader loader) {
+      registerComponent(loader == null ? getClass().getClassLoader() : loader, ClassLoader.class);
+      // make sure the class loader is non-volatile, so it survives restarts.
+      componentLookup.get(ClassLoader.class.getName()).nonVolatile = true;
+   }
+
+   /**
     * Rewires components.  Can only be called if the current state is WIRED or STARTED.
     */
    public void rewire() {
@@ -885,7 +904,7 @@
     *
     * @return a set of components
     */
-   public Set<Component> getRegiteredComponents() {
+   public Set<Component> getRegisteredComponents() {
       HashSet<Component> defensiveCopy = new HashSet<Component>(componentLookup.values());
       return Collections.unmodifiableSet(defensiveCopy);
    }

Added: core/branches/flat/src/main/java/org/horizon/factories/AbstractNamedCacheComponentFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/AbstractNamedCacheComponentFactory.java	                        (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/factories/AbstractNamedCacheComponentFactory.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -0,0 +1,24 @@
+package org.horizon.factories;
+
+import org.horizon.config.Configuration;
+import org.horizon.factories.annotations.Inject;
+import org.horizon.factories.scopes.Scope;
+import org.horizon.factories.scopes.Scopes;
+
+/**
+ * A component factory for creating components scoped per-cache.
+ *
+ * @author Manik Surtani
+ * @since 1.0
+ */
+ at Scope(Scopes.NAMED_CACHE)
+public abstract class AbstractNamedCacheComponentFactory extends AbstractComponentFactory {
+   protected Configuration configuration;
+   protected ComponentRegistry componentRegistry;
+
+   @Inject
+   private void injectGlobalDependencies(Configuration configuration, ComponentRegistry componentRegistry) {
+      this.componentRegistry = componentRegistry;
+      this.configuration = configuration;
+   }
+}

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 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/factories/BootstrapFactory.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -35,11 +35,12 @@
  */
 @DefaultFactoryFor(classes = {CacheSPI.class, Configuration.class, ComponentRegistry.class})
 @NonVolatile
-public class BootstrapFactory extends ComponentFactory {
+public class BootstrapFactory extends AbstractNamedCacheComponentFactory {
    CacheSPI cacheSPI;
 
    public BootstrapFactory(CacheSPI cacheSPI, Configuration configuration, ComponentRegistry componentRegistry) {
-      super(componentRegistry, configuration);
+      this.componentRegistry = componentRegistry;
+      this.configuration = configuration;
       this.cacheSPI = cacheSPI;
    }
 

Deleted: 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 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/factories/ComponentFactory.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -1,87 +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.factories;
-
-import org.horizon.config.Configuration;
-import org.horizon.config.ConfigurationException;
-import org.horizon.factories.annotations.Inject;
-import org.horizon.factories.scopes.Scope;
-import org.horizon.factories.scopes.Scopes;
-import org.horizon.logging.Log;
-import org.horizon.logging.LogFactory;
-
-/**
- * Factory that creates components used internally within JBoss Cache, and also wires dependencies into the components.
- * <p/>
- * The {@link DefaultCacheFactory} is a special subclass of this, which bootstraps the construction of other components.
- * When this class is loaded, it maintains a static list of known default factories for known components, which it then
- * delegates to, when actually performing the construction.
- * <p/>
- *
- * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
- * @see Inject
- * @see ComponentRegistry
- * @since 1.0
- */
- at Scope(Scopes.NAMED_CACHE)
-public abstract class ComponentFactory {
-   protected final Log log = LogFactory.getLog(getClass());
-   protected ComponentRegistry componentRegistry;
-   protected Configuration configuration;
-
-   /**
-    * Constructs a new ComponentFactory.
-    */
-   public ComponentFactory(ComponentRegistry componentRegistry, Configuration configuration) {
-      this.componentRegistry = componentRegistry;
-      this.configuration = configuration;
-   }
-
-   /**
-    * Constructs a new ComponentFactory.
-    */
-   public ComponentFactory() {
-   }
-
-   @Inject
-   private void injectDependencies(Configuration configuration, ComponentRegistry componentRegistry) {
-      this.configuration = configuration;
-      this.componentRegistry = componentRegistry;
-   }
-
-   /**
-    * Constructs a component.
-    *
-    * @param componentType type of component
-    * @return a component
-    */
-   public abstract <T> T construct(Class<T> componentType);
-
-   protected void assertTypeConstructable(Class requestedType, Class... ableToConstruct) {
-      boolean canConstruct = false;
-      for (Class c : ableToConstruct) {
-         canConstruct = canConstruct || requestedType.isAssignableFrom(c);
-      }
-      if (!canConstruct) throw new ConfigurationException("Don't know how to construct " + requestedType);
-   }
-
-}

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 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/factories/ComponentRegistry.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -44,6 +44,8 @@
          registerComponent(this, ComponentRegistry.class);
          registerComponent(configuration, Configuration.class);
          registerComponent(new BootstrapFactory(cache, configuration, this), BootstrapFactory.class);
+
+         globalComponents.registerNamedComponentRegistry(this, cacheName);
       }
       catch (Exception e) {
          throw new CacheException("Unable to construct a ComponentRegistry!", e);
@@ -54,47 +56,45 @@
       return log;
    }
 
-   /**
-    * Registers the default class loader.  This method *must* be called before any other components are registered,
-    * typically called by bootstrap code.  Defensively, it is called in the constructor of ComponentRegistry with a null
-    * parameter.
-    *
-    * @param loader a class loader to use by default.  If this is null, the class loader used to load this instance of
-    *               ComponentRegistry is used.
-    */
-   public void registerDefaultClassLoader(ClassLoader loader) {
-      registerComponent(loader == null ? getClass().getClassLoader() : loader, ClassLoader.class);
-      // make sure the class loader is non-volatile, so it survives restarts.
-      componentLookup.get(ClassLoader.class.getName()).nonVolatile = true;
-   }
-
-
    @Override
    public <T> T getComponent(Class<T> componentType, String name) {
-      // first try in the local registry
-      Scopes componentScope = ScopeDetector.detectScope(componentType);
-      switch (componentScope) {
-         case GLOBAL:
-            return globalComponents.getComponent(componentType, name);
-         case NAMED_CACHE:
-            return super.getComponent(componentType, name);
-         default:
-            throw new IllegalArgumentException("Unknown component scope " + componentScope + " for component type " + componentType);
+      if (isGlobal(componentType)) {
+         return globalComponents.getComponent(componentType, name);
+      } else {
+         return super.getComponent(componentType, name);
       }
    }
 
    @Override
-   protected Map<Class, Class<? extends ComponentFactory>> getDefaultFactoryMap() {
+   protected Map<Class, Class<? extends AbstractComponentFactory>> getDefaultFactoryMap() {
       // delegate to parent.  No sense maintaining multiple copies of this map.
       return globalComponents.getDefaultFactoryMap();
    }
 
    @Override
-   protected ComponentFactory getFactory(Class componentClass) {
-      return super.getFactory(componentClass);
+   protected Component lookupComponent(Class componentClass, String name) {
+      if (isGlobal(componentClass)) {
+         return globalComponents.lookupComponent(componentClass, name);
+      } else {
+         return super.lookupComponent(componentClass, name);
+      }
    }
 
-   public GlobalComponentRegistry getSharedComponentRegistry() {
+   public GlobalComponentRegistry getGlobalComponentRegistry() {
       return globalComponents;
    }
+
+   @Override
+   public void registerComponent(Object component, String name) {
+      if (isGlobal(component.getClass())) {
+         globalComponents.registerComponent(component, name);
+      } else {
+         super.registerComponent(component, name);
+      }
+   }
+
+   private boolean isGlobal(Class clazz) {
+      Scopes componentScope = ScopeDetector.detectScope(clazz);
+      return componentScope == Scopes.GLOBAL;
+   }
 }

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 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/factories/DataContainerFactory.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -32,7 +32,7 @@
  * @since 1.0
  */
 @DefaultFactoryFor(classes = DataContainer.class)
-public class DataContainerFactory extends ComponentFactory implements AutoInstantiableFactory {
+public class DataContainerFactory extends AbstractNamedCacheComponentFactory 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 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/factories/DefaultCacheFactory.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -32,15 +32,15 @@
 /**
  * Default implementation of the {@link CacheFactory} interface.
  * <p/>
- * This is a special instance of a {@link ComponentFactory} which contains bootstrap information for the {@link
+ * This is a special instance of a {@link AbstractComponentFactory} which contains bootstrap information for the {@link
  * ComponentRegistry}.
  * <p/>
  *
  * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
- * @see ComponentFactory
+ * @see AbstractComponentFactory
  * @since 1.0
  */
-public class DefaultCacheFactory<K, V> extends ComponentFactory// implements CacheFactory<K, V>
+public class DefaultCacheFactory<K, V> extends AbstractNamedCacheComponentFactory// implements CacheFactory<K, V>
 {
    private ClassLoader defaultClassLoader;
 

Deleted: 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 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/factories/EmptyConstructorFactory.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -1,69 +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.factories;
-
-
-import org.horizon.batch.BatchContainer;
-import org.horizon.commands.CommandsFactory;
-import org.horizon.config.ConfigurationException;
-import org.horizon.factories.annotations.DefaultFactoryFor;
-import org.horizon.factories.context.ContextFactory;
-import org.horizon.invocation.InvocationContextContainer;
-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;
-
-/**
- * Simple factory that just uses reflection and an empty constructor of the component type.
- *
- * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
- * @since 1.0
- */
- 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 implements AutoInstantiableFactory {
-   @Override
-   public <T> T construct(Class<T> componentType) {
-      try {
-         if (componentType.isInterface()) {
-            Class componentImpl;
-            if (componentType.equals(Marshaller.class)) {
-               componentImpl = VersionAwareMarshaller.class;
-            } else {
-               // add an "Impl" to the end of the class name and try again
-               componentImpl = getClass().getClassLoader().loadClass(componentType.getName() + "Impl");
-            }
-            return componentType.cast(componentImpl.newInstance());
-         } else {
-            return componentType.newInstance();
-         }
-      }
-      catch (Exception e) {
-         throw new ConfigurationException("Unable to create component " + componentType, e);
-      }
-   }
-}

Added: core/branches/flat/src/main/java/org/horizon/factories/EmptyConstructorFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/EmptyConstructorFactory.java	                        (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/factories/EmptyConstructorFactory.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -0,0 +1,38 @@
+package org.horizon.factories;
+
+import org.horizon.config.ConfigurationException;
+import org.horizon.factories.annotations.DefaultFactoryFor;
+import org.horizon.marshall.Marshaller;
+import org.horizon.marshall.VersionAwareMarshaller;
+import org.horizon.notifications.CacheManagerNotifier;
+import org.horizon.remoting.InboundInvocationHandler;
+
+/**
+ * // TODO: Manik: Document this!
+ *
+ * @author Manik Surtani
+ * @since 1.0
+ */
+ at DefaultFactoryFor(classes = {InboundInvocationHandler.class, CacheManagerNotifier.class, Marshaller.class})
+public class EmptyConstructorFactory extends AbstractComponentFactory implements AutoInstantiableFactory {
+   public <T> T construct(Class<T> componentType) {
+      try {
+         if (componentType.isInterface()) {
+            Class componentImpl;
+            if (componentType.equals(Marshaller.class)) {
+               componentImpl = VersionAwareMarshaller.class;
+            } else {
+               // add an "Impl" to the end of the class name and try again
+               componentImpl = getClass().getClassLoader().loadClass(componentType.getName() + "Impl");
+            }
+            return componentType.cast(componentImpl.newInstance());
+         } else {
+            return componentType.newInstance();
+         }
+      }
+      catch (Exception e) {
+         throw new ConfigurationException("Unable to create component " + componentType, e);
+      }
+
+   }
+}

Copied: core/branches/flat/src/main/java/org/horizon/factories/EmptyConstructorNamedCacheFactory.java (from rev 7537, core/branches/flat/src/main/java/org/horizon/factories/EmptyConstructorFactory.java)
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/EmptyConstructorNamedCacheFactory.java	                        (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/factories/EmptyConstructorNamedCacheFactory.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -0,0 +1,67 @@
+/*
+ * 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.factories;
+
+
+import org.horizon.batch.BatchContainer;
+import org.horizon.commands.CommandsFactory;
+import org.horizon.config.ConfigurationException;
+import org.horizon.factories.annotations.DefaultFactoryFor;
+import org.horizon.factories.context.ContextFactory;
+import org.horizon.invocation.InvocationContextContainer;
+import org.horizon.loader.CacheLoaderManager;
+import org.horizon.marshall.Marshaller;
+import org.horizon.marshall.VersionAwareMarshaller;
+import org.horizon.notifications.CacheNotifier;
+import org.horizon.transaction.TransactionTable;
+
+/**
+ * Simple factory that just uses reflection and an empty constructor of the component type.
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 1.0
+ */
+ at DefaultFactoryFor(classes = {CacheNotifier.class, EntryFactory.class, CommandsFactory.class,
+                              CacheLoaderManager.class, InvocationContextContainer.class,
+                              TransactionTable.class, BatchContainer.class, ContextFactory.class})
+public class EmptyConstructorNamedCacheFactory extends AbstractNamedCacheComponentFactory implements AutoInstantiableFactory {
+   @Override
+   public <T> T construct(Class<T> componentType) {
+      try {
+         if (componentType.isInterface()) {
+            Class componentImpl;
+            if (componentType.equals(Marshaller.class)) {
+               componentImpl = VersionAwareMarshaller.class;
+            } else {
+               // add an "Impl" to the end of the class name and try again
+               componentImpl = getClass().getClassLoader().loadClass(componentType.getName() + "Impl");
+            }
+            return componentType.cast(componentImpl.newInstance());
+         } else {
+            return componentType.newInstance();
+         }
+      }
+      catch (Exception e) {
+         throw new ConfigurationException("Unable to create component " + componentType, e);
+      }
+   }
+}


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

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 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/factories/EvictionManagerFactory.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -9,7 +9,7 @@
  * @since 1.0
  */
 @DefaultFactoryFor(classes = {EvictionManager.class})
-public class EvictionManagerFactory extends ComponentFactory implements AutoInstantiableFactory {
+public class EvictionManagerFactory extends AbstractNamedCacheComponentFactory 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 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/factories/GlobalComponentRegistry.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -45,6 +45,7 @@
       try {
          // this order is important ... 
          globalConfiguration = configuration;
+         registerDefaultClassLoader(null);
          registerComponent(this, GlobalComponentRegistry.class);
          registerComponent(cacheManager, CacheManager.class);
          registerComponent(configuration, GlobalConfiguration.class);
@@ -91,4 +92,12 @@
          log.trace("Not registering a shutdown hook.  Configured behavior = {0}", globalConfiguration.getShutdownHookBehavior());
       }
    }
+
+   public ComponentRegistry getNamedComponentRegistry(String name) {
+      return getComponent(ComponentRegistry.class, name);
+   }
+
+   public void registerNamedComponentRegistry(ComponentRegistry componentRegistry, String name) {
+      registerComponent(componentRegistry, name);
+   }
 }

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 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/factories/InterceptorChainFactory.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -43,7 +43,7 @@
  * @since 1.0
  */
 @DefaultFactoryFor(classes = InterceptorChain.class)
-public class InterceptorChainFactory extends ComponentFactory implements AutoInstantiableFactory {
+public class InterceptorChainFactory extends AbstractNamedCacheComponentFactory implements AutoInstantiableFactory {
    private CommandInterceptor createInterceptor(Class<? extends CommandInterceptor> clazz) throws IllegalAccessException, InstantiationException {
       CommandInterceptor chainedInterceptor = componentRegistry.getComponent(clazz);
       if (chainedInterceptor == null) {

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 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/factories/LockManagerFactory.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -32,7 +32,7 @@
  * @since 1.0
  */
 @DefaultFactoryFor(classes = LockManager.class)
-public class LockManagerFactory extends ComponentFactory implements AutoInstantiableFactory {
+public class LockManagerFactory extends AbstractComponentFactory implements AutoInstantiableFactory {
    public <T> T construct(Class<T> componentType) {
       return (T) new StripedLockManager();
    }

Modified: core/branches/flat/src/main/java/org/horizon/factories/NamedComponentFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/NamedComponentFactory.java	2009-01-20 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/factories/NamedComponentFactory.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -8,7 +8,7 @@
  * @author Manik Surtani
  * @since 1.0
  */
-public abstract class NamedComponentFactory extends ComponentFactory {
+public abstract class NamedComponentFactory extends AbstractComponentFactory {
 
    public <T> T construct(Class<T> componentType) {
 

Modified: core/branches/flat/src/main/java/org/horizon/factories/NamedExecutorsFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/NamedExecutorsFactory.java	2009-01-20 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/factories/NamedExecutorsFactory.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -3,8 +3,6 @@
 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;
@@ -19,7 +17,6 @@
  * @since 1.0
  */
 @DefaultFactoryFor(classes = {ExecutorService.class, Executor.class, ScheduledExecutorService.class})
- at Scope(Scopes.GLOBAL)
 public class NamedExecutorsFactory extends NamedComponentFactory implements AutoInstantiableFactory {
 
    @SuppressWarnings("unchecked")
@@ -28,11 +25,11 @@
       Properties props;
       try {
          if (componentName.equals(KnownComponentNames.ASYNC_NOTIFICATION_EXECUTOR)) {
-            ef = (ExecutorFactory) Util.getInstance(configuration.getGlobalConfiguration().getAsyncListenerExecutorFactoryClass());
-            props = configuration.getGlobalConfiguration().getAsyncListenerExecutorProperties();
+            ef = (ExecutorFactory) Util.getInstance(globalConfiguration.getAsyncListenerExecutorFactoryClass());
+            props = globalConfiguration.getAsyncListenerExecutorProperties();
          } else if (componentName.equals(KnownComponentNames.ASYNC_SERIALIZATION_EXECUTOR)) {
-            ef = (ExecutorFactory) Util.getInstance(configuration.getGlobalConfiguration().getAsyncSerializationExecutorFactoryClass());
-            props = configuration.getGlobalConfiguration().getAsyncSerializationExecutorProperties();
+            ef = (ExecutorFactory) Util.getInstance(globalConfiguration.getAsyncSerializationExecutorFactoryClass());
+            props = globalConfiguration.getAsyncSerializationExecutorProperties();
          } else {
             throw new ConfigurationException("Unknown named executor " + componentName);
          }

Modified: core/branches/flat/src/main/java/org/horizon/factories/RPCManagerFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/RPCManagerFactory.java	2009-01-20 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/factories/RPCManagerFactory.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -32,11 +32,11 @@
  * @since 1.0
  */
 @DefaultFactoryFor(classes = RPCManager.class)
-public class RPCManagerFactory extends EmptyConstructorFactory implements AutoInstantiableFactory {
+public class RPCManagerFactory extends EmptyConstructorNamedCacheFactory implements AutoInstantiableFactory {
    @Override
    public <T> T construct(Class<T> componentType) {
       // only do this if we have a transport configured!
-      if (configuration.getGlobalConfiguration().getTransportClass() == null) return null;
+      if (globalConfiguration.getTransportClass() == null) return null;
       return super.construct(componentType);
    }
 }

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 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/factories/ReplicationQueueFactory.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -32,7 +32,7 @@
  * @since 1.0
  */
 @DefaultFactoryFor(classes = ReplicationQueue.class)
-public class ReplicationQueueFactory extends EmptyConstructorFactory implements AutoInstantiableFactory {
+public class ReplicationQueueFactory extends EmptyConstructorNamedCacheFactory 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/StateTransferFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/StateTransferFactory.java	2009-01-20 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/factories/StateTransferFactory.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -33,7 +33,7 @@
  */
 // TODO: Implement me
 //@DefaultFactoryFor(classes = {StateTransferGenerator.class, StateTransferIntegrator.class})
-public class StateTransferFactory extends ComponentFactory implements AutoInstantiableFactory {
+public class StateTransferFactory extends AbstractComponentFactory implements AutoInstantiableFactory {
    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 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/factories/StateTransferManagerFactory.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -32,7 +32,7 @@
  * @since 1.0
  */
 @DefaultFactoryFor(classes = StateTransferManager.class)
-public class StateTransferManagerFactory extends ComponentFactory implements AutoInstantiableFactory {
+public class StateTransferManagerFactory extends AbstractComponentFactory implements AutoInstantiableFactory {
    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 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/factories/TransactionManagerFactory.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -35,7 +35,7 @@
  * @since 1.0
  */
 @DefaultFactoryFor(classes = {TransactionManager.class})
-public class TransactionManagerFactory extends ComponentFactory implements AutoInstantiableFactory {
+public class TransactionManagerFactory extends AbstractNamedCacheComponentFactory implements AutoInstantiableFactory {
    public <T> T construct(Class<T> componentType) {
       // See if we had a TransactionManager injected into our config
       TransactionManager transactionManager = configuration.getRuntimeConfig().getTransactionManager();

Modified: core/branches/flat/src/main/java/org/horizon/factories/TransportFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/TransportFactory.java	2009-01-20 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/factories/TransportFactory.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -2,8 +2,6 @@
 
 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;
 
@@ -14,12 +12,11 @@
  * @since 1.0
  */
 @DefaultFactoryFor(classes = Transport.class)
- at Scope(Scopes.GLOBAL)
-public class TransportFactory extends ComponentFactory implements AutoInstantiableFactory {
+public class TransportFactory extends AbstractComponentFactory implements AutoInstantiableFactory {
 
    @SuppressWarnings("unchecked")
    public <T> T construct(Class<T> componentType) {
-      String transportClass = configuration.getGlobalConfiguration().getTransportClass();
+      String transportClass = globalConfiguration.getTransportClass();
       try {
          if (transportClass == null) return null;
          return (T) Util.getInstance(transportClass);

Modified: core/branches/flat/src/main/java/org/horizon/jmx/JmxRegistrationManager.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/jmx/JmxRegistrationManager.java	2009-01-20 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/jmx/JmxRegistrationManager.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -161,7 +161,7 @@
 
    private List<ResourceDMBean> getResourceDMBeans() {
       List<ResourceDMBean> resourceDMBeans = new ArrayList<ResourceDMBean>();
-      for (ComponentRegistry.Component component : cacheSpi.getComponentRegistry().getRegiteredComponents()) {
+      for (ComponentRegistry.Component component : cacheSpi.getComponentRegistry().getRegisteredComponents()) {
          ResourceDMBean resourceDMBean = new ResourceDMBean(component.getInstance());
          if (resourceDMBean.isManagedResource()) {
             resourceDMBeans.add(resourceDMBean);

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 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/manager/DefaultCacheManager.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -147,6 +147,17 @@
    }
 
    /**
+    * Constructs and starts a new instance of the CacheManager, using the global and default configurations passed in.
+    * If either of these are null, system defaults are used.
+    *
+    * @param globalConfiguration  global configuration to use.  If null, a default instance is created.
+    * @param defaultConfiguration default configuration to use.  If null, a default instance is created.
+    */
+   public DefaultCacheManager(GlobalConfiguration globalConfiguration, Configuration defaultConfiguration) {
+      this(globalConfiguration, defaultConfiguration, true);
+   }
+
+   /**
     * Constructs a new instance of the CacheManager, using the global and default configurations passed in.  If either
     * of these are null, system defaults are used.
     *
@@ -315,7 +326,7 @@
    public void start() {
       // get a hold of the "default" cache to start this?
       CacheSPI defaultCache = (CacheSPI) getCache();
-      globalComponentRegistry = defaultCache.getComponentRegistry().getSharedComponentRegistry();
+      globalComponentRegistry = defaultCache.getComponentRegistry().getGlobalComponentRegistry();
    }
 
    public void stop() {

Modified: core/branches/flat/src/main/java/org/horizon/marshall/CacheMarshallerStarobrno.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/marshall/CacheMarshallerStarobrno.java	2009-01-20 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/marshall/CacheMarshallerStarobrno.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -23,9 +23,8 @@
 
 import org.horizon.CacheException;
 import org.horizon.atomic.DeltaAware;
-import org.horizon.commands.CommandsFactory;
+import org.horizon.commands.RemoteCommandFactory;
 import org.horizon.commands.ReplicableCommand;
-import org.horizon.config.Configuration;
 import org.horizon.io.ByteBuffer;
 import org.horizon.io.ExposedByteArrayOutputStream;
 import org.horizon.logging.Log;
@@ -98,15 +97,12 @@
 
    protected Log log;
    protected boolean trace;
-
-   protected Configuration configuration;
+   private RemoteCommandFactory remoteCommandFactory;
    protected ClassLoader defaultClassLoader;
    protected boolean useRefs = false;
 
-   public void init(Configuration configuration, ClassLoader defaultClassLoader, CommandsFactory commandsFactory) {
+   public void init(ClassLoader defaultClassLoader) {
       this.defaultClassLoader = defaultClassLoader;
-      this.configuration = configuration;
-      this.commandsFactory = commandsFactory;
    }
 
    protected void initLogger() {
@@ -122,8 +118,6 @@
       return bytes;
    }
 
-   protected CommandsFactory commandsFactory;
-
    protected void marshallObject(Object o, ObjectOutputStream out, Map<Object, Integer> refMap) throws Exception {
       if (o != null && o.getClass().isArray() && isKnownType(o.getClass().getComponentType())) {
          marshallArray(o, out, refMap);
@@ -395,7 +389,7 @@
          for (int i = 0; i < numArgs; i++) args[i] = unmarshallObject(in, refMap);
       }
 
-      return commandsFactory.fromStream((byte) methodId, args);
+      return remoteCommandFactory.fromStream((byte) methodId, args);
    }
 
 

Modified: core/branches/flat/src/main/java/org/horizon/marshall/Marshaller.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/marshall/Marshaller.java	2009-01-20 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/marshall/Marshaller.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -21,6 +21,8 @@
  */
 package org.horizon.marshall;
 
+import org.horizon.factories.scopes.Scope;
+import org.horizon.factories.scopes.Scopes;
 import org.horizon.io.ByteBuffer;
 
 import java.io.InputStream;
@@ -52,6 +54,7 @@
  * @author <a href="mailto://manik@jboss.org">Manik Surtani</a>
  * @since 1.0
  */
+ at Scope(Scopes.GLOBAL)
 public interface Marshaller {
    /**
     * Marshalls an object to a given {@link java.io.ObjectOutputStream}

Modified: core/branches/flat/src/main/java/org/horizon/marshall/VersionAwareMarshaller.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/marshall/VersionAwareMarshaller.java	2009-01-20 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/marshall/VersionAwareMarshaller.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -21,8 +21,6 @@
  */
 package org.horizon.marshall;
 
-import org.horizon.commands.CommandsFactory;
-import org.horizon.config.Configuration;
 import org.horizon.factories.annotations.Inject;
 import org.horizon.io.ByteBuffer;
 import org.horizon.io.ExposedByteArrayOutputStream;
@@ -54,12 +52,11 @@
    private CacheMarshallerStarobrno defaultMarshaller;
 
    ClassLoader defaultClassLoader;
-   private Configuration configuration;
 
    @Inject
-   public void init(ClassLoader loader, Configuration configuration, CommandsFactory factory) {
+   public void init(ClassLoader loader) {
       defaultMarshaller = new CacheMarshallerStarobrno();
-      defaultMarshaller.init(configuration, loader, factory);
+      defaultMarshaller.init(loader);
    }
 
    protected int getCustomMarshallerVersionInt() {

Modified: core/branches/flat/src/main/java/org/horizon/remoting/InboundInvocationHandler.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/remoting/InboundInvocationHandler.java	2009-01-20 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/remoting/InboundInvocationHandler.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -1,13 +1,17 @@
 package org.horizon.remoting;
 
 import org.horizon.commands.ReplicableCommand;
+import org.horizon.factories.scopes.Scope;
+import org.horizon.factories.scopes.Scopes;
 
 /**
- * // TODO: Manik: Document this!
+ * A globally scoped component, that is able to locate named caches and invoke remotely originating calls on the
+ * appropriate cache.
  *
  * @author Manik Surtani
  * @since 1.0
  */
+ at Scope(Scopes.GLOBAL)
 public interface InboundInvocationHandler {
 
    /**

Modified: core/branches/flat/src/main/java/org/horizon/remoting/InboundInvocationHandlerImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/remoting/InboundInvocationHandlerImpl.java	2009-01-20 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/main/java/org/horizon/remoting/InboundInvocationHandlerImpl.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -2,6 +2,7 @@
 
 import org.horizon.commands.ReplicableCommand;
 import org.horizon.factories.ComponentRegistry;
+import org.horizon.factories.GlobalComponentRegistry;
 import org.horizon.interceptors.InterceptorChain;
 import org.horizon.invocation.InvocationContextContainer;
 
@@ -15,8 +16,16 @@
    InvocationContextContainer invocationContextContainer;
    ComponentRegistry componentRegistry;
    InterceptorChain interceptorChain;
+   GlobalComponentRegistry gcr;
 
+   public void inject(GlobalComponentRegistry gcr) {
+      this.gcr = gcr;
+   }
 
+   private ComponentRegistry getNamedCacheComponentRegistry(String name) {
+      return gcr.getNamedComponentRegistry(name);
+   }
+
    public Object handle(ReplicableCommand command) {
 
       throw new RuntimeException("Implement me!");

Modified: core/branches/flat/src/test/java/org/horizon/manager/CacheManagerComponentRegistryTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/manager/CacheManagerComponentRegistryTest.java	2009-01-20 19:20:39 UTC (rev 7545)
+++ core/branches/flat/src/test/java/org/horizon/manager/CacheManagerComponentRegistryTest.java	2009-01-20 19:24:46 UTC (rev 7546)
@@ -3,6 +3,7 @@
 import org.horizon.Cache;
 import org.horizon.config.CacheLoaderConfig;
 import org.horizon.config.Configuration;
+import org.horizon.config.GlobalConfiguration;
 import org.horizon.interceptors.BatchingInterceptor;
 import org.horizon.interceptors.InterceptorChain;
 import org.horizon.loader.CacheLoaderManager;
@@ -32,8 +33,10 @@
    public void testForceSharedComponents() throws CacheNameExistsException, NamedCacheNotFoundException {
       Configuration defaultCfg = new Configuration();
       defaultCfg.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+
       // cache manager with default configuration
-      cm = new DefaultCacheManager(defaultCfg);
+      cm = new DefaultCacheManager(GlobalConfiguration.getClusteredDefault(),
+                                   defaultCfg);
 
       // default cache with no overrides
       Cache c = cm.getCache();




More information about the jbosscache-commits mailing list