org.jboss.ha.jmx
Class AbstractHAServiceMBeanSupport<S extends org.jboss.ha.framework.interfaces.HAService<Notification>>

java.lang.Object
  extended by org.jboss.mx.util.JBossNotificationBroadcasterSupport
      extended by org.jboss.system.ServiceMBeanSupport
          extended by org.jboss.ha.jmx.AbstractHAServiceMBeanSupport<S>
All Implemented Interfaces:
EventListener, MBeanRegistration, NotificationBroadcaster, NotificationEmitter, org.jboss.ha.framework.interfaces.HAService<Notification>, org.jboss.ha.framework.interfaces.HAServiceKeyProvider, org.jboss.ha.framework.server.EventFacility<Notification>, org.jboss.ha.framework.server.EventFactory<Notification>, HAServiceMBean, org.jboss.kernel.spi.dependency.KernelControllerContextAware, Service, ServiceMBean
Direct Known Subclasses:
HAServiceMBeanSupport, HASingletonSupport

public abstract class AbstractHAServiceMBeanSupport<S extends org.jboss.ha.framework.interfaces.HAService<Notification>>
extends ServiceMBeanSupport
implements HAServiceMBean, org.jboss.ha.framework.interfaces.HAService<Notification>, org.jboss.ha.framework.server.EventFactory<Notification>, org.jboss.ha.framework.server.EventFacility<Notification>

Abstract implementation of HAServiceMBean for use by subclasses, e.g. HASingletonSupport.

Author:
Paul Ferraro

Field Summary
 
Fields inherited from class org.jboss.system.ServiceMBeanSupport
log, server, SERVICE_CONTROLLER_SIG, serviceName
 
Fields inherited from interface org.jboss.system.ServiceMBean
CREATE_EVENT, CREATED, DESTROY_EVENT, DESTROYED, FAILED, REGISTERED, START_EVENT, STARTED, STARTING, states, STOP_EVENT, STOPPED, STOPPING, UNREGISTERED
 
Constructor Summary
AbstractHAServiceMBeanSupport()
           
 
Method Summary
protected  void callAsyncMethodOnPartition(String methodName, Object[] args, Class[] types)
           
 List callMethodOnPartition(String methodName, Object[] args, Class[] types)
          Convenience method for broadcasting a call to all members of a partition.
 Notification createEvent(Object source, String type)
           
protected abstract  S createHAService()
          Defines the object used to delegate service methods.
protected  void createService()
           
protected  void destroyService()
           
 Serializable getDistributedState(String key)
          Convenience method for sharing state across a cluster partition.
 org.jboss.ha.framework.interfaces.HAPartition getHAPartition()
           
protected  S getHAService()
           
 String getHAServiceKey()
           
 String getPartitionName()
          Gets the name of the partition used by this service.
 boolean getSendLocalLifecycleNotifications()
          Gets whether JMX Notifications should be sent to local (same JVM) listeners if the notification is for an attribute change to attribute "State".
 boolean getSendRemoteLifecycleNotifications()
          Gets whether JMX Notifications should be sent to remote listeners if the notification is for an attribute change to attribute "State".
 String getServiceHAName()
          Override this method only if you need to provide a custom partition wide unique service name.
 void handleEvent(Notification notification)
           
 boolean isRegisterThreadContextClassLoader()
           
 void notifyListeners(Notification notification)
           
 void sendNotification(Notification notification)
          Broadcast the notification to the remote listener nodes (if any) and then invoke super.sendNotification() to notify local listeners.
protected  void sendNotificationRemote(Notification notification)
          Broadcast a notifcation remotely to the partition participants
protected  void sendNotificationToLocalListeners(Notification notification)
           
 void setClusterPartition(ClusterPartitionMBean clusterPartition)
          Sets the underlying partition used by this service.
 void setDistributedState(String key, Serializable value)
          Convenience method for sharing state across a cluster partition.
 void setHAPartition(org.jboss.ha.framework.interfaces.HAPartition partition)
          Sets the underlying partition used by this service.
 void setRegisterThreadContextClassLoader(boolean register)
           
 void setSendLocalLifecycleNotifications(boolean sendLocalLifecycleNotifications)
          Sets whether JMX Notifications should be sent to local (same JVM) listeners if the notification is for an attribute change to attribute "State".
 void setSendRemoteLifecycleNotifications(boolean sendRemoteLifecycleNotifications)
          Sets whether JMX Notifications should be sent to remote listeners if the notification is for an attribute change to attribute "State".
 void setServiceHAName(String haName)
           
protected  void setupPartition()
           
