[jboss-svn-commits] JBL Code SVN: r22918 - in labs/jbossesb/workspace/skeagh: api/service/src/main/java/org/jboss/esb/context and 5 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Sep 19 07:42:41 EDT 2008


Author: tfennelly
Date: 2008-09-19 07:42:41 -0400 (Fri, 19 Sep 2008)
New Revision: 22918

Added:
   labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/federate/bus/BusRoutingContext.java
Modified:
   labs/jbossesb/workspace/skeagh/api/routing/src/main/java/org/jboss/esb/routing/InboundRouter.java
   labs/jbossesb/workspace/skeagh/api/routing/src/main/java/org/jboss/esb/routing/OutboundRouter.java
   labs/jbossesb/workspace/skeagh/api/service/src/main/java/org/jboss/esb/context/DeploymentContext.java
   labs/jbossesb/workspace/skeagh/api/service/src/main/java/org/jboss/esb/service/Service.java
   labs/jbossesb/workspace/skeagh/routing/esb/src/main/java/org/jboss/esb/ServiceRouter.java
   labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/DeploymentRuntime.java
   labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/federate/DeploymentCoordinator.java
   labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/federate/bus/BusInboundRouter.java
Log:
Adding the ServiceRouter.  It's needed (in general) and I wanted it for testing.

Modified: labs/jbossesb/workspace/skeagh/api/routing/src/main/java/org/jboss/esb/routing/InboundRouter.java
===================================================================
--- labs/jbossesb/workspace/skeagh/api/routing/src/main/java/org/jboss/esb/routing/InboundRouter.java	2008-09-19 11:33:55 UTC (rev 22917)
+++ labs/jbossesb/workspace/skeagh/api/routing/src/main/java/org/jboss/esb/routing/InboundRouter.java	2008-09-19 11:42:41 UTC (rev 22918)
@@ -21,6 +21,33 @@
 
 /**
  * Inbound Router.
+ * <h3>Deployment Context</h3>
+ * An instance can have its associated {@link org.jboss.esb.context.DeploymentContext}
+ * set by simply defining a property by the name "deploymentContext" e.g.
+ * <pre>
+ * public MyRouter implements InboundRouter {
+ *      {@link org.jboss.esb.context.DeploymentContext} deploymentContext;
+ * }
+ * </pre>
+ * The framework will inject the value.
+ * <h3>Service Name</h3>
+ * An instance can have its associated {@link org.jboss.esb.service.ServiceName}
+ * set by simply defining a property by the name "serviceName" e.g.
+ * <pre>
+ * public MyRouter implements InboundRouter {
+ *      {@link org.jboss.esb.service.ServiceName} serviceName;
+ * }
+ * </pre>
+ * The framework will inject the value.
+ * <h3>Configuration Name</h3>
+ * An instance can have its associated configuration name (name, id etc from the configuration)
+ * set by simply defining a property by the name "objectName" e.g.
+ * <pre>
+ * public MyRouter implements InboundRouter {
+ *      String objectName;
+ * }
+ * </pre>
+ * The framework will inject the value.
  *
  * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
  */

Modified: labs/jbossesb/workspace/skeagh/api/routing/src/main/java/org/jboss/esb/routing/OutboundRouter.java
===================================================================
--- labs/jbossesb/workspace/skeagh/api/routing/src/main/java/org/jboss/esb/routing/OutboundRouter.java	2008-09-19 11:33:55 UTC (rev 22917)
+++ labs/jbossesb/workspace/skeagh/api/routing/src/main/java/org/jboss/esb/routing/OutboundRouter.java	2008-09-19 11:42:41 UTC (rev 22918)
@@ -23,6 +23,33 @@
 
 /**
  * Outbound Router.
+ * <h3>Deployment Context</h3>
+ * An instance can have its associated {@link org.jboss.esb.context.DeploymentContext}
+ * set by simply defining a property by the name "deploymentContext" e.g.
+ * <pre>
+ * public MyRouter implements OutboundRouter {
+ *      {@link org.jboss.esb.context.DeploymentContext} deploymentContext;
+ * }
+ * </pre>
+ * The framework will inject the value.
+ * <h3>Service Name</h3>
+ * An instance can have its associated {@link org.jboss.esb.service.ServiceName}
+ * set by simply defining a property by the name "serviceName" e.g.
+ * <pre>
+ * public MyRouter implements OutboundRouter {
+ *      {@link org.jboss.esb.service.ServiceName} serviceName;
+ * }
+ * </pre>
+ * The framework will inject the value.
+ * <h3>Configuration Name</h3>
+ * An instance can have its associated configuration name (name, id etc from the configuration)
+ * set by simply defining a property by the name "objectName" e.g.
+ * <pre>
+ * public MyRouter implements OutboundRouter {
+ *      String objectName;
+ * }
+ * </pre>
+ * The framework will inject the value.
  *
  * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
  */

