You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2009/12/03 23:15:28 UTC

svn commit: r886948 - in /cxf/branches/2.2.x-fixes: ./ api/src/main/java/org/apache/cxf/clustering/ rt/core/src/main/java/org/apache/cxf/clustering/ systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/

Author: dkulp
Date: Thu Dec  3 22:15:28 2009
New Revision: 886948

URL: http://svn.apache.org/viewvc?rev=886948&view=rev
Log:
Merged revisions 885426 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r885426 | eglynn | 2009-11-30 08:46:34 -0500 (Mon, 30 Nov 2009) | 2 lines
  
  Allowing failover addresses to be overridden in configuration
........

Added:
    cxf/branches/2.2.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/FailoverAddressOverrideTest.java
      - copied unchanged from r885426, cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/FailoverAddressOverrideTest.java
    cxf/branches/2.2.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/failover_address_override.xml
      - copied unchanged from r885426, cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/failover_address_override.xml
Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/clustering/FailoverStrategy.java
    cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/AbstractStaticFailoverStrategy.java
    cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java
    cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/Messages.properties
    cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/RandomStrategy.java
    cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/SequentialStrategy.java

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/clustering/FailoverStrategy.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/clustering/FailoverStrategy.java?rev=886948&r1=886947&r2=886948&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/clustering/FailoverStrategy.java (original)
+++ cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/clustering/FailoverStrategy.java Thu Dec  3 22:15:28 2009
@@ -44,4 +44,21 @@
      * @return the selected endpoint
      */
     Endpoint selectAlternateEndpoint(List<Endpoint> alternates);
+
+    /**
+     * Get the alternate addresses for this invocation.
+     * These addresses over-ride any addresses specified in the WSDL.
+     * 
+     * @param exchange the current Exchange     
+     * @return a failover endpoint if one is available
+     */
+    List<String> getAlternateAddresses(Exchange exchange);
+
+    /**
+     * Select one of the alternate addresses for a retried invocation.
+     * 
+     * @param alternates List of alternate addresses if available
+     * @return the selected address
+     */
+    String selectAlternateAddress(List<String> addresses);
 }

Modified: cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/AbstractStaticFailoverStrategy.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/AbstractStaticFailoverStrategy.java?rev=886948&r1=886947&r2=886948&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/AbstractStaticFailoverStrategy.java (original)
+++ cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/AbstractStaticFailoverStrategy.java Thu Dec  3 22:15:28 2009
@@ -38,10 +38,47 @@
  * multiple endpoints associated with the same service instance.
  */
 public abstract class AbstractStaticFailoverStrategy implements FailoverStrategy {
-    
     private static final Logger LOG =
         LogUtils.getL7dLogger(AbstractStaticFailoverStrategy.class);
-    
+
+    private List<String> alternateAddresses;
+
+
+    public void setAlternateAddresses(List<String> alternateAddresses) {
+        this.alternateAddresses = alternateAddresses;
+    }
+   
+    /**
+     * Get the alternate addresses for this invocation.
+     * 
+     * @param exchange the current Exchange
+     * @return a List of alternate addresses if available
+     */
+    public List<String> getAlternateAddresses(Exchange exchange) {
+        return alternateAddresses != null
+               ? new ArrayList<String>(alternateAddresses)
+               : null;
+    }
+
+    /**
+     * Select one of the alternate addresses for a retried invocation.
+     * 
+     * @param a List of alternate addresses if available
+     * @return the selected address
+     */
+    public String selectAlternateAddress(List<String> alternates) {
+        String selected = null;
+        if (alternates != null && alternates.size() > 0) {
+            selected = getNextAlternate(alternates);
+            LOG.log(Level.WARNING,
+                    "FAILING_OVER_TO_ADDRESS_OVERRIDE",
+                    selected);
+        } else {
+            LOG.warning("NO_ALTERNATE_TARGETS_REMAIN");
+        }
+        return selected;
+    }
+
     /**
      * Get the alternate endpoints for this invocation.
      * 
@@ -53,6 +90,26 @@
     }
     
     /**
+     * Select one of the alternate endpoints for a retried invocation.
+     * 
+     * @param a List of alternate endpoints if available
+     * @return the selected endpoint
+     */
+    public Endpoint selectAlternateEndpoint(List<Endpoint> alternates) {
+        Endpoint selected = null;
+        if (alternates != null && alternates.size() > 0) {
+            selected = getNextAlternate(alternates);
+            LOG.log(Level.WARNING,
+                    "FAILING_OVER_TO_ALTERNATE_ENDPOINT",
+                     new Object[] {selected.getEndpointInfo().getName(),
+                                   selected.getEndpointInfo().getAddress()});
+        } else {
+            LOG.warning("NO_ALTERNATE_TARGETS_REMAIN");
+        }
+        return selected;
+    }
+    
+    /**
      * Get the endpoints for this invocation.
      * 
      * @param exchange the current Exchange
@@ -91,30 +148,10 @@
     }
 
     /**
-     * Select one of the alternate endpoints for a retried invocation.
-     * 
-     * @param a List of alternate endpoints if available
-     * @return the selected endpoint
-     */
-    public Endpoint selectAlternateEndpoint(List<Endpoint> alternates) {
-        Endpoint selected = null;
-        if (alternates != null && alternates.size() > 0) {
-            selected = getNextAlternate(alternates);
-            LOG.log(Level.WARNING,
-                    "FAILING_OVER_TO",
-                     new Object[] {selected.getEndpointInfo().getName(),
-                                   selected.getEndpointInfo().getAddress()});
-        } else {
-            LOG.warning("NO_ALTERNATE_TARGETS_REMAIN");
-        }
-        return selected;
-    }
-    
-    /**
      * Get next alternate endpoint.
      * 
      * @param alternates non-empty List of alternate endpoints 
      * @return
      */
-    protected abstract Endpoint getNextAlternate(List<Endpoint> alternates);
+    protected abstract <T> T getNextAlternate(List<T> alternates);
 }

