Author: dallen6
Date: 2008-12-18 17:53:04 -0500 (Thu, 18 Dec 2008)
New Revision: 555
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/ObserverImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ConcurrentCache.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBusTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/RecluseSpider.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/invalid/Greyhound.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/invalid/Husky.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/invalid/IrishTerrier.java
Log:
Fixed @Singleton compile errors and conditional observers
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-12-18
20:46:57 UTC (rev 554)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-12-18
22:53:04 UTC (rev 555)
@@ -450,7 +450,7 @@
{
if (MetaDataCache.instance().getScopeModel(bean.getScopeType()).isNormal())
{
- return (T) proxyPool.getClientProxy(bean);
+ return (T) proxyPool.getClientProxy(bean, true);
}
else
{
@@ -502,7 +502,14 @@
public <T> T getMostSpecializedInstance(Bean<T> bean, boolean create)
{
// TODO Implement specialization
- return getInstance(bean);
+ if (MetaDataCache.instance().getScopeModel(bean.getScopeType()).isNormal())
+ {
+ return (T) proxyPool.getClientProxy(bean, create);
+ }
+ else
+ {
+ return getContext(bean.getScopeType()).get(bean, create);
+ }
}
/**
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java 2008-12-18
20:46:57 UTC (rev 554)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java 2008-12-18
22:53:04 UTC (rev 555)
@@ -139,27 +139,37 @@
* Gets a client proxy for a bean
*
* Looks for a proxy in the pool. If not found, one is created and added to
- * the pool
+ * the pool if the create argument is true.
*
- * @param bean
- * @return
+ * @param bean The bean to get a proxy to
+ * @param create Flag indicating if the proxy should be created if it does
+ * not already exist
+ * @return the client proxy for the bean
*/
- public <T> T getClientProxy(final Bean<T> bean)
+ @SuppressWarnings("unchecked")
+ public <T> T getClientProxy(final Bean<T> bean, boolean create)
{
- return pool.putIfAbsent(bean, new Callable<T>()
+ if (create)
{
+ return pool.putIfAbsent(bean, new Callable<T>()
+ {
- public T call() throws Exception
- {
- int beanIndex = CurrentManager.rootManager().getBeans().indexOf(bean);
- if (beanIndex < 0)
+ public T call() throws Exception
{
- throw new DefinitionException(bean + " is not known to the
manager");
+ int beanIndex = CurrentManager.rootManager().getBeans().indexOf(bean);
+ if (beanIndex < 0)
+ {
+ throw new DefinitionException(bean + " is not known to the
manager");
+ }
+ return createClientProxy(bean, beanIndex);
}
- return createClientProxy(bean, beanIndex);
- }
-
- });
+
+ });
+ }
+ else
+ {
+ return (T)pool.getValue(bean);
+ }
}
/**
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java 2008-12-18
20:46:57 UTC (rev 554)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java 2008-12-18
22:53:04 UTC (rev 555)
@@ -221,7 +221,7 @@
DependentContext.INSTANCE.setActive(true);
for (Observer<T> observer : observers)
{
- if (isTransactionActive() && ((ObserverImpl<?>)
observer).isTransactional())
+ if ((observer instanceof ObserverImpl) && isTransactionActive()
&& ((ObserverImpl<?>) observer).isTransactional())
{
deferEvent(event, observer);
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/ObserverImpl.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/ObserverImpl.java 2008-12-18
20:46:57 UTC (rev 554)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/ObserverImpl.java 2008-12-18
22:53:04 UTC (rev 555)
@@ -166,7 +166,7 @@
public void notify(final T event)
{
// Get the most specialized instance of the component
- Object instance = getInstance(isConditional());
+ Object instance = getInstance(!isConditional());
if (instance != null)
{
try
@@ -195,14 +195,14 @@
* Uses the container to retrieve the most specialized instance of this
* observer.
*
- * @param conditional T
+ * @param create True if the instance should be created if not already done
*
* @return the most specialized instance
*/
- protected Object getInstance(boolean conditional)
+ protected Object getInstance(boolean create)
{
// Return the most specialized instance of the component
- return manager.getMostSpecializedInstance(eventBean, conditional);
+ return manager.getMostSpecializedInstance(eventBean, create);
}
/**
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ConcurrentCache.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ConcurrentCache.java 2008-12-18
20:46:57 UTC (rev 554)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ConcurrentCache.java 2008-12-18
22:53:04 UTC (rev 555)
@@ -57,7 +57,7 @@
{
return (Future<T>) super.get(key);
}
-
+
/**
* Gets a value from the map. Blocks until it is available
*
@@ -68,34 +68,42 @@
public <T extends V> T getValue(K key)
{
Future<T> value = (Future<T>) map.get(key);
- boolean interrupted = false;
- try
+ if (value != null)
{
- while (true)
+ boolean interrupted = false;
+ try
{
- try
+ while (true)
{
- return value.get();
+ try
+ {
+ return value.get();
+ }
+ catch (InterruptedException e)
+ {
+ interrupted = true;
+ }
+ catch (ExecutionException e)
+ {
+ rethrow(e);
+ }
+ ;
}
- catch (InterruptedException e)
+ }
+ finally
+ {
+ if (interrupted)
{
- interrupted = true;
+ Thread.currentThread().interrupt();
}
- catch (ExecutionException e)
- {
- rethrow(e);
- };
}
}
- finally
+ else
{
- if (interrupted)
- {
- Thread.currentThread().interrupt();
- }
+ return null;
}
}
-
+
/**
* Adds an item to the map if it's not already there
@@ -130,7 +138,8 @@
catch (ExecutionException e)
{
rethrow(e);
- };
+ }
+ ;
}
}
finally
@@ -152,7 +161,7 @@
{
return map;
}
-
+
/**
* Examines and re-throws an exception
*
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBusTest.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBusTest.java 2008-12-18
20:46:57 UTC (rev 554)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBusTest.java 2008-12-18
22:53:04 UTC (rev 555)
@@ -11,7 +11,6 @@
import javax.webbeans.TypeLiteral;
import javax.webbeans.manager.Bean;
-import org.jboss.webbeans.bindings.InitializedBinding;
import org.jboss.webbeans.contexts.DependentContext;
import org.jboss.webbeans.test.beans.AuroraFinch;
import org.jboss.webbeans.test.beans.BananaSpider;
@@ -463,10 +462,8 @@
/**
* Tests that a conditional observer is not notified of events until after it
* is created by some other separate action.
- *
- * This test will not be supported till after Alpha 1 of the RI.
*/
- @Test(groups = { "broken", "events" })
+ @Test(groups = { "events" })
@SpecAssertion(section = "8.5.5")
public void testConditionalObserver()
{
@@ -475,6 +472,21 @@
manager.fireEvent("New string event");
// Should not be notified since bean is not instantiated yet
assert !RecluseSpider.notified;
+
+ // Now instantiate the bean and fire another event
+ try
+ {
+ DependentContext.INSTANCE.setActive(true);
+ RecluseSpider bean = manager.getInstanceByType(RecluseSpider.class);
+ assert bean != null;
+
+ manager.fireEvent("Another event");
+ assert RecluseSpider.notified;
+ }
+ finally
+ {
+ DependentContext.INSTANCE.setActive(false);
+ }
}
@Test(groups = { "stub", "events" })
@@ -818,130 +830,130 @@
}
}
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "8.6")
- public void testImplicitObserverBeanMatchesAPITypeOfInectionPoint()
- {
- assert false;
- }
+// @Test(groups = { "stub", "events" })
+// @SpecAssertion(section = "8.6")
+// public void testImplicitObserverBeanMatchesAPITypeOfInectionPoint()
+// {
+// assert false;
+// }
+//
+// @Test(groups = { "stub", "events" })
+// @SpecAssertion(section = "8.6")
+// public void testImplicitObserverBeanMatchesBindingAnnotationsOfInjectionPoint()
+// {
+// assert false;
+// }
+//
+// @Test(groups = { "stub", "events" })
+// @SpecAssertion(section = "8.6")
+// public void testImplicitObserverBeanHasStandardDeploymentType()
+// {
+// assert false;
+// }
+//
+// @Test(groups = { "stub", "events" })
+// @SpecAssertion(section = "8.6")
+// public void testImplicitObserverBeanHasDependentScope()
+// {
+// assert false;
+// }
+//
+// @Test(groups = { "stub", "events" })
+// @SpecAssertion(section = "8.6")
+// public void testFireMethodCallsManagerFireWithEventObject()
+// {
+// assert false;
+// }
+//
+// @Test(groups = { "stub", "events" })
+// @SpecAssertion(section = "8.6")
+// public void testFireMethodCallsManagerFireWithBindingAnnotationsExceptObservable()
+// {
+// assert false;
+// }
+//
+// @Test(groups = { "stub", "events" })
+// @SpecAssertion(section = "8.6")
+// public void testFireMethodCallsManagerFireWithAllBindingAnnotationInstances()
+// {
+// assert false;
+// }
+//
+// @Test(groups = { "stub", "events" })
+// @SpecAssertion(section = "8.6")
+// public void testObserveMethodCallsManagerAddObserverWithObserverObject()
+// {
+// assert false;
+// }
+//
+// @Test(groups = { "stub", "events" })
+// @SpecAssertion(section = "8.6")
+// public void
testObserveMethodCallsManagerAddObserverWithAllBindingAnnotationsExceptObservable()
+// {
+// assert false;
+// }
+//
+// @Test(groups = { "stub", "events" })
+// @SpecAssertion(section = "8.6")
+// public void
testObserveMethodCallsManagerAddObserverWithAllBindingAnnotationInstance()
+// {
+// assert false;
+// }
+//
+// @Test(groups = { "stub", "events" })
+// @SpecAssertion(section = "8.7")
+// public void testEventObjectContainsTypeVariablesWhenResolvingFails()
+// {
+// assert false;
+// }
+//
+// @Test(groups = { "stub", "events" })
+// @SpecAssertion(section = "8.7")
+// public void testEventObjectContainsWildcardsWhenResolvingFails()
+// {
+// assert false;
+// }
+//
+// @Test(groups = { "stub", "events" })
+// @SpecAssertion(section = "8.7")
+// public void testDuplicateBindingTypesWhenResolvingFails()
+// {
+// assert false;
+// }
+//
+// @Test(groups = { "stub", "events" })
+// @SpecAssertion(section = "8.7")
+// public void testNonBindingTypeAnnotationWhenResolvingFails()
+// {
+// assert false;
+// }
+//
+// @Test(groups = { "stub", "events" })
+// @SpecAssertion(section = "8.7")
+// public void testResolvingChecksEventType()
+// {
+// assert false;
+// }
+//
+// @Test(groups = { "stub", "events" })
+// @SpecAssertion(section = "8.7")
+// public void testResolvingChecksTypeParameters()
+// {
+// assert false;
+// }
+//
+// @Test(groups = { "stub", "events" })
+// @SpecAssertion(section = "8.7")
+// public void testResolvingChecksBindingTypes()
+// {
+// assert false;
+// }
+//
+// @Test(groups = { "stub", "events" })
+// @SpecAssertion(section = "8.7")
+// public void testResolvingChecksBindingTypeMembers()
+// {
+// assert false;
+// }
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "8.6")
- public void testImplicitObserverBeanMatchesBindingAnnotationsOfInjectionPoint()
- {
- assert false;
- }
-
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "8.6")
- public void testImplicitObserverBeanHasStandardDeploymentType()
- {
- assert false;
- }
-
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "8.6")
- public void testImplicitObserverBeanHasDependentScope()
- {
- assert false;
- }
-
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "8.6")
- public void testFireMethodCallsManagerFireWithEventObject()
- {
- assert false;
- }
-
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "8.6")
- public void testFireMethodCallsManagerFireWithBindingAnnotationsExceptObservable()
- {
- assert false;
- }
-
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "8.6")
- public void testFireMethodCallsManagerFireWithAllBindingAnnotationInstances()
- {
- assert false;
- }
-
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "8.6")
- public void testObserveMethodCallsManagerAddObserverWithObserverObject()
- {
- assert false;
- }
-
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "8.6")
- public void
testObserveMethodCallsManagerAddObserverWithAllBindingAnnotationsExceptObservable()
- {
- assert false;
- }
-
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "8.6")
- public void
testObserveMethodCallsManagerAddObserverWithAllBindingAnnotationInstance()
- {
- assert false;
- }
-
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "8.7")
- public void testEventObjectContainsTypeVariablesWhenResolvingFails()
- {
- assert false;
- }
-
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "8.7")
- public void testEventObjectContainsWildcardsWhenResolvingFails()
- {
- assert false;
- }
-
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "8.7")
- public void testDuplicateBindingTypesWhenResolvingFails()
- {
- assert false;
- }
-
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "8.7")
- public void testNonBindingTypeAnnotationWhenResolvingFails()
- {
- assert false;
- }
-
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "8.7")
- public void testResolvingChecksEventType()
- {
- assert false;
- }
-
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "8.7")
- public void testResolvingChecksTypeParameters()
- {
- assert false;
- }
-
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "8.7")
- public void testResolvingChecksBindingTypes()
- {
- assert false;
- }
-
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "8.7")
- public void testResolvingChecksBindingTypeMembers()
- {
- assert false;
- }
-
}
Modified:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/RecluseSpider.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/RecluseSpider.java 2008-12-18
20:46:57 UTC (rev 554)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/RecluseSpider.java 2008-12-18
22:53:04 UTC (rev 555)
@@ -2,11 +2,13 @@
import javax.webbeans.IfExists;
import javax.webbeans.Observes;
+import javax.webbeans.RequestScoped;
/**
* Simple web bean that conditionally listens to events.
*
*/
+@RequestScoped
public class RecluseSpider
{
public static boolean notified = false;
Modified:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/invalid/Greyhound.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/invalid/Greyhound.java 2008-12-18
20:46:57 UTC (rev 554)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/invalid/Greyhound.java 2008-12-18
22:53:04 UTC (rev 555)
@@ -1,8 +1,9 @@
package org.jboss.webbeans.test.ejb.invalid;
-import javax.ejb.Singleton;
import javax.webbeans.RequestScoped;
+import org.jboss.webbeans.test.annotations.Singleton;
+
@Singleton
@RequestScoped
public class Greyhound
Modified:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/invalid/Husky.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/invalid/Husky.java 2008-12-18
20:46:57 UTC (rev 554)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/invalid/Husky.java 2008-12-18
22:53:04 UTC (rev 555)
@@ -1,9 +1,10 @@
package org.jboss.webbeans.test.ejb.invalid;
-import javax.ejb.Singleton;
import javax.webbeans.ConversationScoped;
+import org.jboss.webbeans.test.annotations.Singleton;
+
@Singleton
@ConversationScoped
public class Husky
Modified:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/invalid/IrishTerrier.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/invalid/IrishTerrier.java 2008-12-18
20:46:57 UTC (rev 554)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/invalid/IrishTerrier.java 2008-12-18
22:53:04 UTC (rev 555)
@@ -1,8 +1,9 @@
package org.jboss.webbeans.test.ejb.invalid;
-import javax.ejb.Singleton;
import javax.webbeans.SessionScoped;
+import org.jboss.webbeans.test.annotations.Singleton;
+
@Singleton
@SessionScoped
public class IrishTerrier