protected  void startService()
           Implementors of this method should not code the singleton logic here.
protected  void stopService()
           Attention: Always call this method when you overwrite it in a subclass
 
Methods inherited from class org.jboss.system.ServiceMBeanSupport
create, destroy, getDeploymentInfo, getLog, getName, getNextNotificationSequenceNumber, getObjectName, getServer, getServiceName, getState, getStateString, jbossInternalCreate, jbossInternalDescription, jbossInternalDestroy, jbossInternalLifecycle, jbossInternalStart, jbossInternalStop, pojoChange, pojoCreate, pojoDestroy, pojoStart, pojoStop, postDeregister, postRegister, preDeregister, preRegister, setKernelControllerContext, start, stop, unsetKernelControllerContext
 
Methods inherited from class org.jboss.mx.util.JBossNotificationBroadcasterSupport
addNotificationListener, getNotificationInfo, handleNotification, nextNotificationSequenceNumber, removeNotificationListener, removeNotificationListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jboss.system.ServiceMBean
getName, getState, getStateString, jbossInternalLifecycle
 
Methods inherited from interface org.jboss.system.Service
create, destroy, start, stop
 
Methods inherited from interface javax.management.NotificationBroadcaster
addNotificationListener, getNotificationInfo, removeNotificationListener
 
Methods inherited from interface org.jboss.ha.framework.interfaces.HAService
create, destroy, start, stop
 

Constructor Detail

AbstractHAServiceMBeanSupport

public AbstractHAServiceMBeanSupport()
Method Detail

createHAService

protected abstract S createHAService()
Defines the object used to delegate service methods.

Returns:
an HAService delegate

getHAService

protected final S getHAService()
Returns:
the object created by createHAService().

getHAPartition

public org.jboss.ha.framework.interfaces.HAPartition getHAPartition()
Specified by:
getHAPartition in interface org.jboss.ha.framework.interfaces.HAServiceKeyProvider

setHAPartition

public void setHAPartition(org.jboss.ha.framework.interfaces.HAPartition partition)
Description copied from interface: HAServiceMBean
Sets the underlying partition used by this service.

Specified by:
setHAPartition in interface org.jboss.ha.framework.interfaces.HAService<Notification>
Specified by:
setHAPartition in interface HAServiceMBean
Parameters:
partition - the partition

setClusterPartition

public void setClusterPartition(ClusterPartitionMBean clusterPartition)
Description copied from interface: HAServiceMBean
Sets the underlying partition used by this service.

Specified by:
setClusterPartition in interface HAServiceMBean
Parameters:
clusterPartition - the partition

getPartitionName

public String getPartitionName()
Description copied from interface: HAServiceMBean
Gets the name of the partition used by this service. This is a convenience method as the partition name is an attribute of HAPartition.

Specified by:
getPartitionName in interface HAServiceMBean
Returns:
the name of the partition

isRegisterThreadContextClassLoader

public boolean isRegisterThreadContextClassLoader()
Specified by:
isRegisterThreadContextClassLoader in interface org.jboss.ha.framework.interfaces.HAService<Notification>

setRegisterThreadContextClassLoader

public void setRegisterThreadContextClassLoader(boolean register)
Specified by:
setRegisterThreadContextClassLoader in interface org.jboss.ha.framework.interfaces.HAService<Notification>

getHAServiceKey

public String getHAServiceKey()
Specified by:
getHAServiceKey in interface org.jboss.ha.framework.interfaces.HAServiceKeyProvider

setDistributedState

public void setDistributedState(String key,
                                Serializable value)
                         throws Exception
Convenience method for sharing state across a cluster partition. Delegates to the DistributedStateService

Specified by:
setDistributedState in interface HAServiceMBean
Parameters:
key - key for the distributed object
value - the distributed object
Throws:
Exception

getDistributedState

public Serializable getDistributedState(String key)
Convenience method for sharing state across a cluster partition. Delegates to the DistributedStateService

Specified by:
getDistributedState in interface HAServiceMBean
Parameters:
key - key for the distributed object
Returns:
Serializable the distributed object

createService

protected void createService()
                      throws Exception
Overrides:
createService in class ServiceMBeanSupport
Throws:
Exception
See Also:
ServiceMBeanSupport.createService()

startService

protected void startService()
                     throws Exception

Implementors of this method should not code the singleton logic here. The MBean lifecycle create/start/stop are separate from the singleton logic. Singleton logic should originate in becomeMaster().

Attention: Always call this method when you overwrite it in a subclass because it elects the master singleton node.

Overrides:
startService in class ServiceMBeanSupport
Throws:
Exception

stopService

