Author: pete.muir(a)jboss.org
Date: 2009-07-23 16:33:52 -0400 (Thu, 23 Jul 2009)
New Revision: 3172
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/CurrentManager.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Singleton.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/IsolatedStaticSingletonProvider.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/TCCLSingletonProvider.java
ri/trunk/tests/src/main/java/org/jboss/webbeans/test/AbstractWebBeansTest.java
Log:
Clean ups to the singleton SPI (and impl) and use them in the Manager singletons
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java 2009-07-23
19:39:27 UTC (rev 3171)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java 2009-07-23
20:33:52 UTC (rev 3172)
@@ -1131,7 +1131,7 @@
applicationContext.destroy();
applicationContext.setActive(false);
applicationContext.setBeanStore(null);
- CurrentManager.cleanup();
+ CurrentManager.clear();
}
/**
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/CurrentManager.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/CurrentManager.java 2009-07-23 19:39:27
UTC (rev 3171)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/CurrentManager.java 2009-07-23 20:33:52
UTC (rev 3172)
@@ -48,10 +48,11 @@
private final static Singleton<Map<Integer, BeanManagerImpl>> managers =
SingletonProvider.instance().create(new IntegerMangerImplMap().getRawType());
- public static void cleanup()
+ public static void clear()
{
- rootManager.set(null);
managers.get().clear();
+ rootManager.clear();
+ managers.clear();
}
/**
@@ -72,7 +73,7 @@
public static void setRootManager(BeanManagerImpl managerImpl)
{
rootManager.set(managerImpl);
- if (managers.get() == null)
+ if (!managers.isSet())
{
managers.set(new ConcurrentHashMap<Integer, BeanManagerImpl>());
}
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Singleton.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Singleton.java 2009-07-23
19:39:27 UTC (rev 3171)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Singleton.java 2009-07-23
20:33:52 UTC (rev 3172)
@@ -45,8 +45,16 @@
* Access the singleton
*
* @return a singleton object
+ * @throws IllegalStateException if the singleton is not set
*/
public T get();
+
+ /**
+ * Check if the singleton is set
+ *
+ * @return true if the singleton is set
+ */
+ public boolean isSet();
/**
* Store a singleton
@@ -54,4 +62,9 @@
* @param object the object to store
*/
public void set(T object);
+
+ /**
+ * Clear the singleton
+ */
+ public void clear();
}
Modified:
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/IsolatedStaticSingletonProvider.java
===================================================================
---
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/IsolatedStaticSingletonProvider.java 2009-07-23
19:39:27 UTC (rev 3171)
+++
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/IsolatedStaticSingletonProvider.java 2009-07-23
20:33:52 UTC (rev 3172)
@@ -48,6 +48,10 @@
public T get()
{
+ if (object == null)
+ {
+ throw new IllegalStateException("Singleton is not set");
+ }
return object;
}
@@ -55,5 +59,15 @@
{
this.object = object;
}
+
+ public void clear()
+ {
+ this.object = null;
+ }
+
+ public boolean isSet()
+ {
+ return object != null;
+ }
}
}
Modified:
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/TCCLSingletonProvider.java
===================================================================
---
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/TCCLSingletonProvider.java 2009-07-23
19:39:27 UTC (rev 3171)
+++
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/TCCLSingletonProvider.java 2009-07-23
20:33:52 UTC (rev 3172)
@@ -54,13 +54,30 @@
public T get()
{
- return store.get(getClassLoader());
+ T instance = store.get(getClassLoader());
+ if (instance == null)
+ {
+ throw new IllegalStateException("Singleton not set for " +
getClassLoader());
+ }
+ return instance;
}
public void set(T object)
{
+ // TODO remove this
+ System.out.println("Adding singleton for " + getClassLoader());
store.put(getClassLoader(), object);
}
+
+ public void clear()
+ {
+ store.remove(getClassLoader());
+ }
+
+ public boolean isSet()
+ {
+ return store.containsKey(getClassLoader());
+ }
private ClassLoader getClassLoader()
{
Modified: ri/trunk/tests/src/main/java/org/jboss/webbeans/test/AbstractWebBeansTest.java
===================================================================
---
ri/trunk/tests/src/main/java/org/jboss/webbeans/test/AbstractWebBeansTest.java 2009-07-23
19:39:27 UTC (rev 3171)
+++
ri/trunk/tests/src/main/java/org/jboss/webbeans/test/AbstractWebBeansTest.java 2009-07-23
20:33:52 UTC (rev 3172)
@@ -25,8 +25,6 @@
import org.jboss.webbeans.mock.el.EL;
import org.jboss.webbeans.util.collections.EnumerationIterable;
import org.testng.ITestContext;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
public abstract class AbstractWebBeansTest extends AbstractTest
@@ -34,8 +32,6 @@
protected static final int BUILT_IN_BEANS = 3;
- private BeanManagerImpl manager;
-
public static boolean visited = false;
@Override
@@ -50,19 +46,6 @@
super.beforeSuite(context);
}
- @BeforeMethod
- public void before() throws Exception
- {
- this.manager = CurrentManager.rootManager();
- }
-
- @AfterMethod
- public void after() throws Exception
- {
- this.manager = null;
- }
-
-
/**
* Checks if all annotations are in a given set of annotations
*
@@ -135,7 +118,7 @@
protected BeanManagerImpl getCurrentManager()
{
- return manager;
+ return CurrentManager.rootManager();
}
public boolean isExceptionInHierarchy(Throwable exception, Class<? extends
Throwable> expectedException )