[seam-commits] Seam SVN: r12760 - in modules/jms/branches: eventbridge and 3 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Wed May 19 23:11:50 EDT 2010


Author: jganoff
Date: 2010-05-19 23:11:50 -0400 (Wed, 19 May 2010)
New Revision: 12760

Added:
   modules/jms/branches/eventbridge/
   modules/jms/branches/eventbridge/distribution.txt
   modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/impl/inject/DestinationProducer.java
Removed:
   modules/jms/branches/eventbridge/distribution.txt
   modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/impl/inject/DestinationProducer.java
Modified:
   modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/Seam3JmsExtension.java
   modules/jms/branches/eventbridge/impl/src/test/java/org/jboss/seam/jms/test/MyQueue.java
   modules/jms/branches/eventbridge/impl/src/test/java/org/jboss/seam/jms/test/MyTopic.java
   modules/jms/branches/eventbridge/impl/src/test/java/org/jboss/seam/jms/test/Util.java
Log:
EventBridge work

Copied: modules/jms/branches/eventbridge (from rev 12757, modules/jms/trunk)

Deleted: modules/jms/branches/eventbridge/distribution.txt
===================================================================
--- modules/jms/trunk/distribution.txt	2010-05-19 18:33:29 UTC (rev 12757)
+++ modules/jms/branches/eventbridge/distribution.txt	2010-05-20 03:11:50 UTC (rev 12760)
@@ -1,5 +0,0 @@
-To create the Seam JMS distribution, run the following Maven command:
-
-mvn clean package -P distribution
-
-Release binaries will be produced in: dist/target
\ No newline at end of file

Copied: modules/jms/branches/eventbridge/distribution.txt (from rev 12758, modules/jms/trunk/distribution.txt)
===================================================================
--- modules/jms/branches/eventbridge/distribution.txt	                        (rev 0)
+++ modules/jms/branches/eventbridge/distribution.txt	2010-05-20 03:11:50 UTC (rev 12760)
@@ -0,0 +1,5 @@
+To create the Seam JMS distribution, run the following Maven command:
+
+mvn clean package -Drelease
+
+Release binaries will be produced in: dist/target
\ No newline at end of file

Modified: modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/Seam3JmsExtension.java
===================================================================
--- modules/jms/trunk/impl/src/main/java/org/jboss/seam/jms/Seam3JmsExtension.java	2010-05-19 18:33:29 UTC (rev 12757)
+++ modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/Seam3JmsExtension.java	2010-05-20 03:11:50 UTC (rev 12760)
@@ -21,16 +21,23 @@
  */
 package org.jboss.seam.jms;
 
+import java.lang.reflect.Type;
+import java.util.Collection;
+import java.util.HashSet;
 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.AnnotatedMethod;
 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.bridge.EgressRoutingObserver;
+import org.jboss.seam.jms.bridge.EventRouting;
+import org.jboss.seam.jms.bridge.Route;
 import org.jboss.seam.jms.impl.wrapper.JmsAnnotatedTypeWrapper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -44,27 +51,65 @@
 {
    private static final Logger log = LoggerFactory.getLogger(Seam3JmsExtension.class);
    
-   public void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager bm)
+   private Set<AnnotatedMethod<?>> eventRoutingRegistry = new HashSet<AnnotatedMethod<?>>();
+   
+   public void buildRoutes(@Observes final AfterBeanDiscovery abd, final BeanManager bm)
    {
-      Set<Bean<?>> configuration = bm.getBeans(JmsForwarding.class);
-      
-      if(configuration == null || configuration.isEmpty())
+      for (AnnotatedMethod<?> m : eventRoutingRegistry)
       {
-         log.info("No {} registered.  Event forwarding disabled.", JmsForwarding.class.getSimpleName());
-      } else
-      {
-         for(Bean<?> c : configuration)
+         Type beanType = m.getDeclaringType().getBaseType();
+         Set<Bean<?>> configBeans = bm.getBeans(beanType);
+         for (Bean<?> configBean : configBeans)
          {
-            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);
+            CreationalContext<?> context = bm.createCreationalContext(configBean);
+            Object config = null;
+            try
+            {
+               Object bean = bm.getReference(configBean, beanType, context);
+               config = m.getJavaMember().invoke(bean);
+            } catch (Exception ex)
+            {
+               abd.addDefinitionError(new IllegalArgumentException(EventRouting.class.getSimpleName() + " could not be loaded from bean " + beanType + ": " + ex.getMessage(), ex));
+            }
+            log.debug("Building " + Route.class.getSimpleName() + "s from " + beanType);
+            if (config != null)
+            {
+               if (Collection.class.isAssignableFrom(config.getClass()))
+               {
+                  Collection<?> routes = Collection.class.cast(config);
+                  for (Object route : routes)
+                  {
+                     if(route == null || !Route.class.isAssignableFrom(route.getClass()))
+                     {
+                        abd.addDefinitionError(new IllegalArgumentException("Non-" + Route.class.getSimpleName() + " found when loading " + EventRouting.class.getSimpleName() + " from " + beanType + ": " + route));
+                     }
+                     createRoute(abd, bm, (Route) route);
+                  }
+               } else if(Route.class.isAssignableFrom(config.getClass()))
+               {
+                  createRoute(abd, bm, Route.class.cast(config));
+               } else
+               {
+                  abd.addDefinitionError(new IllegalArgumentException(EventRouting.class + " methods must return a " + Collection.class + "<? extends " + Route.class + "> or " + Route.class + " directly."));
+               }
+            }
          }
       }
    }
    
