org.jboss.cache.buddyreplication
Class BuddyManager

java.lang.Object
  extended by org.jboss.cache.buddyreplication.BuddyManager

public class BuddyManager
extends java.lang.Object

Class that manages buddy replication groups.

Author:
Manik Surtani (manik@jboss.org)

Nested Class Summary
 class BuddyManager.ViewChangeListener
           
 
Field Summary
static java.lang.String BUDDY_BACKUP_SUBTREE
          Constants representng the buddy backup subtree
static Fqn BUDDY_BACKUP_SUBTREE_FQN
           
 
Constructor Summary
BuddyManager(BuddyReplicationConfig config)
           
 
Method Summary
protected  BuddyLocator createBuddyLocator(BuddyReplicationConfig.BuddyLocatorConfig config)
           
protected  BuddyLocator createDefaultBuddyLocator()
           
 byte[] generateState(Fqn fqn, long timeout, boolean force, boolean suppressErrors)
          Returns the state for the portion of the cache named by fqn.
static Fqn getActualFqn(Fqn fqn)
           
static Fqn getBackupFqn(org.jgroups.Address dataOwnerAddress, Fqn origFqn)
          Utility method that retrieves a buddy backup Fqn given the actual Fqn of some data and the data owner's Address.
 Fqn getBackupFqn(Fqn originalFqn)
          Assumes the backup Fqn if the current instance is the data owner
static Fqn getBackupFqn(Fqn buddyGroupRoot, Fqn origFqn)
          Utility method that retrieves a buddy backup Fqn given the actual Fqn of some data and the backup subtree for the buddy group in question
static Fqn getBackupFqn(java.lang.String buddyGroupName, Fqn origFqn)
          Utility method that retrieves a buddy backup Fqn given the actual Fqn of some data and the buddy group name.
 java.util.List<org.jgroups.Address> getBuddyAddresses()
          Returns a list of buddies for which this instance is Data Owner.
 int getBuddyCommunicationTimeout()
           
 java.lang.String getBuddyPoolName()
           
 BuddyReplicationConfig getConfig()
           
static java.lang.String getGroupNameFromAddress(java.lang.Object address)
           
 void handleAssignToBuddyGroup(BuddyGroup newGroup, java.util.Map<Fqn,byte[]> state)
          Called by CacheImpl._remoteAssignToBuddyGroup(BuddyGroup g) when a method call for this is received from a remote cache.
 void handlePoolNameBroadcast(org.jgroups.Address address, java.lang.String poolName)
          Called by CacheImpl._remoteAnnounceBuddyPoolName(Address address, String buddyPoolName) when a view change occurs and caches need to inform the cluster of which buddy pool it is in.
 void handleRemoveFromBuddyGroup(java.lang.String groupName)
          Called by CacheImpl._remoteRemoveFromBuddyGroup(String groupName) when a method call for this is received from a remote cache.
 void init(CacheImpl cache)
           
 boolean isAutoDataGravitation()
           
static boolean isBackupFqn(Fqn name)
           
 boolean isDataGravitationRemoveOnFind()
           
 boolean isDataGravitationSearchBackupTrees()
           
 boolean isEnabled()
           
 void stop()
          Stops the buddy manager and the related async thread.
 MethodCall transformFqns(MethodCall call)
          Introspects method call for Fqns and changes them such that they are under the current buddy group's backup subtree (e.g., /_buddy_backup_/my_host:7890/) rather than the root (/).
 MethodCall transformFqns(MethodCall call, boolean transformForCurrentCall)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUDDY_BACKUP_SUBTREE

public static final java.lang.String BUDDY_BACKUP_SUBTREE
Constants representng the buddy backup subtree

See Also:
Constant Field Values

BUDDY_BACKUP_SUBTREE_FQN

public static final Fqn BUDDY_BACKUP_SUBTREE_FQN
Constructor Detail

BuddyManager

public BuddyManager(BuddyReplicationConfig config)
Method Detail

getConfig

public BuddyReplicationConfig getConfig()

createBuddyLocator

protected BuddyLocator createBuddyLocator(BuddyReplicationConfig.BuddyLocatorConfig config)
                                   throws java.lang.ClassNotFoundException,
                                          java.lang.IllegalAccessException,
                                          java.lang.InstantiationException
Throws:
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.InstantiationException

createDefaultBuddyLocator

protected BuddyLocator createDefaultBuddyLocator()

isEnabled

public boolean isEnabled()

getBuddyPoolName

public java.lang.String getBuddyPoolName()

getGroupNameFromAddress

public static java.lang.String getGroupNameFromAddress(java.lang.Object address)

