Skip to content

Commit

Permalink
Refactor @ifExists and @Asynchronously as Notify annotation attribute…
Browse files Browse the repository at this point in the history
…s on @observes

Update tests in the EventTest class to the 20090519 spec (actually a bit beyond that)


git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@2861 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
mojavelinux committed Jun 23, 2009
1 parent e73e2af commit 74a0d26
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 97 deletions.
38 changes: 0 additions & 38 deletions api/src/main/java/javax/event/Asynchronously.java

This file was deleted.

40 changes: 0 additions & 40 deletions api/src/main/java/javax/event/IfExists.java

This file was deleted.

28 changes: 28 additions & 0 deletions api/src/main/java/javax/event/Notify.java
@@ -0,0 +1,28 @@
package javax.event;

/**
* An enumeration that is used to declare the condition under which an
* observer method should be called. The default behavior is to
* create the bean and invoke the observer method synchronously.
*
* @author Gavin King
* @author Dan Allen
*/
public enum Notify {
/**
* Specifies that an observer method is only called if the current instance of
* the bean declaring the observer method already exists.
*/
IF_EXISTS,

/**
* Specifies that an observer method is called synchronously.
*/
SYNCHRONOUSLY,

/**
* Specifies that an observer method receives the event notifications
* asynchronously.
*/
ASYNCHRONOUSLY
}
7 changes: 4 additions & 3 deletions api/src/main/java/javax/event/Observes.java
Expand Up @@ -9,7 +9,7 @@
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
Expand All @@ -25,8 +25,8 @@
import java.lang.annotation.Target;

/**
* Specifies that a parameter of a method of a bean
* implementation class is the event parameter
* Specifies that a parameter of a method of a bean
* implementation class is the event parameter
* of an observer method.
*
* @author Gavin King
Expand All @@ -38,4 +38,5 @@
@Documented
public @interface Observes
{
public Notify notifyObserver() default Notify.SYNCHRONOUSLY;
}
12 changes: 6 additions & 6 deletions impl/src/main/java/org/jboss/webbeans/event/ObserverImpl.java
Expand Up @@ -9,7 +9,7 @@
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
Expand All @@ -27,8 +27,7 @@
import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Initializer;
import javax.enterprise.inject.Produces;
import javax.event.Asynchronously;
import javax.event.IfExists;
import javax.event.Notify;
import javax.event.Observer;
import javax.event.ObserverException;
import javax.event.Observes;
Expand Down Expand Up @@ -82,8 +81,9 @@ protected ObserverImpl(final WBMethod<?> observer, final RIBean<?> observerBean,
this.eventType = observerMethod.getAnnotatedParameters(Observes.class).get(0).getBaseType();

this.bindings = observerMethod.getAnnotatedParameters(Observes.class).get(0).getBindingsAsArray();
this.conditional = !observerMethod.getAnnotatedParameters(IfExists.class).isEmpty();
this.asynchronous = !observerMethod.getAnnotatedParameters(Asynchronously.class).isEmpty();
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 @@ -204,7 +204,7 @@ protected void sendEvent(final T event)
}

/**
* Queues the event for later execution
* Queues the event for later execution
* @param event
*/
protected void sendEventAsynchronously(final T event)
Expand Down
Expand Up @@ -9,7 +9,7 @@
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
Expand All @@ -22,8 +22,9 @@
import javax.event.AfterTransactionCompletion;
import javax.event.AfterTransactionFailure;
import javax.event.AfterTransactionSuccess;
import javax.event.Asynchronously;
import javax.event.BeforeTransactionCompletion;
import javax.event.Notify;
import javax.event.Observes;
import javax.transaction.Synchronization;

import org.jboss.webbeans.BeanManagerImpl;
Expand Down Expand Up @@ -104,9 +105,9 @@ private void initTransactionObservationPhase()
if (!observerMethod.getAnnotatedParameters(BeforeTransactionCompletion.class).isEmpty())
{
observationPhases.add(TransactionObservationPhase.BEFORE_COMPLETION);
if (!observerMethod.getAnnotatedParameters(Asynchronously.class).isEmpty())
if (observerMethod.getAnnotatedParameters(Observes.class).get(0).getAnnotation(Observes.class).notifyObserver().equals(Notify.ASYNCHRONOUSLY))
{
throw new DefinitionException("@BeforeTransactionCompletion cannot be used with @Asynchronously on " + observerMethod);
throw new DefinitionException("@BeforeTransactionCompletion cannot be used on an asynchronous observer on " + observerMethod);
}
}
if (!observerMethod.getAnnotatedParameters(AfterTransactionCompletion.class).isEmpty())
Expand Down Expand Up @@ -144,7 +145,7 @@ else if (observationPhases.size() == 1)
private void deferEvent(T event)
{
DeferredEventNotification<T> deferredEvent = null;
if (this.observerMethod.getAnnotatedParameters(Asynchronously.class).isEmpty())
if (this.observerMethod.getAnnotatedParameters(Observes.class).get(0).getAnnotation(Observes.class).notifyObserver().equals(Notify.ASYNCHRONOUSLY))
{
deferredEvent = new DeferredEventNotification<T>(event, this);
}
Expand Down
Expand Up @@ -9,7 +9,7 @@
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
Expand All @@ -28,9 +28,7 @@
import javax.event.AfterTransactionCompletion;
import javax.event.AfterTransactionFailure;
import javax.event.AfterTransactionSuccess;
import javax.event.Asynchronously;
import javax.event.BeforeTransactionCompletion;
import javax.event.IfExists;
import javax.event.Observes;

/**
Expand All @@ -43,7 +41,7 @@
public interface WBMethod<T> extends WBMember<T, Method>
{
@SuppressWarnings("unchecked")
public static final Set<Class<? extends Annotation>> MAPPED_PARAMETER_ANNOTATIONS = new HashSet<Class<? extends Annotation>>(Arrays.asList(Disposes.class, Observes.class, IfExists.class, BeforeTransactionCompletion.class, AfterTransactionCompletion.class, AfterTransactionFailure.class, AfterTransactionSuccess.class, Asynchronously.class, Disposes.class));
public static final Set<Class<? extends Annotation>> MAPPED_PARAMETER_ANNOTATIONS = new HashSet<Class<? extends Annotation>>(Arrays.asList(Disposes.class, Observes.class, BeforeTransactionCompletion.class, AfterTransactionCompletion.class, AfterTransactionFailure.class, AfterTransactionSuccess.class, Disposes.class));

/**
* Gets the abstracted parameters of the method
Expand Down Expand Up @@ -77,7 +75,7 @@ public interface WBMethod<T> extends WBMember<T, Method>
public T invoke(Object instance, Object... parameters) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException;

/**
* Invokes the method on the class of the passed instance, not the declaring
* Invokes the method on the class of the passed instance, not the declaring
* class. Useful with proxies
*
* @param instance The instance to invoke
Expand Down

0 comments on commit 74a0d26

Please sign in to comment.