[jboss-cvs] JBossAS SVN: r76050 - trunk/cluster/src/main/org/jboss/ha/singleton.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Jul 21 01:46:13 EDT 2008
Author: bstansberry at jboss.com
Date: 2008-07-21 01:46:13 -0400 (Mon, 21 Jul 2008)
New Revision: 76050
Added:
trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonElector.java
Modified:
trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicySimple.java
trunk/cluster/src/main/org/jboss/ha/singleton/PreferredMasterElectionPolicy.java
Log:
[JBAS-5782] HASingletonElector interface
Modified: trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicySimple.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicySimple.java 2008-07-21 05:11:42 UTC (rev 76049)
+++ trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicySimple.java 2008-07-21 05:46:13 UTC (rev 76050)
@@ -47,7 +47,7 @@
* <attribute name="Position">2</attribute>
*
* If no election policy is defined, the oldest node in the cluster runs the
- * singleton. This behaivour can be achieved with this policy when "position"
+ * singleton. This behavior can be achieved with this policy when "position"
* is set to 0.
*
* @author <a href="mailto:Alex.Fu at novell.com">Alex Fu</a>
@@ -56,11 +56,13 @@
*/
public class HASingletonElectionPolicySimple
extends HASingletonElectionPolicyBase
- implements HASingletonElectionPolicySimpleMBean
+ implements HASingletonElectionPolicySimpleMBean, HASingletonElector
{
// Attributes
private int mPosition = 0; // Default
+ // ------------------------------------------------------------- Properties
+
/**
* @see HASingletonElectionPolicySimpleMBean#setPosition(int)
*/
@@ -77,11 +79,14 @@
return this.mPosition;
}
- protected ClusterNode elect(List<ClusterNode> candidates)
+ // ----------------------------------------------------- HASingletonElector
+
+ public ClusterNode elect(List<ClusterNode> candidates)
{
int size = candidates.size();
int remainder = ((this.mPosition % size) + size) % size;
return candidates.get(remainder);
}
+
}
Added: trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonElector.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonElector.java (rev 0)
+++ trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonElector.java 2008-07-21 05:46:13 UTC (rev 76050)
@@ -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.ha.singleton;
+
+import java.util.List;
+
+import org.jboss.ha.framework.interfaces.ClusterNode;
+
+/**
+ * Serves as an elector in an HASingleton master election by choosing a master
+ * node from a list of candidates.
+ * <p>
+ * Differs from {@link HASingletonElectionPolicy} in that an election policy
+ * is also responsible for identifying the list of candidates. An election
+ * policy implementation could potentially prepare the list of candidates and
+ * then delegate the actual election to an injected
+ * <code>HASingletonElector</code>.
+ * </p>
+ * @author Brian Stansberry
+ */
+public interface HASingletonElector
+{
+ ClusterNode elect(List<ClusterNode> candidates);
+}
Modified: trunk/cluster/src/main/org/jboss/ha/singleton/PreferredMasterElectionPolicy.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/singleton/PreferredMasterElectionPolicy.java 2008-07-21 05:11:42 UTC (rev 76049)
+++ trunk/cluster/src/main/org/jboss/ha/singleton/PreferredMasterElectionPolicy.java 2008-07-21 05:46:13 UTC (rev 76050)
@@ -43,6 +43,8 @@
{
private String preferredMaster;
+ // ------------------------------------------------------------- Properties
+
/**
* @see PreferredMasterElectionPolicyMBean#setPreferredMaster(String)
*/
@@ -59,8 +61,10 @@
return preferredMaster;
}
+ // ----------------------------------------------------- HASingletonElector
+
@Override
- protected ClusterNode elect(List<ClusterNode> candidates)
+ public ClusterNode elect(List<ClusterNode> candidates)
{
// If preferred master is defined and contained in cluster, return it
if (preferredMaster != null)
@@ -107,6 +111,8 @@
return super.elect(candidates);
}
+ // --------------------------------------------------------------- Protected
+
/**
* Create a URI instance from the given preferred master.
*
More information about the jboss-cvs-commits
mailing list