[seam-commits] Seam SVN: r12761 - in modules/jms/branches/eventbridge: api/src/main/java/org/jboss/seam/jms/bridge and 4 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Wed May 19 23:13:46 EDT 2010
Author: jganoff
Date: 2010-05-19 23:13:45 -0400 (Wed, 19 May 2010)
New Revision: 12761
Added:
modules/jms/branches/eventbridge/api/src/main/java/org/jboss/seam/jms/bridge/
modules/jms/branches/eventbridge/api/src/main/java/org/jboss/seam/jms/bridge/EventBridge.java
modules/jms/branches/eventbridge/api/src/main/java/org/jboss/seam/jms/bridge/EventRouting.java
modules/jms/branches/eventbridge/api/src/main/java/org/jboss/seam/jms/bridge/Route.java
modules/jms/branches/eventbridge/api/src/main/java/org/jboss/seam/jms/bridge/RouteType.java
modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/bridge/
modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/bridge/EgressRoutingObserver.java
modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/bridge/IngressRoutingBean.java
modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/bridge/JmsEventBridge.java
modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/bridge/RouteImpl.java
modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/bridge/RoutingListener.java
modules/jms/branches/eventbridge/impl/src/test/java/org/jboss/seam/jms/test/bridge/JmsEventBridgeTest.java
modules/jms/branches/eventbridge/impl/src/test/java/org/jboss/seam/jms/test/bridge/route/
modules/jms/branches/eventbridge/impl/src/test/java/org/jboss/seam/jms/test/bridge/route/Bridged.java
modules/jms/branches/eventbridge/impl/src/test/java/org/jboss/seam/jms/test/bridge/route/RouteTest.java
modules/jms/branches/eventbridge/impl/src/test/java/org/jboss/seam/jms/test/bridge/route/RoutingConfig.java
Log:
Start of EventBridge api and egress routing implementation
Added: modules/jms/branches/eventbridge/api/src/main/java/org/jboss/seam/jms/bridge/EventBridge.java
===================================================================
--- modules/jms/branches/eventbridge/api/src/main/java/org/jboss/seam/jms/bridge/EventBridge.java (rev 0)
+++ modules/jms/branches/eventbridge/api/src/main/java/org/jboss/seam/jms/bridge/EventBridge.java 2010-05-20 03:13:45 UTC (rev 12761)
@@ -0,0 +1,43 @@
+/*
+ * 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.bridge;
+
+import java.lang.reflect.Type;
+
+/**
+ * Facilitates bridging of events between CDI and a messaging system.
+ *
+ * @author Jordan Ganoff
+ *
+ */
+public interface EventBridge
+{
+ /**
+ * Creates a routing for the provided payload (event) type.
+ *
+ * @param type Type or direction of routing.
+ * @param payloadType Payload type to route. This is the event type we wish
+ * to observe events for.
+ * @return
+ */
+ public Route createRoute(RouteType type, Type payloadType);
+}
Added: modules/jms/branches/eventbridge/api/src/main/java/org/jboss/seam/jms/bridge/EventRouting.java
===================================================================
--- modules/jms/branches/eventbridge/api/src/main/java/org/jboss/seam/jms/bridge/EventRouting.java (rev 0)
+++ modules/jms/branches/eventbridge/api/src/main/java/org/jboss/seam/jms/bridge/EventRouting.java 2010-05-20 03:13:45 UTC (rev 12761)
@@ -0,0 +1,59 @@
+/*
+ * 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.bridge;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * <p>
+ * Identifies an Event Routing configuration method. May be applied to a method
+ * of a bean class.
+ * </p>
+ *
+ * <p>
+ * The method may return {@link EventBridge} or {@code List<}{@link EventBridge}{@code>}.
+ * </p>
+ *
+ * <pre>
+ * @Inject
+ * EventBridge bridge;
+ *
+ * @EventRouting
+ * public static Route eventRoutingConfig()
+ * {
+ * return bridge.createRoute(EGRESS, Object.class).addQualifier(SPECIAL).connectTo(Topic.class, myTopic);
+ * }
+ * </pre>
+ *
+ * @author Jordan Ganoff
+ */
+ at Target( { METHOD })
+ at Retention(RUNTIME)
+ at Documented
+public @interface EventRouting
+{
+}
Added: modules/jms/branches/eventbridge/api/src/main/java/org/jboss/seam/jms/bridge/Route.java
===================================================================
--- modules/jms/branches/eventbridge/api/src/main/java/org/jboss/seam/jms/bridge/Route.java (rev 0)
+++ modules/jms/branches/eventbridge/api/src/main/java/org/jboss/seam/jms/bridge/Route.java 2010-05-20 03:13:45 UTC (rev 12761)
@@ -0,0 +1,76 @@
+/*
+ * 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.bridge;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Set;
+
+import javax.jms.Destination;
+
+/**
+ * Routing configuration between CDI and JMS.
+ *
+ * @author Jordan Ganoff
+ *
+ */
+public interface Route
+{
+
+ /**
+ * Connect this route to a destination. Multiple destinations may be defined.
+ *
+ * @param <D> Destination type
+ * @param d Destination type (e.g. javax.jms.Topic)
+ * @param destination Destination to connect this route to
+ * @return this
+ */
+ public <D extends Destination> Route connectTo(Class<D> d, D destination);
+
+ /**
+ * Apply the qualifiers listed to this route.
+ *
+ * @param qualifiers Qualifiers for the payload type
+ * @return this
+ */
+ public Route addQualifiers(Annotation... qualifiers);
+
+ /**
+ * @return the routing type
+ */
+ public RouteType getType();
+
+ /**
+ * @return the type this route routes
+ */
+ public Type getPayloadType();
+
+ /**
+ * @return the qualifiers
+ */
+ public Set<Annotation> getQualifiers();
+
+ /**
+ * @return The destinations involved in this routing
+ */
+ public Set<? extends Destination> getDestinations();
+}
Added: modules/jms/branches/eventbridge/api/src/main/java/org/jboss/seam/jms/bridge/RouteType.java
===================================================================
--- modules/jms/branches/eventbridge/api/src/main/java/org/jboss/seam/jms/bridge/RouteType.java (rev 0)
+++ modules/jms/branches/eventbridge/api/src/main/java/org/jboss/seam/jms/bridge/RouteType.java 2010-05-20 03:13:45 UTC (rev 12761)
@@ -0,0 +1,45 @@
+/*
+ * 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.bridge;
+
+/**
+ * All valid {@link Route} types.
+ *
+ * @author Jordan Ganoff
+ *
+ */
+public enum RouteType
+{
+ /**
+ * Inbound route. Any route defined as INGRESS will listen for objects
+ * delivered to the registered destinations and fire events for all that
+ * match the configuration as defined by the route.
+ */
+ INGRESS,
+
+ /**
+ * Outbound route. Any route defined as EGRESS will forward CDI events that
+ * match the configuration as defined by the route to the registered
+ * destinations.
+ */
+ EGRESS;
+}
Added: modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/bridge/EgressRoutingObserver.java
===================================================================
--- modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/bridge/EgressRoutingObserver.java (rev 0)
+++ modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/bridge/EgressRoutingObserver.java 2010-05-20 03:13:45 UTC (rev 12761)
@@ -0,0 +1,135 @@
+/*
+ * 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.bridge;
+
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+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.inject.Named;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Session;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Forwards CDI events that match the provided {@link Route} configuration to
+ * the configured destinations.
+ *
+ * @author Jordan Ganoff
+ *
+ */
+ at Named
+ at ApplicationScoped
+public class EgressRoutingObserver implements ObserverMethod<Object>
+{
+ private Logger log;
+ private BeanManager bm;
+ private Route routing;
+
+ public EgressRoutingObserver(BeanManager bm, Route routing)
+ {
+ this.bm = bm;
+ this.routing = routing;
+ log = LoggerFactory.getLogger(routing.getClass());
+ }
+
+ public Class<?> getBeanClass()
+ {
+ return null;
+ }
+
+ public Set<Annotation> getObservedQualifiers()
+ {
+ return routing.getQualifiers();
+ }
+
+ public Type getObservedType()
+ {
+ return routing.getPayloadType();
+ }
+
+ public Reception getReception()
+ {
+ return Reception.ALWAYS;
+ }
+
+ public TransactionPhase getTransactionPhase()
+ {
+ return TransactionPhase.AFTER_SUCCESS;
+ }
+
+ public void notify(Object evt)
+ {
+ // FIXME Include qualifiers once CDI 1.0 MR is complete and
+ // notify(Event, Set<Annotation>) is added
+ forwardEvent(evt, null);
+ }
+
+ private void forwardEvent(Object event, Set<Annotation> qualifiers)
+ {
+ // TODO Allow session to be configured
+ Set<Bean<?>> beans = bm.getBeans(Session.class);
+ Bean<?> bean = bm.resolve(beans);
+ Session s = (Session) bm.getReference(bean, Session.class, bm.createCreationalContext(bean));
+ try
+ {
+ for (Destination d : routing.getDestinations())
+ {
+ log.info("Routing event {} over destination {}", event, d);
+ try
+ {
+ Message m = s.createObjectMessage((Serializable) event);
+ // Safe to create producers here always? In an app server these
+ // should be cached via JCA managed connection factory but what
+ // about other environments?
+ s.createProducer(d).send(m);
+ }
+ catch (JMSException ex)
+ {
+ log.error("Unable to forward event", ex);
+ }
+ }
+ }
+ finally
+ {
+ try
+ {
+ s.close();
+ }
+ catch (JMSException ex)
+ {
+ log.error("Unable to close session", ex);
+ }
+ }
+ }
+}
Added: modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/bridge/IngressRoutingBean.java
===================================================================
--- modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/bridge/IngressRoutingBean.java (rev 0)
+++ modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/bridge/IngressRoutingBean.java 2010-05-20 03:13:45 UTC (rev 12761)
@@ -0,0 +1,105 @@
+/*
+ * 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.bridge;
+
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+
+/**
+ * Translates received JMS messages from the configured destinations into CDI
+ * events that match the provided {@link Route} configuration.
+ *
+ * @author Jordan Ganoff
+ *
+ */
+public class IngressRoutingBean implements Bean
+{
+
+ public Class getBeanClass()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Set getInjectionPoints()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getName()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Set getQualifiers()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Class getScope()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Set getStereotypes()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Set getTypes()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean isAlternative()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isNullable()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public Object create(CreationalContext creationalContext)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void destroy(Object instance, CreationalContext creationalContext)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Added: modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/bridge/JmsEventBridge.java
===================================================================
--- modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/bridge/JmsEventBridge.java (rev 0)
+++ modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/bridge/JmsEventBridge.java 2010-05-20 03:13:45 UTC (rev 12761)
@@ -0,0 +1,38 @@
+/*
+ * 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.bridge;
+
+import java.lang.reflect.Type;
+
+/**
+ * Default JMS Event Bridge
+ *
+ * @author Jordan Ganoff
+ *
+ */
+public class JmsEventBridge implements EventBridge
+{
+ public Route createRoute(RouteType type, Type payloadType)
+ {
+ return new RouteImpl(type, payloadType);
+ }
+}
Added: modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/bridge/RouteImpl.java
===================================================================
--- modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/bridge/RouteImpl.java (rev 0)
+++ modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/bridge/RouteImpl.java 2010-05-20 03:13:45 UTC (rev 12761)
@@ -0,0 +1,95 @@
+/*
+ * 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.bridge;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.inject.Qualifier;
+import javax.jms.Destination;
+
+/**
+ * JMS Event Bridge Routing
+ *
+ * @author Jordan Ganoff
+ *
+ */
+public class RouteImpl implements Route
+{
+ private RouteType type;
+ private Type payloadType;
+ private Set<Annotation> qualifiers;
+ private Set<Destination> destinations;
+
+ public RouteImpl(RouteType type, Type payloadType)
+ {
+ this.type = type;
+ this.payloadType = payloadType;
+ qualifiers = new HashSet<Annotation>();
+ destinations = new HashSet<Destination>();
+ }
+
+ public Route addQualifiers(Annotation... q)
+ {
+ if (q != null)
+ {
+ for (int i = 0; i < q.length; i++)
+ {
+ Annotation qualifier = q[i];
+ if (!qualifier.annotationType().isAnnotationPresent(Qualifier.class))
+ {
+ throw new IllegalArgumentException("not a qualifier: " + qualifier);
+ }
+ qualifiers.add(q[i]);
+ }
+ }
+ return this;
+ }
+
+ public <D extends Destination> Route connectTo(java.lang.Class<D> d, D destination)
+ {
+ destinations.add(Destination.class.cast(destination));
+ return this;
+ };
+
+ public RouteType getType()
+ {
+ return type;
+ }
+
+ public Type getPayloadType()
+ {
+ return payloadType;
+ }
+
+ public Set<Annotation> getQualifiers()
+ {
+ return qualifiers;
+ }
+
+ public Set<? extends Destination> getDestinations()
+ {
+ return destinations;
+ }
+}
Added: modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/bridge/RoutingListener.java
===================================================================
--- modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/bridge/RoutingListener.java (rev 0)
+++ modules/jms/branches/eventbridge/impl/src/main/java/org/jboss/seam/jms/bridge/RoutingListener.java 2010-05-20 03:13:45 UTC (rev 12761)
@@ -0,0 +1,38 @@
+/*
+ * 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.bridge;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+
+ at ApplicationScoped
+public class RoutingListener implements MessageListener
+{
+
+ public void onMessage(Message arg0)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Added: modules/jms/branches/eventbridge/impl/src/test/java/org/jboss/seam/jms/test/bridge/JmsEventBridgeTest.java
===================================================================
--- modules/jms/branches/eventbridge/impl/src/test/java/org/jboss/seam/jms/test/bridge/JmsEventBridgeTest.java (rev 0)
+++ modules/jms/branches/eventbridge/impl/src/test/java/org/jboss/seam/jms/test/bridge/JmsEventBridgeTest.java 2010-05-20 03:13:45 UTC (rev 12761)
@@ -0,0 +1,70 @@
+/*
+ * 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;
+
+import static org.jboss.seam.jms.bridge.RouteType.EGRESS;
+import static org.jboss.seam.jms.bridge.RouteType.INGRESS;
+
+import javax.enterprise.util.AnnotationLiteral;
+import javax.inject.Qualifier;
+import javax.jms.JMSException;
+import javax.jms.Topic;
+
+import org.jboss.seam.jms.bridge.JmsEventBridge;
+import org.junit.Test;
+
+public class JmsEventBridgeTest
+{
+ @Test
+ public void createRoute()
+ {
+ new JmsEventBridge().createRoute(EGRESS, Object.class);
+ }
+
+ @Test
+ public void createConnectedRoute()
+ {
+ new JmsEventBridge().createRoute(INGRESS, String.class).connectTo(Topic.class, new Topic()
+ {
+
+ public String getTopicName() throws JMSException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ });
+ }
+
+ @Qualifier
+ public @interface TestQualifier
+ {
+ }
+
+ @Test
+ public void addQualifiers()
+ {
+ new JmsEventBridge().createRoute(EGRESS, Object.class).addQualifiers(new AnnotationLiteral<TestQualifier>()
+ {
+ });
+ }
+
+}
Added: modules/jms/branches/eventbridge/impl/src/test/java/org/jboss/seam/jms/test/bridge/route/Bridged.java
===================================================================
--- modules/jms/branches/eventbridge/impl/src/test/java/org/jboss/seam/jms/test/bridge/route/Bridged.java (rev 0)
+++ modules/jms/branches/eventbridge/impl/src/test/java/org/jboss/seam/jms/test/bridge/route/Bridged.java 2010-05-20 03:13:45 UTC (rev 12761)
@@ -0,0 +1,34 @@
+/*
+ * 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.route;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+
+import javax.inject.Qualifier;
+
+ at Qualifier
+ at Retention(RUNTIME)
+public @interface Bridged
+{
+}
Added: modules/jms/branches/eventbridge/impl/src/test/java/org/jboss/seam/jms/test/bridge/route/RouteTest.java
===================================================================
--- modules/jms/branches/eventbridge/impl/src/test/java/org/jboss/seam/jms/test/bridge/route/RouteTest.java (rev 0)
+++ modules/jms/branches/eventbridge/impl/src/test/java/org/jboss/seam/jms/test/bridge/route/RouteTest.java 2010-05-20 03:13:45 UTC (rev 12761)
@@ -0,0 +1,72 @@
+package org.jboss.seam.jms.test.bridge.route;
+
+import javax.enterprise.event.Event;
+import javax.inject.Inject;
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.ObjectMessage;
+import javax.jms.TopicSubscriber;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.jms.annotations.JmsDestination;
+import org.jboss.seam.jms.test.Util;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+ at RunWith(Arquillian.class)
+public class RouteTest
+{
+ @Deployment
+ public static JavaArchive createDeployment()
+ {
+ JavaArchive a = Util.createDeployment(RouteTest.class);
+ a.addPackage(RouteTest.class.getPackage());
+
+// JavaArchive ejbJar = ShrinkWrap.create("test.jar", JavaArchive.class)
+// .addManifestResource(new ByteArrayAsset(new byte[0]), "beans.xml")
+// .addPackage(Seam3JmsExtension.class.getPackage())
+// .addPackage(JmsSession.class.getPackage())
+// .addPackage(ConnectionProducer.class.getPackage())
+// .addPackage(JmsAnnotatedTypeWrapper.class.getPackage())
+// .addPackage(Route.class.getPackage())
+// .addPackage(RouteTest.class.getPackage());
+//
+// EnterpriseArchive ear = ShrinkWrap.create("test.ear", EnterpriseArchive.class)
+// .addModule(ejbJar)
+// .addManifestResource("topic_T-service.xml")
+// .addManifestResource("queue_Q-service.xml");
+
+ return a;
+ }
+
+ @Inject Connection c;
+ @Inject @JmsDestination(jndiName="jms/T") TopicSubscriber ts;
+ @Inject @Bridged Event<String> event;
+ @Inject Event<String> plainEvent;
+
+ @Test
+ public void forwardSimpleEvent() throws JMSException
+ {
+ String expected = "test";
+ c.start();
+ event.fire(expected);
+ Message m = ts.receive(3000);
+ Assert.assertTrue(m != null);
+ Assert.assertTrue(m instanceof ObjectMessage);
+ Assert.assertEquals(expected, ((ObjectMessage) m).getObject());
+ }
+
+ @Test
+ public void noMatchingRoutes() throws JMSException
+ {
+ String expected = "test";
+ c.start();
+ plainEvent.fire(expected);
+ Message m = ts.receive(3000);
+ Assert.assertNull(m);
+ }
+}
Added: modules/jms/branches/eventbridge/impl/src/test/java/org/jboss/seam/jms/test/bridge/route/RoutingConfig.java
===================================================================
--- modules/jms/branches/eventbridge/impl/src/test/java/org/jboss/seam/jms/test/bridge/route/RoutingConfig.java (rev 0)
+++ modules/jms/branches/eventbridge/impl/src/test/java/org/jboss/seam/jms/test/bridge/route/RoutingConfig.java 2010-05-20 03:13:45 UTC (rev 12761)
@@ -0,0 +1,51 @@
+/*
+ * 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.route;
+
+import static org.jboss.seam.jms.bridge.RouteType.EGRESS;
+
+import javax.enterprise.util.AnnotationLiteral;
+import javax.inject.Inject;
+import javax.jms.Topic;
+
+import org.jboss.seam.jms.annotations.JmsDestination;
+import org.jboss.seam.jms.bridge.EventBridge;
+import org.jboss.seam.jms.bridge.EventRouting;
+import org.jboss.seam.jms.bridge.Route;
+
+public class RoutingConfig
+{
+ @Inject EventBridge bridge;
+
+ @Inject @JmsDestination(jndiName = "jms/T") Topic t;
+
+ private static final AnnotationLiteral<Bridged> BRIDGED = new AnnotationLiteral<Bridged>()
+ {
+ private static final long serialVersionUID = 1L;
+ };
+
+ @EventRouting
+ public Route getRoute()
+ {
+ return bridge.createRoute(EGRESS, String.class).addQualifiers(BRIDGED).connectTo(Topic.class, t);
+ }
+}
More information about the seam-commits
mailing list