Modified: cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java?rev=886948&r1=886947&r2=886948&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java (original)
+++ cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java Thu Dec  3 22:15:28 2009
@@ -102,7 +102,7 @@
     }
 
     /**
-     * Called on completion of the MEP for which the Conduit was required.
+     * Called on completion of the MEP for which the Condit was required.
      * 
      * @param exchange represents the completed MEP
      */
@@ -116,7 +116,7 @@
         if (requiresFailover(exchange)) {
             Endpoint failoverTarget = getFailoverTarget(exchange, invocation);
             if (failoverTarget != null) {
-                endpoint = failoverTarget;
+                setEndpoint(failoverTarget);
                 selectedConduit.close();
                 selectedConduit = null;
                 Exception prevExchangeFault =
@@ -146,12 +146,7 @@
                     }
                 }
             } else {
-                if (endpoint != invocation.getOriginalEndpoint()) {
-                    endpoint = invocation.getOriginalEndpoint();
-                    getLogger().log(Level.INFO,
-                                    "REVERT_TO_ORIGINAL_TARGET",
-                                    endpoint.getEndpointInfo().getName());
-                }
+                setEndpoint(invocation.retrieveOriginalEndpoint(endpoint));
             }
         }
         if (!failover) {
@@ -225,16 +220,39 @@
      * @return a failover endpoint if one is available
      */
     private Endpoint getFailoverTarget(Exchange exchange,
-                                       InvocationContext invocation) {        
-        if (invocation.getAlternateTargets() == null) {
+                                       InvocationContext invocation) {
+        List<String> alternateAddresses = null;
+        if (!invocation.hasAlternates()) {
             // no previous failover attempt on this invocation
             //
-            invocation.setAlternateTargets(
-                getStrategy().getAlternateEndpoints(exchange));
-        } 
+            alternateAddresses = 
+                getStrategy().getAlternateAddresses(exchange);
+            if (alternateAddresses != null) {
+                invocation.setAlternateAddresses(alternateAddresses);
+            } else {
+                invocation.setAlternateEndpoints(
+                    getStrategy().getAlternateEndpoints(exchange));
+            }
+        } else {
+            alternateAddresses = invocation.getAlternateAddresses();
+        }
 
-        return getStrategy().selectAlternateEndpoint(
-                   invocation.getAlternateTargets());
+        Endpoint failoverTarget = null;
+        if (alternateAddresses != null) {
+            String alternateAddress = 
+                getStrategy().selectAlternateAddress(alternateAddresses);
+            if (alternateAddress != null) {
+                // re-use current endpoint
+                //
+                failoverTarget = getEndpoint();
+
+                failoverTarget.getEndpointInfo().setAddress(alternateAddress);
+            }
+        } else {
+            failoverTarget = getStrategy().selectAlternateEndpoint(
+                                 invocation.getAlternateEndpoints());
+        }
+        return failoverTarget;
     }
     
     /**
@@ -282,24 +300,38 @@
     /**
      * Records the context of an invocation.
      */
-    private static class InvocationContext {
+    private class InvocationContext {
         private Endpoint originalEndpoint;
+        private String originalAddress;
         private BindingOperationInfo bindingOperationInfo;
         private Object[] params; 
         private Map<String, Object> context;
-        private List<Endpoint> alternateTargets;
+        private List<Endpoint> alternateEndpoints;
+        private List<String> alternateAddresses;
         
         InvocationContext(Endpoint endpoint,
                           BindingOperationInfo boi,
                           Object[] prms, 
                           Map<String, Object> ctx) {
             originalEndpoint = endpoint;
+            originalAddress = endpoint.getEndpointInfo().getAddress();
             bindingOperationInfo = boi;
             params = prms;
             context = ctx;
         }
 
-        Endpoint getOriginalEndpoint() {
+        Endpoint retrieveOriginalEndpoint(Endpoint endpoint) {
+            if (endpoint != originalEndpoint) {
+                getLogger().log(Level.INFO,
+                                "REVERT_TO_ORIGINAL_TARGET",
+                                endpoint.getEndpointInfo().getName());
+            }
+            if (!endpoint.getEndpointInfo().getAddress().equals(originalAddress)) {
+                endpoint.getEndpointInfo().setAddress(originalAddress);
+                getLogger().log(Level.INFO,
+                                "REVERT_TO_ORIGINAL_ADDRESS",
+                                endpoint.getEndpointInfo().getAddress());
+            }
             return originalEndpoint;
         }
         
@@ -315,12 +347,24 @@
             return context;
         }
         
-        List<Endpoint> getAlternateTargets() {
-            return alternateTargets;
+        List<Endpoint> getAlternateEndpoints() {
+            return alternateEndpoints;
+        }
+
+        List<String> getAlternateAddresses() {
+            return alternateAddresses;
+        }
+
+        void setAlternateEndpoints(List<Endpoint> alternates) {
+            alternateEndpoints = alternates;
+        }
+
+        void setAlternateAddresses(List<String> alternates) {
+            alternateAddresses = alternates;
         }
 
-        void setAlternateTargets(List<Endpoint> alternates) {
-            alternateTargets = alternates;
+        boolean hasAlternates() {
+            return !(alternateEndpoints == null && alternateAddresses == null);
         }
     }    
 }

Modified: cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/Messages.properties
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/Messages.properties?rev=886948&r1=886947&r2=886948&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/Messages.properties (original)
+++ cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/Messages.properties Thu Dec  3 22:15:28 2009
@@ -20,10 +20,12 @@
 #
 USING_STRATEGY = Using failover strategy {0}
 REVERT_TO_ORIGINAL_TARGET = reverted to original endpoint {0}
+REVERT_TO_ORIGINAL_ADDRESS = reverted to original address {0}
 FAILOVER_NOT_REQUIRED = failover not required
 NO_ALTERNATE_TARGETS_REMAIN = no alternate targets remain => giving up on failover
 CHECK_LAST_INVOKE_FAILED = last invocation raised fault?: {0}
 CHECK_FAILURE_IN_TRANSPORT = failure {0} caused at transport level?: {1}
 FAILOVER_CANDIDATE_ACCEPTED = failover candidate {0} accepted
 FAILOVER_CANDIDATE_REJECTED = failover candidate {0} rejected on binding mismatch
-FAILING_OVER_TO = failing over to alternate target {0}
\ No newline at end of file
+FAILING_OVER_TO_ALTERNATE_ENDPOINT = failing over to alternate target {0}
+FAILING_OVER_TO_ADRESS_OVERRIDE = failing over to alternate address {0}

Modified: cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/RandomStrategy.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/RandomStrategy.java?rev=886948&r1=886947&r2=886948&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/RandomStrategy.java (original)
+++ cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/RandomStrategy.java Thu Dec  3 22:15:28 2009
@@ -22,8 +22,6 @@
 import java.util.List;
 import java.util.Random;
 
-import org.apache.cxf.endpoint.Endpoint;
-
 /**
  * Failover strategy based on a randomized walk through the
  * static cluster represented by multiple endpoints associated 
@@ -46,7 +44,7 @@
      * @param alternates non-empty List of alternate endpoints 
      * @return
      */
-    protected Endpoint getNextAlternate(List<Endpoint> alternates) {
+    protected <T> T getNextAlternate(List<T> alternates) {
         return alternates.remove(random.nextInt(alternates.size()));
     }
 }
\ No newline at end of file

Modified: cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/SequentialStrategy.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/SequentialStrategy.java?rev=886948&r1=886947&r2=886948&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/SequentialStrategy.java (original)
+++ cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/SequentialStrategy.java Thu Dec  3 22:15:28 2009
@@ -21,8 +21,6 @@
 
 import java.util.List;
 
-import org.apache.cxf.endpoint.Endpoint;
-
 /**
  * Failover strategy based on a sequential walk through the
  * static cluster represented by multiple endpoints associated 
@@ -36,7 +34,7 @@
      * @param alternates non-empty List of alternate endpoints 
      * @return
      */
-    protected Endpoint getNextAlternate(List<Endpoint> alternates) {
+    protected <T> T getNextAlternate(List<T> alternates) {
         return alternates.remove(0);
     }
 }