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

java.lang.Object
  extended by org.jboss.ha.framework.server.HAServiceImpl<E>
Type Parameters:
E - type of event generated by this service
All Implemented Interfaces:
EventListener, DistributedReplicantManager.ReplicantListener, HAService<E>, HAServiceKeyProvider, EventFacility<E>
Direct Known Subclasses:
HASingletonImpl

public class HAServiceImpl<E extends EventObject>
extends Object
implements HAService<E>, EventFacility<E>, DistributedReplicantManager.ReplicantListener

Base class for clustered services. Provides clustered event facility.

Author:
Paul Ferraro

Nested Class Summary
protected  class HAServiceImpl.RpcHandler
           
 
Field Summary
protected  org.jboss.logging.Logger log
           
 
Constructor Summary
HAServiceImpl(EventFactory<E> eventFactory)
           
HAServiceImpl(EventFactory<E> eventFactory, EventFacility<E> eventFacility)
           
 
Method Summary
 void addEventListener(EventListener<E> listener)
           
protected  void callAsyncMethodOnPartition(String methodName, Object[] args, Class<?>[] types)
           
protected
<T> List<T>
callMethodOnPartition(String methodName, Object[] args, Class<?>[] types)
           
 void create()
           
 void destroy()
           
protected  EventFacility<E> getEventFacility()
           
protected  EventFactory<E> getEventFactory()
           
 HAPartition getHAPartition()
          Get the underlying partition used by this service.
 String getHAServiceKey()
          Get the key used to identify a service within a clustering service.
protected  Serializable getReplicant()
           
protected  HAServiceRpcHandler<E> getRpcHandler()
           
 String getServiceHAName()
           
 void handleEvent(E event)
           
 boolean isRegisterThreadContextClassLoader()
          Test whether the thread context classloader should be used in RPC calls.
 void notifyListeners(E event)
           
protected  void partitionTopologyChanged(List<?> newReplicants, int newReplicantsViewId, boolean merge)
           
protected  void registerDRMListener()
           
protected  void registerRPCHandler()
           
 void removeEventListener(EventListener<E> listener)
           
 void replicantsChanged(String key, List newReplicants, int newReplicantsViewId, boolean merge)
          Callback called when the content/list of replicant for a given replicant key has changed
 void setHAPartition(HAPartition partition)
           
 void setRegisterThreadContextClassLoader(boolean registerClassLoader)
          Sets a flag specifying whether the calling thread's context classloader should be used when making RPC calls.
 void setServiceHAName(String name)
           
 void start()
           
 void stop()
           
protected  void unregisterDRMListener()
           
protected  void unregisterRPCHandler()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final org.jboss.logging.Logger log
Constructor Detail

HAServiceImpl

public HAServiceImpl(EventFactory<E> eventFactory,
                     EventFacility<E> eventFacility)

HAServiceImpl

public HAServiceImpl(EventFactory<E> eventFactory)
Method Detail

addEventListener

public void addEventListener(EventListener<E> listener)

removeEventListener

public void removeEventListener(EventListener<E> listener)

notifyListeners

public void notifyListeners(E event)
Specified by:
notifyListeners in interface EventFacility<E extends EventObject>
See Also:
EventFacility.notifyListeners(java.util.EventObject)

getHAPartition

public HAPartition getHAPartition()
Description copied from interface: HAServiceKeyProvider
Get the underlying partition used by this service.

Specified by:
getHAPartition in interface HAServiceKeyProvider
Returns:
the partition
See Also:
HAServiceKeyProvider.getHAPartition()

setHAPartition

public void setHAPartition(HAPartition partition)
Specified by:
setHAPartition in interface HAService<E extends EventObject>
See Also:
HAService.setHAPartition(org.jboss.ha.framework.interfaces.HAPartition)

isRegisterThreadContextClassLoader

public boolean isRegisterThreadContextClassLoader()
Description copied from interface: HAService
Test whether the thread context classloader should be used in RPC calls.

Specified by:
isRegisterThreadContextClassLoader in interface HAService<E extends EventObject>
Returns:
whether the thread context classloader should be used in RPC calls.
See Also:
HAService.isRegisterThreadContextClassLoader()

setRegisterThreadContextClassLoader

public void setRegisterThreadContextClassLoader(boolean registerClassLoader)
Description copied from interface: HAService
Sets a flag specifying whether the calling thread's context classloader should be used when making RPC calls. This flag must be set before the RPC handler is registered in startService(). The default value is false. This would typically be used in conjunction with a scoped classloader.

Specified by:
setRegisterThreadContextClassLoader in interface HAService<E extends EventObject>
Parameters:
registerClassLoader - whether to use the thread context classloader when registering the service's RPC handler.
See Also:
HAService.setRegisterThreadContextClassLoader(boolean)

getServiceHAName

public String getServiceHAName()
Specified by:
getServiceHAName in interface HAService<E extends EventObject>

setServiceHAName

public void setServiceHAName(String name)
Specified by:
setServiceHAName in interface HAService<E extends EventObject>
See Also:
HAService.setServiceHAName(java.lang.String)

handleEvent

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

getRpcHandler

protected HAServiceRpcHandler<E> getRpcHandler()

getEventFactory

protected EventFactory<E> getEventFactory()

getEventFacility

protected EventFacility<E> getEventFacility()

create

public void create()
            throws Exception
Specified by:
create in interface HAService<E extends EventObject>
Throws:
Exception
See Also:
HAService.create()

start

public void start()
           throws Exception
Specified by:
start in interface HAService<E extends EventObject>
Throws:
Exception
See Also:
HAService.start()

stop

public void stop()
Specified by:
stop in interface HAService<E extends EventObject>
See Also:
HAService.stop()

destroy

public void destroy()
Specified by:
destroy in interface HAService<E extends EventObject>
See Also:
HAService.destroy()

callMethodOnPartition

protected <T> List<T> callMethodOnPartition(String methodName,
                                            Object[] args,
                                            Class<?>[] types)
                                 throws Exception
Throws:
Exception

callAsyncMethodOnPartition

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

registerRPCHandler

protected void registerRPCHandler()

unregisterRPCHandler

protected void unregisterRPCHandler()

registerDRMListener

protected void registerDRMListener()
                            throws Exception
Throws:
Exception

unregisterDRMListener

protected void unregisterDRMListener()
                              throws Exception
Throws:
Exception

getHAServiceKey

public String getHAServiceKey()
Get the key used to identify a service within a clustering service.

Specified by:
getHAServiceKey in interface HAServiceKeyProvider
Returns:
the key used by the DRM and partition rpc handler mapping.

getReplicant

protected Serializable getReplicant()
Returns:
the object to be registered with the DistributedReplicantManager.

replicantsChanged

public void replicantsChanged(String key,
                              List newReplicants,
                              int newReplicantsViewId,
                              boolean merge)
Description copied from interface: DistributedReplicantManager.ReplicantListener
Callback called when the content/list of replicant for a given replicant key has changed

Specified by:
replicantsChanged in interface DistributedReplicantManager.ReplicantListener
Parameters:
key - The name of the key of the replicant that has changed
newReplicants - The list of new replicants for the give replicant key. This list will be in a consistent order on all cluster nodes on which the current viewId is in effect
newReplicantsViewId - The new replicant view id corresponding to this change
merge - Is the change due to a merge (i.e. the healing of a cluster split)?
See Also:
DistributedReplicantManager.ReplicantListener.replicantsChanged(java.lang.String, java.util.List, int, boolean)

partitionTopologyChanged

protected void partitionTopologyChanged(List<?> newReplicants,
                                        int newReplicantsViewId,
                                        boolean merge)


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