You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by ru...@apache.org on 2008/05/06 09:08:37 UTC

svn commit: r653692 - in /synapse/trunk/java/modules/core/src/main/java/org/apache/synapse: config/xml/endpoints/ endpoints/ endpoints/utils/

Author: ruwan
Date: Tue May  6 00:08:35 2008
New Revision: 653692

URL: http://svn.apache.org/viewvc?rev=653692&view=rev
Log:
Removed almost all the redundant code in Endpoint factories and serializers

Modified:
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointSerializer.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointSerializer.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointFactory.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointSerializer.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/AddressEndpoint.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/WSDLEndpoint.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/utils/EndpointDefinition.java

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java?rev=653692&r1=653691&r2=653692&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java Tue May  6 00:08:35 2008
@@ -69,9 +69,8 @@
     public Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint) {
 
         AddressEndpoint addressEndpoint = new AddressEndpoint();
-
-        OMAttribute name
-                = epConfig.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
+        OMAttribute name = epConfig.getAttribute(
+                new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
 
         if (name != null) {
             addressEndpoint.setName(name.getAttributeValue());
@@ -79,30 +78,9 @@
 
         OMElement addressElement = epConfig.getFirstChildWithName(
                 new QName(SynapseConstants.SYNAPSE_NAMESPACE, "address"));
-
         if (addressElement != null) {
             EndpointDefinition endpoint = createEndpointDefinition(addressElement);
             addressEndpoint.setEndpoint(endpoint);
-
-            // set the suspend on fail duration.
-            OMElement suspendElement = addressElement.getFirstChildWithName(new QName(
-                    SynapseConstants.SYNAPSE_NAMESPACE,
-                    org.apache.synapse.config.xml.XMLConfigConstants.SUSPEND_DURATION_ON_FAILURE));
-
-            if (suspendElement != null) {
-                String suspend = suspendElement.getText();
-
-                try {
-                    if (suspend != null) {
-                        long suspendDuration = Long.parseLong(suspend.trim());
-                        addressEndpoint.setSuspendOnFailDuration(suspendDuration * 1000);
-                    }
-
-                } catch (NumberFormatException e) {
-                    handleException("The suspend duration should be specified as a valid number :: "
-                        + e.getMessage(), e);
-                }
-            }
         }
 
         return addressEndpoint;
@@ -119,7 +97,6 @@
     public EndpointDefinition createEndpointDefinition(OMElement elem) {
 
         OMAttribute address = elem.getAttribute(new QName("uri"));
-
         EndpointDefinition endpointDefinition = new EndpointDefinition();
 
         if (address != null) {
@@ -127,7 +104,6 @@
         }
 
         extractQOSInformation(endpointDefinition, elem);
-
         return endpointDefinition;
     }
 }

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointSerializer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointSerializer.java?rev=653692&r1=653691&r2=653692&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointSerializer.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointSerializer.java Tue May  6 00:08:35 2008
@@ -54,18 +54,6 @@
         OMElement addressElement = serializeEndpointDefinition(epAddress);
         endpointElement.addChild(addressElement);
 
-        long suspendDuration = addressEndpoint.getSuspendOnFailDuration();
-        if (suspendDuration != -1) {
-            // user has set some value for this. let's serialize it.
-
-            OMElement suspendElement = fac.createOMElement(
-                    org.apache.synapse.config.xml.XMLConfigConstants.SUSPEND_DURATION_ON_FAILURE,
-                    SynapseConstants.SYNAPSE_OMNAMESPACE);
-
-            suspendElement.setText(Long.toString(suspendDuration / 1000));
-            addressElement.addChild(suspendElement);
-        }
-
         return endpointElement;
     }
 

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java?rev=653692&r1=653691&r2=653692&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java Tue May  6 00:08:35 2008
@@ -243,6 +243,20 @@
                 }
             }
         }
+
+        // set the suspend on fail duration.
+        OMElement suspendElement = elem.getFirstChildWithName(new QName(
+                SynapseConstants.SYNAPSE_NAMESPACE,
+                XMLConfigConstants.SUSPEND_DURATION_ON_FAILURE));
+        if (suspendElement != null && suspendElement.getText() != null) {
+            try {
+                long suspendDuration = Long.parseLong(suspendElement.getText().trim());
+                endpointDefinition.setSuspendOnFailDuration(suspendDuration * 1000);
+            } catch (NumberFormatException e) {
+                handleException("The suspend duration should be specified as a valid number :: "
+                        + e.getMessage(), e);
+            }
+        }
     }
 
     protected static void handleException(String msg) {

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointSerializer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointSerializer.java?rev=653692&r1=653691&r2=653692&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointSerializer.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointSerializer.java Tue May  6 00:08:35 2008
@@ -160,6 +160,17 @@
             }
             timeout.addChild(action);
         }
