openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1796994 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: component/creation/ event/ inject/impl/ portable/
Date Wed, 31 May 2017 08:13:10 GMT
Author: struberg
Date: Wed May 31 08:13:10 2017
New Revision: 1796994

URL: http://svn.apache.org/viewvc?rev=1796994&view=rev
Log:
OWB-1189 first improvements and checks for Async Events

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BaseProducerFactory.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ObserverMethodsBuilder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeansBuilder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java?rev=1796994&r1=1796993&r2=1796994&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
Wed May 31 08:13:10 2017
@@ -19,6 +19,7 @@
 package org.apache.webbeans.component.creation;
 
 import javax.enterprise.event.Observes;
+import javax.enterprise.event.ObservesAsync;
 import javax.enterprise.inject.Disposes;
 import javax.enterprise.inject.Produces;
 import javax.enterprise.inject.spi.AnnotatedField;
@@ -116,9 +117,9 @@ public abstract class AbstractBeanBuilde
 
             for (AnnotatedParameter<?> parameter : annotatedMethod.getParameters())
             {
-                if (parameter.isAnnotationPresent(Observes.class))
+                if (parameter.isAnnotationPresent(Observes.class) || parameter.isAnnotationPresent(ObservesAsync.class))
                 {
-                    throw new WebBeansConfigurationException("This class must not have a
@Observes method " + annotatedMethod.getJavaMember());
+                    throw new WebBeansConfigurationException("This class must not have an
@Observes nor @ObservesAsync method " + annotatedMethod.getJavaMember());
                 }
             }
         }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BaseProducerFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BaseProducerFactory.java?rev=1796994&r1=1796993&r2=1796994&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BaseProducerFactory.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BaseProducerFactory.java
Wed May 31 08:13:10 2017
@@ -27,6 +27,7 @@ import org.apache.webbeans.util.ClassUti
 import org.apache.webbeans.util.GenericsUtil;
 
 import javax.enterprise.event.Observes;
+import javax.enterprise.event.ObservesAsync;
 import javax.enterprise.inject.Default;
 import javax.enterprise.inject.Disposes;
 import javax.enterprise.inject.Produces;
@@ -197,6 +198,7 @@ public abstract class BaseProducerFactor
         
         if(annotatedMethod.isAnnotationPresent(Inject.class) 
             || AnnotationUtil.hasAnnotatedMethodParameterAnnotation(annotatedMethod, Observes.class)
+            || AnnotationUtil.hasAnnotatedMethodParameterAnnotation(annotatedMethod, ObservesAsync.class)
             || annotatedMethod.isAnnotationPresent(Produces.class))
         {
             throw new WebBeansConfigurationException("Error in definining disposal method
of annotated method : " + annotatedMethod

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ObserverMethodsBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ObserverMethodsBuilder.java?rev=1796994&r1=1796993&r2=1796994&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ObserverMethodsBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ObserverMethodsBuilder.java
Wed May 31 08:13:10 2017
@@ -25,6 +25,7 @@ import java.util.Set;
 
 import javax.enterprise.context.Dependent;
 import javax.enterprise.event.Observes;
+import javax.enterprise.event.ObservesAsync;
 import javax.enterprise.event.Reception;
 import javax.enterprise.inject.Default;
 import javax.enterprise.inject.Disposes;
@@ -77,7 +78,7 @@ public class ObserverMethodsBuilder<T>
             AnnotatedParameter<?> observesParameter = null;
             for(AnnotatedParameter<?> parameter : parameters)
             {
-                if(parameter.isAnnotationPresent(Observes.class))
+                if(parameter.isAnnotationPresent(Observes.class) || parameter.isAnnotationPresent(ObservesAsync.class))
                 {
                     if (observesParameter != null)
                     {
@@ -145,8 +146,18 @@ public class ObserverMethodsBuilder<T>
         if (bean.getScope().equals(Dependent.class))
         {
             //Check Reception
+            Reception reception;
             Observes observes = annotatedParameter.getAnnotation(Observes.class);
-            Reception reception = observes.notifyObserver();
+            if (observes != null)
+            {
+                reception = observes.notifyObserver();
+            }
+            else
+            {
+                ObservesAsync observesAsync = annotatedParameter.getAnnotation(ObservesAsync.class);
+                reception = observesAsync.notifyObserver();
+            }
+
             if(reception.equals(Reception.IF_EXISTS))
             {
                 throw new WebBeansConfigurationException("Dependent Bean : " + annotatedType.getJavaClass()
+ " can not define observer method with @Receiver = IF_EXIST");

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeansBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeansBuilder.java?rev=1796994&r1=1796993&r2=1796994&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeansBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeansBuilder.java
Wed May 31 08:13:10 2017
@@ -29,6 +29,7 @@ import org.apache.webbeans.util.Asserts;
 import org.apache.webbeans.util.WebBeansUtil;
 
 import javax.enterprise.event.Observes;
+import javax.enterprise.event.ObservesAsync;
 import javax.enterprise.inject.Disposes;
 import javax.enterprise.inject.Produces;
 import javax.enterprise.inject.Specializes;
@@ -139,7 +140,8 @@ public class ProducerMethodBeansBuilder<
 
         if (annotatedMethod.isAnnotationPresent(Inject.class) || 
                 annotatedMethod.isAnnotationPresent(Disposes.class) ||  
-                annotatedMethod.isAnnotationPresent(Observes.class))
+                annotatedMethod.isAnnotationPresent(Observes.class) ||
+                annotatedMethod.isAnnotationPresent(ObservesAsync.class))
         {
             throw new WebBeansConfigurationException("Producer annotated method : " + annotatedMethod
+ " can not be annotated with"
                                                      + " @Initializer/@Destructor annotation
or has a parameter annotated with @Disposes/@Observes");

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=1796994&r1=1796993&r2=1796994&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
Wed May 31 08:13:10 2017
@@ -38,6 +38,7 @@ import javax.enterprise.context.Dependen
 import javax.enterprise.context.spi.Context;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.event.Observes;
+import javax.enterprise.event.ObservesAsync;
 import javax.enterprise.event.Reception;
 import javax.enterprise.event.TransactionPhase;
 import javax.enterprise.inject.spi.AnnotatedMethod;
@@ -115,6 +116,8 @@ public class ObserverMethodImpl<T> imple
     private AnnotatedParameter<T> annotatedObservesParameter;
 
     private int priority = ObserverMethod.DEFAULT_PRIORITY;
+
+    private boolean isAsync = false;
     
     private static class ObserverParams
     {
@@ -139,8 +142,25 @@ public class ObserverMethodImpl<T> imple
         this.annotatedObserverMethod = annotatedObserverMethod;
         observedEventType = annotatedObservesParameter.getBaseType();
         Observes observes = annotatedObservesParameter.getAnnotation(Observes.class);
-        ifExist = observes.notifyObserver() == Reception.IF_EXISTS;
-        phase = observes.during();
+
+        Class<? extends Annotation> observerAnnotation;
+
+        if (observes != null)
+        {
+            ifExist = observes.notifyObserver() == Reception.IF_EXISTS;
+            phase = observes.during();
+            observerAnnotation = Observes.class;
+        }
+        else
+        {
+            ObservesAsync observesAsync = annotatedObservesParameter.getAnnotation(ObservesAsync.class);
+            ifExist = observesAsync.notifyObserver() == Reception.IF_EXISTS;
+            phase = TransactionPhase.IN_PROGRESS;
+            observerAnnotation = ObservesAsync.class;
+
+            isAsync = true;
+        }
+
         observedQualifiers = new HashSet<Annotation>();
         for (Annotation annotation: annotatedObservesParameter.getAnnotations())
         {
@@ -167,10 +187,10 @@ public class ObserverMethodImpl<T> imple
             view = annotatedObserverMethod.getJavaMember();
         }
 
-        injectionPoints = new LinkedHashSet<InjectionPoint>();
+        injectionPoints = new LinkedHashSet<>();
         for (AnnotatedParameter<?> parameter: annotatedObserverMethod.getParameters())
         {
-            if (!parameter.isAnnotationPresent(Observes.class))
+            if (!parameter.isAnnotationPresent(observerAnnotation))
             {
                 Collection<Annotation> qualifierAnnots = getWebBeansContext().getAnnotationManager().getQualifierAnnotations(parameter.getAnnotations());
 
@@ -190,6 +210,12 @@ public class ObserverMethodImpl<T> imple
     }
 
     @Override
+    public boolean isAsync()
+    {
+        return isAsync;
+    }
+
+    @Override
     public int getPriority()
     {
         return priority;

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java?rev=1796994&r1=1796993&r2=1796994&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java
Wed May 31 08:13:10 2017
@@ -27,6 +27,7 @@ import org.apache.webbeans.util.Annotati
 import org.apache.webbeans.util.Asserts;
 
 import javax.enterprise.event.Observes;
+import javax.enterprise.event.ObservesAsync;
 import javax.enterprise.inject.Disposes;
 import javax.enterprise.inject.Produces;
 import javax.enterprise.inject.spi.AnnotatedCallable;
@@ -177,8 +178,8 @@ public class InjectionPointFactory
 
         for (AnnotatedParameter<?> parameter : parameters)
         {
-            //@Observes is not injection point type for method parameters
-            if (parameter.getAnnotation(Observes.class) == null)
+            // @Observes and @ObservesAsync are not injection point type for method parameters
+            if (parameter.getAnnotation(Observes.class) == null && parameter.getAnnotation(ObservesAsync.class)
== null)
             {
                 lists.add(buildInjectionPoint(owner, parameter, true));
             }
@@ -207,9 +208,10 @@ public class InjectionPointFactory
                 throw new WebBeansConfigurationException("Constructor parameter annotations
can not contain @Disposes annotation in annotated constructor : " + constructor);
             }
 
-            if(parameter.isAnnotationPresent(Observes.class))
+            if(parameter.isAnnotationPresent(Observes.class) || parameter.isAnnotationPresent(ObservesAsync.class))
             {
-                throw new WebBeansConfigurationException("Constructor parameter annotations
can not contain @Observes annotation in annotated constructor : " + constructor);
+                throw new WebBeansConfigurationException("Constructor parameter annotations
can not contain @Observes nor @ObservesAsync annotation in annotated constructor : "
+                                                         + constructor);
             }
         }
     }
@@ -242,11 +244,12 @@ public class InjectionPointFactory
             annotationManager.checkForNewQualifierForDeployment(annotatedParameter.getBaseType(),
annotatedMethod.getDeclaringType().getJavaClass(),
                     method.getName(), AnnotationUtil.asArray(annotatedParameter.getAnnotations()));
 
-            if(annotatedParameter.isAnnotationPresent(Disposes.class) ||
-                    annotatedParameter.isAnnotationPresent(Observes.class))
+            if (annotatedParameter.isAnnotationPresent(Disposes.class) ||
+                annotatedParameter.isAnnotationPresent(Observes.class) ||
+                annotatedParameter.isAnnotationPresent(ObservesAsync.class))
             {
                 throw new WebBeansConfigurationException("Error in defining injected methods
in annotated method : " + annotatedMethod+ 
-                ". Reason : Initializer method parameters does not contain @Observes or @Dispose
annotations.");
+                ". Reason : Initializer method parameters does not contain @Observes, @ObservesAsync
or @Dispose annotations.");
                 
             }
         }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java?rev=1796994&r1=1796993&r2=1796994&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
Wed May 31 08:13:10 2017
@@ -42,6 +42,7 @@ import org.apache.webbeans.util.Exceptio
 
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.event.Observes;
+import javax.enterprise.event.ObservesAsync;
 import javax.enterprise.inject.Disposes;
 import javax.enterprise.inject.Produces;
 import javax.enterprise.inject.spi.AnnotatedConstructor;
@@ -410,7 +411,7 @@ public class InjectionTargetImpl<T> exte
         {
             for (Annotation annotation : annotations)
             {
-                if (annotation.annotationType().equals(Observes.class))
+                if (annotation.annotationType().equals(Observes.class) || annotation.annotationType().equals(ObservesAsync.class))
                 {
                     return true;
                 }



Mime
View raw message