[seam-commits] Seam SVN: r12689 - in modules/jms/branches/simple-forwarding: api/src/main/java/org/jboss/seam/jms/annotations and 2 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Thu May 6 20:33:56 EDT 2010
Author: jganoff
Date: 2010-05-06 20:33:56 -0400 (Thu, 06 May 2010)
New Revision: 12689
Added:
modules/jms/branches/simple-forwarding/api/src/main/java/org/jboss/seam/jms/JmsForwarding.java
modules/jms/branches/simple-forwarding/impl/src/test/java/org/jboss/seam/jms/test/bridge/simple/Bridged.java
modules/jms/branches/simple-forwarding/impl/src/test/java/org/jboss/seam/jms/test/bridge/simple/MyForwarding.java
Removed:
modules/jms/branches/simple-forwarding/api/src/main/java/org/jboss/seam/jms/annotations/Bridged.java
Modified:
modules/jms/branches/simple-forwarding/impl/src/main/java/org/jboss/seam/jms/BridgedObserver.java
modules/jms/branches/simple-forwarding/impl/src/main/java/org/jboss/seam/jms/Seam3JmsExtension.java
modules/jms/branches/simple-forwarding/impl/src/test/java/org/jboss/seam/jms/test/bridge/simple/SimpleBridgedEventTest.java
Log:
Ironing out bridging configuration. Does not work yet due to producer scope issues. Will fix in trunk and merge back here.
Added: modules/jms/branches/simple-forwarding/api/src/main/java/org/jboss/seam/jms/JmsForwarding.java
===================================================================
--- modules/jms/branches/simple-forwarding/api/src/main/java/org/jboss/seam/jms/JmsForwarding.java (rev 0)
+++ modules/jms/branches/simple-forwarding/api/src/main/java/org/jboss/seam/jms/JmsForwarding.java 2010-05-07 00:33:56 UTC (rev 12689)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.jms;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Set;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Named;
+import javax.jms.Destination;
+
+/**
+ * Configuration for the forwarding of events to JMS.
+ *
+ * @author Jordan Ganoff
+ */
+ at Named
+ at ApplicationScoped
+public interface JmsForwarding
+{
+ /**
+ * Destinations to forward events to.
+ */
+ public Set<? extends Destination> getDestinations();
+
+ /**
+ * Event type to observe and forward.
+ */
+ public Type getEventType();
+
+ /**
+ * Set of qualifiers that must exist on each event of type {@link #getEventType()}.
+ */
+ public Set<Annotation> getQualifiers();
+}
Deleted: modules/jms/branches/simple-forwarding/api/src/main/java/org/jboss/seam/jms/annotations/Bridged.java
===================================================================
--- modules/jms/branches/simple-forwarding/api/src/main/java/org/jboss/seam/jms/annotations/Bridged.java 2010-05-06 22:16:27 UTC (rev 12688)
+++ modules/jms/branches/simple-forwarding/api/src/main/java/org/jboss/seam/jms/annotations/Bridged.java 2010-05-07 00:33:56 UTC (rev 12689)
@@ -1,28 +0,0 @@
-package org.jboss.seam.jms.annotations;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import javax.inject.Qualifier;
-
-/**
- * Bridged Event
- *
- * @author Jordan Ganoff
- */
- at Qualifier
- at Documented
- at Inherited
- at Target( { FIELD, METHOD, TYPE, PARAMETER })
- at Retention(RUNTIME)
-public @interface Bridged
-{
-}
\ No newline at end of file
Modified: modules/jms/branches/simple-forwarding/impl/src/main/java/org/jboss/seam/jms/BridgedObserver.java
===================================================================
--- modules/jms/branches/simple-forwarding/impl/src/main/java/org/jboss/seam/jms/BridgedObserver.java 2010-05-06 22:16:27 UTC (rev 12688)
+++ modules/jms/branches/simple-forwarding/impl/src/main/java/org/jboss/seam/jms/BridgedObserver.java 2010-05-07 00:33:56 UTC (rev 12689)
@@ -3,21 +3,20 @@
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
-import java.util.Collections;
import java.util.Set;
+import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Reception;
import javax.enterprise.event.TransactionPhase;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.ObserverMethod;
-import javax.enterprise.util.AnnotationLiteral;
+import javax.inject.Named;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
-import org.jboss.seam.jms.annotations.Bridged;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -26,22 +25,19 @@
*
* @author Jordan Ganoff
*/
+ at Named
+ at ApplicationScoped
public class BridgedObserver implements ObserverMethod<Object>
{
private Logger log = LoggerFactory.getLogger(getClass());
- private static final Set<Annotation> BRIDGED = Collections.<Annotation> singleton(new AnnotationLiteral<Bridged>()
- {
- private static final long serialVersionUID = 1L;
- });
-
private BeanManager bm;
- private Destination destination;
- private Set<Annotation> qualifiers;
+ private JmsForwarding config;
- public BridgedObserver(BeanManager bm)
+ public BridgedObserver(BeanManager bm, JmsForwarding config)
{
this.bm = bm;
+ this.config = config;
}
public Class<?> getBeanClass()
@@ -51,13 +47,12 @@
public Set<Annotation> getObservedQualifiers()
{
- // Note, annotation MUST be @Qualifier. No error given but will not work!
- return BRIDGED;
+ return config.getQualifiers();
}
public Type getObservedType()
{
- return Object.class;
+ return config.getEventType();
}
public Reception getReception()
@@ -79,7 +74,7 @@
private void forwardEvent(Object event, Set<Annotation> qualifiers)
{
- log.info("Forwarding event {}", event);
+ log.info("Forwarding event: {}", event);
// p.forwardEvent(event, qualifiers);
// for (EventPropagator p : ServiceLoader.load(EventPropagator.class))
@@ -95,10 +90,17 @@
Bean<?> bean = bm.resolve(beans);
Session s = (Session) bm.getReference(bean, Session.class, bm.createCreationalContext(bean));
log.info("Forwarding with session {}", s);
- log.info("To destination {}", destination);
- Message m = s.createObjectMessage((Serializable) event);
- s.createProducer(destination).send(m);
- s.close();
+ log.info("To destinations {}", config.getDestinations());
+ // FIXME Cache producers
+ for(Destination d : config.getDestinations())
+ {
+ log.info("Forwarding to destination {}", d);
+ Message m = s.createObjectMessage((Serializable) event);
+ s.createProducer(d).send(m);
+ }
+// s.close();
+
+
}
catch (JMSException ex)
{
Modified: modules/jms/branches/simple-forwarding/impl/src/main/java/org/jboss/seam/jms/Seam3JmsExtension.java
===================================================================
--- modules/jms/branches/simple-forwarding/impl/src/main/java/org/jboss/seam/jms/Seam3JmsExtension.java 2010-05-06 22:16:27 UTC (rev 12688)
+++ modules/jms/branches/simple-forwarding/impl/src/main/java/org/jboss/seam/jms/Seam3JmsExtension.java 2010-05-07 00:33:56 UTC (rev 12689)
@@ -21,13 +21,19 @@
*/
package org.jboss.seam.jms;
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.Extension;
import javax.enterprise.inject.spi.ProcessAnnotatedType;
import org.jboss.seam.jms.impl.wrapper.JmsAnnotatedTypeWrapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Seam 3 JMS Portable Extension
@@ -36,11 +42,27 @@
*/
public class Seam3JmsExtension implements Extension
{
+ private static final Logger log = LoggerFactory.getLogger(Seam3JmsExtension.class);
+
public void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager bm)
{
- // Temporary creation of bridged overserver (This should be changed to allow configuration from XML)
- BridgedObserver b = new BridgedObserver(bm);
- abd.addObserverMethod(b);
+ Set<Bean<?>> configuration = bm.getBeans(JmsForwarding.class);
+
+ if(configuration == null || configuration.isEmpty())
+ {
+ log.info("No {} registered. Event forwarding disabled.", JmsForwarding.class.getSimpleName());
+ } else
+ {
+ for(Bean<?> c : configuration)
+ {
+ log.info("Creating {} for configuration {}", BridgedObserver.class.getSimpleName(), c);
+ CreationalContext<?> context = bm.createCreationalContext(c);
+ // TODO Verify configuration for correctness (e.g. getQualifiers() must contain only @Qualifier annotations)
+ JmsForwarding config = JmsForwarding.class.cast(bm.getReference(c, JmsForwarding.class, context));
+ BridgedObserver b = new BridgedObserver(bm, config);
+ abd.addObserverMethod(b);
+ }
+ }
}
public <X> void decorateAnnotatedType(@Observes ProcessAnnotatedType<X> pat)
Copied: modules/jms/branches/simple-forwarding/impl/src/test/java/org/jboss/seam/jms/test/bridge/simple/Bridged.java (from rev 12682, modules/jms/branches/simple-forwarding/api/src/main/java/org/jboss/seam/jms/annotations/Bridged.java)
===================================================================
--- modules/jms/branches/simple-forwarding/impl/src/test/java/org/jboss/seam/jms/test/bridge/simple/Bridged.java (rev 0)
+++ modules/jms/branches/simple-forwarding/impl/src/test/java/org/jboss/seam/jms/test/bridge/simple/Bridged.java 2010-05-07 00:33:56 UTC (rev 12689)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.jms.test.bridge.simple;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+/**
+ * Bridged Event Qualifer that denotes the implicit forwarding over JMS
+ *
+ * @author Jordan Ganoff
+ */
+ at Qualifier
+ at Documented
+ at Inherited
+ at Target( { FIELD, METHOD, TYPE, PARAMETER })
+ at Retention(RUNTIME)
+public @interface Bridged
+{
+}
\ No newline at end of file
Added: modules/jms/branches/simple-forwarding/impl/src/test/java/org/jboss/seam/jms/test/bridge/simple/MyForwarding.java
===================================================================
--- modules/jms/branches/simple-forwarding/impl/src/test/java/org/jboss/seam/jms/test/bridge/simple/MyForwarding.java (rev 0)
+++ modules/jms/branches/simple-forwarding/impl/src/test/java/org/jboss/seam/jms/test/bridge/simple/MyForwarding.java 2010-05-07 00:33:56 UTC (rev 12689)
@@ -0,0 +1,46 @@
+package org.jboss.seam.jms.test.bridge.simple;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.Set;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.util.AnnotationLiteral;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.jms.Destination;
+import javax.jms.Topic;
+
+import org.jboss.seam.jms.JmsForwarding;
+import org.jboss.seam.jms.annotations.JmsDestination;
+
+ at Named
+ at ApplicationScoped
+public class MyForwarding implements JmsForwarding
+{
+ private static final Set<Annotation> BRIDGED = Collections.<Annotation> singleton(new AnnotationLiteral<Bridged>()
+ {
+ private static final long serialVersionUID = 1L;
+ });
+
+ @Inject
+ @JmsDestination(jndiName="jms/T")
+ private Topic t;
+
+ public Set<? extends Destination> getDestinations()
+ {
+ return Collections.singleton(t);
+ }
+
+ public Type getEventType()
+ {
+ return Object.class;
+ }
+
+ public Set<Annotation> getQualifiers()
+ {
+ return BRIDGED;
+ }
+
+}
Modified: modules/jms/branches/simple-forwarding/impl/src/test/java/org/jboss/seam/jms/test/bridge/simple/SimpleBridgedEventTest.java
===================================================================
--- modules/jms/branches/simple-forwarding/impl/src/test/java/org/jboss/seam/jms/test/bridge/simple/SimpleBridgedEventTest.java 2010-05-06 22:16:27 UTC (rev 12688)
+++ modules/jms/branches/simple-forwarding/impl/src/test/java/org/jboss/seam/jms/test/bridge/simple/SimpleBridgedEventTest.java 2010-05-07 00:33:56 UTC (rev 12689)
@@ -5,14 +5,12 @@
import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.Message;
-import javax.jms.MessageConsumer;
import javax.jms.ObjectMessage;
import javax.jms.Session;
-import javax.jms.Topic;
+import javax.jms.TopicSubscriber;
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.seam.jms.annotations.Bridged;
import org.jboss.seam.jms.annotations.JmsDestination;
import org.jboss.seam.jms.test.Util;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
@@ -31,24 +29,16 @@
@Inject Connection c;
@Inject Session s;
- @Inject @JmsDestination(jndiName="jms/T") Topic t;
-
+ @Inject @JmsDestination(jndiName="jms/T") TopicSubscriber ts;
@Inject @Bridged Event<String> event;
@Test
- public void a()
- {
-
- }
-
- @Test
public void forwardSimpleEvent() throws JMSException
{
String expected = "test";
- MessageConsumer mc = s.createConsumer(t);
c.start();
event.fire(expected);
- Message m = mc.receive();
+ Message m = ts.receive(3000);
Assert.assertTrue(m != null);
Assert.assertTrue(m instanceof ObjectMessage);
Assert.assertEquals(expected, ((ObjectMessage) m).getObject());
More information about the seam-commits
mailing list