Skip to content

Commit

Permalink
Fix detection and handling of AroundTimeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbogoevici committed Oct 21, 2009
1 parent 54e9a85 commit 29aa6b6
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bom/pom.xml
Expand Up @@ -76,7 +76,7 @@
<javassist.version>3.11.0.GA</javassist.version>
<cdi.tck.version>1.0.0-SNAPSHOT</cdi.tck.version>
<atinject.tck.version>1.0.0-PFD-3</atinject.tck.version>
<jboss.interceptor.version>1.0.0-CR3</jboss.interceptor.version>
<jboss.interceptor.version>1.0.0-SNAPSHOT</jboss.interceptor.version>
<slf4j.version>1.5.8</slf4j.version>
</properties>

Expand Down
23 changes: 18 additions & 5 deletions impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java
Expand Up @@ -46,6 +46,7 @@
import org.jboss.weld.BeanManagerImpl;
import org.jboss.weld.DefinitionException;
import org.jboss.weld.DeploymentException;
import org.jboss.weld.ejb.EJBApiAbstraction;
import org.jboss.weld.bean.proxy.DecoratorProxyMethodHandler;
import org.jboss.weld.bootstrap.BeanDeployerEnvironment;
import org.jboss.weld.context.SerializableContextual;
Expand Down Expand Up @@ -432,7 +433,7 @@ protected void initCdiBoundInterceptors()
builder.interceptPostActivate().with(toSerializableContextualArray(resolvedPostActivateInterceptors));

}
List<WeldMethod<?, ?>> businessMethods = Beans.getInterceptableBusinessMethods(getAnnotatedItem());
List<WeldMethod<?, ?>> businessMethods = Beans.getInterceptableMethods(getAnnotatedItem());
for (WeldMethod<?, ?> method : businessMethods)
{
Set<Annotation> methodBindingAnnotations = new HashSet<Annotation>(classBindingAnnotations);
Expand All @@ -441,8 +442,17 @@ protected void initCdiBoundInterceptors()
{
if (Beans.findInterceptorBindingConflicts(manager, classBindingAnnotations))
throw new DeploymentException("Conflicting interceptor bindings found on " + getType() + "." + method.getName() + "()");
List<Interceptor<?>> methodBoundInterceptors = manager.resolveInterceptors(InterceptionType.AROUND_INVOKE, methodBindingAnnotations.toArray(new Annotation[]{}));
builder.interceptAroundInvoke(((AnnotatedMethod) method).getJavaMember()).with(toSerializableContextualArray(methodBoundInterceptors));

if (method.isAnnotationPresent(manager.getServices().get(EJBApiAbstraction.class).TIMEOUT_ANNOTATION_CLASS))
{
List<Interceptor<?>> methodBoundInterceptors = manager.resolveInterceptors(InterceptionType.AROUND_TIMEOUT, methodBindingAnnotations.toArray(new Annotation[]{}));
builder.interceptAroundTimeout(((AnnotatedMethod) method).getJavaMember()).with(toSerializableContextualArray(methodBoundInterceptors));
}
else
{
List<Interceptor<?>> methodBoundInterceptors = manager.resolveInterceptors(InterceptionType.AROUND_INVOKE, methodBindingAnnotations.toArray(new Annotation[]{}));
builder.interceptAroundInvoke(((AnnotatedMethod) method).getJavaMember()).with(toSerializableContextualArray(methodBoundInterceptors));
}
}
}
InterceptionModel<Class<?>,SerializableContextual<Interceptor<?>,?>> serializableContextualInterceptionModel = builder.build();
Expand Down Expand Up @@ -547,7 +557,7 @@ protected void initDirectlyDefinedInterceptors()
builder.interceptAll().with(classDeclaredInterceptors);
}