+   private void createRoute(final AfterBeanDiscovery abd, final BeanManager bm, final Route route)
+   {
+      switch(route.getType())
+      {
+         case EGRESS:
+            abd.addObserverMethod(new EgressRoutingObserver(bm, route));
+            log.debug("Built " + route);
+            break;
+         default:
+            abd.addDefinitionError(new IllegalArgumentException("Unsupported routing type: " + route.getType()));
+      }
+   }
+   
    public <X> void decorateAnnotatedType(@Observes ProcessAnnotatedType<X> pat)
    {
       /**
@@ -72,4 +117,15 @@
        */
       pat.setAnnotatedType(JmsAnnotatedTypeWrapper.decorate(pat.getAnnotatedType()));
    }
+   
+   public void registerEventRouting(@Observes ProcessAnnotatedType<?> pat)
+   {
+      for(AnnotatedMethod<?> m : pat.getAnnotatedType().getMethods())
+      {
+         if(m.isAnnotationPresent(EventRouting.class))
+         {
+            eventRoutingRegistry.add(m);
+         }
+      }
+   }
 }

Deleted: modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/impl/inject/DestinationProducer.java
===================================================================
--- modules/jms/trunk/impl/src/main/java/org/jboss/seam/jms/impl/inject/DestinationProducer.java	2010-05-19 18:33:29 UTC (rev 12757)
+++ modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/impl/inject/DestinationProducer.java	2010-05-20 03:11:50 UTC (rev 12760)
@@ -1,55 +0,0 @@
-/*
- * 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.impl.inject;
-
-import static org.jboss.seam.jms.impl.inject.InjectionUtil.getExpectedQualifier;
-
-import javax.enterprise.context.RequestScoped;
-import javax.enterprise.inject.Produces;
-import javax.enterprise.inject.spi.InjectionPoint;
-import javax.jms.Queue;
-import javax.jms.Topic;
-import javax.naming.Context;
-import javax.naming.NamingException;
-
-import org.jboss.seam.jms.annotations.JmsDestination;
-import org.jboss.seam.jms.annotations.Module;
-
-public @RequestScoped class DestinationProducer
-{
-
-   @Produces
-   @JmsDestination
-   public Topic getTopic(InjectionPoint ip, @Module Context c) throws NamingException
-   {
-      JmsDestination d = getExpectedQualifier(JmsDestination.class, ip.getQualifiers());
-      return (Topic) c.lookup(d.jndiName());
-   }
-   
-   @Produces
-   @JmsDestination
-   public Queue getQueue(InjectionPoint ip, @Module Context c) throws NamingException
-   {
-      JmsDestination d = getExpectedQualifier(JmsDestination.class, ip.getQualifiers());
-      return (Queue) c.lookup(d.jndiName());
-   }
-}

Copied: modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/impl/inject/DestinationProducer.java (from rev 12759, modules/jms/trunk/impl/src/main/java/org/jboss/seam/jms/impl/inject/DestinationProducer.java)
===================================================================
--- modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/impl/inject/DestinationProducer.java	                        (rev 0)
+++ modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/impl/inject/DestinationProducer.java	2010-05-20 03:11:50 UTC (rev 12760)
@@ -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.impl.inject;
+
+import static org.jboss.seam.jms.impl.inject.InjectionUtil.getExpectedQualifier;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.jms.Queue;
+import javax.jms.Topic;
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import org.jboss.seam.jms.annotations.JmsDestination;
+import org.jboss.seam.jms.annotations.Module;
+
+public @ApplicationScoped class DestinationProducer
+{
+
+   @Produces
+   @JmsDestination
+   public Topic getTopic(InjectionPoint ip, @Module Context c) throws NamingException
+   {
+      JmsDestination d = getExpectedQualifier(JmsDestination.class, ip.getQualifiers());
+      return (Topic) c.lookup(d.jndiName());
+   }
+   
+   @Produces
+   @JmsDestination
+   public Queue getQueue(InjectionPoint ip, @Module Context c) throws NamingException
+   {
+      JmsDestination d = getExpectedQualifier(JmsDestination.class, ip.getQualifiers());
+      return (Queue) c.lookup(d.jndiName());
+   }
+}

Modified: modules/jms/branches/eventbridge/impl/src/test/java/org/jboss/seam/jms/test/MyQueue.java
===================================================================
--- modules/jms/trunk/impl/src/test/java/org/jboss/seam/jms/test/MyQueue.java	2010-05-19 18:33:29 UTC (rev 12757)
+++ modules/jms/branches/eventbridge/impl/src/test/java/org/jboss/seam/jms/test/MyQueue.java	2010-05-20 03:11:50 UTC (rev 12760)
@@ -21,14 +21,9 @@
  */
 package org.jboss.seam.jms.test;
 