Modified: labs/jbossesb/workspace/skeagh/api/service/src/main/java/org/jboss/esb/context/DeploymentContext.java
===================================================================
--- labs/jbossesb/workspace/skeagh/api/service/src/main/java/org/jboss/esb/context/DeploymentContext.java	2008-09-19 11:33:55 UTC (rev 22917)
+++ labs/jbossesb/workspace/skeagh/api/service/src/main/java/org/jboss/esb/context/DeploymentContext.java	2008-09-19 11:42:41 UTC (rev 22918)
@@ -25,8 +25,7 @@
 /**
  * Deployment Context.
  * <p/>
- * Mutable context scoped around the deployment unit to which the caller
- * is part of.
+ * Mutable context scoped around a deployment runtime instance .
  * <p/>
  * Deployment resources are handled explicitly because we need to manage
  * their lifecycle.

Modified: labs/jbossesb/workspace/skeagh/api/service/src/main/java/org/jboss/esb/service/Service.java
===================================================================
--- labs/jbossesb/workspace/skeagh/api/service/src/main/java/org/jboss/esb/service/Service.java	2008-09-19 11:33:55 UTC (rev 22917)
+++ labs/jbossesb/workspace/skeagh/api/service/src/main/java/org/jboss/esb/service/Service.java	2008-09-19 11:42:41 UTC (rev 22918)
@@ -23,6 +23,24 @@
 
 /**
  * ESB Service interface.
+ * <h3>Deployment Context</h3>
+ * An instance can have its associated {@link org.jboss.esb.context.DeploymentContext}
+ * set by simply defining a property by the name "deploymentContext" e.g.
+ * <pre>
+ * public MyService implements Service {
+ *      {@link org.jboss.esb.context.DeploymentContext} deploymentContext;
+ * }
+ * </pre>
+ * The framework will inject the value.
+ * <h3>Service Name</h3>
+ * An instance can have its associated {@link org.jboss.esb.service.ServiceName}
+ * set by simply defining a property by the name "serviceName" e.g.
+ * <pre>
+ * public MyService implements Service {
+ *      {@link org.jboss.esb.service.ServiceName} serviceName;
+ * }
+ * </pre>
+ * The framework will inject the value.
  *
  * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
  */

Modified: labs/jbossesb/workspace/skeagh/routing/esb/src/main/java/org/jboss/esb/ServiceRouter.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/esb/src/main/java/org/jboss/esb/ServiceRouter.java	2008-09-19 11:33:55 UTC (rev 22917)
+++ labs/jbossesb/workspace/skeagh/routing/esb/src/main/java/org/jboss/esb/ServiceRouter.java	2008-09-19 11:42:41 UTC (rev 22918)
@@ -19,21 +19,130 @@
  */
 package org.jboss.esb;
 
+import org.jboss.esb.annotations.Initialize;
+import org.jboss.esb.annotations.Property;
+import org.jboss.esb.context.AddressingContext;
+import org.jboss.esb.context.DeploymentContext;
+import org.jboss.esb.context.InvocationContext;
+import org.jboss.esb.deploy.DeploymentException;
+import org.jboss.esb.deploy.DeploymentRuntime;
+import org.jboss.esb.deploy.DeploymentUtil;
+import org.jboss.esb.federate.DeploymentCoordinator;
+import org.jboss.esb.federate.DeploymentMonitor;
+import org.jboss.esb.federate.bus.BusInboundRouter;
+import org.jboss.esb.federate.bus.BusMessage;
+import org.jboss.esb.federate.bus.BusRoutingContext;
 import org.jboss.esb.message.Message;
 import org.jboss.esb.routing.OutboundRouter;
 import org.jboss.esb.routing.RoutingException;
