[jbosscache-commits] JBoss Cache SVN: r5102 - core/trunk/src/main/java/org/jboss/cache/factories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Tue Jan 8 19:45:11 EST 2008


Author: manik.surtani at jboss.com
Date: 2008-01-08 19:45:11 -0500 (Tue, 08 Jan 2008)
New Revision: 5102

Modified:
   core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
Log:
Fixed proper bootstrapping after a reset

Modified: core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java	2008-01-08 22:57:05 UTC (rev 5101)
+++ core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java	2008-01-09 00:45:11 UTC (rev 5102)
@@ -75,6 +75,7 @@
    Map<Class, Class<? extends ComponentFactory>> defaultFactories = null;
 
    private static Log log = LogFactory.getLog(ComponentRegistry.class);
+   private Bootstrap bootstrap;
 
    /**
     * Creates an instance of the component registry.  The configuration passed in is automatically registered.
@@ -560,13 +561,8 @@
       conf.changeState(CONSTRUCTED);
       cr.changeState(CONSTRUCTED);
 
-      componentLookup.put(Configuration.class.getName(), conf);
-      componentLookup.put(ComponentRegistry.class.getName(), cr);
-      componentLookup.put(CacheImpl.class.getName(), impl);
-      componentLookup.put(CacheSPI.class.getName(), spi);
+      bootstrap = new Bootstrap((CacheImpl) impl.instance, (CacheSPI) spi.instance, (ComponentRegistry) cr.instance, (Configuration) conf.instance);
 
-      spi.changeState(WIRED);
-
       overallState = null;
    }
 
@@ -591,15 +587,20 @@
     */
    public void wire()
    {
+      if (bootstrap != null && !bootstrap.isBootstrapped())
+      {
+         bootstrap.bootstrap();
+      }
+
       moveComponentsToState(WIRED);
    }
 
    void moveComponentsToState(State state)
    {
-      if (overallState == null)
+      if (overallState == null && bootstrap != null && !bootstrap.isBootstrapped())
       {
          // we have been destroyed!  Need to bootstrap again.
-         bootstrap();
+         bootstrap.bootstrap();
       }
 
       for (Component c : componentLookup.values())
@@ -610,22 +611,6 @@
    }
 
    /**
-    * Always assumes that the 4 core bootstrap components are in the registry. Will now attempt to make sure their dependencies are built.
-    */
-   void bootstrap()
-   {
-      // the bootstrap classes
-      Component spi = componentLookup.get(CacheSPI.class.getName());
-      Component impl = componentLookup.get(CacheImpl.class.getName());
-      Component conf = componentLookup.get(Configuration.class.getName());
-      Component cr = componentLookup.get(ComponentRegistry.class.getName());
-      addComponentDependencies(spi, true);
-      addComponentDependencies(impl, true);
-      addComponentDependencies(conf, true);
-      addComponentDependencies(cr, true);
-   }
-
-   /**
     * Represents the state of a component
     */
    enum State
@@ -797,10 +782,6 @@
                      // of we are "moving up" - only do this if the component is lower than what is needed.
                      if ((increase && newState.isGreaterThan(c.state)) || (!increase && newState.isLessThan(c.state)))
                      {
-                        if (c.name.endsWith("CacheLoaderManager"))
-                        {
-                           boolean itrue = true;
-                        }
                         c.changeState(newState);
                      }
 
@@ -911,4 +892,37 @@
          return "Component (name = " + name + ", state = " + state + ")";
       }
    }
+
+   class Bootstrap
+   {
+      CacheImpl cacheImpl;
+      CacheSPI cacheSPI;
+      ComponentRegistry componentRegistry;
+      Configuration configuration;
+
+      Bootstrap(CacheImpl cacheImpl, CacheSPI cacheSPI, ComponentRegistry componentRegistry, Configuration configuration)
+      {
+         this.cacheImpl = cacheImpl;
+         this.cacheSPI = cacheSPI;
+         this.componentRegistry = componentRegistry;
+         this.configuration = configuration;
+      }
+
+      boolean isBootstrapped()
+      {
+         return componentLookup.containsKey(Configuration.class.getName()) &&
+               componentLookup.containsKey(CacheImpl.class.getName()) &&
+               componentLookup.containsKey(CacheSPI.class.getName()) &&
+               componentLookup.containsKey(ComponentRegistry.class.getName());
+      }
+
+      void bootstrap()
+      {
+         overallState = CONSTRUCTED;
+         registerComponent(Configuration.class.getName(), configuration, Configuration.class);
+         registerComponent(ComponentRegistry.class.getName(), componentRegistry, ComponentRegistry.class);
+         registerComponent(CacheImpl.class.getName(), cacheImpl, CacheImpl.class);
+         registerComponent(CacheSPI.class.getName(), cacheSPI, CacheSPI.class);
+      }
+   }
 }
\ No newline at end of file




More information about the jbosscache-commits mailing list