Author: azeez
Date: Fri Mar 2 12:01:41 2012
New Revision: 1296163
URL: http://svn.apache.org/viewvc?rev=1296163&view=rev
Log:
Merging the following changes from trunk to the 1_6 branch
1. Do not replicate if state manager is not available
2. Added method to suspend Member
3. Added custom state replication functionality
Modified:
axis/axis2/java/core/branches/1_6/modules/clustering/src/org/apache/axis2/clustering/state/DefaultStateManager.java
axis/axis2/java/core/branches/1_6/modules/clustering/src/org/apache/axis2/clustering/state/commands/StateClusteringCommandCollection.java
axis/axis2/java/core/branches/1_6/modules/kernel/src/org/apache/axis2/clustering/state/Replicator.java
axis/axis2/java/core/branches/1_6/modules/kernel/src/org/apache/axis2/clustering/state/StateManager.java
Modified:
axis/axis2/java/core/branches/1_6/modules/clustering/src/org/apache/axis2/clustering/state/DefaultStateManager.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/clustering/src/org/apache/axis2/clustering/state/DefaultStateManager.java?rev=1296163&r1=1296162&r2=1296163&view=diff
==============================================================================
---
axis/axis2/java/core/branches/1_6/modules/clustering/src/org/apache/axis2/clustering/state/DefaultStateManager.java
(original)
+++
axis/axis2/java/core/branches/1_6/modules/clustering/src/org/apache/axis2/clustering/state/DefaultStateManager.java
Fri Mar 2 12:01:41 2012
@@ -57,15 +57,15 @@ public class DefaultStateManager impleme
public void updateContext(AbstractContext context) throws ClusteringFault {
StateClusteringCommand cmd =
StateClusteringCommandFactory.getUpdateCommand(context,
-
excludedReplicationPatterns,
- false);
+
excludedReplicationPatterns,
+ false);
if (cmd != null) {
sender.sendToGroup(cmd);
}
}
public void updateContext(AbstractContext context,
- String[] propertyNames) throws ClusteringFault
{
+ String[] propertyNames) throws ClusteringFault {
StateClusteringCommand cmd =
StateClusteringCommandFactory.getUpdateCommand(context,
propertyNames);
if (cmd != null) {
@@ -76,8 +76,14 @@ public class DefaultStateManager impleme
public void updateContexts(AbstractContext[] contexts) throws
ClusteringFault {
StateClusteringCommandCollection cmd =
StateClusteringCommandFactory.getCommandCollection(contexts,
-
excludedReplicationPatterns);
- sender.sendToGroup(cmd);
+
excludedReplicationPatterns);
+ if (!cmd.isEmpty()) {
+ sender.sendToGroup(cmd);
+ }
+ }
+
+ public void replicateState(StateClusteringCommand command) throws
ClusteringFault {
+ sender.sendToGroup(command);
}
public void removeContext(AbstractContext context) throws ClusteringFault {
Modified:
axis/axis2/java/core/branches/1_6/modules/clustering/src/org/apache/axis2/clustering/state/commands/StateClusteringCommandCollection.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/clustering/src/org/apache/axis2/clustering/state/commands/StateClusteringCommandCollection.java?rev=1296163&r1=1296162&r2=1296163&view=diff
==============================================================================
---
axis/axis2/java/core/branches/1_6/modules/clustering/src/org/apache/axis2/clustering/state/commands/StateClusteringCommandCollection.java
(original)
+++
axis/axis2/java/core/branches/1_6/modules/clustering/src/org/apache/axis2/clustering/state/commands/StateClusteringCommandCollection.java
Fri Mar 2 12:01:41 2012
@@ -24,27 +24,29 @@ import org.apache.axis2.clustering.state
import org.apache.axis2.context.ConfigurationContext;
import java.util.ArrayList;
+import java.util.List;
/**
- *
+ * A StateClusteringCommand consisting of a collection of other
StateClusteringCommands
*/
public class StateClusteringCommandCollection extends StateClusteringCommand {
- private final ArrayList commands;
+ private final List<StateClusteringCommand> commands;
- public StateClusteringCommandCollection(ArrayList commands) {
+ public StateClusteringCommandCollection(List<StateClusteringCommand>
commands) {
this.commands = commands;
}
public void execute(ConfigurationContext configContext) throws
ClusteringFault {
- for (int i = 0; i < commands.size(); i++) {
- StateClusteringCommand cmd = (StateClusteringCommand)
commands.get(i);
- if (cmd != null) {
- cmd.execute(configContext);
- }
+ for (StateClusteringCommand command : commands) {
+ command.execute(configContext);
}
}
+ public boolean isEmpty(){
+ return commands != null && commands.isEmpty();
+ }
+
public String toString() {
return "StateClusteringCommandCollection";
}
Modified:
axis/axis2/java/core/branches/1_6/modules/kernel/src/org/apache/axis2/clustering/state/Replicator.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/kernel/src/org/apache/axis2/clustering/state/Replicator.java?rev=1296163&r1=1296162&r2=1296163&view=diff
==============================================================================
---
axis/axis2/java/core/branches/1_6/modules/kernel/src/org/apache/axis2/clustering/state/Replicator.java
(original)
+++
axis/axis2/java/core/branches/1_6/modules/kernel/src/org/apache/axis2/clustering/state/Replicator.java
Fri Mar 2 12:01:41 2012
@@ -26,6 +26,7 @@ import org.apache.axis2.context.Configur
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.ServiceContext;
import org.apache.axis2.context.ServiceGroupContext;
+import org.apache.axis2.engine.AxisConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -35,10 +36,28 @@ import java.util.List;
/**
* Replicates serializable properties
*/
+@SuppressWarnings("unused")
public final class Replicator {
private static final Log log = LogFactory.getLog(Replicator.class);
+
+ /**
+ * Replicate state using a custom StateClusteringCommand
+ *
+ * @param command The StateClusteringCommand which is used for replicating
state
+ * @param axisConfig The AxisConfiguration
+ * @throws ClusteringFault If replication fails
+ */
+ public static void replicateState(StateClusteringCommand command,
+ AxisConfiguration axisConfig) throws
ClusteringFault {
+
+ StateManager stateManager = getStateManager(axisConfig);
+ if (stateManager != null) {
+ stateManager.replicateState(command);
+ }
+ }
+
/**
* Replicates all serializable properties in the ConfigurationContext,
ServiceGroupContext &
* ServiceContext
@@ -54,8 +73,11 @@ public final class Replicator {
log.debug("Going to replicate state stored in ConfigurationContext," +
" ServiceGroupContext, ServiceContext associated with " +
msgContext + "...");
ConfigurationContext configurationContext =
msgContext.getConfigurationContext();
- StateManager stateManager = getContextManager(msgContext);
- List contexts = new ArrayList();
+ StateManager stateManager = getStateManager(msgContext);
+ if (stateManager == null) {
+ return;
+ }
+ List<AbstractContext> contexts = new ArrayList<AbstractContext>();
// Do we need to replicate state stored in ConfigurationContext?
if (!configurationContext.getPropertyDifferences().isEmpty()) {
@@ -76,8 +98,7 @@ public final class Replicator {
// Do the actual replication here
if (!contexts.isEmpty()) {
- AbstractContext[] contextArray =
- (AbstractContext[]) contexts.toArray(new
AbstractContext[contexts.size()]);
+ AbstractContext[] contextArray = contexts.toArray(new
AbstractContext[contexts.size()]);
stateManager.updateContexts(contextArray);
}
}
@@ -93,9 +114,11 @@ public final class Replicator {
return;
}
log.debug("Going to replicate state in " + abstractContext + "...");
- StateManager stateManager = getContextManager(abstractContext);
- if (!abstractContext.getPropertyDifferences().isEmpty()) {
- stateManager.updateContext(abstractContext);
+ StateManager stateManager = getStateManager(abstractContext);
+ if (stateManager != null &&
!abstractContext.getPropertyDifferences().isEmpty()) {
+ synchronized (abstractContext) { // This IDEA/FindBugs warning can
be ignored
+ stateManager.updateContext(abstractContext);
+ }
}
}
@@ -113,18 +136,28 @@ public final class Replicator {
return;
}
log.debug("Going to replicate selected properties in " +
abstractContext + "...");
- StateManager stateManager = getContextManager(abstractContext);
- stateManager.updateContext(abstractContext, propertyNames);
+ StateManager stateManager = getStateManager(abstractContext);
+ if (stateManager != null) {
+ stateManager.updateContext(abstractContext, propertyNames);
+ }
}
private static ClusteringAgent getClusterManager(AbstractContext
abstractContext) {
return
abstractContext.getRootContext().getAxisConfiguration().getClusteringAgent();
}
- private static StateManager getContextManager(AbstractContext
abstractContext) {
+ private static StateManager getStateManager(AbstractContext
abstractContext) {
return getClusterManager(abstractContext).getStateManager();
}
+ private static StateManager getStateManager(AxisConfiguration
axisConfiguration) {
+ ClusteringAgent clusteringAgent =
axisConfiguration.getClusteringAgent();
+ if (clusteringAgent != null) {
+ return clusteringAgent.getStateManager();
+ }
+ return null;
+ }
+
/**
* Check whether the state store in the specified
<code>abstractContext</code> can be replicated.
* Also note that if there are no members, we need not do any replication
Modified:
axis/axis2/java/core/branches/1_6/modules/kernel/src/org/apache/axis2/clustering/state/StateManager.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/kernel/src/org/apache/axis2/clustering/state/StateManager.java?rev=1296163&r1=1296162&r2=1296163&view=diff
==============================================================================
---
axis/axis2/java/core/branches/1_6/modules/kernel/src/org/apache/axis2/clustering/state/StateManager.java
(original)
+++
axis/axis2/java/core/branches/1_6/modules/kernel/src/org/apache/axis2/clustering/state/StateManager.java
Fri Mar 2 12:01:41 2012
@@ -88,6 +88,14 @@ public interface StateManager extends Pa
void updateContexts(AbstractContext[] contexts) throws ClusteringFault;
/**
+ * Replicate state using a custom StateClusteringCommand
+ *
+ * @param command The custom StateClusteringCommand which can be used for
replicating state
+ * @throws ClusteringFault If replication fails
+ */
+ void replicateState(StateClusteringCommand command) throws ClusteringFault;
+
+ /**
* This method is called when {@link AbstractContext} is removed from the
system
*
* @param context The AbstractContext to be removed