KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ha > singleton > HASingletonElectionPolicyBase


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.ha.singleton;
23
24
25 import org.jboss.ha.framework.interfaces.HAPartition;
26 import org.jboss.ha.framework.server.ClusterPartition;
27 import org.jboss.logging.Logger;
28 import org.jboss.system.ServiceMBeanSupport;
29
30 /**
31  * A base class for policy service that decides which node in the cluster should be
32  * the master node to run certain HASingleton service.
33  *
34  * @author <a HREF="mailto:afu@novell.com">Alex Fu</a>
35  * @version $Revision: 46010 $
36  */

37 public abstract class HASingletonElectionPolicyBase
38    extends ServiceMBeanSupport
39    implements HASingletonElectionPolicyMBean
40 {
41    private Object JavaDoc mManagedSingleton;
42    private HAPartition mPartition;
43    
44    /**
45     * @see HASingletonElectionPolicyMBean#setManagedSingleton(Object)
46     */

47    public void setManagedSingleton(Object JavaDoc singleton)
48    {
49       this.mManagedSingleton = singleton;
50    }
51
52    /**
53     * @see HASingletonElectionPolicyMBean#getManagedSingleton()
54     */

55    public Object JavaDoc getManagedSingleton()
56    {
57       return this.mManagedSingleton;
58    }
59
60    /**
61     * @see HASingletonElectionPolicyMBean#setHAPartition(HAPartition)
62     */

63    public void setHAPartition(HAPartition partition)
64    {
65       this.mPartition = partition;
66    }
67
68    /**
69     * @see HASingletonElectionPolicyMBean#getHAPartition()
70     */

71    public HAPartition getHAPartition()
72    {
73       return this.mPartition;
74    }
75    
76    /**
77     * @see HASingletonElectionPolicyMBean#isElectedMaster()
78     */

79    public boolean isElectedMaster()
80    {
81       if (null == this.mPartition)
82          throw new IllegalStateException JavaDoc("HAPartition is not set");
83       
84       return pickSingleton().equals(this.mPartition.getClusterNode());
85    }
86     
87    /**
88     * @see HASingletonElectionPolicyMBean#isElectedMaster(HAPartition)
89     */

90    public boolean isElectedMaster(HAPartition partition)
91    {
92       if (null == partition)
93          throw new IllegalStateException JavaDoc("parameter cannot be null");
94
95       return pickSingleton(partition).equals(partition.getClusterNode());
96    }
97 }
98
Popular Tags