+import org.jboss.esb.service.ServiceName;
 
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 /**
  * Service Message {@link OutboundRouter}.
  * <p/>
- * Allows routing to an ESB message to another Service instance.
+ * Allows routing of an ESB message to another Service instance.
  *
  * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
  */
 public class ServiceRouter implements OutboundRouter
 {
+    /**
+     * The service name i.e. the "from" service. Injected by the framework.
+     */
+    private ServiceName serviceName;
+    /**
+     * Is the "to" Service local i.e. within the local deployment.
+     */
+    private boolean isLocalService = false;
+    /**
+     * Deployment context.
+     */
+    private DeploymentContext deploymentContext;
+    /**
+     * The Category name of the "to" service.
+     */
+    @Property
+    private String toCategory;
+    /**
+     * The name of the "to" service.
+     */
+    @Property
+    private String toService;
+    /**
+     * The qualified "to" service name.
+     */
+    private ServiceName toServiceName;
+    /**
+     * The Category name of the "fault" service.
+     */
+    @Property(use = Property.Use.OPTIONAL)
+    private String faultToCategory;
+    /**
+     * The name of the "fault" service.
+     */
+    @Property(use = Property.Use.OPTIONAL)
+    private String faultToService;
+    /**
+     * The qualified "fault" service name.
+     */
+    private ServiceName faultToServiceName;
+    /**
+     * The Category name of the "replyTo" service.
+     */
+    @Property(use = Property.Use.OPTIONAL)
+    private String replyToCategory;
+    /**
+     * The name of the "replyTo" service.
+     */
+    @Property(use = Property.Use.OPTIONAL)
+    private String replyToService;
+    /**
+     * The qualified "replyTo" service name.
+     */
+    private ServiceName replyToServiceName;
+    /**
+     * Local reference to the deployment runtime within which this
+     * router is executing.
+     */
+    private DeploymentRuntime deploymentRuntime;
 
     /**
+     * Initialize the router.
+     */
+    @Initialize
+    public void initialize() throws DeploymentException
+    {
+        deploymentRuntime = DeploymentRuntime.getRuntime(deploymentContext);
+
+        toServiceName = new ServiceName(toCategory, toService);
+        // The "to" service name should not be this service...
+        if(toServiceName.equals(serviceName))
+        {
+            throw new DeploymentException("Invalid ServiceRouter configuration on deployment '" + deploymentRuntime.getDeploymentName() + "'.  The 'to' service name (" + serviceName + ") cannot be the name of the service itself.");
+        }
+
+        if(faultToCategory != null && faultToService != null)
+        {
+            faultToServiceName = new ServiceName(faultToCategory, faultToService);
+        }
+        if(replyToCategory != null && replyToService != null)
+        {
+            replyToServiceName = new ServiceName(replyToCategory, replyToService);
+        }
+
+        // Work out whether or not the target service is local,
+        // or on another deployment...
+        if(DeploymentUtil.getService(toServiceName, deploymentRuntime) != null)
+        {
+            isLocalService = true;
+        }
+    }
+
+    /**
      * Route the message.
      *
      * @param message The message to be routed.
@@ -41,5 +150,96 @@
      */
     public final void route(final Message message) throws RoutingException
     {
+        AddressingContext addressingContext = new AddressingContext();
+
+        addressingContext.setTo(toServiceName);
+        addressingContext.setFrom(serviceName);
+        addressingContext.setReplyTo(replyToServiceName);
+        addressingContext.setFaultTo(faultToServiceName);
+
+        if(isLocalService)
+        {
+            routeLocal(message, addressingContext);
+        }
+        else
+        {
+            routeNonLocal(message, addressingContext);
+        }
     }
+
+    /**
+     * Route the message to a local Service.
+     * @param message The message.
+     * @param invokeAddressingContext The {@link AddressingContext} for the invocation.
+     * @throws RoutingException Exception during invocation.
+     */
+    private void routeLocal(final Message message, final AddressingContext invokeAddressingContext) throws RoutingException
+    {
+        InvocationContext thisInvocationContext = InvocationContext.getContext();
+        AddressingContext thisAddressingContext = AddressingContext.getContext();
+
+        // Set the Addressing context for the new Service Invocation...
+        AddressingContext.setContext(invokeAddressingContext);
+        try
+        {
+            try
+            {
+                BusRoutingContext routingContext = BusRoutingContext.getContext(deploymentContext);
+                BusInboundRouter inRouter = routingContext.getBusInRouters().get(toServiceName);
+
+                // Going to use the same InvocationContext...
+                inRouter.dispatch(message, thisInvocationContext);
+            }
+            finally
+            {
+                // Make sure the invocation context is still set on the
+                // local thread...
+                InvocationContext.setContext(thisInvocationContext);
+            }
+        }
+        finally
+        {
+            // Reset the addressing context...
+            AddressingContext.setContext(thisAddressingContext);
+        }
+    }
+
+    /**
+     * Route the message to a non-local Service.
+     * @param message The message.
+     * @param invokeAddressingContext The {@link AddressingContext} for the invocation.
+     * @throws RoutingException Exception during invocation.
+     */
+    private void routeNonLocal(final Message message, final AddressingContext invokeAddressingContext) throws RoutingException
+    {
+        InvocationContext thisInvocationContext = InvocationContext.getContext();
+        List<DeploymentCoordinator.BusDeployment> busDeployments = deploymentRuntime.getDeploymentCoordinator().getBusDeployments();
+
+        // Iterate over all the Bus deployments looking for a deployment that
+        // is online and is hosting the target service...
+        for (DeploymentCoordinator.BusDeployment busDeployment : busDeployments)
+        {
+            Set<Map.Entry<String, DeploymentMonitor>> monitors = busDeployment.getDeploymentMonitors().entrySet();
+            for (Map.Entry<String, DeploymentMonitor> entry : monitors)
+            {
+                String deploymentId = entry.getKey();
+                DeploymentMonitor monitor = entry.getValue();
+
+                if(monitor.isOnline() && monitor.hasService(toServiceName))
+                {
+                    BusMessage busMessage = new BusMessage();
+
+                    busMessage.setMessage(message);
+                    busMessage.setInvocationParameters(thisInvocationContext.getInvocationParameters());
+                    busMessage.setAddressingContext(invokeAddressingContext);
+
+                    monitor.getBus().send(busMessage, deploymentId);
+
+                    return;
+                }
+            }
+        }
+
+        throw new RoutingException("Failed to route message from service '" + serviceName + "' to service '" + toServiceName + "'.  Target service is not available.");
+    }
 }