protected void stopService()
                    throws Exception

Attention: Always call this method when you overwrite it in a subclass

Overrides:
stopService in class ServiceMBeanSupport
Throws:
Exception

destroyService

protected void destroyService()
                       throws Exception
Overrides:
destroyService in class ServiceMBeanSupport
Throws:
Exception
See Also:
ServiceMBeanSupport.destroyService()

setupPartition

protected void setupPartition()
                       throws Exception
Throws:
Exception

callMethodOnPartition

public List callMethodOnPartition(String methodName,
                                  Object[] args,
                                  Class[] types)
                           throws Exception
Description copied from interface: HAServiceMBean
Convenience method for broadcasting a call to all members of a partition.

Specified by:
callMethodOnPartition in interface HAServiceMBean
args - array of Java Object representing the set of parameters to be given to the remote method
types - The types of the parameters
Returns:
a list of responses from remote nodes
Throws:
Exception

callAsyncMethodOnPartition

protected void callAsyncMethodOnPartition(String methodName,
                                          Object[] args,
                                          Class[] types)
                                   throws Exception
Throws:
Exception

getSendLocalLifecycleNotifications

public boolean getSendLocalLifecycleNotifications()
Gets whether JMX Notifications should be sent to local (same JVM) listeners if the notification is for an attribute change to attribute "State".

Default is true.

See Also:
sendNotification(Notification)

setSendLocalLifecycleNotifications

public void setSendLocalLifecycleNotifications(boolean sendLocalLifecycleNotifications)
Sets whether JMX Notifications should be sent to local (same JVM) listeners if the notification is for an attribute change to attribute "State".

Default is true.

See Also:
sendNotification(Notification)

getSendRemoteLifecycleNotifications

public boolean getSendRemoteLifecycleNotifications()
Gets whether JMX Notifications should be sent to remote listeners if the notification is for an attribute change to attribute "State".

Default is true.

See http://jira.jboss.com/jira/browse/JBAS-3194 for an example of a use case where this property should be set to false.

See Also:
sendNotification(Notification)

setSendRemoteLifecycleNotifications

public void setSendRemoteLifecycleNotifications(boolean sendRemoteLifecycleNotifications)
Sets whether JMX Notifications should be sent to remote listeners if the notification is for an attribute change to attribute "State".

Default is true.

See http://jira.jboss.com/jira/browse/JBAS-3194 for an example of a use case where this property should be set to false.

See Also:
sendNotification(Notification)

sendNotification

public void sendNotification(Notification notification)
Broadcast the notification to the remote listener nodes (if any) and then invoke super.sendNotification() to notify local listeners.

Specified by:
sendNotification in interface HAServiceMBean
Overrides:
sendNotification in class JBossNotificationBroadcasterSupport
Parameters:
notification - sent out to local listeners and other nodes. It should be serializable. It is recommended that the source of the notification is an ObjectName of an MBean that is is available on all nodes where the broadcaster MBean is registered.
See Also:
getSendLocalLifecycleNotifications(), getSendRemoteLifecycleNotifications(), NotificationBroadcasterSupport.sendNotification(Notification), JBossNotificationBroadcasterSupport.sendNotification(javax.management.Notification)

sendNotificationRemote

protected void sendNotificationRemote(Notification notification)
                               throws Exception
Broadcast a notifcation remotely to the partition participants

Parameters:
notification -
Throws:
Exception

sendNotificationToLocalListeners

protected void sendNotificationToLocalListeners(Notification notification)

notifyListeners

public void notifyListeners(Notification notification)
Specified by:
notifyListeners in interface org.jboss.ha.framework.server.EventFacility<Notification>
See Also:
EventFacility.notifyListeners(java.util.EventObject)

handleEvent

public void handleEvent(Notification notification)
                 throws Exception
Throws:
Exception
See Also:
EventListener.handleEvent(java.util.EventObject)

createEvent

public Notification createEvent(Object source,
                                String type)
Specified by:
createEvent in interface org.jboss.ha.framework.server.EventFactory<Notification>
See Also:
EventFactory.createEvent(java.lang.Object, java.lang.String)

getServiceHAName

public String getServiceHAName()
Override this method only if you need to provide a custom partition wide unique service name. The default implementation will usually work, provided that the getServiceName() method returns a unique canonical MBean name.

Specified by:
getServiceHAName in interface org.jboss.ha.framework.interfaces.HAService<Notification>
Returns:
partition wide unique service name

setServiceHAName

public void setServiceHAName(String haName)
Specified by:
setServiceHAName in interface org.jboss.ha.framework.interfaces.HAService<Notification>


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