stop

public void stop()
Stops the buddy manager and the related async thread.


init

public void init(CacheImpl cache)
          throws CacheException
Throws:
CacheException

isAutoDataGravitation

public boolean isAutoDataGravitation()

isDataGravitationRemoveOnFind

public boolean isDataGravitationRemoveOnFind()

isDataGravitationSearchBackupTrees

public boolean isDataGravitationSearchBackupTrees()

getBuddyCommunicationTimeout

public int getBuddyCommunicationTimeout()

handlePoolNameBroadcast

public void handlePoolNameBroadcast(org.jgroups.Address address,
                                    java.lang.String poolName)
Called by CacheImpl._remoteAnnounceBuddyPoolName(Address address, String buddyPoolName) when a view change occurs and caches need to inform the cluster of which buddy pool it is in.


handleRemoveFromBuddyGroup

public void handleRemoveFromBuddyGroup(java.lang.String groupName)
                                throws BuddyNotInitException
Called by CacheImpl._remoteRemoveFromBuddyGroup(String groupName) when a method call for this is received from a remote cache.

Throws:
BuddyNotInitException

handleAssignToBuddyGroup

public void handleAssignToBuddyGroup(BuddyGroup newGroup,
                                     java.util.Map<Fqn,byte[]> state)
                              throws java.lang.Exception
Called by CacheImpl._remoteAssignToBuddyGroup(BuddyGroup g) when a method call for this is received from a remote cache.

Parameters:
newGroup - the buddy group
state - Map of any state from the DataOwner. Cannot be null.
Throws:
java.lang.Exception

getBackupFqn

public static Fqn getBackupFqn(org.jgroups.Address dataOwnerAddress,
                               Fqn origFqn)
Utility method that retrieves a buddy backup Fqn given the actual Fqn of some data and the data owner's Address.

Parameters:
dataOwnerAddress - the JGroups Address of the data owner
origFqn - the original Fqn
Returns:
a backup Fqn

getBackupFqn

public static Fqn getBackupFqn(java.lang.String buddyGroupName,
                               Fqn origFqn)
Utility method that retrieves a buddy backup Fqn given the actual Fqn of some data and the buddy group name.

Parameters:
buddyGroupName - the buddy group name
origFqn - the original Fqn
Returns:
a backup Fqn

getBackupFqn

public static Fqn getBackupFqn(Fqn buddyGroupRoot,
                               Fqn origFqn)
Utility method that retrieves a buddy backup Fqn given the actual Fqn of some data and the backup subtree for the buddy group in question

Parameters:
buddyGroupRoot - the subtree under which data for a particular buddy is backed up
origFqn - the original Fqn
Returns:
a backup Fqn

isBackupFqn

public static boolean isBackupFqn(Fqn name)

getBuddyAddresses

public java.util.List<org.jgroups.Address> getBuddyAddresses()
Returns a list of buddies for which this instance is Data Owner. List excludes self. Used by the BaseRPCInterceptor when deciding who to replicate to.


transformFqns

public MethodCall transformFqns(MethodCall call)
Introspects method call for Fqns and changes them such that they are under the current buddy group's backup subtree (e.g., /_buddy_backup_/my_host:7890/) rather than the root (/). Called by BaseRPCInterceptor to transform method calls before broadcasting.


transformFqns

public MethodCall transformFqns(MethodCall call,
                                boolean transformForCurrentCall)

generateState

public byte[] generateState(Fqn fqn,
                            long timeout,
                            boolean force,
                            boolean suppressErrors)
                     throws java.lang.Throwable
Returns the state for the portion of the cache named by fqn.

State returned is a serialized byte[][], element 0 is the transient state (or null), and element 1 is the persistent state (or null).

Parameters:
fqn - Fqn indicating the uppermost node in the portion of the cache whose state should be returned.
timeout - max number of ms this method should wait to acquire a read lock on the nodes being transferred
force - if a read lock cannot be acquired after timeout ms, should the lock acquisition be forced, and any existing transactions holding locks on the nodes be rolled back? NOTE: In release 1.2.4, this parameter has no effect.
suppressErrors - should any Throwable thrown be suppressed?
Returns:
a serialized byte[][], element 0 is the transient state (or null), and element 1 is the persistent state (or null).
Throws:
java.lang.Throwable

getBackupFqn

public Fqn getBackupFqn(Fqn originalFqn)
Assumes the backup Fqn if the current instance is the data owner

Parameters:
originalFqn -
Returns:
backup fqn

getActualFqn

public static Fqn getActualFqn(Fqn fqn)