Skip to content

Commit

Permalink
Upgraded observer methods to latest specification and added the @current
Browse files Browse the repository at this point in the history
 binding back to all observers

git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@2947 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
drallen committed Jul 1, 2009
1 parent 09e8670 commit 0f4bc83
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 281 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 3 additions & 8 deletions api/src/main/java/javax/enterprise/event/Notify.java
Expand Up @@ -23,6 +23,7 @@
*
* @author Gavin King
* @author Dan Allen
* @author David Allen
*/
public enum Notify
{
Expand All @@ -33,13 +34,7 @@ public enum Notify
IF_EXISTS,

/**
* Specifies that an observer method is called synchronously.
* Specifies that an observer method always receives the event notifications.
*/
SYNCHRONOUSLY,

/**
* Specifies that an observer method receives the event notifications
* asynchronously.
*/
ASYNCHRONOUSLY
ALWAYS
}
17 changes: 16 additions & 1 deletion api/src/main/java/javax/enterprise/event/Observes.java
Expand Up @@ -31,12 +31,27 @@
*
* @author Gavin King
* @author Pete Muir
* @author David Allen
*/

@Target(PARAMETER)
@Retention(RUNTIME)
@Documented
public @interface Observes
{
public Notify notifyObserver() default Notify.SYNCHRONOUSLY;
/**
* Specifies when an observer method should be notified of an event.
* Defaults to ALWAYS meaning that if a bean instance with the observer
* method does not already exist, one will be created to receive the
* event.
*/
public Notify notifyObserver() default Notify.ALWAYS;

/**
* Specifies whether or not the notification should occur as part of
* an ongoing transaction, and if so, in which phase of the transaction
* the notification should occur. The default is IN_PROGRESS meaning
* the notification is not transactional.
*/
public TransactionPhase during() default TransactionPhase.IN_PROGRESS;
}
Expand Up @@ -91,10 +91,7 @@ private void checkEventBindings(Annotation[] bindingAnnotations)
{
throw new IllegalArgumentException(annotation + " is already present in the bindings list for " + this);
}
if (!annotation.annotationType().equals(Current.class))
{
eventBindings.add(annotation);
}
eventBindings.add(annotation);
}
}

Expand Down
Expand Up @@ -16,6 +16,8 @@
*/
package org.jboss.webbeans.event;

import javax.enterprise.event.TransactionPhase;

import org.jboss.webbeans.BeanManagerImpl;
import org.jboss.webbeans.bean.RIBean;
import org.jboss.webbeans.introspector.WBMethod;
Expand All @@ -40,9 +42,10 @@ public class ObserverFactory
public static <T> ObserverImpl<T> create(WBMethod<?> method, RIBean<?> declaringBean, BeanManagerImpl manager)
{
ObserverImpl<T> result = null;
if (manager.getServices().contains(TransactionServices.class) && TransactionalObserverImpl.isObserverMethodTransactional(method))
TransactionPhase transactionPhase = TransactionalObserverImpl.getTransactionalPhase(method);
if (manager.getServices().contains(TransactionServices.class) && !transactionPhase.equals(TransactionPhase.IN_PROGRESS))
{
result = new TransactionalObserverImpl<T>(method, declaringBean, manager);
result = new TransactionalObserverImpl<T>(method, declaringBean, transactionPhase, manager);
}
else
{
Expand Down
16 changes: 1 addition & 15 deletions impl/src/main/java/org/jboss/webbeans/event/ObserverImpl.java
Expand Up @@ -56,7 +56,6 @@ public class ObserverImpl<T> implements Observer<T>
protected final RIBean<?> observerBean;
protected final MethodInjectionPoint<?> observerMethod;
private final boolean conditional;
private final boolean asynchronous;
protected BeanManagerImpl manager;
private final Type eventType;
private final Annotation[] bindings;
Expand All @@ -79,7 +78,6 @@ protected ObserverImpl(final WBMethod<?> observer, final RIBean<?> observerBean,
this.bindings = observerMethod.getAnnotatedParameters(Observes.class).get(0).getBindingsAsArray();
Observes observesAnnotation = observerMethod.getAnnotatedParameters(Observes.class).get(0).getAnnotation(Observes.class);
this.conditional = observesAnnotation.notifyObserver().equals(Notify.IF_EXISTS);
this.asynchronous = observesAnnotation.notifyObserver().equals(Notify.ASYNCHRONOUSLY);
}

/**
Expand Down Expand Up @@ -140,23 +138,11 @@ else if (type instanceof WildcardType)
throw new DefinitionException(this + " cannot be annotated with @Initializer");
}

// We cannot allow asynchronously invoked conditional observers either
if (this.asynchronous && this.conditional)
{
throw new DefinitionException(this + " cannot be annotated with both @Asynchronously and @IfExists");
}
}

public boolean notify(final T event)
{
if (this.asynchronous)
{
sendEventAsynchronously(event);
}
else
{
sendEvent(event);
}
sendEvent(event);
return false;
}

Expand Down

0 comments on commit 0f4bc83

Please sign in to comment.