[jboss-cvs] JBossCache/src/org/jboss/cache/buddyreplication ...
Manik Surtani
msurtani at jboss.com
Fri Nov 10 15:32:52 EST 2006
User: msurtani
Date: 06/11/10 15:32:52
Modified: src/org/jboss/cache/buddyreplication BuddyManager.java
Added: src/org/jboss/cache/buddyreplication
BuddyNotInitException.java
Log:
Fixed BR deadlock issue on startup
Revision Changes Path
1.48 +80 -24 JBossCache/src/org/jboss/cache/buddyreplication/BuddyManager.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: BuddyManager.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/buddyreplication/BuddyManager.java,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -b -r1.47 -r1.48
--- BuddyManager.java 6 Nov 2006 23:34:08 -0000 1.47
+++ BuddyManager.java 10 Nov 2006 20:32:52 -0000 1.48
@@ -97,6 +97,15 @@
public static final Fqn BUDDY_BACKUP_SUBTREE_FQN = Fqn.fromString(BUDDY_BACKUP_SUBTREE);
/**
+ * number of times to retry communicating with a selected buddy if the buddy has not been initialised.
+ */
+ private static int UNINIT_BUDDIES_RETRIES = 3;
+ /**
+ * wait time between retries
+ */
+ private static final long UNINIT_BUDDIES_RETRY_NAPTIME = 500;
+
+ /**
* Flag to prevent us receiving and processing remote calls before we've started
*/
private boolean initialised = false;
@@ -324,9 +333,10 @@
* Called by TreeCache._remoteRemoveFromBuddyGroup(String groupName)
* when a method call for this is received from a remote cache.
*/
- public void handleRemoveFromBuddyGroup(String groupName)
+ public void handleRemoveFromBuddyGroup(String groupName) throws BuddyNotInitException
{
- waitForInit();
+ if (!initialised) throw new BuddyNotInitException("Not yet initialised");
+
if (log.isInfoEnabled()) log.info("Removing self from buddy group " + groupName);
buddyGroupsIParticipateIn.remove(groupName);
@@ -352,7 +362,8 @@
*/
public void handleAssignToBuddyGroup(BuddyGroup newGroup, Map state) throws Exception
{
- waitForInit();
+ if (!initialised) throw new BuddyNotInitException("Not yet initialised");
+
if (log.isInfoEnabled()) log.info("Assigning self to buddy group " + newGroup);
buddyGroupsIParticipateIn.put(newGroup.getGroupName(), newGroup);
@@ -452,7 +463,7 @@
// -------------- internal helpers methods --------------------
- private void removeFromGroup(List buddies)
+ private void removeFromGroup(List buddies) throws InterruptedException
{
if (log.isDebugEnabled())
log.debug("Removing obsolete buddies from buddy group [" + buddyGroup.getGroupName() + "]. Obsolete buddies are " + buddies);
@@ -461,13 +472,34 @@
MethodCall membershipCall = MethodCallFactory.create(MethodDeclarations.remoteRemoveFromBuddyGroupMethod, buddyGroup.getGroupName());
MethodCall replicateCall = MethodCallFactory.create(MethodDeclarations.replicateMethod, membershipCall);
+ int attemptsLeft = UNINIT_BUDDIES_RETRIES;
+
+ while (attemptsLeft-- > 0)
+ {
try
{
makeRemoteCall(buddies, replicateCall);
+ break;
}
catch (Exception e)
{
- log.error("Problems broadcasting removeFromGroup to specific buddies", e);
+ if (e instanceof BuddyNotInitException || e.getCause() instanceof BuddyNotInitException)
+ {
+ if (attemptsLeft > 0)
+ {
+ log.info("One of the buddies have not been initialised. Will retry after a short nap.");
+ Thread.sleep(UNINIT_BUDDIES_RETRY_NAPTIME);
+ }
+ else
+ {
+ throw new BuddyNotInitException("Unable to contact buddy after " + UNINIT_BUDDIES_RETRIES + " retries");
+ }
+ }
+ else
+ {
+ log.error("Unable to communicate with Buddy for some reason", e);
+ }
+ }
}
log.trace("removeFromGroup notification complete");
}
@@ -528,14 +560,36 @@
MethodCall membershipCall = MethodCallFactory.create(MethodDeclarations.remoteAssignToBuddyGroupMethod, buddyGroup, stateMap);
MethodCall replicateCall = MethodCallFactory.create(MethodDeclarations.replicateMethod, membershipCall);
+ int attemptsLeft = UNINIT_BUDDIES_RETRIES;
+
+ while (attemptsLeft-- > 0)
+ {
try
{
makeRemoteCall(buddies, replicateCall);
+ break;
}
catch (Exception e)
{
- log.error("Problems broadcasting assignToGroup to specific buddies", e);
+ if (e instanceof BuddyNotInitException || e.getCause() instanceof BuddyNotInitException)
+ {
+ if (attemptsLeft > 0)
+ {
+ log.info("One of the buddies have not been initialised. Will retry after a short nap.");
+ Thread.sleep(UNINIT_BUDDIES_RETRY_NAPTIME);
}
+ else
+ {
+ throw new BuddyNotInitException("Unable to contact buddy after " + UNINIT_BUDDIES_RETRIES + " retries");
+ }
+ }
+ else
+ {
+ log.error("Unable to communicate with Buddy for some reason", e);
+ }
+ }
+ }
+
log.trace("addToGroup notification complete");
}
@@ -740,6 +794,8 @@
public void run()
{
+ // don't start this thread until the Buddy Manager has initialised as it cocks things up.
+ waitForInit();
while (!Thread.interrupted())
{
try
1.2 +27 -0 JBossCache/src/org/jboss/cache/buddyreplication/BuddyNotInitException.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: BuddyNotInitException.java
===================================================================
RCS file: BuddyNotInitException.java
diff -N BuddyNotInitException.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ BuddyNotInitException.java 10 Nov 2006 20:32:52 -0000 1.2
@@ -0,0 +1,27 @@
+package org.jboss.cache.buddyreplication;
+
+import org.jboss.cache.CacheException;
+
+/**
+ * Exception to depict that a buddy has not been initialised to participate in any comms
+ *
+ * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
+ * @since 1.4.1
+ */
+public class BuddyNotInitException extends CacheException
+{
+
+ public BuddyNotInitException()
+ {
+ }
+
+ public BuddyNotInitException(String msg)
+ {
+ super(msg);
+ }
+
+ public BuddyNotInitException(String msg, Throwable cause)
+ {
+ super(msg, cause);
+ }
+}
More information about the jboss-cvs-commits
mailing list