List<WeldMethod<?, ?>> businessMethods = Beans.getInterceptableBusinessMethods(getAnnotatedItem());
List<WeldMethod<?, ?>> businessMethods = Beans.getInterceptableMethods(getAnnotatedItem());
for (WeldMethod<?, ?> method : businessMethods)
{
boolean excludeClassInterceptors = method.isAnnotationPresent(InterceptionUtils.getExcludeClassInterceptorsAnnotationClass());
Expand All @@ -562,7 +572,10 @@ protected void initDirectlyDefinedInterceptors()
}
if (methodDeclaredInterceptors != null)
{
builder.interceptAroundInvoke(((AnnotatedMethod) method).getJavaMember()).with(methodDeclaredInterceptors);
if (method.isAnnotationPresent(manager.getServices().get(EJBApiAbstraction.class).TIMEOUT_ANNOTATION_CLASS))
builder.interceptAroundTimeout(((AnnotatedMethod) method).getJavaMember()).with(methodDeclaredInterceptors);
else
builder.interceptAroundInvoke(((AnnotatedMethod) method).getJavaMember()).with(methodDeclaredInterceptors);
}
}
InterceptionModel<Class<?>, Class<?>> interceptionModel = builder.build();
Expand Down
4 changes: 3 additions & 1 deletion impl/src/main/java/org/jboss/weld/ejb/EJBApiAbstraction.java
Expand Up @@ -36,12 +36,14 @@ public EJBApiAbstraction(ResourceLoader resourceLoader)
ENTERPRISE_BEAN_CLASS = classForName("javax.ejb.EnterpriseBean");
EJB_ANNOTATION_CLASS = annotationTypeForName("javax.ejb.EJB");
RESOURCE_ANNOTATION_CLASS = annotationTypeForName("javax.annotation.Resource");

TIMEOUT_ANNOTATION_CLASS = annotationTypeForName("javax.ejb.Timeout");
}

public final Class<?> ENTERPRISE_BEAN_CLASS;
public final Class<? extends Annotation> EJB_ANNOTATION_CLASS;
public final Class<? extends Annotation> RESOURCE_ANNOTATION_CLASS;
public final Class<? extends Annotation> TIMEOUT_ANNOTATION_CLASS;


public void cleanup() {}

Expand Down
2 changes: 1 addition & 1 deletion impl/src/main/java/org/jboss/weld/util/Beans.java
Expand Up @@ -224,7 +224,7 @@ else if (preDestroyMethods.size() == 1)
}
}

public static List<WeldMethod<?,?>> getInterceptableBusinessMethods(WeldClass<?> type)
public static List<WeldMethod<?,?>> getInterceptableMethods(WeldClass<?> type)
{
List<WeldMethod<?, ?>> annotatedMethods = new ArrayList<WeldMethod<?, ?>>();
for (WeldMethod<?, ?> annotatedMethod : type.getWeldMethods())
Expand Down
Expand Up @@ -18,11 +18,12 @@
package org.jboss.weld.test.unit.interceptor.ejb;

import javax.ejb.Stateless;
import javax.ejb.Timeout;

/**
* @author <a href="mailto:mariusb@redhat.com">Marius Bogoevici</a>
*/
@Stateless
@Stateless @TimeBound
public class BallImpl implements Ball
{
@Shot
Expand All @@ -34,4 +35,10 @@ public void shoot()
public void pass()
{
}

@Timeout
public void finishGame()
{

}
}
Expand Up @@ -32,18 +32,25 @@ public void testEnterpriseBeanInterceptionMetadataAdded() throws Exception
List<javax.enterprise.inject.spi.Interceptor> interceptors =
new ArrayList<javax.enterprise.inject.spi.Interceptor>(interceptorBindings.getAllInterceptors());

assert interceptors.size() == 2;
List<Class<?>> expectedInterceptors = Arrays.<Class<?>>asList(Goalkeeper.class, Defender.class);
assert interceptors.size() == 3;
List<Class<?>> expectedInterceptors = Arrays.<Class<?>>asList(Goalkeeper.class, Defender.class, Referee.class);
assert expectedInterceptors.contains(interceptors.get(0).getBeanClass());
assert expectedInterceptors.contains(interceptors.get(1).getBeanClass());
assert expectedInterceptors.contains(interceptors.get(2).getBeanClass());


assert interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_TIMEOUT, ballSessionBean.getType().getMethod("shoot")).size() == 0;
assert interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_INVOKE, ballSessionBean.getType().getMethod("shoot")).size() == 1;
assert interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_INVOKE, ballSessionBean.getType().getMethod("shoot")).get(0).getBeanClass().equals(Goalkeeper.class);

