[webbeans-commits] Webbeans SVN: r2772 - in ri/trunk: impl/src/main/java/org/jboss/webbeans/event and 1 other directory.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Sat Jun 6 11:33:07 EDT 2009
Author: dallen6
Date: 2009-06-06 11:33:07 -0400 (Sat, 06 Jun 2009)
New Revision: 2772
Modified:
ri/trunk/api/src/main/java/javax/event/Observer.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/event/EventImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/event/EventManager.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/event/ObserverImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/event/TransactionalObserverImpl.java
Log:
Changed signature of notify() to return boolean for event notification
Modified: ri/trunk/api/src/main/java/javax/event/Observer.java
===================================================================
--- ri/trunk/api/src/main/java/javax/event/Observer.java 2009-06-05 14:58:54 UTC (rev 2771)
+++ ri/trunk/api/src/main/java/javax/event/Observer.java 2009-06-06 15:33:07 UTC (rev 2772)
@@ -9,5 +9,5 @@
*/
public interface Observer<T>
{
- public void notify(T event);
+ public boolean notify(T event);
}
\ No newline at end of file
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/event/EventImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/event/EventImpl.java 2009-06-05 14:58:54 UTC (rev 2771)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/event/EventImpl.java 2009-06-06 15:33:07 UTC (rev 2772)
@@ -80,7 +80,7 @@
*/
public void observe(Observer<T> observer, Annotation... bindings)
{
- getManager().addObserver(observer, type, mergeInBindings(bindings));
+ getManager().addObserver(observer, mergeInBindings(bindings));
}
@Override
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/event/EventManager.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/event/EventManager.java 2009-06-05 14:58:54 UTC (rev 2771)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/event/EventManager.java 2009-06-06 15:33:07 UTC (rev 2772)
@@ -19,6 +19,8 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
+import java.lang.reflect.WildcardType;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
@@ -29,6 +31,7 @@
import org.jboss.webbeans.context.DependentContext;
import org.jboss.webbeans.log.Log;
import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.util.Reflections;
import org.jboss.webbeans.util.Reflections.HierarchyDiscovery;
/**
@@ -77,6 +80,7 @@
*/
public <T> Set<Observer<T>> getObservers(T event, Annotation... bindings)
{
+// checkEventType(event.getClass());
Set<Observer<T>> interestedObservers = new HashSet<Observer<T>>();
Set<Type> types = new HierarchyDiscovery(event.getClass()).getFlattenedTypes();
for (Type type : types)
@@ -111,7 +115,11 @@
DependentContext.instance().setActive(true);
for (Observer<T> observer : observers)
{
- observer.notify(event);
+ if (observer.notify(event))
+ {
+ // We can remove the once-only observer
+ removeObserver(observer);
+ }
}
}
finally
@@ -126,7 +134,6 @@
*
* @param observer The observer to remove
* @param eventType The event type of the observer to remove
- * @param bindings The bindings of the observer to remove
*/
public void removeObserver(Observer<?> observer)
{
@@ -144,16 +151,15 @@
buffer.append(manager.getRegisteredObservers().toString());
return buffer.toString();
}
-
- public Type getTypeOfObserver(Observer<?> observer)
- {
- for (Type type : observer.getClass().getGenericInterfaces())
- {
- if (type instanceof ParameterizedType)
- {
+ public Type getTypeOfObserver(Observer<?> observer)
+ {
+ for (Type type : observer.getClass().getGenericInterfaces())
+ {
+ if (type instanceof ParameterizedType)
+ {
ParameterizedType ptype = (ParameterizedType) type;
- if (Observer.class.isAssignableFrom((Class)ptype.getRawType()))
+ if (Observer.class.isAssignableFrom((Class<?>) ptype.getRawType()))
{
return ptype.getActualTypeArguments()[0];
}
@@ -161,5 +167,4 @@
}
throw new RuntimeException("Cannot find observer's event type: " + observer);
}
-
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/event/ObserverImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/event/ObserverImpl.java 2009-06-05 14:58:54 UTC (rev 2771)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/event/ObserverImpl.java 2009-06-06 15:33:07 UTC (rev 2772)
@@ -149,7 +149,7 @@
}
}
- public void notify(final T event)
+ public boolean notify(final T event)
{
if (this.asynchronous)
{
@@ -159,6 +159,7 @@
{
sendEvent(event);
}
+ return false;
}
/**
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/event/TransactionalObserverImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/event/TransactionalObserverImpl.java 2009-06-05 14:58:54 UTC (rev 2771)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/event/TransactionalObserverImpl.java 2009-06-06 15:33:07 UTC (rev 2772)
@@ -85,7 +85,7 @@
}
@Override
- public void notify(T event)
+ public boolean notify(T event)
{
if ((manager.getServices().get(TransactionServices.class) != null) && (manager.getServices().get(TransactionServices.class).isTransactionActive()))
{
@@ -95,6 +95,7 @@
{
sendEvent(event);
}
+ return false;
}
private void initTransactionObservationPhase()
More information about the weld-commits
mailing list