Modified: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/DeploymentRuntime.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/DeploymentRuntime.java	2008-09-19 11:33:55 UTC (rev 22917)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/DeploymentRuntime.java	2008-09-19 11:42:41 UTC (rev 22918)
@@ -34,6 +34,7 @@
 import org.jboss.esb.federate.bus.BusDispatcher;
 import org.jboss.esb.federate.bus.BusInboundRouter;
 import org.jboss.esb.federate.bus.BusOutboundRouter;
+import org.jboss.esb.federate.bus.BusRoutingContext;
 import org.jboss.esb.message.MessageTransformer;
 import org.jboss.esb.properties.ApplicationProperties;
 import org.jboss.esb.schedule.JobScheduler;
@@ -200,6 +201,17 @@
     }
 
     /**
+     * Get the DeploymentRumtime instance associated with the supplied
+     * DeploymentContext.
+     * @param deploymentContext The deployment context.
+     * @return The Deployment Runtime.
+     */
+    public static DeploymentRuntime getRuntime(final DeploymentContext deploymentContext)
+    {
+        return (DeploymentRuntime) deploymentContext.getContextObject(DeploymentRuntime.class);
+    }
+
+    /**
      * Deploy the Runtime.
      *
      * @throws org.jboss.esb.deploy.DeploymentException
@@ -214,12 +226,13 @@
             throw new DeploymentException("Runtime already deployed.");
         }
 
+        context = new DeploymentContext();
+        context.setContextObject(DeploymentRuntime.class, this);
+
         deploymentProperties = PropertiesUtil.getDeploymentConfig(deploymentName);
         deploymentId = deploymentProperties.getProperty("deployment.id", UUID.randomUUID().toString());
         deploymentId += ":" + deploymentName;
 
-        context = new DeploymentContext();
-
         logger.info("Starting JBoss ESB deployment: '" + deploymentName + "'.");
         try
         {
@@ -250,16 +263,21 @@
      */
     public final void undeploy() throws DeploymentException
     {
-        logger.info("Starting JBoss ESB undeployment: '" + deploymentName + "'.");
-        // Make sure to undeploy the scheduler first i.e. block scheduled triggers...
-        undeploy(JobScheduler.SCHEDULER_RESOURCE_ID, JobScheduler.getScheduler(context));
-        // Undeploy any objects manually set in the ESB deployment context...
-        undeploy(context.getAll());
-        // Undeploy all objects that were deployed on ESB Startup...
-        undeploy(deployedObjects);
-        logger.info("JBoss ESB undeployment completed successfully: '" + deploymentName + "'.");
-
-        context = null;
+        try
+        {
+            logger.info("Starting JBoss ESB undeployment: '" + deploymentName + "'.");
+            // Make sure to undeploy the scheduler first i.e. block scheduled triggers...
+            undeploy(JobScheduler.SCHEDULER_RESOURCE_ID, JobScheduler.getScheduler(context));
+            // Undeploy any objects manually set in the ESB deployment context...
+            undeploy(context.getAll());
+            // Undeploy all objects that were deployed on ESB Startup...
+            undeploy(deployedObjects);
+            logger.info("JBoss ESB undeployment completed successfully: '" + deploymentName + "'.");
+        }
+        finally
+        {
+            context = null;
+        }
     }
 
     /**
@@ -544,15 +562,30 @@
     }
 
     /**
+     * Create the BusRouting context for the this deployment.
+     * @return The Routing context.
+     */
+    public final BusRoutingContext createRoutingContext()
+    {
+        BusRoutingContext routingContext = new BusRoutingContext(this);
+
+        addBusOutboundRouters(routingContext);
+        addBusInboundRouters(routingContext);
+
+        return routingContext;
+    }
+
+    /**
      * Add a {@link BusOutboundRouter} for each Inbound Router Dispatcher.
      * <p/>
      * Add a {@link BusOutboundRouter} for every service, updating the supplied busRouters
      * Map.
      *
-     * @param busRouters The Map to which the routers are to be added.
+     * @param routingContext The Routing Context to be updated..
      */
