You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by az...@apache.org on 2007/03/20 11:47:05 UTC

svn commit: r520349 - in /webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/cluster/tribes: TribesClusterManager.java TribesMembershipListener.java configuration/TribesConfigurationManager.java context/TribesContextManager.java

Author: azeez
Date: Tue Mar 20 03:46:59 2007
New Revision: 520349

URL: http://svn.apache.org/viewvc?view=rev&rev=520349
Log:
1. Added member TribesMembershipListener
2. Do not send messages to group if you are the only member in the group


Added:
    webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/cluster/tribes/TribesMembershipListener.java
Modified:
    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/configuration/TribesConfigurationManager.java
    webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/cluster/tribes/context/TribesContextManager.java

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=520349&r1=520348&r2=520349
==============================================================================
--- 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 Mar 20 03:46:59 2007
@@ -60,10 +60,11 @@
 	}
 
 	public void init(ConfigurationContext configurationContext) throws ClusteringFault {
-		log.debug("initializing tibes");
+		log.debug("Initializing tribes");
 		this.configContext = configurationContext;
 		ChannelSender sender = new ChannelSender ();
-		ChannelListener listener = new ChannelListener (configurationManager, contextManager);
+
+        ChannelListener listener = new ChannelListener (configurationManager, contextManager);
 
 		TransientTribesChannelInfo channelInfo = new TransientTribesChannelInfo();
 		TransientTribesMemberInfo memberInfo = new TransientTribesMemberInfo();
@@ -72,14 +73,15 @@
 		configurationContext.setProperty("CHANNEL_INFO", channelInfo);
 
 		contextManager.setSender(sender);
-		configurationManager.setSender(sender);
-		
-		try {
+        configurationManager.setSender(sender);
+
+        try {
 			Channel channel = new GroupChannel();
 			channel.addChannelListener (listener);
 			channel.addChannelListener(channelInfo);
 			channel.addMembershipListener(memberInfo);
-			channel.start(Channel.DEFAULT);
+            channel.addMembershipListener(new TribesMembershipListener());
+            channel.start(Channel.DEFAULT);
 			sender.setChannel(channel);
 			contextManager.setSender(sender);
 			configurationManager.setSender(sender);
@@ -90,7 +92,7 @@
 			listener.setUpdater(updater);
 			listener.setContextManager(contextManager);
 			
-			registerTribesInfoService(configurationContext);
+//			registerTribesInfoService(configurationContext);
 
 		} catch (ChannelException e) {
 			String message = "Error starting Tribes channel";
@@ -118,6 +120,4 @@
 	public void setContextManager(ContextManager contextManager) {
 		this.contextManager = (TribesContextManager) contextManager;
 	}
-
-	
 }

Added: webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/cluster/tribes/TribesMembershipListener.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/cluster/tribes/TribesMembershipListener.java?view=auto&rev=520349
==============================================================================
--- webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/cluster/tribes/TribesMembershipListener.java (added)
+++ webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/cluster/tribes/TribesMembershipListener.java Tue Mar 20 03:46:59 2007
@@ -0,0 +1,47 @@
+/*                                                                             
+ * Copyright 2004,2005 The Apache Software Foundation.                         
+ *                                                                             
+ * Licensed 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.axis2.cluster.tribes;
+
+import org.apache.catalina.tribes.Member;
+import org.apache.catalina.tribes.MembershipListener;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * 
+ */
+public class TribesMembershipListener implements MembershipListener {
+
+    private static Log log = LogFactory.getLog(TribesMembershipListener.class);
+
+    public void memberAdded(Member member) {
+        log.info("New member " + getHostIP(member) + ":" + member.getPort() +
+                 " added to Tribes group.");
+    }
+
+    public void memberDisappeared(Member member) {
+        log.info("Member " + getHostIP(member) + " left Tribes group");
+    }
+
+    private String getHostIP(Member member) {
+        String host = "";
+        byte[] hostBytes = member.getHost();
+        for (int i = 0; i < hostBytes.length; i++) {
+            host += hostBytes[i] + ".";
+        }
+        return host;
+    }
+}

Modified: webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/cluster/tribes/configuration/TribesConfigurationManager.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/cluster/tribes/configuration/TribesConfigurationManager.java?view=diff&rev=520349&r1=520348&r2=520349
==============================================================================
--- webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/cluster/tribes/configuration/TribesConfigurationManager.java (original)
+++ webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/cluster/tribes/configuration/TribesConfigurationManager.java Tue Mar 20 03:46:59 2007
@@ -16,9 +16,6 @@
 
 package org.apache.axis2.cluster.tribes.configuration;
 
-import java.util.ArrayList;
-import java.util.Iterator;
-
 import org.apache.axis2.cluster.ClusteringFault;
 import org.apache.axis2.cluster.configuration.ConfigurationEvent;
 import org.apache.axis2.cluster.configuration.ConfigurationManager;
@@ -28,94 +25,102 @@
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.neethi.Policy;
 
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
 public class TribesConfigurationManager implements ConfigurationManager {
 
-	private ArrayList listeners = null;
-	private ChannelSender sender = null;
-	private AxisConfiguration axisConfiguration = null;
-	
-	public TribesConfigurationManager () {
-		listeners = new ArrayList ();
-	}
-	
-	public void addConfigurationManagerListener(ConfigurationManagerListener listener) {
-		if (axisConfiguration!=null)
-			listener.setAxisConfiguration(axisConfiguration);
-		
-		listeners.add(listener);
-	}
-
-	public void applyPolicy(String serviceGroupName, Policy policy)  throws ClusteringFault {
-		ConfigurationCommand command = new ConfigurationCommand (CommandType.APPLY_POLICY);
-		command.setSgcName(serviceGroupName);
-		command.setPolicyId(policy.getId());
-		send (command);
-	}
-
-	public void commit()  throws ClusteringFault {
-		ConfigurationCommand command = new ConfigurationCommand (CommandType.COMMIT);
-		send (command);
-	}
-
-	public void loadServiceGroup(String serviceGroupName)  throws ClusteringFault {
-		ConfigurationCommand command = new ConfigurationCommand (CommandType.LOAD_SERVICE_GROUP);
-		command.setSgcName(serviceGroupName);
-		send (command);
-	}
-
-	public void prepare()  throws ClusteringFault {
-		ConfigurationCommand command = new ConfigurationCommand (CommandType.PREPARE);
-		send (command);
-	}
-
-	public void reloadConfiguration() throws ClusteringFault {
-		ConfigurationCommand command = new ConfigurationCommand (CommandType.RELOAD_CONFIGURATION);
-		send (command);		
-	}
-
-	public void rollback()  throws ClusteringFault {
-		ConfigurationCommand command = new ConfigurationCommand (CommandType.ROLLBACK);
-		send (command);			
-	}
-
-	public void unloadServiceGroup(String serviceGroupName)  throws ClusteringFault {
-		ConfigurationCommand command = new ConfigurationCommand (CommandType.UNLOAD_SERVICE_GROUP);
-		command.setSgcName(serviceGroupName);
-		send (command);
-	}
-
-	private void send (ConfigurationCommand command) throws ClusteringFault {
-		sender.send(command);
-	}
-
-	public void setSender(ChannelSender sender) {
-		this.sender = sender;
-	}
-	
-	public void notifyListeners (int command, ConfigurationEvent event) {
-		
-		for (Iterator it=listeners.iterator();it.hasNext();) {
-			ConfigurationManagerListener listener = (ConfigurationManagerListener) it.next();
-			
-			if (CommandType.LOAD_SERVICE_GROUP==command) 
-				listener.serviceGroupLoaded(event);
-			else if (CommandType.UNLOAD_SERVICE_GROUP==command)
-				listener.serviceGroupUnloaded(event);
-			else if (CommandType.APPLY_POLICY==command)
-				listener.policyApplied(event);
-			else if (CommandType.RELOAD_CONFIGURATION==command)
-				listener.configurationReloaded(event);
-			else if (CommandType.PREPARE==command)
-				listener.prepareCalled(event);
-			else if (CommandType.COMMIT==command)
-				listener.commitCalled(event);
-			else if (CommandType.ROLLBACK==command)
-				listener.rollbackCalled(event);
-		}
-	}
-
-	public void setAxisConfiguration(AxisConfiguration axisConfiguration) {
-		this.axisConfiguration = axisConfiguration;
-	}
-	
+    private List listeners = null;
+    private ChannelSender sender = null;
+    private AxisConfiguration axisConfiguration = null;
+
+    public TribesConfigurationManager() {
+        listeners = new ArrayList();
+    }
+
+    public void addConfigurationManagerListener(ConfigurationManagerListener listener) {
+        if (axisConfiguration != null) {
+            listener.setAxisConfiguration(axisConfiguration);
+        }
+
+        listeners.add(listener);
+    }
+
+    public void applyPolicy(String serviceGroupName, Policy policy) throws ClusteringFault {
+        ConfigurationCommand command = new ConfigurationCommand(CommandType.APPLY_POLICY);
+        command.setSgcName(serviceGroupName);
+        command.setPolicyId(policy.getId());
+        send(command);
+    }
+
+    public void commit() throws ClusteringFault {
+        ConfigurationCommand command = new ConfigurationCommand(CommandType.COMMIT);
+        send(command);
+    }
+
+    public void loadServiceGroup(String serviceGroupName) throws ClusteringFault {
+        ConfigurationCommand command = new ConfigurationCommand(CommandType.LOAD_SERVICE_GROUP);
+        command.setSgcName(serviceGroupName);
+        send(command);
+    }
+
+    public void prepare() throws ClusteringFault {
+        ConfigurationCommand command = new ConfigurationCommand(CommandType.PREPARE);
+        send(command);
+    }
+
+    public void reloadConfiguration() throws ClusteringFault {
+        ConfigurationCommand command = new ConfigurationCommand(CommandType.RELOAD_CONFIGURATION);
+        send(command);
+    }
+
+    public void rollback() throws ClusteringFault {
+        ConfigurationCommand command = new ConfigurationCommand(CommandType.ROLLBACK);
+        send(command);
+    }
+
+    public void unloadServiceGroup(String serviceGroupName) throws ClusteringFault {
+        ConfigurationCommand command = new ConfigurationCommand(CommandType.UNLOAD_SERVICE_GROUP);
+        command.setSgcName(serviceGroupName);
+        send(command);
+    }
+
+    private void send(ConfigurationCommand command) throws ClusteringFault {
+        if (sender.getChannel().getMembers().length > 0) {
+            sender.send(command);
+        }
+    }
+
+    public void setSender(ChannelSender sender) {
+        this.sender = sender;
+    }
+
+    public void notifyListeners(int command, ConfigurationEvent event) {
+
+        for (Iterator it = listeners.iterator(); it.hasNext();) {
+            ConfigurationManagerListener listener = (ConfigurationManagerListener) it.next();
+
+            if (CommandType.LOAD_SERVICE_GROUP == command) {
+                listener.serviceGroupLoaded(event);
+            } else if (CommandType.UNLOAD_SERVICE_GROUP == command) {
+                listener.serviceGroupUnloaded(event);
+            } else if (CommandType.APPLY_POLICY == command) {
+                listener.policyApplied(event);
+            } else if (CommandType.RELOAD_CONFIGURATION == command) {
+                listener.configurationReloaded(event);
+            } else if (CommandType.PREPARE == command) {
+                listener.prepareCalled(event);
+            } else if (CommandType.COMMIT == command) {
+                listener.commitCalled(event);
+            } else if (CommandType.ROLLBACK == command) {
+                listener.rollbackCalled(event);
+            }
+        }
+    }
+
+    public void setAxisConfiguration(AxisConfiguration axisConfiguration) {
+        this.axisConfiguration = axisConfiguration;
+    }
+
 }

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=520349&r1=520348&r2=520349
==============================================================================
--- 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 Mar 20 03:46:59 2007
@@ -16,18 +16,13 @@
 
 package org.apache.axis2.cluster.tribes.context;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
 import org.apache.axis2.cluster.ClusteringFault;
 import org.apache.axis2.cluster.context.ContextEvent;
 import org.apache.axis2.cluster.context.ContextManager;
 import org.apache.axis2.cluster.context.ContextManagerListener;
 import org.apache.axis2.cluster.listeners.DefaultContextManagerListener;
 import org.apache.axis2.cluster.tribes.ChannelSender;
+import org.apache.axis2.cluster.tribes.CommandMessage;
 import org.apache.axis2.cluster.tribes.CommandType;
 import org.apache.axis2.context.AbstractContext;
 import org.apache.axis2.context.ConfigurationContext;
@@ -38,253 +33,273 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import java.util.*;
+
 public class TribesContextManager implements ContextManager {
 
     private static final Log log = LogFactory.getLog(TribesContextManager.class);
-    
-	private ConfigurationContext configContext;
-	private ContextUpdater updater;
-
-	private Map orphanedServiceCtxs = new HashMap ();
-	private ArrayList addedServiceGrpCtxs = new ArrayList ();
-	private ArrayList addedServiceCtxs = new ArrayList ();
-	private ArrayList listeners = null;
-	
-	private ChannelSender sender;
-	
-	public void setSender(ChannelSender sender) {
-		this.sender = sender;
-	}
-
-	public TribesContextManager (ConfigurationContext configurationContext, ContextUpdater updater) {
-		this ();
-		this.configContext = configurationContext;
-		this.updater = updater;
-	}
-	
-	public TribesContextManager () {
-		listeners = new ArrayList ();
-	}
-	
-	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)
-				listener.contextRemoved(event);
-			else if (eventType == ContextListenerEventType.UPDATE_CONTEXT)
-				listener.contextUpdated(event);
-		}
-		
-	}
-	
-	public void addContext(AbstractContext context) throws ClusteringFault {
-		ContextCommandMessage comMsg = null;
-
-		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)) {
-				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);
-				sender.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)) {
-				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())) {
-				return;
-			}
-
-			updater.addServiceGroupContext(contextId);
-
-			comMsg = new ContextCommandMessage(CommandType.CREATE_SERVICE_GROUP_CONTEXT, "",
-					contextId, srvGrpCtx.getDescription().getServiceGroupName(),
-					ContextType.SERVICE_GROUP_CONTEXT);
-
-			sender.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);
-
-					sender.send(command);
-
-				}
-
-				orphanedServiceCtxs.remove(srvGrpCtx.getDescription().getServiceGroupName());
-			}
-		}
-	}
-
-	/*
-	 * public void addProperty(AbstractContext ctx,String contextId, String
-	 * parentId, String propertyName, Object propertyValue) { if (ctx instanceof
-	 * ServiceContext){ ctxManager.addPropToServiceContext(parentId, contextId,
-	 * propertyName, propertyValue); }else{
-	 * ctxManager.addPropToServiceGroupContext(contextId, propertyName,
-	 * propertyValue); } }
-	 */
-
-	public void removeContext(AbstractContext context) throws ClusteringFault {
-		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);
-		}
-
-		sender.send(comMsg);
-	}
-
-	/*
-	 * public void removeProperty(AbstractContext ctx, String contextId, String
-	 * parentId, String propertyName) { if (ctx instanceof ServiceContext){
-	 * ctxManager.removePropFromServiceContext(parentId, contextId,
-	 * propertyName); }else{
-	 * ctxManager.removePropFromServiceGroupContext(contextId, propertyName); } }
-	 */
-
-	public void updateState(AbstractContext context) throws ClusteringFault {
-
-		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();
-				sender.send(msg);
-			}
-		}
-
-		ContextCommandMessage comMsg = new ContextCommandMessage(CommandType.UPDATE_STATE,
-				parentContextId, contextId, contextId, contextType);
-
-		sender.send(comMsg);
-	}
-
-	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;
-	}
-
-	public void addToDuplicateServiceGroupContexts (String id) {
-		
-	}
-	
-	public void addToDuplicateServiceContexts (String id) {
-		
-	}
-
-	public void addContextManagerListener(ContextManagerListener listener) {
-		if (configContext!=null)
-			listener.setConfigurationContext(configContext);
-		
-		listeners.add(listener);
-	}
-
-	public void setUpdater(ContextUpdater updater) {
-		this.updater = updater;
-		
-		//updating the listeners
-		for (Iterator it = listeners.iterator();it.hasNext();) {
-			DefaultContextManagerListener listener = (DefaultContextManagerListener) it.next();
-			listener.setUpdater(updater);
-		}
-	}
-
-	public void setConfigurationContext(ConfigurationContext configurationContext) {
-		this.configContext = configurationContext;
-		
-		//setting this to the listeners as well.
-		if (listeners!=null) {
-			for (Iterator it=listeners.iterator();it.hasNext();) {
-				ContextManagerListener listener = (ContextManagerListener) it.next();
-				listener.setConfigurationContext(configurationContext);
-			}
-		}
-	}
-	
+
+    private ConfigurationContext configContext;
+    private ContextUpdater updater;
+
+    private Map orphanedServiceCtxs = new HashMap();
+    private List addedServiceGrpCtxs = new ArrayList();
+    private List addedServiceCtxs = new ArrayList();
+    private List listeners = null;
+
+    private ChannelSender sender;
+
+    public void setSender(ChannelSender sender) {
+        this.sender = sender;
+    }
+
+    public TribesContextManager(ConfigurationContext configurationContext, ContextUpdater updater) {
+        this();
+        this.configContext = configurationContext;
+        this.updater = updater;
+    }
+
+    public TribesContextManager() {
+        listeners = new ArrayList();
+    }
+
+    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) {
+                listener.contextRemoved(event);
+            } else if (eventType == ContextListenerEventType.UPDATE_CONTEXT) {
+                listener.contextUpdated(event);
+            }
+        }
+
+    }
+
+    public void addContext(AbstractContext context) throws ClusteringFault {
+        ContextCommandMessage comMsg = null;
+
+        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)) {
+                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)) {
+                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())) {
+                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());
+            }
+        }
+    }
+
+    /*
+      * public void addProperty(AbstractContext ctx,String contextId, String
+      * parentId, String propertyName, Object propertyValue) { if (ctx instanceof
+      * ServiceContext){ ctxManager.addPropToServiceContext(parentId, contextId,
+      * propertyName, propertyValue); }else{
+      * ctxManager.addPropToServiceGroupContext(contextId, propertyName,
+      * propertyValue); } }
+      */
+
+    public void removeContext(AbstractContext context) throws ClusteringFault {
+        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);
+    }
+
+    /*
+      * public void removeProperty(AbstractContext ctx, String contextId, String
+      * parentId, String propertyName) { if (ctx instanceof ServiceContext){
+      * ctxManager.removePropFromServiceContext(parentId, contextId,
+      * propertyName); }else{
+      * ctxManager.removePropFromServiceGroupContext(contextId, propertyName); } }
+      */
+
+    public void updateState(AbstractContext context) throws ClusteringFault {
+
+        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);
+    }
+
+    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;
+    }
+
+    public void addToDuplicateServiceGroupContexts(String id) {
+
+    }
+
+    public void addToDuplicateServiceContexts(String id) {
+
+    }
+
+    public void addContextManagerListener(ContextManagerListener listener) {
+        if (configContext != null) {
+            listener.setConfigurationContext(configContext);
+        }
+
+        listeners.add(listener);
+    }
+
+    public void setUpdater(ContextUpdater updater) {
+        this.updater = updater;
+
+        //updating the listeners
+        for (Iterator it = listeners.iterator(); it.hasNext();) {
+            DefaultContextManagerListener listener = (DefaultContextManagerListener) it.next();
+            listener.setUpdater(updater);
+        }
+    }
+
+    public void setConfigurationContext(ConfigurationContext configurationContext) {
+        this.configContext = configurationContext;
+
+        //setting this to the listeners as well.
+        if (listeners != null) {
+            for (Iterator it = listeners.iterator(); it.hasNext();) {
+                ContextManagerListener listener = (ContextManagerListener) it.next();
+                listener.setConfigurationContext(configurationContext);
+            }
+        }
+    }
+
+    private void send(CommandMessage command) throws ClusteringFault {
+        if (sender.getChannel().getMembers().length > 0) {
+            sender.send(command);
+        }
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org