assert interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_TIMEOUT, ballSessionBean.getType().getMethod("pass")).size() == 0;
assert interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_INVOKE, ballSessionBean.getType().getMethod("pass")).size() == 1;
assert interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_INVOKE, ballSessionBean.getType().getMethod("pass")).get(0).getBeanClass().equals(Defender.class);

assert interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_INVOKE, ballSessionBean.getType().getMethod("finishGame")).size() == 0;
assert interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_TIMEOUT, ballSessionBean.getType().getMethod("finishGame")).size() == 1;
assert interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_TIMEOUT, ballSessionBean.getType().getMethod("finishGame")).get(0).getBeanClass().equals(Referee.class);

}

}
@@ -0,0 +1,37 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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,
* 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.
*/
package org.jboss.weld.test.unit.interceptor.ejb;

import javax.interceptor.Interceptor;
import javax.interceptor.AroundTimeout;
import javax.interceptor.InvocationContext;

/**
* @author <a href="mailto:mariusb@redhat.com">Marius Bogoevici</a>
*/
@Interceptor @TimeBound
public class Referee
{
public static boolean ballCollected = false;

@AroundTimeout
public Object collectBall(InvocationContext context) throws Exception
{
ballCollected = true;
return context.proceed();
}
}
@@ -0,0 +1,37 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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,
* 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.
*/

package org.jboss.weld.test.unit.interceptor.ejb;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
import java.lang.annotation.Documented;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import javax.interceptor.InterceptorBinding;

/**
* @author <a href="mailto:mariusb@redhat.com">Marius Bogoevici</a>
*/
@InterceptorBinding
@Retention(RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
@Documented
public @interface TimeBound
{
}
Expand Up @@ -25,7 +25,7 @@
/**
* @author Marius Bogoevici
*/
@Interceptors(Goalkeeper.class)
@Interceptors({Goalkeeper.class, Referee.class})
public class Ball
{
public static boolean played = false;
Expand Down
@@ -0,0 +1,39 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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,
* 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.
*/
package org.jboss.weld.test.unit.interceptor.ejb3model;

import org.jboss.weld.test.unit.interceptor.ejb.TimeBound;

import javax.interceptor.Interceptor;
import javax.interceptor.AroundTimeout;
import javax.interceptor.InvocationContext;

/**
* @author <a href="mailto:mariusb@redhat.com">Marius Bogoevici</a>
*/
@Interceptor @TimeBound
public class Referee
{
public static boolean ballCollected = false;

@AroundTimeout
public Object collectBall(InvocationContext context) throws Exception
{
ballCollected = true;
return context.proceed();
}
}
Expand Up @@ -2,5 +2,6 @@
<interceptors>
<class>org.jboss.weld.test.unit.interceptor.ejb.Goalkeeper</class>
<class>org.jboss.weld.test.unit.interceptor.ejb.Defender</class>
<class>org.jboss.weld.test.unit.interceptor.ejb.Referee</class>
</interceptors>
</beans>
4 changes: 4 additions & 0 deletions tests/unit-tests.xml
Expand Up @@ -52,6 +52,10 @@
<package name="org.jboss.weld.test.unit.implementation.producer.method" />
<package name="org.jboss.weld.test.unit.implementation.proxy" />
<package name="org.jboss.weld.test.unit.implementation.proxy.enterprise" />
<package name="org.jboss.weld.test.unit.interceptor.ejb" />
<package name="org.jboss.weld.test.unit.interceptor.ejb3model" />
<package name="org.jboss.weld.test.unit.interceptor.passivation" />
<package name="org.jboss.weld.test.unit.interceptor.simple" />
<package name="org.jboss.weld.test.unit.lookup" />
<package name="org.jboss.weld.test.unit.lookup.circular" />
<package name="org.jboss.weld.test.unit.lookup.wbri279" />
Expand Down

0 comments on commit 29aa6b6

Please sign in to comment.