-    public final void addBusOutboundRouters(final Map<ServiceName, BusOutboundRouter> busRouters)
+    private final void addBusOutboundRouters(final BusRoutingContext routingContext)
     {
+        Map<ServiceName, BusOutboundRouter> busRouters = routingContext.getBusOutRouters();
         Set<Map.Entry<ServiceName, List<OutboundRouterConfig>>> outRouters = aggregatedDeploymentUnit.getOutboundRouters().entrySet();
 
         for (Map.Entry<ServiceName, List<OutboundRouterConfig>> serviceOutRouters : outRouters)
@@ -579,10 +612,11 @@
      * Add {@link BusInboundRouter} for all the services (and outbound routers)
      * serviced by this deployment.
      *
-     * @param busRouters The bus dispatchers table to be updated.
+     * @param routingContext The Routing Context to be updated..
      */
-    public final void addBusInboundRouters(final Map<ServiceName, BusInboundRouter> busRouters)
+    private final void addBusInboundRouters(final BusRoutingContext routingContext)
     {
+        Map<ServiceName, BusInboundRouter> busRouters = routingContext.getBusInRouters();
         Set<Map.Entry<ServiceName, List<OutboundRouterConfig>>> outRouters = aggregatedDeploymentUnit.getOutboundRouters().entrySet();
 
         for (Map.Entry<ServiceName, List<OutboundRouterConfig>> serviceOutRouters : outRouters)

Modified: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/federate/DeploymentCoordinator.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/federate/DeploymentCoordinator.java	2008-09-19 11:33:55 UTC (rev 22917)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/federate/DeploymentCoordinator.java	2008-09-19 11:42:41 UTC (rev 22918)
@@ -31,6 +31,7 @@
 import org.jboss.esb.federate.bus.BusMessage;
 import org.jboss.esb.federate.bus.BusMessageListener;
 import org.jboss.esb.federate.bus.BusOutboundRouter;
+import org.jboss.esb.federate.bus.BusRoutingContext;
 import org.jboss.esb.federate.notify.AbstractDeploymentNotification;
 import org.jboss.esb.federate.notify.DeploymentDetailsNotification;
 import org.jboss.esb.federate.notify.DeploymentHeartbeatNotification;
@@ -44,7 +45,6 @@
 import org.jboss.esb.util.AssertArgument;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -102,13 +102,9 @@
      */
     private long monitorTimeout;
     /**
-     * Bus Outbound Routers - sending messages out onto a bus.
+     * The Routing Context for the local deployment.
      */
-    private Map<ServiceName, BusOutboundRouter> busOutRouters = new HashMap<ServiceName, BusOutboundRouter>();
-    /**
-     * Bus Inbound Routers - receiving messages from a bus and dispatching them to the target service.
-     */
-    private Map<ServiceName, BusInboundRouter> busInRouters = new HashMap<ServiceName, BusInboundRouter>();
+    private BusRoutingContext routingContext;
 
     /**
      * Public constructor.
@@ -138,11 +134,10 @@
         // Set the deploymnt monitor timeout - 3 missed heartbeats...
         monitorTimeout = (deploymentProperties.getLongProperty(COORDINATOR_HEARTBEAT_FREQUENCY_KEY, COORDINATOR_HEARTBEAT_DEFAULT_FREQUENCY) * 3);
 
-        // Add the bus outbound and inbound routers before starting the local bus interfaces.
-        // This way they're available to have DeploymentMonitors attached and receive messages
+        // Create the BusRoutingContext before starting the local bus interfaces.
+        // This way it's available to have DeploymentMonitors attached and receive messages
         // as soon as this deployment gets "online" notifications from other deployments...
-        runtime.addBusOutboundRouters(busOutRouters);
-        runtime.addBusInboundRouters(busInRouters);
+        routingContext = runtime.createRoutingContext();
 
         // Start all configured bus interfaces...
         Set<Map.Entry<Object, Object>> configEntries = deploymentProperties.entrySet();
@@ -289,9 +284,9 @@
      */
     private void attachDeploymentMonitor(final DeploymentMonitor monitor)
     {
-        synchronized (busOutRouters)
+        synchronized (routingContext)
         {
-            Set<Map.Entry<ServiceName, BusOutboundRouter>> serviceOutRouterSet = busOutRouters.entrySet();
+            Set<Map.Entry<ServiceName, BusOutboundRouter>> serviceOutRouterSet = routingContext.getBusOutRouters().entrySet();
 
             for (Map.Entry<ServiceName, BusOutboundRouter> serviceOutRouter : serviceOutRouterSet)
             {
@@ -316,9 +311,9 @@
      */
     private void detachDeploymentMonitor(final DeploymentMonitor monitor)
     {
-        synchronized (busOutRouters)
+        synchronized (routingContext)
         {
-            Set<Map.Entry<ServiceName, BusOutboundRouter>> serviceOutRouterSet = busOutRouters.entrySet();
+            Set<Map.Entry<ServiceName, BusOutboundRouter>> serviceOutRouterSet = routingContext.getBusOutRouters().entrySet();
 
             for (Map.Entry<ServiceName, BusOutboundRouter> serviceOutRouter : serviceOutRouterSet)
             {
@@ -513,7 +508,7 @@
                     throw new RoutingException("Invalid ESB Message. 'To' address not set.  Message from '" + addressing.getFrom() + "'.");
                 }
 
-                BusInboundRouter inRouter = busInRouters.get(toService);
+                BusInboundRouter inRouter = routingContext.getBusInRouters().get(toService);
                 if (inRouter == null)
                 {
                     throw new RoutingException("Invalid ESB Message from '" + addressing.getFrom() + "'.  Service '" + toService + "' unknown on this deployment.");

Modified: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/federate/bus/BusInboundRouter.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/federate/bus/BusInboundRouter.java	2008-09-19 11:33:55 UTC (rev 22917)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/federate/bus/BusInboundRouter.java	2008-09-19 11:42:41 UTC (rev 22918)
@@ -71,11 +71,22 @@
         AddressingContext.setContext(addressingContext);
         try
         {
-            dispatcher.dispatch(esbMessage, invocationContext);
+            dispatch(esbMessage, invocationContext);
         }
         finally
         {
             AddressingContext.setContext(null);
         }
     }
+
+    /**
+     * Dispatch the supplied message to the target service
+     * @param esbMessage The ESB Message.
+     * @param invocationContext The Invocation Context to be used.
+     * @throws RoutingException An exception occured while dispatching the message.
+     */
+    public final void dispatch(final Message esbMessage, final InvocationContext invocationContext) throws RoutingException
+    {
+        dispatcher.dispatch(esbMessage, invocationContext);
+    }
 }

Added: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/federate/bus/BusRoutingContext.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/federate/bus/BusRoutingContext.java	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/federate/bus/BusRoutingContext.java	2008-09-19 11:42:41 UTC (rev 22918)
@@ -0,0 +1,121 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright XXXX, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2008, JBoss Inc.
+ */
+package org.jboss.esb.federate.bus;
+
+import org.jboss.esb.context.DeploymentContext;
+import org.jboss.esb.deploy.DeploymentRuntime;
+import org.jboss.esb.service.ServiceName;
+import org.jboss.esb.util.AssertArgument;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Bus routing context.
+ * <p/>
+ * Contains {@link Bus} routing info relating to the local deployment.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class BusRoutingContext
+{
+    /**
+     * The associated Deployment Runtime.
+     */
+    private DeploymentRuntime deploymentRuntime;
+    /**
+     * Bus Inbound Routers - receiving messages from a bus and dispatching them to the target service.
+     */
+    private Map<ServiceName, BusInboundRouter> busInRouters = new HashMap<ServiceName, BusInboundRouter>();
+    /**
+     * Bus Outbound Routers - sending messages out onto a bus.
+     */
+    private Map<ServiceName, BusOutboundRouter> busOutRouters = new HashMap<ServiceName, BusOutboundRouter>();
+
+    /**
+     * Public Constructor.
+     *
+     * @param deploymentRuntime The associated deployment runtime.
+     */
+    public BusRoutingContext(final DeploymentRuntime deploymentRuntime)
+    {
+        AssertArgument.isNotNull(deploymentRuntime, "deploymentRuntime");
+        this.deploymentRuntime = deploymentRuntime;
+
+        // And store the routing context in the DeploymentContext...
+        deploymentRuntime.getContext().setContextObject(BusRoutingContext.class, this);
+    }
+
+    /**
+     * Get the {@link BusRoutingContext} associated with the supplied {@link DeploymentContext}.
+     *
+     * @param deploymentContext The associated {@link DeploymentContext}.
+     * @return The BusRoutingContext.
+     */
+    public static BusRoutingContext getContext(final DeploymentContext deploymentContext)
+    {
+        BusRoutingContext context = (BusRoutingContext) deploymentContext.getContextObject(BusRoutingContext.class);
+        if(context == null)
+        {
+            throw new IllegalStateException("Cannot access the BusRoutingContext before the DeploymentRuntime is fully deployed.");
+        }
+        return context;
+    }
+
+    /**
+     * Get the {@link BusInboundRouter} for the local deployment.
+     *
+     * @return The {@link BusInboundRouter} for the local deployment.
+     */
+    public final Map<ServiceName, BusInboundRouter> getBusInRouters()
+    {
+        return busInRouters;
+    }
+
+    /**
+     * Set the {@link BusInboundRouter} for the local deployment.
+     *
+     * @param busInRouters The {@link BusInboundRouter} for the local deployment.
+     */
+    public final void setBusInRouters(final Map<ServiceName, BusInboundRouter> busInRouters)
+    {
+        this.busInRouters = busInRouters;
+    }
+
+    /**
+     * Get the {@link BusOutboundRouter} for the local deployment.
+     *
+     * @return The {@link BusOutboundRouter} for the local deployment.
+     */
+    public final Map<ServiceName, BusOutboundRouter> getBusOutRouters()
+    {
+        return busOutRouters;
+    }
+
+    /**
+     * Set the {@link BusOutboundRouter} for the local deployment.
+     *
+     * @param busOutRouters The {@link BusOutboundRouter} for the local deployment.
+     */
+    public final void setBusOutRouters(final Map<ServiceName, BusOutboundRouter> busOutRouters)
+    {
+        this.busOutRouters = busOutRouters;
+    }
+}


Property changes on: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/federate/bus/BusRoutingContext.java
___________________________________________________________________
Name: svn:eol-style
   + native




More information about the jboss-svn-commits mailing list