+
+        long suspendDuration = endpointDefinition.getSuspendOnFailDuration();
+        if (suspendDuration != -1) {
+            // user has set some value for this. let's serialize it.
+            OMElement suspendElement = fac.createOMElement(
+                    org.apache.synapse.config.xml.XMLConfigConstants.SUSPEND_DURATION_ON_FAILURE,
+                    SynapseConstants.SYNAPSE_OMNAMESPACE);
+
+            suspendElement.setText(Long.toString(suspendDuration / 1000));
+            element.addChild(suspendElement);
+        }
     }
 
     protected void handleException(String message) {

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointFactory.java?rev=653692&r1=653691&r2=653692&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointFactory.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointFactory.java Tue May  6 00:08:35 2008
@@ -64,7 +64,6 @@
     public Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint) {
 
         WSDLEndpoint wsdlEndpoint = new WSDLEndpoint();
-
         OMAttribute name = epConfig.getAttribute(new QName(
                 org.apache.synapse.config.xml.XMLConfigConstants.NULL_NAMESPACE, "name"));
 
@@ -74,36 +73,14 @@
 
         OMElement wsdlElement = epConfig.getFirstChildWithName
                 (new QName(SynapseConstants.SYNAPSE_NAMESPACE, "wsdl"));
-
         if (wsdlElement != null) {
 
-            // set the suspend on fail duration.
-            OMElement suspendElement = wsdlElement.getFirstChildWithName(new QName(
-                    SynapseConstants.SYNAPSE_NAMESPACE,
-                    org.apache.synapse.config.xml.XMLConfigConstants.SUSPEND_DURATION_ON_FAILURE));
-
-            if (suspendElement != null) {
-                String suspend = suspendElement.getText();
-
-                try {
-                    if (suspend != null) {
-                        long suspendDuration = Long.parseLong(suspend.trim());
-                        wsdlEndpoint.setSuspendOnFailDuration(suspendDuration * 1000);
-                    }
-
-                } catch (NumberFormatException e) {
-                    handleException("suspendDurationOnFailure should be valid number.");
-                }
-            }
-
             EndpointDefinition endpoint = null;
 
             // get the service name and port name. at this point we should not worry about
             // the presence of those parameters. they are handled by corresponding WSDL builders.
             String serviceName = wsdlElement.getAttributeValue(new QName("service"));
-
             String portName = wsdlElement.getAttributeValue(new QName("port"));
-
             // check if wsdl is supplied as a URI
             String wsdlURI = wsdlElement.getAttributeValue(new QName("uri"));
 
@@ -167,6 +144,7 @@
                 wsdlEndpoint.setWsdlDoc(descriptionElement);
                 handleException("WSDL 2.0 Endpoints are currently not supported.");
             }
+            
             if (endpoint != null) {
                 // for now, QOS information has to be provided explicitly.
                 extractQOSInformation(endpoint, wsdlElement);
@@ -178,5 +156,5 @@
 
         return wsdlEndpoint;
     }
-    
+
 }

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointSerializer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointSerializer.java?rev=653692&r1=653691&r2=653692&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointSerializer.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointSerializer.java Tue May  6 00:08:35 2008
@@ -77,18 +77,6 @@
             wsdlElement.addChild(wsdlDoc);
         }
 
-        long suspendDuration = wsdlEndpoint.getSuspendOnFailDuration();
-        if (suspendDuration != -1) {
-            // user has set some value for this. let's serialize it.
-
-            OMElement suspendElement = fac.createOMElement(
-                    org.apache.synapse.config.xml.XMLConfigConstants.SUSPEND_DURATION_ON_FAILURE,
-                    SynapseConstants.SYNAPSE_OMNAMESPACE);
-
-            suspendElement.setText(Long.toString(suspendDuration / 1000));
-            wsdlElement.addChild(suspendElement);
-        }
-
         // currently, we have to get QOS information from the endpoint definition and set them as
         // special elements under the wsdl element. in future, these information should be
         // extracted from the wsdl.

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/AddressEndpoint.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/AddressEndpoint.java?rev=653692&r1=653691&r2=653692&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/AddressEndpoint.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/AddressEndpoint.java Tue May  6 00:08:35 2008
@@ -61,12 +61,6 @@
     private Endpoint parentEndpoint = null;
 
     /**
-     * Leaf level endpoints will be suspended for the specified time by this variable, after a
-     * failure. If this is not explicitly set, it is set to -1, which causes endpoints to suspended forever.
-     */
-    private long suspendOnFailDuration = -1;
-
-    /**
      * The endpoint context , place holder for keep any runtime states related to the endpoint
      */
     private final EndpointContext endpointContext = new EndpointContext();