-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.Retention;
-import java.lang.annotation.Target;
 
 import javax.inject.Qualifier;
 

Modified: modules/jms/branches/eventbridge/impl/src/test/java/org/jboss/seam/jms/test/MyTopic.java
===================================================================
--- modules/jms/trunk/impl/src/test/java/org/jboss/seam/jms/test/MyTopic.java	2010-05-19 18:33:29 UTC (rev 12757)
+++ modules/jms/branches/eventbridge/impl/src/test/java/org/jboss/seam/jms/test/MyTopic.java	2010-05-20 03:11:50 UTC (rev 12760)
@@ -21,14 +21,9 @@
  */
 package org.jboss.seam.jms.test;
 
-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.Retention;
-import java.lang.annotation.Target;
 
 import javax.inject.Qualifier;
 

Modified: modules/jms/branches/eventbridge/impl/src/test/java/org/jboss/seam/jms/test/Util.java
===================================================================
--- modules/jms/trunk/impl/src/test/java/org/jboss/seam/jms/test/Util.java	2010-05-19 18:33:29 UTC (rev 12757)
+++ modules/jms/branches/eventbridge/impl/src/test/java/org/jboss/seam/jms/test/Util.java	2010-05-20 03:11:50 UTC (rev 12760)
@@ -25,6 +25,7 @@
 
 import org.jboss.seam.jms.Seam3JmsExtension;
 import org.jboss.seam.jms.annotations.JmsSession;
+import org.jboss.seam.jms.bridge.Route;
 import org.jboss.seam.jms.impl.inject.ConnectionProducer;
 import org.jboss.seam.jms.impl.wrapper.JmsAnnotatedTypeWrapper;
 import org.jboss.shrinkwrap.api.ArchivePaths;
@@ -43,9 +44,10 @@
       archive.addPackage(JmsSession.class.getPackage());
       archive.addPackage(ConnectionProducer.class.getPackage());
       archive.addPackage(JmsAnnotatedTypeWrapper.class.getPackage());
+      archive.addPackage(Route.class.getPackage());
       archive.addManifestResource(new ByteArrayAsset("<beans/>".getBytes()), ArchivePaths.create("beans.xml"));
       archive.addServiceProvider(Extension.class, Seam3JmsExtension.class);
-      archive.addManifestResource("topic_T-service.xml");
+//      archive.addManifestResource("topic_T-service.xml");
       archive.addManifestResource("queue_Q-service.xml");
 
       archive.addPackage(c.getPackage());



More information about the seam-commits mailing list