openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1796940 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: container/BeanManagerImpl.java event/NotificationManager.java event/ObserverMethodImpl.java
Date Tue, 30 May 2017 20:44:05 GMT
Author: struberg
Date: Tue May 30 20:44:04 2017
New Revision: 1796940

URL: http://svn.apache.org/viewvc?rev=1796940&view=rev
Log:
OWB-1189 implement @Priority for events

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java?rev=1796940&r1=1796939&r2=1796940&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
Tue May 30 20:44:04 2017
@@ -25,6 +25,8 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -1280,7 +1282,14 @@ public class BeanManagerImpl implements
 
     public <T> Set<ObserverMethod<? super T>> resolveObserverMethods(T
event, EventMetadataImpl metadata)
     {
-        return notificationManager.resolveObservers(event, metadata, false);
+        LinkedList<ObserverMethod<? super Object>> observerMethods
+            = new LinkedList<>(notificationManager.resolveObservers(event, metadata,
false));
+
+        // new in CDI-2.0: sort observers
+        Collections.sort(observerMethods,
+            (ObserverMethod o1, ObserverMethod o2) -> Integer.compare(o1.getPriority(),
o2.getPriority()));
+
+        return new LinkedHashSet<>(observerMethods);
     }
 
     @Override

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java?rev=1796940&r1=1796939&r2=1796940&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
Tue May 30 20:44:04 2017
@@ -26,7 +26,9 @@ import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashSet;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -633,7 +635,12 @@ public final class NotificationManager
             throw new IllegalArgumentException("Firing container events is forbidden");
         }
 
-        Set<ObserverMethod<? super Object>> observerMethods = resolveObservers(event,
metadata, isLifecycleEvent);
+        LinkedList<ObserverMethod<? super Object>> observerMethods = new LinkedList<>(resolveObservers(event,
metadata, isLifecycleEvent));
+
+        // new in CDI-2.0: sort observers
+        Collections.sort(observerMethods,
+            (ObserverMethod o1, ObserverMethod o2) -> Integer.compare(o1.getPriority(),
o2.getPriority()));
+
 
         for (ObserverMethod<? super Object> observer : observerMethods)
         {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java?rev=1796940&r1=1796939&r2=1796940&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
Tue May 30 20:44:04 2017
@@ -32,6 +32,7 @@ import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import javax.annotation.Priority;
 import javax.enterprise.context.ContextNotActiveException;
 import javax.enterprise.context.Dependent;
 import javax.enterprise.context.spi.Context;
@@ -44,6 +45,7 @@ import javax.enterprise.inject.spi.Annot
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.EventMetadata;
 import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.ObserverMethod;
 import javax.enterprise.inject.spi.WithAnnotations;
 
 import org.apache.webbeans.component.AbstractOwbBean;
@@ -111,6 +113,8 @@ public class ObserverMethodImpl<T> imple
     
     /**\@Observes parameter*/
     private AnnotatedParameter<T> annotatedObservesParameter;
+
+    private int priority = ObserverMethod.DEFAULT_PRIORITY;
     
     private static class ObserverParams
     {
@@ -145,6 +149,13 @@ public class ObserverMethodImpl<T> imple
                 observedQualifiers.add(annotation);
             }
         }
+
+        // detect the Priority
+        Priority priorityAnn = annotatedObservesParameter.getAnnotation(Priority.class);
+        if (priorityAnn != null)
+        {
+            priority = priorityAnn.value();
+        }
         
         final OpenWebBeansEjbPlugin ejbPlugin = getWebBeansContext().getPluginLoader().getEjbPlugin();
         if (ejbPlugin != null && ejbPlugin.isNewSessionBean(bean.getBeanClass()))
@@ -178,6 +189,11 @@ public class ObserverMethodImpl<T> imple
         }
     }
 
+    @Override
+    public int getPriority()
+    {
+        return priority;
+    }
 
     /**
      * {@inheritDoc}



Mime
View raw message