@@ -124,10 +118,11 @@
         // this method simultaneously.
 
         if (!active) {
-            if (suspendOnFailDuration != -1) {
+            if (endpoint.getSuspendOnFailDuration() != -1) {
                 // Calculating a new value by adding suspendOnFailDuration to current time.
                 // as the endpoint is set as failed
-                endpointContext.setRecoverOn(System.currentTimeMillis() + suspendOnFailDuration);
+                endpointContext.setRecoverOn(
+                        System.currentTimeMillis() + endpoint.getSuspendOnFailDuration());
             } else {
                 endpointContext.setRecoverOn(Long.MAX_VALUE);
             }
@@ -244,19 +239,6 @@
         this.parentEndpoint = parentEndpoint;
     }
 
-    public long getSuspendOnFailDuration() {
-        return suspendOnFailDuration;
-    }
-
-    /**
-     * Set the suspend on fail duration.
-     * 
-     * @param suspendOnFailDuration a duration in milliseconds
-     */
-    public void setSuspendOnFailDuration(long suspendOnFailDuration) {
-        this.suspendOnFailDuration = suspendOnFailDuration;
-    }
-
     public void onFault(MessageContext synCtx) {
         // perform retries here
 

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/WSDLEndpoint.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/WSDLEndpoint.java?rev=653692&r1=653691&r2=653692&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/WSDLEndpoint.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/WSDLEndpoint.java Tue May  6 00:08:35 2008
@@ -53,12 +53,6 @@
     private String serviceName;
     private String portName;
 
-    /**
-     * Leaf level endpoints will be suspended for the specified time by this variable, after a
-     * failure. If this is not explicitly set, it is set to -1, which causes endpoints to suspended forever.
-     */
-    private long suspendOnFailDuration = -1;
-
     private Endpoint parentEndpoint = null;
     private EndpointDefinition endpoint = null;
 
@@ -200,14 +194,6 @@
         this.name = name.trim();
     }
 
-    public long getSuspendOnFailDuration() {
-        return suspendOnFailDuration;
-    }
-
-    public void setSuspendOnFailDuration(long suspendOnFailDuration) {
-        this.suspendOnFailDuration = suspendOnFailDuration;
-    }
-
     public String getWsdlURI() {
         return wsdlURI;
     }
@@ -269,10 +255,11 @@
     public void setActive(boolean active, MessageContext synMessageContext) {
 
         if (!active) {
-            if (suspendOnFailDuration != -1) {
+            if (endpoint.getSuspendOnFailDuration() != -1) {
                 // Calculating a new value by adding suspendOnFailDuration to current time.
                 // as the endpoint is set as failed
-                endpointContext.setRecoverOn(System.currentTimeMillis() + suspendOnFailDuration);
+                endpointContext.setRecoverOn(
+                        System.currentTimeMillis() + endpoint.getSuspendOnFailDuration());
             } else {
                 endpointContext.setRecoverOn(Long.MAX_VALUE);
             }

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/utils/EndpointDefinition.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/utils/EndpointDefinition.java?rev=653692&r1=653691&r2=653692&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/utils/EndpointDefinition.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/utils/EndpointDefinition.java Tue May  6 00:08:35 2008
@@ -110,6 +110,13 @@
     private int timeoutAction = SynapseConstants.NONE;
 
     /**
+     * Leaf level endpoints will be suspended for the specified time by this variable, after a
+     * failure. If this is not explicitly set, it is set to -1, which causes endpoints to
+     * suspended forever.
+     */
+    private long suspendOnFailDuration = -1;
+
+    /**
      * To decide to whether statistics should have collected or not
      */
     private int statisticsState = SynapseConstants.STATISTICS_UNSET;
@@ -333,8 +340,8 @@
 
     /**
      * Get the charset encoding for messages sent to the endpoint.
-     * 
-     * @param charSetEncoding
+     *
+     * @return charSetEncoding
      */
     public String getCharSetEncoding() {
         return charSetEncoding;
@@ -350,6 +357,24 @@
     }
 
     /**
+     * Get the suspend on fail duration.
+     *
+     * @return suspendOnFailDuration
+     */
+    public long getSuspendOnFailDuration() {
+        return suspendOnFailDuration;
+    }
+
+    /**
+     * Set the suspend on fail duration.
+     *
+     * @param suspendOnFailDuration a duration in milliseconds
+     */
+    public void setSuspendOnFailDuration(long suspendOnFailDuration) {
+        this.suspendOnFailDuration = suspendOnFailDuration;
+    }
+
+    /**
      * To check whether statistics should have collected or not
      *
      * @return Returns the int value that indicate statistics is enabled or not.