synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@apache.org
Subject svn commit: r582461 - in /webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core: SynapseEnvironment.java axis2/Axis2SynapseEnvironment.java
Date Sat, 06 Oct 2007 06:42:46 GMT
Author: ruwan
Date: Fri Oct  5 23:42:46 2007
New Revision: 582461

URL: http://svn.apache.org/viewvc?rev=582461&view=rev
Log:
Fixing the issue with the sendBack in Axis2SynapseEnvironment.java

Modified:
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/SynapseEnvironment.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/SynapseEnvironment.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/SynapseEnvironment.java?rev=582461&r1=582460&r2=582461&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/SynapseEnvironment.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/SynapseEnvironment.java
Fri Oct  5 23:42:46 2007
@@ -20,6 +20,7 @@
 package org.apache.synapse.core;
 
 import org.apache.synapse.MessageContext;
+import org.apache.synapse.mediators.base.SequenceMediator;
 import org.apache.synapse.endpoints.utils.EndpointDefinition;
 import org.apache.synapse.statistics.StatisticsCollector;
 import edu.emory.mathcs.backport.java.util.concurrent.ExecutorService;
@@ -42,14 +43,28 @@
     public boolean injectMessage(MessageContext smc);
 
     /**
-     * This method allows a message to be sent through the underlying SOAP engine.
-     * <p/>
-     * This will send request messages on (forward), and send the response messages back
to the client
+     * This method injects a new message into the synapse engine for the mediation
+     * by the specified sequence. This is used by custom mediation tasks like splitting message
+     * in EIP mediations. This method will do the mediation asynchronouslly using a separate
+     * thread from the environment thread pool
+     *
+     * @param smc - Synapse message context to be injected
+     * @param seq - Sequence to be used for mediation
+     */
+    public void injectAsync(MessageContext smc, SequenceMediator seq);
+
+    /**
+     * This method allows a message to be sent through the underlying SOAP engine. This will
+     * send request messages on (forward), and send the response messages back to the client
+     *
+     * @param endpoint  - Endpoint to be used for sending
+     * @param smc       - Synapse MessageContext to be sent
      */
     public void send(EndpointDefinition endpoint, MessageContext smc);
 
     /**
      * Creates a new Synapse <code>MessageContext</code> instance.
+     *
      * @return a MessageContext
      */
     public MessageContext createMessageContext();
@@ -62,12 +77,12 @@
     public StatisticsCollector getStatisticsCollector();
 
     /**
-     * To set the StatisticsCollector
+     * To set the StatisticsCollector to the environment
      *
-     * @param statisticsCollector
+     * @param statisticsCollector - StatisticsCollector to be set
      */
     public void setStatisticsCollector(StatisticsCollector statisticsCollector);
-    
+
     /**
      * This is used by anyone who needs access to a ThreadPool. It offers the ability to
      * start work. See the backport concurrent documentation

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java?rev=582461&r1=582460&r2=582461&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java
Fri Oct  5 23:42:46 2007
@@ -24,20 +24,20 @@
 import org.apache.axis2.context.ServiceContext;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.SynapseConstants;
 import org.apache.synapse.Mediator;
 import org.apache.synapse.MessageContext;
+import org.apache.synapse.SynapseConstants;
 import org.apache.synapse.SynapseException;
-import org.apache.synapse.util.UUIDGenerator;
 import org.apache.synapse.config.SynapseConfiguration;
-import org.apache.synapse.endpoints.utils.EndpointDefinition;
 import org.apache.synapse.core.SynapseEnvironment;
+import org.apache.synapse.endpoints.utils.EndpointDefinition;
+import org.apache.synapse.mediators.base.SequenceMediator;
 import org.apache.synapse.statistics.StatisticsCollector;
 import org.apache.synapse.statistics.StatisticsUtils;
-
+import org.apache.synapse.util.UUIDGenerator;
 
 /**
- * <p> This is the Axis2 implementation of the MessageContext
+ * This is the Axis2 implementation of the SynapseEnvironment
  */
 public class Axis2SynapseEnvironment implements SynapseEnvironment {
 
@@ -70,7 +70,7 @@
             StatisticsUtils.processSequenceStatistics(synCtx);
         }
 
