You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by az...@apache.org on 2007/05/15 17:18:33 UTC
svn commit: r538202 - in /webservices/axis2/trunk/java/modules: clustering/
clustering/src/org/apache/axis2/cluster/handlers/
clustering/src/org/apache/axis2/cluster/tribes/
clustering/src/org/apache/axis2/cluster/tribes/context/
clustering/test/org/ap...
Author: azeez
Date: Tue May 15 08:18:32 2007
New Revision: 538202
URL: http://svn.apache.org/viewvc?view=rev&rev=538202
Log:
Busy waiting of replication send requests when the TribesClusterManager has not still initialized.
Modified:
webservices/axis2/trunk/java/modules/clustering/project.xml
webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/cluster/handlers/ReplicationHandler.java
webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/cluster/tribes/TribesClusterManager.java
webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/cluster/tribes/context/TribesContextManager.java
webservices/axis2/trunk/java/modules/clustering/test/org/apache/axis2/clustering/UpdateStateTestCase.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/cluster/context/ContextManager.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/AbstractContext.java
Modified: webservices/axis2/trunk/java/modules/clustering/project.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/clustering/project.xml?view=diff&rev=538202&r1=538201&r2=538202
==============================================================================
--- webservices/axis2/trunk/java/modules/clustering/project.xml (original)
+++ webservices/axis2/trunk/java/modules/clustering/project.xml Tue May 15 08:18:32 2007
@@ -21,7 +21,7 @@
<extend>../../etc/project.xml</extend>
<name>Apache Axis 2.0 - Cluster</name>
- <id>axis2-cluster</id>
+ <id>axis2-clustering</id>
<groupId>org.apache.axis2</groupId>
<description>Clustering Support for Axis 2.0</description>
Modified: webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/cluster/handlers/ReplicationHandler.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/cluster/handlers/ReplicationHandler.java?view=diff&rev=538202&r1=538201&r2=538202
==============================================================================
--- webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/cluster/handlers/ReplicationHandler.java (original)
+++ webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/cluster/handlers/ReplicationHandler.java Tue May 15 08:18:32 2007
@@ -71,14 +71,14 @@
ServiceGroupContext serviceGroupContext = message.getServiceGroupContext();
- contextManager.updateState(configurationContext);
+ contextManager.updateContext(configurationContext);
if (serviceGroupContext != null) {
- contextManager.updateState(serviceGroupContext);
+ contextManager.updateContext(serviceGroupContext);
}
if (serviceContext != null) {
- contextManager.updateState(serviceContext);
+ contextManager.updateContext(serviceContext);
}
}
Modified: webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/cluster/tribes/TribesClusterManager.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/cluster/tribes/TribesClusterManager.java?view=diff&rev=538202&r1=538201&r2=538202
==============================================================================
--- webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/cluster/tribes/TribesClusterManager.java (original)
+++ webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/cluster/tribes/TribesClusterManager.java Tue May 15 08:18:32 2007
@@ -16,10 +16,6 @@
package org.apache.axis2.cluster.tribes;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-
import org.apache.axiom.om.OMElement;
import org.apache.axis2.AxisFault;
import org.apache.axis2.cluster.ClusterManager;
@@ -41,156 +37,151 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+
public class TribesClusterManager implements ClusterManager {
- private TribesConfigurationManager configurationManager = null;
- private TribesContextManager contextManager = null;
- private ContextUpdater updater;
- private static long timeout = 1000L; // this should be configured in the axis2.xml
- private HashMap parameters = null;
- Channel channel = null;
- TransientTribesChannelInfo channelInfo = null;
- TransientTribesMemberInfo memberInfo = null;
-
+ private TribesConfigurationManager configurationManager;
+ private TribesContextManager contextManager;
+
+ private HashMap parameters = null;
+ private Channel channel = null;
+ private TransientTribesChannelInfo channelInfo = null;
+ private TransientTribesMemberInfo memberInfo = null;
+
private static final Log log = LogFactory.getLog(TribesClusterManager.class);
- public TribesClusterManager () {
- contextManager = new TribesContextManager ();
- configurationManager = new TribesConfigurationManager ();
- parameters = new HashMap ();
+ public TribesClusterManager() {
+ parameters = new HashMap();
+ }
+
+ public ContextManager getContextManager() {
+ return contextManager;
}
- public ContextManager getContextManager() {
- return contextManager;
- }
+ public ConfigurationManager getConfigurationManager() {
+ return configurationManager;
+ }
- public ConfigurationManager getConfigurationManager() {
- return configurationManager;
- }
+ public void init() throws ClusteringFault {
+ if (log.isDebugEnabled()) {
+ log.debug("Enter: TribesClusterManager::init");
+ }
- public void init() throws ClusteringFault {
-
- if (log.isDebugEnabled())
- log.debug("Enter: TribesClusterManager::init");
-
- ChannelSender sender = new ChannelSender ();
+ ChannelSender sender = new ChannelSender();
- ChannelListener listener = new ChannelListener (configurationManager, contextManager);
+ ChannelListener listener = new ChannelListener(configurationManager, contextManager);
- channelInfo = new TransientTribesChannelInfo();
- memberInfo = new TransientTribesMemberInfo();
+ channelInfo = new TransientTribesChannelInfo();
+ memberInfo = new TransientTribesMemberInfo();
- contextManager.setSender(sender);
+ contextManager.setSender(sender);
configurationManager.setSender(sender);
try {
- ManagedChannel channel = new GroupChannel();
- this.channel = channel;
- channel.addChannelListener (listener);
- channel.addChannelListener(channelInfo);
- channel.addMembershipListener(memberInfo);
+ ContextUpdater updater = new ContextUpdater();
+ contextManager.setUpdater(updater);
+
+ ManagedChannel channel = new GroupChannel();
+ this.channel = channel;
+
+ channel.addChannelListener(listener);
+ channel.addChannelListener(channelInfo);
+ channel.addMembershipListener(memberInfo);
channel.addMembershipListener(new TribesMembershipListener());
channel.start(Channel.DEFAULT);
- sender.setChannel(channel);
- contextManager.setSender(sender);
- configurationManager.setSender(sender);
-
- Member[] members = channel.getMembers();
- TribesUtil.printMembers (members);
-
- updater = new ContextUpdater ();
- contextManager.setUpdater(updater);
-
- listener.setUpdater(updater);
- listener.setContextManager(contextManager);
-
- } catch (ChannelException e) {
-
- if (log.isDebugEnabled())
- log.debug("Exit: TribesClusterManager::init");
-
- String message = "Error starting Tribes channel";
- throw new ClusteringFault (message, e);
- }
-
- if (log.isDebugEnabled())
- log.debug("Exit: TribesClusterManager::init");
- }
-
-// private void registerTribesInfoService(ConfigurationContext configContext2) throws ClusteringFault {
-// try {
-// AxisService service = AxisService.createService(
-// "org.apache.axis2.cluster.tribes.info.TribesInfoWebService", configContext
-// .getAxisConfiguration(), RPCMessageReceiver.class);
-//
-// configContext.getAxisConfiguration().addService(service);
-// } catch (AxisFault e) {
-// String message = "Unable to create Tribes info web service";
-// throw new ClusteringFault (message, e);
-// }
-// }
-
- public void setConfigurationManager(ConfigurationManager configurationManager) {
- this.configurationManager = (TribesConfigurationManager) configurationManager;
- }
-
- public void setContextManager(ContextManager contextManager) {
- this.contextManager = (TribesContextManager) contextManager;
- }
-
- public void addParameter(Parameter param) throws AxisFault {
- parameters.put(param.getName(), param);
- }
-
- public void deserializeParameters(OMElement parameterElement) throws AxisFault {
- throw new UnsupportedOperationException ();
- }
-
- public Parameter getParameter(String name) {
- return (Parameter) parameters.get(name);
- }
-
- public ArrayList getParameters() {
- ArrayList list = new ArrayList ();
- for (Iterator it=parameters.keySet().iterator();it.hasNext();) {
- list.add(parameters.get(it.next()));
- }
- return list;
- }
-
- public boolean isParameterLocked(String parameterName) {
-
- Parameter parameter = (Parameter) parameters.get(parameterName);
- if (parameter!=null)
- return parameter.isLocked();
-
- return false;
- }
-
- public void removeParameter(Parameter param) throws AxisFault {
- parameters.remove(param.getName());
- }
-
- public void shutdown() throws ClusteringFault {
-
- if (log.isDebugEnabled())
- log.debug("Enter: TribesClusterManager::shutdown");
-
- if (channel!=null) {
- try {
- channel.stop(Channel.DEFAULT);
- } catch (ChannelException e) {
-
- if (log.isDebugEnabled())
- log.debug("Exit: TribesClusterManager::shutdown");
-
- throw new ClusteringFault (e);
- }
- }
-
- if (log.isDebugEnabled())
- log.debug("Exit: TribesClusterManager::shutdown");
- }
+ sender.setChannel(channel);
+ contextManager.setSender(sender);
+ configurationManager.setSender(sender);
+
+ Member[] members = channel.getMembers();
+ TribesUtil.printMembers(members);
+
+ listener.setUpdater(updater);
+ listener.setContextManager(contextManager);
+
+ } catch (ChannelException e) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("Exit: TribesClusterManager::init");
+ }
+
+ String message = "Error starting Tribes channel";
+ throw new ClusteringFault(message, e);
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("Exit: TribesClusterManager::init");
+ }
+ }
+
+ public void setConfigurationManager(ConfigurationManager configurationManager) {
+ this.configurationManager = (TribesConfigurationManager) configurationManager;
+ }
+
+ public void setContextManager(ContextManager contextManager) {
+ this.contextManager = (TribesContextManager) contextManager;
+ }
+
+ public void addParameter(Parameter param) throws AxisFault {
+ parameters.put(param.getName(), param);
+ }
+
+ public void deserializeParameters(OMElement parameterElement) throws AxisFault {
+ throw new UnsupportedOperationException();
+ }
+
+ public Parameter getParameter(String name) {
+ return (Parameter) parameters.get(name);
+ }
+
+ public ArrayList getParameters() {
+ ArrayList list = new ArrayList();
+ for (Iterator it = parameters.keySet().iterator(); it.hasNext();) {
+ list.add(parameters.get(it.next()));
+ }
+ return list;
+ }
+
+ public boolean isParameterLocked(String parameterName) {
+
+ Parameter parameter = (Parameter) parameters.get(parameterName);
+ if (parameter != null) {
+ return parameter.isLocked();
+ }
+
+ return false;
+ }
+
+ public void removeParameter(Parameter param) throws AxisFault {
+ parameters.remove(param.getName());
+ }
+
+ public void shutdown() throws ClusteringFault {
+
+ if (log.isDebugEnabled()) {
+ log.debug("Enter: TribesClusterManager::shutdown");
+ }
+
+ if (channel != null) {
+ try {
+ channel.stop(Channel.DEFAULT);
+ } catch (ChannelException e) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("Exit: TribesClusterManager::shutdown");
+ }
+
+ throw new ClusteringFault(e);
+ }
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("Exit: TribesClusterManager::shutdown");
+ }
+ }
+
-
}
Modified: webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/cluster/tribes/context/TribesContextManager.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/cluster/tribes/context/TribesContextManager.java?view=diff&rev=538202&r1=538201&r2=538202
==============================================================================
--- webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/cluster/tribes/context/TribesContextManager.java (original)
+++ webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/cluster/tribes/context/TribesContextManager.java Tue May 15 08:18:32 2007
@@ -16,6 +16,8 @@
package org.apache.axis2.cluster.tribes.context;
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.AxisFault;
import org.apache.axis2.cluster.ClusteringFault;
import org.apache.axis2.cluster.CommandType;
import org.apache.axis2.cluster.context.ContextEvent;
@@ -31,9 +33,6 @@
import org.apache.axis2.description.AxisService;
import org.apache.axis2.description.AxisServiceGroup;
import org.apache.axis2.description.Parameter;
-import org.apache.axis2.AxisFault;
-import org.apache.axiom.om.OMElement;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -47,32 +46,41 @@
private ContextUpdater updater;
private Map orphanedServiceCtxs = new HashMap();
- private List addedServiceGrpCtxs = new ArrayList();
- private List addedServiceCtxs = new ArrayList();
- private List listeners = null;
+ private List listeners = new ArrayList();
private Map parameters = new HashMap();
private ChannelSender sender;
+ private ContextReplicationProcessor processor = new ContextReplicationProcessor();
public void setSender(ChannelSender sender) {
this.sender = sender;
}
- public TribesContextManager(ConfigurationContext configurationContext, ContextUpdater updater) {
- this();
- this.configContext = configurationContext;
- this.updater = updater;
+ public TribesContextManager() {
}
- public TribesContextManager() {
- listeners = new ArrayList();
+ public void addContext(final AbstractContext context) throws ClusteringFault {
+ processor.process(new AddContextCommand(), context);
+ }
+
+ public void removeContext(AbstractContext context) throws ClusteringFault {
+ processor.process(new RemoveContextCommand(), context);
+ }
+
+ public void updateContext(AbstractContext context) throws ClusteringFault {
+ processor.process(new UpdateContextCommand(), context);
+ }
+
+ public boolean isContextClusterable(AbstractContext context) {
+ return (context instanceof ConfigurationContext) ||
+ (context instanceof ServiceContext) ||
+ (context instanceof ServiceGroupContext);
}
public void notifyListeners(ContextEvent event, int eventType) {
for (Iterator it = listeners.iterator(); it.hasNext();) {
ContextManagerListener listener = (ContextManagerListener) it.next();
-
if (eventType == ContextListenerEventType.ADD_CONTEXT) {
listener.contextAdded(event);
} else if (eventType == ContextListenerEventType.REMOVE_CONTEXT) {
@@ -81,201 +89,16 @@
listener.contextUpdated(event);
}
}
-
- }
-
- public void addContext(AbstractContext context) throws ClusteringFault {
-
- if (log.isDebugEnabled())
- log.debug("Enter: TribesContextManager::addContext");
-
- ContextCommandMessage comMsg;
-
- String contextId = getContextID(context);
- String parentContextId = getContextID(context.getParent());
-
- // The ServiceContex does not define a contextId
- // therefore the service name is used
- if (context instanceof ServiceContext) {
-
- if (addedServiceCtxs.contains(parentContextId + contextId)) {
-
- if (log.isDebugEnabled())
- log.debug("Exit: TribesContextManager::addContext");
-
- return; // this is a duplicate replication request
- }
-
- if (updater.getServiceGroupProps(parentContextId) != null) {
- updater.addServiceContext(parentContextId, contextId);
- comMsg = new ContextCommandMessage(CommandType.CREATE_SERVICE_CONTEXT,
- parentContextId,
- contextId,
- contextId,
- ContextType.SERVICE_CONTEXT);
- send(comMsg);
- } else {
- // put in the queue until the service group context is created
- // with an id
- comMsg = new ContextCommandMessage(CommandType.CREATE_SERVICE_CONTEXT,
- parentContextId,
- contextId,
- contextId,
- ContextType.SERVICE_CONTEXT);
-
- AxisServiceGroup serviceGroupDesc = ((ServiceContext) context)
- .getServiceGroupContext().getDescription();
- List list = (List) orphanedServiceCtxs.get(serviceGroupDesc
- .getServiceGroupName());
- if (list == null) {
- list = new ArrayList();
- orphanedServiceCtxs.put(serviceGroupDesc.getServiceGroupName(), list);
- }
- list.add(comMsg);
- }
- } else if (context instanceof ServiceGroupContext) {
-
- if (addedServiceGrpCtxs.contains(contextId)) {
-
- if (log.isDebugEnabled())
- log.debug("Exit: TribesContextManager::addContext");
-
- return; // this is a duplicate replication request
- }
-
- ServiceGroupContext srvGrpCtx = (ServiceGroupContext) context;
-
- // The new serialization code sets the service group name as it's id initially
- if (srvGrpCtx.getId().equals(srvGrpCtx.getDescription().getServiceGroupName())) {
-
- if (log.isDebugEnabled())
- log.debug("Exit: TribesContextManager::addContext");
-
- return;
- }
-
- updater.addServiceGroupContext(contextId);
-
- comMsg = new ContextCommandMessage(CommandType.CREATE_SERVICE_GROUP_CONTEXT,
- "",
- contextId,
- srvGrpCtx.getDescription().getServiceGroupName(),
- ContextType.SERVICE_GROUP_CONTEXT);
-
- send(comMsg);
-
- // now iterate through the list of service contexts and replicate them
- List list = (List) orphanedServiceCtxs.get(srvGrpCtx.getDescription()
- .getServiceGroupName());
-
- if (list != null) {
- for (Iterator it = list.iterator(); it.hasNext();) {
-
- ContextCommandMessage command = (ContextCommandMessage) it.next();
- updater.addServiceContext(contextId, command.getContextId());
- command.setParentId(contextId);
-
- send(command);
-
- }
-
- orphanedServiceCtxs.remove(srvGrpCtx.getDescription().getServiceGroupName());
- }
- }
-
- if (log.isDebugEnabled())
- log.debug("Exit: TribesContextManager::addContext");
- }
-
- public void removeContext(AbstractContext context) throws ClusteringFault {
-
- if (log.isDebugEnabled())
- log.debug("Enter: TribesContextManager::removeContext");
-
- ContextCommandMessage comMsg = null;
-
- String contextId = getContextID(context);
- String parentContextId = getContextID(context.getParent());
-
- if (context instanceof ServiceContext) {
- updater.removeServiceContext(parentContextId, contextId);
- comMsg = new ContextCommandMessage(CommandType.CREATE_SERVICE_GROUP_CONTEXT,
- parentContextId, contextId, contextId, ContextType.SERVICE_CONTEXT);
- } else if (context instanceof ServiceGroupContext) {
- updater.removeServiceGroupContext(contextId);
- comMsg = new ContextCommandMessage(CommandType.REMOVE_SERVICE_GROUP_CONTEXT, "",
- contextId, ((ServiceGroupContext) context).getDescription()
- .getServiceGroupName(), ContextType.SERVICE_CONTEXT);
- }
-
- send(comMsg);
-
- if (log.isDebugEnabled())
- log.debug("Exit: TribesContextManager::removeContext");
- }
-
- public void updateState(AbstractContext context) throws ClusteringFault {
-
- if (log.isDebugEnabled())
- log.debug("Enter: TribesContextManager::updateState");
-
- String contextId = getContextID(context);
- String parentContextId = getContextID(context.getParent());
-
- Map props = context.getProperties();
-
- List mapEntryMsgs = null;
-
- int contextType = 0;
- if (context instanceof ServiceContext) {
- contextType = ContextType.SERVICE_CONTEXT;
- mapEntryMsgs = updater
- .updateStateOnServiceContext(parentContextId, contextId, props);
- } else if (context instanceof ServiceGroupContext) {
- contextType = ContextType.SERVICE_GROUP_CONTEXT;
- mapEntryMsgs = updater.updateStateOnServiceGroupContext(contextId, props);
- }
-
- if (mapEntryMsgs != null) {
- for (Iterator it = mapEntryMsgs.iterator(); it.hasNext();) {
- ContextUpdateEntryCommandMessage msg = (ContextUpdateEntryCommandMessage) it.next();
- send(msg);
- }
- }
-
- ContextCommandMessage comMsg = new ContextCommandMessage(CommandType.UPDATE_STATE,
- parentContextId,
- contextId,
- contextId,
- contextType);
-
- send(comMsg);
-
- if (log.isDebugEnabled())
- log.debug("Exit: TribesContextManager::updateState");
- }
-
- public boolean isContextClusterable(AbstractContext context) {
-
- if ((context instanceof ConfigurationContext) || (context instanceof ServiceContext)
- || (context instanceof ServiceGroupContext)) {
- return true;
- }
-
- return false;
}
private String getContextID(AbstractContext context) {
-
String id = null;
-
if (context instanceof ServiceContext) {
AxisService axisService = ((ServiceContext) context).getAxisService();
return axisService.getName();
} else if (context instanceof ServiceGroupContext) {
return ((ServiceGroupContext) context).getId();
}
-
return id;
}
@@ -291,7 +114,6 @@
if (configContext != null) {
listener.setConfigurationContext(configContext);
}
-
listeners.add(listener);
}
@@ -347,5 +169,219 @@
public void deserializeParameters(OMElement parameterElement) throws AxisFault {
throw new UnsupportedOperationException();
+ }
+
+ private interface ContextCommand {
+ void execute(AbstractContext context) throws ClusteringFault;
+ }
+
+ private class AddContextCommand implements ContextCommand {
+
+ public void execute(AbstractContext context) throws ClusteringFault {
+ if (log.isDebugEnabled()) {
+ log.debug("Enter: TribesContextManager::addContext");
+ }
+ ContextCommandMessage comMsg;
+
+ String contextId = getContextID(context);
+ String parentContextId = getContextID(context.getParent());
+
+ // The ServiceContex does not define a contextId
+ // therefore the service name is used
+ if (context instanceof ServiceContext) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("Exit: TribesContextManager::addContext");
+ }
+
+ if (updater.getServiceGroupProps(parentContextId) != null) {
+ updater.addServiceContext(parentContextId, contextId);
+ comMsg = new ContextCommandMessage(CommandType.CREATE_SERVICE_CONTEXT,
+ parentContextId,
+ contextId,
+ contextId,
+ ContextType.SERVICE_CONTEXT);
+ send(comMsg);
+ } else {
+ // put in the queue until the service group context is created
+ // with an id
+ comMsg = new ContextCommandMessage(CommandType.CREATE_SERVICE_CONTEXT,
+ parentContextId,
+ contextId,
+ contextId,
+ ContextType.SERVICE_CONTEXT);
+
+ AxisServiceGroup serviceGroupDesc = ((ServiceContext) context)
+ .getServiceGroupContext().getDescription();
+ List list = (List) orphanedServiceCtxs.get(serviceGroupDesc
+ .getServiceGroupName());
+ if (list == null) {
+ list = new ArrayList();
+ orphanedServiceCtxs.put(serviceGroupDesc.getServiceGroupName(), list);
+ }
+ list.add(comMsg);
+ }
+ } else if (context instanceof ServiceGroupContext) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("Exit: TribesContextManager::addContext");
+ }
+
+ ServiceGroupContext srvGrpCtx = (ServiceGroupContext) context;
+
+ // The new serialization code sets the service group name as it's id initially
+ if (srvGrpCtx.getId().equals(srvGrpCtx.getDescription().getServiceGroupName())) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("Exit: TribesContextManager::addContext");
+ }
+
+ return;
+ }
+
+ updater.addServiceGroupContext(contextId);
+
+ comMsg = new ContextCommandMessage(CommandType.CREATE_SERVICE_GROUP_CONTEXT,
+ "",
+ contextId,
+ srvGrpCtx.getDescription().getServiceGroupName(),
+ ContextType.SERVICE_GROUP_CONTEXT);
+
+ send(comMsg);
+
+ // now iterate through the list of service contexts and replicate them
+ List list = (List) orphanedServiceCtxs.get(srvGrpCtx.getDescription()
+ .getServiceGroupName());
+
+ if (list != null) {
+ for (Iterator it = list.iterator(); it.hasNext();) {
+
+ ContextCommandMessage command = (ContextCommandMessage) it.next();
+ updater.addServiceContext(contextId, command.getContextId());
+ command.setParentId(contextId);
+
+ send(command);
+
+ }
+ orphanedServiceCtxs.remove(srvGrpCtx.getDescription().getServiceGroupName());
+ }
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("Exit: TribesContextManager::addContext");
+ }
+ }
+ }
+
+ private class RemoveContextCommand implements ContextCommand {
+
+ public void execute(AbstractContext context) throws ClusteringFault {
+ if (log.isDebugEnabled()) {
+ log.debug("Enter: TribesContextManager::removeContext");
+ }
+
+ ContextCommandMessage comMsg = null;
+
+ String contextId = getContextID(context);
+ String parentContextId = getContextID(context.getParent());
+
+ if (context instanceof ServiceContext) {
+ updater.removeServiceContext(parentContextId, contextId);
+ comMsg = new ContextCommandMessage(CommandType.CREATE_SERVICE_GROUP_CONTEXT,
+ parentContextId,
+ contextId,
+ contextId,
+ ContextType.SERVICE_CONTEXT);
+ } else if (context instanceof ServiceGroupContext) {
+ updater.removeServiceGroupContext(contextId);
+ comMsg = new ContextCommandMessage(CommandType.REMOVE_SERVICE_GROUP_CONTEXT,
+ "",
+ contextId,
+ ((ServiceGroupContext) context).getDescription().getServiceGroupName(),
+ ContextType.SERVICE_CONTEXT);
+ }
+
+ send(comMsg);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Exit: TribesContextManager::removeContext");
+ }
+ }
+ }
+
+ private class UpdateContextCommand implements ContextCommand {
+
+ public void execute(AbstractContext context) throws ClusteringFault {
+
+ if (log.isDebugEnabled()) {
+ log.debug("Enter: TribesContextManager::updateState");
+ }
+
+ String contextId = getContextID(context);
+ String parentContextId = getContextID(context.getParent());
+
+ Map props = context.getProperties();
+
+ List mapEntryMsgs = null;
+
+ int contextType = 0;
+ if (context instanceof ServiceContext) {
+ contextType = ContextType.SERVICE_CONTEXT;
+ mapEntryMsgs = updater
+ .updateStateOnServiceContext(parentContextId, contextId, props);
+ } else if (context instanceof ServiceGroupContext) {
+ contextType = ContextType.SERVICE_GROUP_CONTEXT;
+ mapEntryMsgs = updater.updateStateOnServiceGroupContext(contextId, props);
+ }
+
+ if (mapEntryMsgs != null) {
+ for (Iterator it = mapEntryMsgs.iterator(); it.hasNext();) {
+ ContextUpdateEntryCommandMessage msg = (ContextUpdateEntryCommandMessage) it.next();
+ send(msg);
+ }
+ }
+
+ ContextCommandMessage comMsg = new ContextCommandMessage(CommandType.UPDATE_STATE,
+ parentContextId,
+ contextId,
+ contextId,
+ contextType);
+
+ send(comMsg);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Exit: TribesContextManager::updateState");
+ }
+ }
+ }
+
+ private class ContextReplicationProcessor {
+ public void process(final ContextCommand cmd,
+ final AbstractContext context) throws ClusteringFault {
+
+ // If the updater is NULL, it means the TribesClusterManager is still being initailized
+ // So we need to busy wait.
+ if (updater == null) {
+ Thread processorThread = new Thread("ProcessorThread") {
+ public void run() {
+ while (updater == null) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ try {
+ cmd.execute(context);
+ } catch (ClusteringFault clusteringFault) {
+ throw new RuntimeException(clusteringFault);
+ }
+ }
+ };
+ processorThread.start();
+ } else {
+ cmd.execute(context);
+ }
+ }
}
}
Modified: webservices/axis2/trunk/java/modules/clustering/test/org/apache/axis2/clustering/UpdateStateTestCase.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/clustering/test/org/apache/axis2/clustering/UpdateStateTestCase.java?view=diff&rev=538202&r1=538201&r2=538202
==============================================================================
--- webservices/axis2/trunk/java/modules/clustering/test/org/apache/axis2/clustering/UpdateStateTestCase.java (original)
+++ webservices/axis2/trunk/java/modules/clustering/test/org/apache/axis2/clustering/UpdateStateTestCase.java Tue May 15 08:18:32 2007
@@ -70,9 +70,9 @@
clusterManager1.getContextManager().addContext(serviceGroupContext1);
clusterManager1.getContextManager().addContext(serviceContext1);
- clusterManager1.getContextManager().updateState(configurationContext1);
- clusterManager1.getContextManager().updateState(serviceGroupContext1);
- clusterManager1.getContextManager().updateState(serviceContext1);
+ clusterManager1.getContextManager().updateContext(configurationContext1);
+ clusterManager1.getContextManager().updateContext(serviceGroupContext1);
+ clusterManager1.getContextManager().updateContext(serviceContext1);
Thread.sleep(1000);
}
@@ -121,8 +121,8 @@
serviceGroupContext1.getProperties().remove(key2);
serviceContext1.getProperties().remove(key3);
- clusterManager1.getContextManager().updateState(serviceContext1);
- clusterManager1.getContextManager().updateState(serviceGroupContext1);
+ clusterManager1.getContextManager().updateContext(serviceContext1);
+ clusterManager1.getContextManager().updateContext(serviceGroupContext1);
Thread.sleep(1000);
@@ -153,8 +153,8 @@
serviceGroupContext1.setProperty(key2, val3);
serviceContext1.setProperty(key3, val2);
- clusterManager1.getContextManager().updateState(serviceContext1);
- clusterManager1.getContextManager().updateState(serviceGroupContext1);
+ clusterManager1.getContextManager().updateContext(serviceContext1);
+ clusterManager1.getContextManager().updateContext(serviceGroupContext1);
Thread.sleep(1000);
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/cluster/context/ContextManager.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/cluster/context/ContextManager.java?view=diff&rev=538202&r1=538201&r2=538202
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/cluster/context/ContextManager.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/cluster/context/ContextManager.java Tue May 15 08:18:32 2007
@@ -26,7 +26,7 @@
public void removeContext(AbstractContext context) throws ClusteringFault;
- public void updateState(AbstractContext context) throws ClusteringFault;
+ public void updateContext(AbstractContext context) throws ClusteringFault;
public boolean isContextClusterable(AbstractContext context) throws ClusteringFault;
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/AbstractContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/AbstractContext.java?view=diff&rev=538202&r1=538201&r2=538202
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/AbstractContext.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/AbstractContext.java Tue May 15 08:18:32 2007
@@ -185,7 +185,7 @@
if (clusterManager != null) {
ContextManager contextManager = clusterManager.getContextManager();
if (contextManager!=null && contextManager.isContextClusterable (this))
- contextManager.updateState(this);
+ contextManager.updateContext(this);
}
//Other logic needed for flushing the contexts
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org