[jboss-cvs] JBossCache/src/org/jboss/cache/buddyreplication ...
Manik Surtani
manik at jboss.org
Mon Mar 12 17:36:01 EDT 2007
User: msurtani
Date: 07/03/12 17:36:01
Modified: src/org/jboss/cache/buddyreplication BuddyManager.java
Log:
refactorings
Revision Changes Path
1.66 +32 -30 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.65
retrieving revision 1.66
diff -u -b -r1.65 -r1.66
--- BuddyManager.java 12 Mar 2007 18:13:48 -0000 1.65
+++ BuddyManager.java 12 Mar 2007 21:36:00 -0000 1.66
@@ -39,8 +39,9 @@
import java.util.Set;
import java.util.Vector;
import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
/**
@@ -75,7 +76,7 @@
/**
* Map of buddy pools received from broadcasts
*/
- Map<Address, String> buddyPool = new ConcurrentHashMap<Address, String>();
+ final Map<Address, String> buddyPool = new HashMap<Address, String>();
/**
* The nullBuddyPool is a set of addresses that have not specified buddy pools.
@@ -87,7 +88,7 @@
* Keyed on String group name, values are BuddyGroup objects.
* Needs to deal with concurrent access - concurrent assignTo/removeFrom buddy grp
*/
- Map<String, BuddyGroup> buddyGroupsIParticipateIn = new ConcurrentHashMap<String, BuddyGroup>();
+ Map<String, BuddyGroup> buddyGroupsIParticipateIn = new HashMap<String, BuddyGroup>();
/**
* Queue to deal with queued up view change requests - which are handled asynchronously
@@ -121,11 +122,7 @@
private final Object poolInfoNotifierLock = new Object();
- /**
- * Flag to prevent us receiving and processing remote calls before we've started
- */
- private boolean initialised = false;
- // private Latch initLatch = new Latch();
+ private CountDownLatch initialisationLatch = new CountDownLatch(0);
public BuddyManager(BuddyReplicationConfig config)
{
@@ -202,7 +199,7 @@
broadcastBuddyPoolMembership();
// allow waiting threads to process.
- initialised = true;
+ initialisationLatch.countDown();
// register a CacheImpl Listener to reassign buddies as and when view changes occur
cache.getNotifier().addCacheListener(new AbstractCacheListener()
@@ -374,7 +371,15 @@
*/
public void handleRemoveFromBuddyGroup(String groupName) throws BuddyNotInitException
{
- if (!initialised) throw new BuddyNotInitException("Not yet initialised");
+ try
+ {
+ if (!initialisationLatch.await(0, TimeUnit.NANOSECONDS))
+ throw new BuddyNotInitException("Not yet initialised");
+ }
+ catch (InterruptedException e)
+ {
+ log.debug("Caught InterruptedException", e);
+ }
if (log.isInfoEnabled()) log.info("Removing self from buddy group " + groupName);
buddyGroupsIParticipateIn.remove(groupName);
@@ -401,7 +406,15 @@
*/
public void handleAssignToBuddyGroup(BuddyGroup newGroup, Map<Fqn, byte[]> state) throws Exception
{
- if (!initialised) throw new BuddyNotInitException("Not yet initialised");
+ try
+ {
+ if (!initialisationLatch.await(0, TimeUnit.NANOSECONDS))
+ throw new BuddyNotInitException("Not yet initialised");
+ }
+ catch (InterruptedException e)
+ {
+ log.debug("Caught InterruptedException", e);
+ }
if (log.isInfoEnabled()) log.info("Assigning self to buddy group " + newGroup);
buddyGroupsIParticipateIn.put(newGroup.getGroupName(), newGroup);
@@ -862,23 +875,6 @@
return getBackupFqn(buddyGroup == null || buddyGroup.getGroupName() == null ? "null" : buddyGroup.getGroupName(), originalFqn);
}
- /**
- * Blocks until the BuddyManager has finished initialising
- */
- private void waitForInit()
- {
- while (!initialised)
- {
- try
- {
- Thread.sleep(100);
- }
- catch (InterruptedException e)
- {
- }
- }
- }
-
public static Fqn getActualFqn(Fqn fqn)
{
if (!isBackupFqn(fqn)) return fqn;
@@ -886,7 +882,6 @@
return fqn.getSubFqn(2, fqn.size());
}
-
/**
* Asynchronous thread that deals with handling view changes placed on a queue
*/
@@ -908,7 +903,14 @@
public void run()
{
// don't start this thread until the Buddy Manager has initialised as it cocks things up.
- waitForInit();
+ try
+ {
+ initialisationLatch.await();
+ }
+ catch (InterruptedException e)
+ {
+ log.debug("Caught InterruptedException", e);
+ }
while (!Thread.interrupted())
{
try
More information about the jboss-cvs-commits
mailing list