Skip to content

Commit

Permalink
Removed async behavior, didn't work as expected. Added in support for…
Browse files Browse the repository at this point in the history
… changing @Inject point to use Routing literals.  Added new test case to verify behavior.  Reduced logging levels.
  • Loading branch information
johnament committed Mar 14, 2011
1 parent 677befa commit 3d743ac
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@ target
.project
.settings
*.sw?
transaction.log
4 changes: 2 additions & 2 deletions api/src/main/java/org/jboss/seam/jms/annotations/Routing.java
Expand Up @@ -16,7 +16,7 @@
*/
package org.jboss.seam.jms.annotations;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
Expand All @@ -28,7 +28,7 @@
*/
@Qualifier
@Retention(RUNTIME)
@Target({METHOD})
@Target( { FIELD, METHOD, TYPE, PARAMETER })
public @interface Routing {
public RouteType value();
}
5 changes: 5 additions & 0 deletions api/src/main/java/org/jboss/seam/jms/bridge/RouteType.java
Expand Up @@ -38,5 +38,10 @@ public enum RouteType
*/
EGRESS,

/**
* This shouldn't be used with Routes developed, but instead with interfaces.
* Represents a route that will be generated that has both Egress and Ingress
* capabilities.
*/
BOTH;
}
12 changes: 6 additions & 6 deletions impl/src/main/java/org/jboss/seam/jms/Seam3JmsExtension.java
Expand Up @@ -73,7 +73,7 @@ public Seam3JmsExtension() {
private boolean readyToRoute = false;

public void buildRoutes(@Observes final AfterBeanDiscovery abd, final BeanManager bm) {
log.info("Building JMS Routes.");
log.debug("Building JMS Routes.");
for (AnnotatedMethod<?> m : eventRoutingRegistry) {
Type beanType = m.getDeclaringType().getBaseType();
Set<Bean<?>> configBeans = bm.getBeans(beanType);
Expand Down Expand Up @@ -172,16 +172,16 @@ public void registerRouteCollectionProducer(@Observes ProcessProducer<?, ? exten
}

public void setBeanManager(BeanManager beanManager) {
log.info("Handling AfterDeploymentValidation, loading active bean manager into all beans.");
log.debug("Handling AfterDeploymentValidation, loading active bean manager into all beans.");
if(!this.readyToRoute) {
for(EgressRoutingObserver ero : this.observerMethods) {
log.info("Setting observer method beanmanager. "+beanManager);
log.debug("Setting observer method beanmanager. "+beanManager);
ero.setBeanManager(beanManager);
}
this.readyToRoute = true;
}
log.info("EgressRoutingObservers: "+this.observerMethods);
log.info("Ingress routes: "+this.ingressRoutes);
log.debug("EgressRoutingObservers: "+this.observerMethods);
log.debug("Ingress routes: "+this.ingressRoutes);
}

public boolean isReadyToRoute() {
Expand Down Expand Up @@ -239,7 +239,7 @@ private boolean registerRouteProducer(AnnotatedMember<?> m) {

private static Set<Annotation> getQualifiersFrom(Set<Annotation> annotations) {
Set<Annotation> q = new HashSet<Annotation>();
log.info("Annotations in getQualifiersFrom: "+annotations);
log.debug("Annotations in getQualifiersFrom: "+annotations);
for (Annotation a : annotations) {
if (a.annotationType().isAnnotationPresent(Qualifier.class)) {
q.add(a);
Expand Down
@@ -0,0 +1,46 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, 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.seam.jms.annotations;

import javax.enterprise.util.AnnotationLiteral;

import org.jboss.seam.jms.bridge.RouteType;

/**RoutingLiteral - literal implementation of the Routing qualifier.
*
* provides two static members, representing EGRESS and INGRESS.
*
* @author johnament
*
*/
public class RoutingLiteral extends AnnotationLiteral<Routing> implements Routing {
private RouteType routeType;

public static final Routing EGRESS = new RoutingLiteral(RouteType.EGRESS);
public static final Routing INGRESS = new RoutingLiteral(RouteType.INGRESS);

public RoutingLiteral(RouteType routeType) {
this.routeType = routeType;
}

@Override
public RouteType value() {
// TODO Auto-generated method stub
return routeType;
}

}
Expand Up @@ -46,6 +46,7 @@
import org.jboss.seam.jms.Seam3JmsExtension;
import org.jboss.seam.solder.bean.ImmutableInjectionPoint;
import org.jboss.seam.solder.literal.DefaultLiteral;
import static org.jboss.seam.jms.annotations.RoutingLiteral.EGRESS;

/**
* Forwards CDI events that match the provided {@link Route} configuration to
Expand Down Expand Up @@ -84,14 +85,10 @@ public Class<?> getBeanClass() {
}

public Set<Annotation> getObservedQualifiers() {
log.debugf("Inidicating that i observe these qualifiers: [%s]",routing.getQualifiers());
Set<Annotation> as = routing.getQualifiers();
if(as.isEmpty()) {
Set<Annotation> a = new HashSet<Annotation>();
//a.add(new DefaultLiteral());
log.debug("Return empty set, no qualifiers found.");
return a;
}
Set<Annotation> as = new HashSet<Annotation>();
as.addAll(routing.getQualifiers());
as.add(EGRESS);
log.debugf("Inidicating that I observe these qualifiers: [%s]",as);
return routing.getQualifiers();
}

Expand Down
Expand Up @@ -21,13 +21,12 @@
import java.util.HashSet;
import java.util.Set;
import javax.enterprise.inject.spi.BeanManager;
import javax.inject.Inject;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import org.jboss.logging.Logger;
import org.jboss.seam.jms.annotations.AsyncLiteral;
import static org.jboss.seam.jms.annotations.RoutingLiteral.INGRESS;

/**
*
Expand All @@ -53,7 +52,7 @@ public void setRoute(Route route) {
if (!route.getQualifiers().isEmpty()) {
annotations.addAll(route.getQualifiers());
}
annotations.add(new AsyncLiteral());
annotations.add(INGRESS);
logger.info("Qualifiers: "+annotations);
this.qualifiers = annotations.toArray(new Annotation[]{});
}
Expand All @@ -75,17 +74,12 @@ public void onMessage(Message msg) {
ObjectMessage om = (ObjectMessage) msg;
try {
Serializable data = (Serializable)om.getObject();
logger.info(" data was: " + om.getObject()+" of type "+data.getClass().getCanonicalName());
//if(qualifiers == null) {
//BeanManager beanManager = Utils.lookupBM();
logger.info("data was: " + om.getObject()+" of type "+data.getClass().getCanonicalName());
try {
beanManager.fireEvent(data);
beanManager.fireEvent(data,getAnnotations());
} catch (Exception e) {
logger.error("Unable to fire event", e);
}
/*} else {
beanManager.fireEvent(data, qualifiers);
}*/
} catch (JMSException ex) {
logger.warn("Unable to read data in message " + msg);
}
Expand Down
1 change: 0 additions & 1 deletion impl/src/test/java/org/jboss/seam/jms/test/Util.java
Expand Up @@ -47,7 +47,6 @@ public static Archive<?> createDeployment(Class<?>... classes)
ejbModule.addPackage(JmsAnnotatedTypeWrapper.class.getPackage());
ejbModule.addPackage(Route.class.getPackage());
ejbModule.addClasses(IngressInterfaceProducer.class);
ejbModule.addClasses(DefaultLiteral.class,DefaultBean.class);
ejbModule.addManifestResource(EmptyAsset.INSTANCE, "beans.xml");
ejbModule.addServiceProvider(Extension.class, Seam3JmsExtension.class);
for (Class<?> c : classes)
Expand Down
@@ -0,0 +1,49 @@
package org.jboss.seam.jms.test.bridge.intf;

import javax.enterprise.event.Event;
import javax.enterprise.event.Observes;
import javax.inject.Inject;

import junit.framework.Assert;

import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.seam.jms.annotations.Routing;
import org.jboss.seam.jms.bridge.RouteBuilder;
import org.jboss.seam.jms.bridge.RouteType;
import org.jboss.seam.jms.impl.inject.ConnectionProducer;
import org.jboss.seam.jms.impl.inject.DestinationProducer;
import org.jboss.seam.jms.impl.inject.MessagePubSubProducer;
import org.jboss.seam.jms.test.Util;
import org.jboss.seam.solder.bean.ImmutableInjectionPoint;
import org.jboss.shrinkwrap.api.Archive;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(Arquillian.class)
public class BidirectionalTest {

@Deployment
public static Archive<?> createDeployment() {
return Util.createDeployment(ObserverInterface.class, ImmutableInjectionPoint.class,
DestinationProducer.class, MessagePubSubProducer.class,
RouteBuilder.class, ConnectionProducer.class);
}

@Inject @Routing(RouteType.EGRESS)
Event<Double> doubleEvent;
@Inject RouteBuilder builder;

private static boolean received = false;

@Test
public void testSendingAndReceiving() throws Exception {
doubleEvent.fire(7.08);
Thread.sleep(7000);
Assert.assertTrue(received);
}

public void observeDoubleOverJms(@Observes @Routing(RouteType.INGRESS) Double d) {
received = true;
}
}
Expand Up @@ -31,13 +31,16 @@
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.seam.jms.annotations.JmsDestination;
import org.jboss.seam.jms.annotations.Routing;
import org.jboss.seam.jms.bridge.RouteBuilder;
import org.jboss.seam.jms.bridge.RouteType;
import org.jboss.seam.jms.impl.inject.ConnectionProducer;
import org.jboss.seam.jms.impl.inject.DestinationProducer;
import org.jboss.seam.jms.impl.inject.MessagePubSubProducer;
import org.jboss.seam.jms.test.Util;
import org.jboss.seam.solder.bean.ImmutableInjectionPoint;
import org.jboss.shrinkwrap.api.Archive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

Expand All @@ -58,6 +61,9 @@ public static Archive<?> createDeployment() {
@Inject Connection conn;
@Inject Session session;
@Inject @JmsDestination(jndiName="jms/T2") Topic t;

private static boolean received = false;

@Test
public void testObserveMessage() throws JMSException, InterruptedException {
//conn.start();
Expand All @@ -68,9 +74,11 @@ public void testObserveMessage() throws JMSException, InterruptedException {
Thread.sleep(5 * 1000);
mp.close();
//conn.stop();
Assert.assertTrue(received);
}

public void observeString(@Observes Long l) {
public void observeString(@Observes @Routing(RouteType.INGRESS) Long l) {
System.out.println("Received message "+l);
received= true;
}
}
Expand Up @@ -31,4 +31,6 @@ public interface ObserverInterface {
public void obsStringToTopic(@Observes String s, @JmsDestination(jndiName="jms/T2") Topic t);
@Routing(RouteType.INGRESS)
public void obsLongToTopic(@Observes Long l, @JmsDestination(jndiName="jms/T2") Topic t);
@Routing(RouteType.BOTH)
public void obsDoubleToTopic(@Observes Double d, @JmsDestination(jndiName="jms/T2") Topic t);
}
Expand Up @@ -16,17 +16,18 @@
*/
package org.jboss.seam.jms.test.bridge.intf;

import javax.enterprise.inject.Default;
import org.jboss.seam.jms.bridge.RouteBuilder;
import org.jboss.seam.jms.bridge.RouteType;

import javax.jms.MessageConsumer;
import javax.jms.Session;
import javax.jms.Topic;
import org.jboss.logging.Logger;
import javax.jms.Connection;
import javax.jms.ObjectMessage;
import javax.jms.JMSException;
import org.jboss.seam.jms.impl.inject.MessagePubSubProducer;
import org.jboss.seam.jms.annotations.JmsDestination;
import org.jboss.seam.jms.annotations.Routing;
import org.jboss.seam.solder.bean.ImmutableInjectionPoint;
import javax.enterprise.event.Event;
import javax.inject.Inject;
Expand All @@ -51,7 +52,7 @@ public static Archive<?> createDeployment() {
}
private static final String EVENT_MSG = "hello, world!";

@Inject @Default
@Inject @Routing(RouteType.EGRESS)
Event<String> stringEvent;
@Inject Connection c;
@Inject @JmsDestination(jndiName="jms/T2") Topic t;
Expand Down

0 comments on commit 3d743ac

Please sign in to comment.