org.jboss.ha.framework.server
Class HASingletonImpl<E extends EventObject>

java.lang.Object
  extended by org.jboss.ha.framework.server.HAServiceImpl<E>
      extended by org.jboss.ha.framework.server.HASingletonImpl<E>
All Implemented Interfaces:
EventListener, DistributedReplicantManager.ReplicantListener, HAService<E>, HAServiceKeyProvider, HASingleton<E>, HASingletonLifecycle, HASingletonMBean, EventFacility<E>, HAServiceRpcHandler<E>, HASingletonRpcHandler<E>

public class HASingletonImpl<E extends EventObject>
extends HAServiceImpl<E>
implements HASingleton<E>, HASingletonRpcHandler<E>

Base class for HA-singleton based services.

Author:
Paul Ferraro

Nested Class Summary
protected  class HASingletonImpl.RpcHandler
           
 
Field Summary
 
Fields inherited from class org.jboss.ha.framework.server.HAServiceImpl
log
 
Fields inherited from interface org.jboss.ha.framework.interfaces.HASingleton
HASINGLETON_STARTED_NOTIFICATION, HASINGLETON_STARTING_NOTIFICATION, HASINGLETON_STOPPED_NOTIFICATION, HASINGLETON_STOPPING_NOTIFICATION
 
Constructor Summary
HASingletonImpl(EventFactory<E> eventFactory)
           
HASingletonImpl(EventFactory<E> eventFactory, EventFacility<E> eventHandler, HASingletonLifecycle singletonLifecycle)
           
 
Method Summary
protected  List<ClusterNode> getElectionCandidates()
           
 HASingletonElectionPolicy getElectionPolicy()
          Gets the policy used to determine which cluster node will become the master when the service topology changes.
 boolean getRestartOnMerge()
          Gets whether this singleton will stop and restart itself if it is the master and a cluster merge occurs.
protected  HAServiceRpcHandler<E> getRpcHandler()
           
protected  boolean isDRMMasterReplica()
           
 boolean isMasterNode()
          True if this cluster node has the active mbean singleton, false otherwise
protected  void makeThisNodeMaster()
           
protected  void partitionTopologyChanged(List<?> newReplicants, int newViewId, boolean merge)
          When topology changes, a new master is elected based on the result of the isDRMMasterReplica() call.
protected  void registerDRMListener()
           
protected  void restartMaster()
           
 void setElectionPolicy(HASingletonElectionPolicy electionPolicy)
          Sets the policy used to determine which cluster node will become the master when the service topology changes.
 void setRestartOnMerge(boolean restart)
          Sets whether this singleton will stop and restart itself if it is the master and a cluster merge occurs.
protected  void startNewMaster()
           
 void startSingleton()
          Invoked when this mbean is elected to run the singleton service, or in other words when this node is elected for master.
protected  void stopIfMaster()
           
 void stopOldMaster()
           
 void stopSingleton()
          Invoked when this mbean is elected to no longer run the singleton service, or in other words when this node is elected for slave.
 
Methods inherited from class org.jboss.ha.framework.server.HAServiceImpl
addEventListener, callAsyncMethodOnPartition, callMethodOnPartition, create, destroy, getEventFacility, getEventFactory, getHAPartition, getHAServiceKey, getReplicant, getServiceHAName, handleEvent, isRegisterThreadContextClassLoader, notifyListeners, registerRPCHandler, removeEventListener, replicantsChanged, setHAPartition, setRegisterThreadContextClassLoader, setServiceHAName, start, stop, unregisterDRMListener, unregisterRPCHandler
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jboss.ha.framework.interfaces.HAService
create, destroy, getServiceHAName, isRegisterThreadContextClassLoader, setHAPartition, setRegisterThreadContextClassLoader, setServiceHAName, start, stop
 
Methods inherited from interface org.jboss.ha.framework.interfaces.HAServiceKeyProvider
getHAPartition, getHAServiceKey
 
Methods inherited from interface org.jboss.ha.framework.interfaces.EventListener
handleEvent
 

Constructor Detail

HASingletonImpl

public HASingletonImpl(EventFactory<E> eventFactory,
                       EventFacility<E> eventHandler,
                       HASingletonLifecycle singletonLifecycle)

