[jboss-cvs] JBossAS SVN: r88120 - in branches/JBPAPP_4_2_0_GA_CP: testsuite/imports/sections and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sat May 2 01:53:43 EDT 2009
Author: jiwils
Date: 2009-05-02 01:53:43 -0400 (Sat, 02 May 2009)
New Revision: 88120
Added:
branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/ExtendedElectionPolicy.java
branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/ExtendedElectionPolicyBase.java
branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/ExtendedElectionPolicyMBean.java
branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/ExtendedElectionPolicySimple.java
branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/ExtendedElectionPolicySimpleMBean.java
branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/test/ExtendedHASingletonElectionPolicyTestCase.java
branches/JBPAPP_4_2_0_GA_CP/testsuite/src/resources/ha/electionpolicy/extended-ha-electionpolicy-service.xml
Modified:
branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicy.java
branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicyBase.java
branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicySimple.java
branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java
branches/JBPAPP_4_2_0_GA_CP/testsuite/imports/sections/cluster.xml
Log:
Fix for JBPAPP-1976. Ported JBAS-5170 to the cumulative patch branch.
Copied: branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/ExtendedElectionPolicy.java (from rev 72388, branches/Branch_4_2/cluster/src/main/org/jboss/ha/singleton/ExtendedElectionPolicy.java)
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/ExtendedElectionPolicy.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/ExtendedElectionPolicy.java 2009-05-02 05:53:43 UTC (rev 88120)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.singleton;
+
+/**
+ * Extended HASingleton election policy that allows setting HASingleton's name.
+ * This enables election policies to work correctly in heterogenous topologies
+ * where HASingletons are not deployed in all nodes in the cluster.
+ *
+ * By setting the HASingleton name in the election policy, the policy is able
+ * to query the DistributedReplicantManager in order to find out the List nodes
+ * where the HASingleton is deployed and then, choose from this list the node
+ * that should be running it.
+ *
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+public interface ExtendedElectionPolicy extends HASingletonElectionPolicy
+{
+ /**
+ * Called by the HASingleton, during the start service phase, to set the
+ * name with which the singleton is registered with the HAPartition.
+ *
+ * @param serviceName the singleton service name.
+ */
+ void setSingletonName(String serviceName);
+
+ /**
+ * Get the singleton name for this election policy.
+ *
+ * @return the singleton service name.
+ */
+ String getSingletonName();
+}
Copied: branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/ExtendedElectionPolicyBase.java (from rev 72388, branches/Branch_4_2/cluster/src/main/org/jboss/ha/singleton/ExtendedElectionPolicyBase.java)
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/ExtendedElectionPolicyBase.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/ExtendedElectionPolicyBase.java 2009-05-02 05:53:43 UTC (rev 88120)
@@ -0,0 +1,137 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.singleton;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.ha.framework.interfaces.ClusterNode;
+import org.jboss.ha.framework.interfaces.DistributedReplicantManager;
+import org.jboss.ha.framework.interfaces.HAPartition;
+
+/**
+ * Base extended election policy providing helper methods for concrete
+ * implementations.
+ *
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+public abstract class ExtendedElectionPolicyBase extends HASingletonElectionPolicyBase
+ implements ExtendedElectionPolicyMBean
+{
+ private String singletonName;
+
+ public String getSingletonName()
+ {
+ return singletonName;
+ }
+
+ public void setSingletonName(String serviceName)
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("Singleton name set to " + serviceName);
+ }
+
+ singletonName = serviceName;
+ }
+
+ public ClusterNode pickSingleton()
+ {
+ List<ClusterNode> candidates = getCandidates();
+ if (candidates == null)
+ {
+ log.debug("List of cluster node candidates where to run the singleton is null");
+ return null;
+ }
+
+ return elect(candidates);
+ }
+
+ @Override
+ public boolean isElectedMaster()
+ {
+ ClusterNode selectedNode = pickSingleton();
+ if (selectedNode != null)
+ {
+ return selectedNode.equals(getHAPartition().getClusterNode());
+ }
+
+ return false;
+ }
+
+ /**
+ * Get the list of candidate {@link ClusterNode} instances where the
+ * singleton could be deployed.
+ *
+ * @return List of {@link ClusterNode} instances.
+ */
+ protected List<ClusterNode> getCandidates()
+ {
+ HAPartition partition = getHAPartition();
+
+ if (partition == null)
+ {
+ throw new IllegalStateException("HAPartition has not been set");
+ }
+
+ DistributedReplicantManager drm = partition.getDistributedReplicantManager();
+ /* retrieve node names where singleton is deployed */
+ List<String> nodeNames = drm.lookupReplicantsNodeNames(getSingletonName());
+ if (nodeNames != null)
+ {
+ ClusterNode[] allNodes = partition.getClusterNodes();
+ List<ClusterNode> nodesSingletonIn = new ArrayList<ClusterNode>(nodeNames.size());
+
+ /* For each node in the list of nodes where the singleton is deployed,
+ * find the corresponding ClusterNode object and add it to the list of
+ * ClusterNode candidates where the singleton can run.
+ *
+ * This is certainly not the most efficient way to do it's we can do
+ * given the limited DRM API in AS 4.x. */
+ for (String nodeName : nodeNames)
+ {
+ for(int i = 0; i < allNodes.length; i++)
+ {
+ ClusterNode node = allNodes[i];
+ if (node.getName().equals(nodeName))
+ {
+ nodesSingletonIn.add(node);
+ break;
+ }
+ }
+ }
+
+ return nodesSingletonIn;
+ }
+
+ return null;
+ }
+
+ /**
+ * Given a List of candidate {@link ClusterNode} instances, return the
+ * elected node where the singleton should run.
+ *
+ * @param candidates List of {@link ClusterNode}.
+ * @return {@link ClusterNode} instance.
+ */
+ protected abstract ClusterNode elect(List<ClusterNode> candidates);
+}
\ No newline at end of file
Copied: branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/ExtendedElectionPolicyMBean.java (from rev 72388, branches/Branch_4_2/cluster/src/main/org/jboss/ha/singleton/ExtendedElectionPolicyMBean.java)
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/ExtendedElectionPolicyMBean.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/ExtendedElectionPolicyMBean.java 2009-05-02 05:53:43 UTC (rev 88120)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.singleton;
+
+/**
+ * ExtendedHASingletonElectionPolicyMBean.
+ *
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+public interface ExtendedElectionPolicyMBean
+ extends HASingletonElectionPolicyMBean, ExtendedElectionPolicy
+{
+}
Copied: branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/ExtendedElectionPolicySimple.java (from rev 72388, branches/Branch_4_2/cluster/src/main/org/jboss/ha/singleton/ExtendedElectionPolicySimple.java)
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/ExtendedElectionPolicySimple.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/ExtendedElectionPolicySimple.java 2009-05-02 05:53:43 UTC (rev 88120)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.singleton;
+
+import java.util.List;
+
+import org.jboss.ha.framework.interfaces.ClusterNode;
+
+/**
+ * Simple extended election policy implementation:
+ *
+ * A simple concrete policy service that decides which node in the cluster
+ * should be the master node to run certain HASingleton service based on
+ * attribute "Position". The value will be divided by partition size and only
+ * remainder will be used.
+ *
+ * Let's say partition size is n:
+ * 0 means the first oldest node.
+ * 1 means the 2nd oldest node.
+ * ...
+ * n-1 means the nth oldest node.
+ *
+ * -1 means the youngest node.
+ * -2 means the 2nd youngest node.
+ * ...
+ * -n means the nth youngest node.
+ *
+ * E.g. the following attribute says the singleton will be running on the 3rd
+ * oldest node of the current partition:
+ * <attribute name="Position">2</attribute>
+ *
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+public class ExtendedElectionPolicySimple extends ExtendedElectionPolicyBase
+ implements ExtendedElectionPolicySimpleMBean
+{
+ private int position = 0; // Default
+
+ public void setPosition(int pos)
+ {
+ position = pos;
+ }
+
+ public int getPosition()
+ {
+ return position;
+ }
+
+ @Override
+ protected ClusterNode elect(List<ClusterNode> candidates)
+ {
+ int size = candidates.size();
+ int remainder = ((position % size) + size) % size;
+
+ return candidates.get(remainder);
+ }
+}
Copied: branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/ExtendedElectionPolicySimpleMBean.java (from rev 72388, branches/Branch_4_2/cluster/src/main/org/jboss/ha/singleton/ExtendedElectionPolicySimpleMBean.java)
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/ExtendedElectionPolicySimpleMBean.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/ExtendedElectionPolicySimpleMBean.java 2009-05-02 05:53:43 UTC (rev 88120)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.singleton;
+
+/**
+ * ExtendedElectionPolicySimpleMBean.
+ *
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+public interface ExtendedElectionPolicySimpleMBean
+ extends HASingletonElectionPolicySimpleMBean, ExtendedElectionPolicy
+{
+}
Modified: branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicy.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicy.java 2009-05-02 00:47:42 UTC (rev 88119)
+++ branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicy.java 2009-05-02 05:53:43 UTC (rev 88120)
@@ -3,6 +3,13 @@
import org.jboss.ha.framework.interfaces.ClusterNode;
import org.jboss.ha.framework.interfaces.HAPartition;
+/**
+ * HASingletonElectionPolicy.
+ *
+ * @author <a href="mailto:Alex.Fu at novell.com">Alex Fu</a>
+ * @author Brian Stansberry
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
public interface HASingletonElectionPolicy
{
@@ -27,17 +34,22 @@
HAPartition getHAPartition();
/**
- * Return the elected master node.
- * @return the master node
+ * Return the elected master node or null if there are no cluster nodes
+ * where the singleton can be deployed.
+ * @return the master node or null.
*/
ClusterNode pickSingleton();
/**
- * Given the HAPartition, return the elected master node.
+ * Given the HAPartition, return the elected master node or null if there are
+ * no cluster nodes where the singleton can be deployed.
* @param partition
- * @return the master node
+ * @return the master node or null.
+ * @deprecated HAPartition is now set during the HASingleton start phase, as
+ * part of the HAPartition set up. Implementations of this method should
+ * delegate to {@link #pickSingleton()}.
*/
- ClusterNode pickSingleton(HAPartition partition);
+ @Deprecated ClusterNode pickSingleton(HAPartition partition);
/**
* Conducts an election and returns whether the managed service
@@ -50,7 +62,10 @@
* Given the HAPartition, return whether the managed service is the master.
* @param partition
* @return true only if the managed service is the master
+ * @deprecated HAPartition is set during the HASingleton start phase, as
+ * part of the HAPartition set up. Implementations of this method should
+ * delegate to {@link #isElectedMaster()}.
*/
- boolean isElectedMaster(HAPartition partition);
+ @Deprecated boolean isElectedMaster(HAPartition partition);
}
\ No newline at end of file
Modified: branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicyBase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicyBase.java 2009-05-02 00:47:42 UTC (rev 88119)
+++ branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicyBase.java 2009-05-02 05:53:43 UTC (rev 88120)
@@ -21,10 +21,8 @@
*/
package org.jboss.ha.singleton;
-
+import org.jboss.ha.framework.interfaces.ClusterNode;
import org.jboss.ha.framework.interfaces.HAPartition;
-import org.jboss.ha.framework.server.ClusterPartition;
-import org.jboss.logging.Logger;
import org.jboss.system.ServiceMBeanSupport;
/**
@@ -32,6 +30,7 @@
* the master node to run certain HASingleton service.
*
* @author <a href="mailto:afu at novell.com">Alex Fu</a>
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
* @version $Revision: 46010 $
*/
public abstract class HASingletonElectionPolicyBase
@@ -62,6 +61,11 @@
*/
public void setHAPartition(HAPartition partition)
{
+ if (log.isTraceEnabled())
+ {
+ log.trace("Partition set to " + partition);
+ }
+
this.mPartition = partition;
}
@@ -87,11 +91,18 @@
/**
* @see HASingletonElectionPolicyMBean#isElectedMaster(HAPartition)
*/
+ @Deprecated
public boolean isElectedMaster(HAPartition partition)
{
- if (null == partition)
- throw new IllegalStateException("parameter cannot be null");
+ return isElectedMaster();
+ }
- return pickSingleton(partition).equals(partition.getClusterNode());
+ /**
+ * @see HASingletonElectionPolicyMBean#pickSingleton(HAPartition)
+ */
+ @Deprecated
+ public ClusterNode pickSingleton(HAPartition partition)
+ {
+ return pickSingleton();
}
}
Modified: branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicySimple.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicySimple.java 2009-05-02 00:47:42 UTC (rev 88119)
+++ branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicySimple.java 2009-05-02 05:53:43 UTC (rev 88120)
@@ -46,6 +46,7 @@
* <attribute name="Position">2</attribute>
*
* @author <a href="mailto:Alex.Fu at novell.com">Alex Fu</a>
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
* @version $Revision: 46010 $
*/
public class HASingletonElectionPolicySimple
@@ -73,16 +74,11 @@
public ClusterNode pickSingleton()
{
- return pickSingleton(getHAPartition());
- }
-
- public ClusterNode pickSingleton(HAPartition partition)
- {
- ClusterNode[] nodes = partition.getClusterNodes();
+ ClusterNode[] nodes = getHAPartition().getClusterNodes();
int size = nodes.length;
int remainder = ((this.mPosition % size) + size) % size;
- return nodes[remainder];
- }
+ return nodes[remainder];
+ }
}
Modified: branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java 2009-05-02 00:47:42 UTC (rev 88119)
+++ branches/JBPAPP_4_2_0_GA_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java 2009-05-02 05:53:43 UTC (rev 88120)
@@ -24,9 +24,13 @@
import java.util.List;
import javax.management.Notification;
+import javax.management.ReflectionException;
import org.jboss.ha.framework.interfaces.ClusterMergeStatus;
import org.jboss.ha.jmx.HAServiceMBeanSupport;
+import org.jboss.invocation.jrmp.server.JRMPProxyFactoryMBean;
+import org.jboss.mx.util.MBeanProxyExt;
+import org.jboss.mx.util.MBeanProxyInstance;
/**
* Base class for HA-Singleton services.
@@ -34,6 +38,7 @@
* @author <a href="mailto:ivelin at apache.org">Ivelin Ivanov</a>
* @author <a href="mailto:scott.stark at jboss.org">Scott Stark</a>
* @author <a href="mailto:dimitris at jboss.org">Dimitris Andreadis</a>
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
* @version $Revision$
*/
public class HASingletonSupport extends HAServiceMBeanSupport
@@ -166,7 +171,7 @@
{
boolean isElectedNewMaster;
if (this.mElectionPolicyMB != null)
- isElectedNewMaster = this.mElectionPolicyMB.isElectedMaster(this.getPartition());
+ isElectedNewMaster = this.mElectionPolicyMB.isElectedMaster();
else
isElectedNewMaster = isDRMMasterReplica();
@@ -276,6 +281,33 @@
startNewMaster();
}
+ @Override
+ protected void setupPartition() throws Exception
+ {
+ super.setupPartition();
+
+ if (mElectionPolicyMB != null)
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("Optional singleton election policy defined: " + mElectionPolicyMB);
+ }
+
+ mElectionPolicyMB.setHAPartition(getPartition());
+
+ try
+ {
+ server.invoke(((MBeanProxyInstance)mElectionPolicyMB).getMBeanProxyObjectName(),
+ "setSingletonName", new Object[] {getServiceHAName()},
+ new String[] {"java.lang.String"});
+ }
+ catch(ReflectionException re)
+ {
+ log.debug("Selected election policy does not support setting singleton name, skipping assignment.");
+ }
+ }
+ }
+
// Private -------------------------------------------------------
private void sendLocalNotification(String type)
Modified: branches/JBPAPP_4_2_0_GA_CP/testsuite/imports/sections/cluster.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/imports/sections/cluster.xml 2009-05-02 00:47:42 UTC (rev 88119)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/imports/sections/cluster.xml 2009-05-02 05:53:43 UTC (rev 88120)
@@ -40,6 +40,11 @@
<copy todir="${build.lib}"
file="${build.resources}/ha/electionpolicy/ha-electionpolicy-service.xml"
overwrite="true"/>
+
+ <!-- mbeans for testing HASingleton ExtendedElectionPolicy -->
+ <copy todir="${build.lib}"
+ file="${build.resources}/ha/electionpolicy/extended-ha-electionpolicy-service.xml"
+ overwrite="true"/>
<!-- build httpsessionreplication.jar -->
<war warfile="${build.lib}/http-sr.war"
Copied: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/test/ExtendedHASingletonElectionPolicyTestCase.java (from rev 72389, branches/Branch_4_2/testsuite/src/main/org/jboss/test/cluster/test/ExtendedHASingletonElectionPolicyTestCase.java)
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/test/ExtendedHASingletonElectionPolicyTestCase.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/test/ExtendedHASingletonElectionPolicyTestCase.java 2009-05-02 05:53:43 UTC (rev 88120)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.cluster.test;
+
+import junit.framework.Test;
+
+/**
+ * Runs the HASingleton election policy tests with extended ha singleton
+ * election policies.
+ *
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+public class ExtendedHASingletonElectionPolicyTestCase extends HASingletonElectionPolicyTestCase
+{
+ public ExtendedHASingletonElectionPolicyTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite() throws Exception
+ {
+ // Refer to jboss-service.xml under resources/ha/electionpolicy
+ return getDeploySetup(ExtendedHASingletonElectionPolicyTestCase.class, "extended-ha-electionpolicy-service.xml");
+ }
+}
\ No newline at end of file
Copied: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/resources/ha/electionpolicy/extended-ha-electionpolicy-service.xml (from rev 72389, branches/Branch_4_2/testsuite/src/resources/ha/electionpolicy/extended-ha-electionpolicy-service.xml)
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/resources/ha/electionpolicy/extended-ha-electionpolicy-service.xml (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/resources/ha/electionpolicy/extended-ha-electionpolicy-service.xml 2009-05-02 05:53:43 UTC (rev 88120)
@@ -0,0 +1,208 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE server>
+<server>
+ <!-- First HASingleton, Election policy is to choose the oldest node as master -->
+ <mbean code="org.jboss.ha.singleton.examples.HASingletonMBeanExample"
+ name="jboss.examples:service=HASingletonMBeanExample_1">
+ </mbean>
+
+ <mbean code="org.jboss.ha.singleton.ExtendedElectionPolicySimple"
+ name="jboss.examples:service=HASingletonMBeanExample-ExtendedElectionPolicySimple_1">
+ <attribute name="Position">0</attribute>
+ </mbean>
+
+ <mbean code="org.jboss.ha.singleton.HASingletonController"
+ name="jboss.examples:service=HASingletonMBeanExample-HASingletonController_1">
+
+ <depends optional-attribute-name="ClusterPartition"
+ proxy-type="attribute">test:service=ElectionPolicyTestPartition</depends>
+ <depends>jboss.examples:service=HASingletonMBeanExample_1</depends>
+ <depends optional-attribute-name="ElectionPolicy"
+ proxy-type="attribute">jboss.examples:service=HASingletonMBeanExample-ExtendedElectionPolicySimple_1</depends>
+ <attribute name="TargetName">jboss.examples:service=HASingletonMBeanExample_1</attribute>
+ <attribute name="TargetStartMethod">startSingleton</attribute>
+ <attribute name="TargetStopMethod">stopSingleton</attribute>
+ <attribute name="TargetStopMethodArgument">true</attribute>
+ </mbean>
+
+ <!-- Second HASingleton, Election policy is to choose the youngest node as master -->
+ <mbean code="org.jboss.ha.singleton.examples.HASingletonMBeanExample"
+ name="jboss.examples:service=HASingletonMBeanExample_2">
+ </mbean>
+
+ <mbean code="org.jboss.ha.singleton.ExtendedElectionPolicySimple"
+ name="jboss.examples:service=HASingletonMBeanExample-ExtendedElectionPolicySimple_2">
+ <attribute name="Position">-1</attribute>
+ </mbean>
+
+ <mbean code="org.jboss.ha.singleton.HASingletonController"
+ name="jboss.examples:service=HASingletonMBeanExample-HASingletonController_2">
+
+ <depends optional-attribute-name="ClusterPartition"
+ proxy-type="attribute">test:service=ElectionPolicyTestPartition</depends>
+ <depends>jboss.examples:service=HASingletonMBeanExample_2</depends>
+ <depends optional-attribute-name="ElectionPolicy"
+ proxy-type="attribute">jboss.examples:service=HASingletonMBeanExample-ExtendedElectionPolicySimple_2</depends>
+ <attribute name="TargetName">jboss.examples:service=HASingletonMBeanExample_2</attribute>
+ <attribute name="TargetStartMethod">startSingleton</attribute>
+ <attribute name="TargetStopMethod">stopSingleton</attribute>
+ <attribute name="TargetStopMethodArgument">true</attribute>
+ </mbean>
+
+ <!-- Third HASingleton, Election policy is to choose the 2nd oldest node as master -->
+ <mbean code="org.jboss.ha.singleton.examples.HASingletonMBeanExample"
+ name="jboss.examples:service=HASingletonMBeanExample_3">
+ </mbean>
+
+ <mbean code="org.jboss.ha.singleton.ExtendedElectionPolicySimple"
+ name="jboss.examples:service=HASingletonMBeanExample-ExtendedElectionPolicySimple_3">
+ <attribute name="Position">1</attribute>
+ </mbean>
+
+ <mbean code="org.jboss.ha.singleton.HASingletonController"
+ name="jboss.examples:service=HASingletonMBeanExample-HASingletonController_3">
+
+ <depends optional-attribute-name="ClusterPartition"
+ proxy-type="attribute">test:service=ElectionPolicyTestPartition</depends>
+ <depends>jboss.examples:service=HASingletonMBeanExample_3</depends>
+ <depends optional-attribute-name="ElectionPolicy"
+ proxy-type="attribute">jboss.examples:service=HASingletonMBeanExample-ExtendedElectionPolicySimple_3</depends>
+ <attribute name="TargetName">jboss.examples:service=HASingletonMBeanExample_3</attribute>
+ <attribute name="TargetStartMethod">startSingleton</attribute>
+ <attribute name="TargetStopMethod">stopSingleton</attribute>
+ <attribute name="TargetStopMethodArgument">true</attribute>
+ </mbean>
+
+ <!-- Fourth HASingleton, No election policy defined. By default, the oldest node is selected -->
+ <mbean code="org.jboss.ha.singleton.examples.HASingletonMBeanExample"
+ name="jboss.examples:service=HASingletonMBeanExample_4">
+ </mbean>
+
+ <mbean code="org.jboss.ha.singleton.HASingletonController"
+ name="jboss.examples:service=HASingletonMBeanExample-HASingletonController_4">
+
+ <depends optional-attribute-name="ClusterPartition"
+ proxy-type="attribute">test:service=ElectionPolicyTestPartition</depends>
+ <depends>jboss.examples:service=HASingletonMBeanExample_4</depends>
+ <attribute name="TargetName">jboss.examples:service=HASingletonMBeanExample_4</attribute>
+ <attribute name="TargetStartMethod">startSingleton</attribute>
+ <attribute name="TargetStopMethod">stopSingleton</attribute>
+ <attribute name="TargetStopMethodArgument">true</attribute>
+ </mbean>
+
+ <!-- ==================================================================== -->
+ <!-- Partition used by the above beans -->
+ <!-- ==================================================================== -->
+
+ <mbean code="org.jboss.ha.framework.server.ClusterPartition"
+ name="test:service=ElectionPolicyTestPartition">
+
+ <!-- Name of the partition being built -->
+ <attribute name="PartitionName">ElectionPolicyTestPartition</attribute>
+
+ <!-- The address used to determine the node name -->
+ <attribute name="NodeAddress">${jboss.bind.address}</attribute>
+
+ <!-- Determine if deadlock detection is enabled -->
+ <attribute name="DeadlockDetection">False</attribute>
+
+ <!-- Keep this timeout short -->
+ <attribute name="StateTransferTimeout">2000</attribute>
+
+ <!-- The JGroups protocol configuration -->
+ <attribute name="PartitionConfig">
+ <!--
+ The default UDP stack:
+ - If you have a multihomed machine, set the UDP protocol's bind_addr attribute to the
+ appropriate NIC IP address, e.g bind_addr="192.168.0.2".
+ - On Windows machines, because of the media sense feature being broken with multicast
+ (even after disabling media sense) set the UDP protocol's loopback attribute to true
+ -->
+ <Config>
+ <UDP mcast_addr="${jboss.partition.udpGroup:228.1.2.3}"
+ mcast_port="${jboss.hapartition.mcast_port:45566}"
+ tos="8"
+ ucast_recv_buf_size="20000000"
+ ucast_send_buf_size="640000"
+ mcast_recv_buf_size="25000000"
+ mcast_send_buf_size="640000"
+ loopback="false"
+ discard_incompatible_packets="true"
+ enable_bundling="false"
+ max_bundle_size="64000"
+ max_bundle_timeout="30"
+ use_incoming_packet_handler="true"
+ use_outgoing_packet_handler="false"
+ ip_ttl="${jgroups.udp.ip_ttl:2}"
+ down_thread="false" up_thread="false"/>
+ <PING timeout="2000"
+ down_thread="false" up_thread="false" num_initial_members="3"/>
+ <MERGE2 max_interval="100000"
+ down_thread="false" up_thread="false" min_interval="20000"/>
+ <FD_SOCK down_thread="false" up_thread="false"/>
+ <FD timeout="10000" max_tries="5" down_thread="false" up_thread="false" shun="true"/>
+ <VERIFY_SUSPECT timeout="1500" down_thread="false" up_thread="false"/>
+ <pbcast.NAKACK max_xmit_size="60000"
+ use_mcast_xmit="false" gc_lag="0"
+ retransmit_timeout="300,600,1200,2400,4800"
+ down_thread="false" up_thread="false"
+ discard_delivered_msgs="true"/>
+ <UNICAST timeout="300,600,1200,2400,3600"
+ down_thread="false" up_thread="false"/>
+ <pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
+ down_thread="false" up_thread="false"
+ max_bytes="400000"/>
+ <pbcast.GMS print_local_addr="true" join_timeout="3000"
+ down_thread="false" up_thread="false"
+ join_retry_timeout="2000" shun="true"
+ view_bundling="true"/>
+ <FRAG2 frag_size="60000" down_thread="false" up_thread="false"/>
+ <pbcast.STATE_TRANSFER down_thread="false" up_thread="false" use_flush="false"/>
+ </Config>
+
+ <!-- Alternate TCP stack: customize it for your environment, change bind_addr and initial_hosts -->
+ <!--
+ <Config>
+ <TCP bind_addr="thishost" start_port="7800" loopback="true"
+ tcp_nodelay="true"
+ recv_buf_size="20000000"
+ send_buf_size="640000"
+ discard_incompatible_packets="true"
+ enable_bundling="false"
+ max_bundle_size="64000"
+ max_bundle_timeout="30"
+ use_incoming_packet_handler="true"
+ use_outgoing_packet_handler="false"
+ down_thread="false" up_thread="false"
+ use_send_queues="false"
+ sock_conn_timeout="300"
+ skip_suspected_members="true"/>
+ <TCPPING initial_hosts="thishost[7800],otherhost[7800]" port_range="3"
+ timeout="3000"
+ down_thread="false" up_thread="false"
+ num_initial_members="3"/>
+ <MERGE2 max_interval="100000"
+ down_thread="false" up_thread="false" min_interval="20000"/>
+ <FD_SOCK down_thread="false" up_thread="false"/>
+ <FD timeout="10000" max_tries="5" down_thread="false" up_thread="false" shun="true"/>
+ <VERIFY_SUSPECT timeout="1500" down_thread="false" up_thread="false"/>
+ <pbcast.NAKACK max_xmit_size="60000"
+ use_mcast_xmit="false" gc_lag="0"
+ retransmit_timeout="300,600,1200,2400,4800"
+ down_thread="false" up_thread="false"
+ discard_delivered_msgs="true"/>
+ <pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
+ down_thread="false" up_thread="false"
+ max_bytes="400000"/>
+ <pbcast.GMS print_local_addr="true" join_timeout="3000"
+ down_thread="false" up_thread="false"
+ join_retry_timeout="2000" shun="true"
+ view_bundling="true"/>
+ <pbcast.STATE_TRANSFER down_thread="false" up_thread="false" use_flush="false"/>
+ </Config>
+ -->
+ </attribute>
+
+ </mbean>
+
+</server>
More information about the jboss-cvs-commits
mailing list