-        // if this is a response to a proxy service 
+        // if this is a response to a proxy service
         if (synCtx.getProperty(SynapseConstants.PROXY_SERVICE) != null) {
 
             if (synCtx.getConfiguration().getProxyService((String) synCtx.getProperty(
@@ -120,19 +120,68 @@
         return true;
     }
 
+    public void injectAsync(final MessageContext synCtx, SequenceMediator seq) {
+        if (log.isDebugEnabled()) {
+            log.debug("Injecting MessageContext for asynchronous mediation using the "
+                + seq.getName() == null? "Anonymous" : seq.getName());
+        }
+        synCtx.setEnvironment(this);
+        // todo: do we need to have this in here ? ruwan
+        if (synCtx.isResponse()) {
+            //Process statistics related to a sequence which has send mediator as a child,end
point
+            StatisticsUtils.processEndPointStatistics(synCtx);
+            StatisticsUtils.processProxyServiceStatistics(synCtx);
+            StatisticsUtils.processSequenceStatistics(synCtx);
+        }
+
+        ((Axis2MessageContext) synCtx).getAxis2MessageContext()
+            .getConfigurationContext().getThreadPool().execute(new SynapseWorker(seq, synCtx));
+
+    }
+
+    /**
+     * This will be used for sending the message provided, to the endpoint specified by the
+     * EndpointDefinition using the axis2 environment.
+     *
+     * @param endpoint - EndpointDefinition to be used to find the endpoint information
+     *                      and the properties of the sending process
+     * @param synCtx   - Synapse MessageContext to be sent
+     */
     public void send(EndpointDefinition endpoint, MessageContext synCtx) {
-        if (synCtx.isResponse())
-            Axis2Sender.sendBack(synCtx);
-        else
+        if (synCtx.isResponse()) {
+
+            if (endpoint != null) {
+                // not sure whether we need to collect statistics here
+                StatisticsUtils.processEndPointStatistics(synCtx);
+                StatisticsUtils.processProxyServiceStatistics(synCtx);
+                StatisticsUtils.processAllSequenceStatistics(synCtx);
+
+                Axis2Sender.sendOn(endpoint, synCtx);
+
+            } else {
+                Axis2Sender.sendBack(synCtx);
+            }
+        } else {
             Axis2Sender.sendOn(endpoint, synCtx);
+        }
     }
 
+    /**
+     * This method will be used to create a new MessageContext in the Axis2 environment for
+     * synapse. This will set all the relevant parts to the messagecontext, but for this
message
+     * context to be usefull creator has to fill in the data like envelope and operation
context
+     * and so on. This will set a default envelope of type soap12 and a new messageID for
the
+     * created message along with the ConfigurationContext is being set in to the message
+     * correctly.
+     *
+     * @return Synapse MessageContext with the underlying axis2 message context set
+     */
     public MessageContext createMessageContext() {
 
         if (log.isDebugEnabled()) {
             log.debug("Creating Message Context");
         }
-        
+
         org.apache.axis2.context.MessageContext axis2MC
                 = new org.apache.axis2.context.MessageContext();
         axis2MC.setConfigurationContext(this.configContext);
@@ -162,11 +211,53 @@
     /**
      * To set the StatisticsCollector
      *
-     * @param collector
+     * @param collector - Statistics collector to be set
      */
     public void setStatisticsCollector(StatisticsCollector collector) {
         this.statisticsCollector = collector;
     }
 
+    /**
+     * This inner class will be used as the executer for the injectAsync method for the
+     * sequence mediation
+     */
+    private class SynapseWorker implements Runnable {
+
+        /** Mediator to be executed */
+        private Mediator seq = null;
+
+        /** MessageContext to be mediated using the mediator */
+        private MessageContext synCtx = null;
+
+        /**
+         * Constructor of the SynapseWorker which sets the sequence and the message context
+         *
+         * @param seq    - Sequence Mediator to be set
+         * @param synCtx - Synapse MessageContext to be set
+         */
+        public SynapseWorker(Mediator seq, MessageContext synCtx) {
+            this.seq = seq;
+            this.synCtx = synCtx;
+        }
+
+        /**
+         * Constructor od the SynapseWorker which sets the provided message context and the
+         * main sequence as the sequence for mediation
+         *
+         * @param synCtx - Synapse MessageContext to be set
+         */
+        public SynapseWorker(MessageContext synCtx) {
+            this.synCtx = synCtx;
+            seq = synCtx.getMainSequence();
+        }
+
+        /**
+         * Execution method of the thread. This will just call the mediation of the specified
+         * Synapse MessageContext using the specified Sequence Mediator
+         */
+        public void run() {
+            seq.mediate(synCtx);
+        }
+    }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org


Mime
View raw message