You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by in...@apache.org on 2008/06/16 16:15:24 UTC
svn commit: r668171 - in
/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse:
endpoints/EndpointContext.java endpoints/algorithms/AlgorithmContext.java
endpoints/dispatch/DispatcherContext.java util/Replicator.java
Author: indika
Date: Mon Jun 16 07:15:23 2008
New Revision: 668171
URL: http://svn.apache.org/viewvc?rev=668171&view=rev
Log:
Some refactoring
Added:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/Replicator.java
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/EndpointContext.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/algorithms/AlgorithmContext.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/DispatcherContext.java
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/EndpointContext.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/EndpointContext.java?rev=668171&r1=668170&r2=668171&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/EndpointContext.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/EndpointContext.java Mon Jun 16 07:15:23 2008
@@ -18,12 +18,11 @@
*/
package org.apache.synapse.endpoints;
-import org.apache.axis2.clustering.ClusteringFault;
-import org.apache.axis2.clustering.context.Replicator;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.SynapseException;
+import org.apache.synapse.util.Replicator;
/**
* Keeps the states of the endpoint.This hides where those states are kept .For a cluster
@@ -110,7 +109,7 @@
if (this.isClusteringEnable) { // if this is a clustering env.
// replicates the state so that all instances across cluster can see this state
- setAndReplicateState(this.activePropertyKey, active);
+ Replicator.setAndReplicateState(this.activePropertyKey, active, configCtx);
} else {
this.active = active;
}
@@ -163,7 +162,7 @@
if (this.isClusteringEnable) { // if this is a clustering env.
// replicates the state so that all instances across cluster can see this state
- setAndReplicateState(this.recoverOnPropertyKey, recoverOn);
+ Replicator.setAndReplicateState(this.recoverOnPropertyKey, recoverOn, configCtx);
} else {
this.recoverOn = recoverOn;
}
@@ -219,55 +218,13 @@
}
-
- /**
- * Helper method to replicates states of the property with given key
- * replicates the given state so that all instances across cluster can see this state
- *
- * @param key The key of the property
- * @param value The value of the property
- */
- private void setAndReplicateState(String key, Object value) {
-
- if (configCtx != null && key != null && value != null) {
-
- try {
- if (log.isDebugEnabled()) {
- log.debug("Start replicating the property with key : " + key +
- " value : " + value);
- }
-
- configCtx.setProperty(key, value);
- Replicator.replicate(configCtx, new String[]{key});
-
- if (log.isDebugEnabled()) {
- log.debug("Completed replication of the property with key : " + key);
- }
-
- } catch (ClusteringFault clusteringFault) {
- handleException("Error during the replicating states ", clusteringFault);
- }
- }
- }
-
/**
* Helper methods for handle errors.
*
* @param msg The error message
*/
- protected void handleException(String msg) {
+ private void handleException(String msg) {
log.error(msg);
throw new SynapseException(msg);
}
-
- /**
- * Helper methods for handle errors.
- *
- * @param msg The error message
- * @param e The exception
- */
- protected void handleException(String msg, Exception e) {
- log.error(msg, e);
- throw new SynapseException(msg, e);
- }
}
\ No newline at end of file
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/algorithms/AlgorithmContext.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/algorithms/AlgorithmContext.java?rev=668171&r1=668170&r2=668171&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/algorithms/AlgorithmContext.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/algorithms/AlgorithmContext.java Mon Jun 16 07:15:23 2008
@@ -18,12 +18,11 @@
*/
package org.apache.synapse.endpoints.algorithms;
-import org.apache.axis2.clustering.ClusteringFault;
-import org.apache.axis2.clustering.context.Replicator;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.SynapseException;
+import org.apache.synapse.util.Replicator;
/**
* Keeps the states of the load balance algorithm.This hides where those states are kept.For a
@@ -108,7 +107,7 @@
+ " with the key " + currentEPRPropertyKey);
}
// Sets the property and replicates the current state so that all instances
- setAndReplicateState(currentEPRPropertyKey, currentEPR);
+ Replicator.setAndReplicateState(currentEPRPropertyKey, currentEPR, configCtx);
}
} else {
if (log.isDebugEnabled()) {
@@ -171,51 +170,8 @@
*
* @param msg The error message
*/
- protected void handleException(String msg) {
+ private void handleException(String msg) {
log.error(msg);
throw new SynapseException(msg);
}
-
- /**
- * Helper methods for handle errors.
- *
- * @param msg The error message
- * @param e The exception
- */
- protected void handleException(String msg, Exception e) {
- log.error(msg, e);
- throw new SynapseException(msg, e);
- }
-
- /**
- * Helper method to replicates states of the property with given key
- * Sets property and replicates the current state so that all instances
- * across cluster can see this state
- *
- * @param key The key of the property
- * @param value The value of the property
- */
- private void setAndReplicateState(String key, Object value) {
-
- if (configCtx != null && key != null && value != null) {
-
- try {
- if (log.isDebugEnabled()) {
- log.debug("Start replicating the property with key : " + key
- + " value : " + value);
- }
-
- configCtx.setProperty(key, value);
- Replicator.replicate(configCtx, new String[]{key});
-
- if (log.isDebugEnabled()) {
- log.debug("Completed replication of the property with key : " + key);
- }
-
- } catch (ClusteringFault clusteringFault) {
- handleException("Error during the replicating states ", clusteringFault);
- }
- }
- }
-
}
\ No newline at end of file
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/DispatcherContext.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/DispatcherContext.java?rev=668171&r1=668170&r2=668171&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/DispatcherContext.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/DispatcherContext.java Mon Jun 16 07:15:23 2008
@@ -18,8 +18,6 @@
*/
package org.apache.synapse.endpoints.dispatch;
-import org.apache.axis2.clustering.ClusteringFault;
-import org.apache.axis2.clustering.context.Replicator;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -28,6 +26,7 @@
import org.apache.synapse.endpoints.Endpoint;
import org.apache.synapse.endpoints.IndirectEndpoint;
import org.apache.synapse.endpoints.SALoadbalanceEndpoint;
+import org.apache.synapse.util.Replicator;
import java.util.Collections;
import java.util.HashMap;
@@ -132,14 +131,14 @@
}
endpointName = SynapseConstants.ANONYMOUS_ENDPOINT;
}
-
+
if (keyPrefix != null) {
if (log.isDebugEnabled()) {
log.debug("Adding the enpoint " + endpointName + " with the session id "
+ keyPrefix + sessionID + " for replication to the session");
}
// replicates the state so that all instances across cluster can see this state
- setAndReplicateState(keyPrefix + sessionID, endpointName);
+ Replicator.setAndReplicateState(keyPrefix + sessionID, endpointName, configCtx);
}
} else {
@@ -171,7 +170,7 @@
}
//Removes the endpoint name and then replicates the current
//state so that all instances
- removeAndReplicateState(keyPrefix + id);
+ Replicator.removeAndReplicateState(keyPrefix + id, configCtx);
}
} else {
@@ -239,86 +238,12 @@
*
* @param msg The error message
*/
- protected void handleException(String msg) {
+ private void handleException(String msg) {
log.error(msg);
throw new SynapseException(msg);
}
/**
- * Helper methods for handle errors.
- *
- * @param msg The error message
- * @param e The exception
- */
- protected void handleException(String msg, Exception e) {
- log.error(msg, e);
- throw new SynapseException(msg, e);
- }
-
- /**
- * Helper method to replicates states of the property with given key
- * Sets property and replicates the current state so that all instances
- * across cluster can see this state
- *
- * @param key The key of the property
- * @param value The value of the property
- */
- private void setAndReplicateState(String key, Object value) {
-
- if (configCtx != null && key != null && value != null) {
-
- try {
- if (log.isDebugEnabled()) {
- log.debug("Start replicating the property with key : " +
- key + " value : " + value);
- }
-
- Object prop = configCtx.getPropertyNonReplicable(key);
- if (prop == null) {
- configCtx.setProperty(key, value);
- Replicator.replicate(configCtx, new String[]{key});
- }
-
- if (log.isDebugEnabled()) {
- log.debug("Completed replication of the property with key: " + key);
- }
-
- } catch (ClusteringFault clusteringFault) {
- handleException("Error during the replicating states ", clusteringFault);
- }
- }
- }
-
- /**
- * Helper method to replicates states of the property with given key
- * Removes the property and then replicates the current state so that all instances
- * across cluster can see this state
- *
- * @param key The key of the property
- */
- private void removeAndReplicateState(String key) {
-
- if (configCtx != null && key != null) {
-
- try {
- if (log.isDebugEnabled()) {
- log.debug("Start replicating the property removal with key : " + key);
- }
-
- configCtx.removeProperty(key);
- Replicator.replicate(configCtx, new String[]{key});
-
- if (log.isDebugEnabled()) {
- log.debug("Completed replication of the property removal with key : " + key);
- }
-
- } catch (ClusteringFault clusteringFault) {
- handleException("Error during the replicating states ", clusteringFault);
- }
- }
- }
-
- /**
* Returns whether clustering is enable or not
*
* @return True - enable , false -> this is not a cluster env.
@@ -344,7 +269,7 @@
} else {
endpointName = endpoint.getName();
}
-
+
if (endpointName == null) {
if (log.isDebugEnabled() && isClusteringEnable()) {
log.warn(SALoadbalanceEndpoint.WARN_MESSAGE);
Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/Replicator.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/Replicator.java?rev=668171&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/Replicator.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/Replicator.java Mon Jun 16 07:15:23 2008
@@ -0,0 +1,107 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.synapse.util;
+
+import org.apache.axis2.clustering.ClusteringFault;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.synapse.SynapseException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Helper class for replicating states
+ */
+public class Replicator {
+
+ private static final Log log = LogFactory.getLog(Replicator.class);
+
+ /**
+ * Helper method to replicates states of the property with given key
+ * Removes the property and then replicates the current state so that all instances
+ * across cluster can see this state
+ *
+ * @param key The key of the property
+ * @param configCtx Axis2 configuration context
+ */
+ public static void removeAndReplicateState(String key, ConfigurationContext configCtx) {
+
+ if (configCtx != null && key != null) {
+
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("Start replicating the property removal with key : " + key);
+ }
+
+ configCtx.removeProperty(key);
+ org.apache.axis2.clustering.context.Replicator.replicate(
+ configCtx, new String[]{key});
+
+ if (log.isDebugEnabled()) {
+ log.debug("Completed replication of the property removal with key : " + key);
+ }
+
+ } catch (ClusteringFault clusteringFault) {
+ handleException("Error during the replicating states ", clusteringFault);
+ }
+ }
+ }
+
+ /**
+ * Helper method to replicates states of the property with given key
+ * replicates the given state so that all instances across cluster can see this state
+ *
+ * @param key The key of the property
+ * @param value The value of the property
+ * @param configCtx Axis2 COnfiguration Context
+ */
+ public static void setAndReplicateState(String key, Object value, ConfigurationContext configCtx) {
+
+ if (configCtx != null && key != null && value != null) {
+
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("Start replicating the property with key : " + key +
+ " value : " + value);
+ }
+
+ configCtx.setProperty(key, value);
+ org.apache.axis2.clustering.context.Replicator.replicate(
+ configCtx, new String[]{key});
+
+ if (log.isDebugEnabled()) {
+ log.debug("Completed replication of the property with key : " + key);
+ }
+
+ } catch (ClusteringFault clusteringFault) {
+ handleException("Error during the replicating states ", clusteringFault);
+ }
+ }
+ }
+
+ /**
+ * Helper methods for handle errors.
+ *
+ * @param msg The error message
+ * @param e The exception
+ */
+ private static void handleException(String msg, Exception e) {
+ log.error(msg, e);
+ throw new SynapseException(msg, e);
+ }
+}