HASingletonImpl

public HASingletonImpl(EventFactory<E> eventFactory)
Method Detail

getElectionPolicy

public HASingletonElectionPolicy getElectionPolicy()
Description copied from interface: HASingleton
Gets the policy used to determine which cluster node will become the master when the service topology changes.

Specified by:
getElectionPolicy in interface HASingleton<E extends EventObject>
Returns:
the policy. Can be null.

setElectionPolicy

public void setElectionPolicy(HASingletonElectionPolicy electionPolicy)
Description copied from interface: HASingleton
Sets the policy used to determine which cluster node will become the master when the service topology changes. Injection of common attributes into the election policy should be done during createService() method call.

Specified by:
setElectionPolicy in interface HASingleton<E extends EventObject>
Parameters:
electionPolicy - the policy. Can be null.

getRestartOnMerge

public boolean getRestartOnMerge()
Description copied from interface: HASingleton
Gets whether this singleton will stop and restart itself if it is the master and a cluster merge occurs.

A restart allows the service to reset any state that may have gotten out-of-sync with the rest of the cluster while the just-merged split was in effect.

Specified by:
getRestartOnMerge in interface HASingleton<E extends EventObject>
Returns:
true if a restart will occur, false otherwise

setRestartOnMerge

public void setRestartOnMerge(boolean restart)
Description copied from interface: HASingleton
Sets whether this singleton will stop and restart itself if it is the master and a cluster merge occurs.

A restart allows the service to reset any state that may have gotten out-of-sync with the rest of the cluster while the just-merged split was in effect.

Specified by:
setRestartOnMerge in interface HASingleton<E extends EventObject>
Parameters:
restart - true if a restart should occur, false otherwise. Default is true.

isMasterNode

public boolean isMasterNode()
Description copied from interface: HASingletonMBean
True if this cluster node has the active mbean singleton, false otherwise

Specified by:
isMasterNode in interface HASingletonMBean

registerDRMListener

protected void registerDRMListener()
                            throws Exception
Overrides:
registerDRMListener in class HAServiceImpl<E extends EventObject>
Throws:
Exception
See Also:
HAServiceImpl.registerDRMListener()

startSingleton

public void startSingleton()
Description copied from interface: HASingletonLifecycle
Invoked when this mbean is elected to run the singleton service, or in other words when this node is elected for master.

Specified by:
startSingleton in interface HASingletonLifecycle
See Also:
HASingletonLifecycle.startSingleton()

stopSingleton

public void stopSingleton()
Description copied from interface: HASingletonLifecycle
Invoked when this mbean is elected to no longer run the singleton service, or in other words when this node is elected for slave.

Specified by:
stopSingleton in interface HASingletonLifecycle
See Also:
HASingletonLifecycle.stopSingleton()

partitionTopologyChanged

protected void partitionTopologyChanged(List<?> newReplicants,
                                        int newViewId,
                                        boolean merge)
When topology changes, a new master is elected based on the result of the isDRMMasterReplica() call.

Overrides:
partitionTopologyChanged in class HAServiceImpl<E extends EventObject>
See Also:
HAServiceImpl.partitionTopologyChanged(java.util.List, int, boolean), DistributedReplicantManager.isMasterReplica(String)

getElectionCandidates

protected List<ClusterNode> getElectionCandidates()

stopOldMaster

public void stopOldMaster()
                   throws Exception
Specified by:
stopOldMaster in interface HASingletonRpcHandler<E extends EventObject>
Throws:
Exception
See Also:
org.jboss.ha.singleton.HASingleton.RpcHandler#stopOldMaster()

isDRMMasterReplica

protected boolean isDRMMasterReplica()

makeThisNodeMaster

protected void makeThisNodeMaster()

startNewMaster

protected void startNewMaster()

restartMaster

protected void restartMaster()

stopIfMaster

protected void stopIfMaster()

getRpcHandler

protected HAServiceRpcHandler<E> getRpcHandler()
Overrides:
getRpcHandler in class HAServiceImpl<E extends EventObject>


Copyright © 2009 JBoss, a division of Red Hat, Inc.. All Rights Reserved.