[jboss-cvs] JBossCache/src/org/jboss/cache/buddyreplication ...
Elias Ross
genman at noderunner.net
Fri Dec 8 13:49:18 EST 2006
User: genman
Date: 06/12/08 13:49:18
Modified: src/org/jboss/cache/buddyreplication BuddyManager.java
Log:
JBCACHE-892 Use JDK1.5 concurrent classes
Revision Changes Path
1.49 +24 -13 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.48
retrieving revision 1.49
diff -u -b -r1.48 -r1.49
--- BuddyManager.java 10 Nov 2006 20:32:52 -0000 1.48
+++ BuddyManager.java 8 Dec 2006 18:49:18 -0000 1.49
@@ -6,9 +6,6 @@
*/
package org.jboss.cache.buddyreplication;
-import EDU.oswego.cs.dl.util.concurrent.BoundedLinkedQueue;
-import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
-import EDU.oswego.cs.dl.util.concurrent.SynchronizedInt;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.AbstractCacheListener;
@@ -36,6 +33,10 @@
import java.util.List;
import java.util.Map;
import java.util.Vector;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.LinkedBlockingQueue;
/**
* Class that manages buddy replication groups.
@@ -69,26 +70,25 @@
/**
* Map of buddy pools received from broadcasts
*/
- Map buddyPool;
+ Map<IpAddress, String> buddyPool;
/**
* Map of bddy groups the current instance participates in as a backup node.
* Keyed on String group name, values are BuddyGroup objects.
* Needs to deal with concurrent access - concurrent assignTo/removeFrom buddy grp
*/
- Map buddyGroupsIParticipateIn = new ConcurrentReaderHashMap();
-// Map buddyGroupsIParticipateIn = new HashMap();
+ Map<String, BuddyGroup> buddyGroupsIParticipateIn = new ConcurrentHashMap();
/**
* Queue to deal with queued up view change requests - which are handled asynchronously
*/
- private final BoundedLinkedQueue queue = new BoundedLinkedQueue();
+ private final BlockingQueue<MembershipChange> queue = new LinkedBlockingQueue();
/**
* Async thread that handles items on the view change queue
*/
private AsyncViewChangeHandlerThread asyncViewChangeHandler = new AsyncViewChangeHandlerThread();
- private static SynchronizedInt threadId = new SynchronizedInt(0);
+ private static AtomicInteger threadId = new AtomicInteger(0);
/**
* Constants representng the buddy backup subtree
@@ -116,7 +116,7 @@
this.config = config;
if (config.getBuddyPoolName() != null)
- buddyPool = new ConcurrentReaderHashMap();
+ buddyPool = new ConcurrentHashMap();
BuddyLocatorConfig blc = config.getBuddyLocatorConfig();
try
@@ -241,12 +241,22 @@
// -------------- methods to be called by the tree cache listener --------------------
+ static class MembershipChange {
+ List oldMembers;
+ List newMembers;
+ public MembershipChange(List oldMembers, List newMembers)
+ {
+ this.oldMembers = oldMembers;
+ this.newMembers = newMembers;
+ }
+ }
+
private void enqueueViewChange(List oldMembers, List newMembers)
{
// put this on a queue
try
{
- queue.put(new List[]{oldMembers, newMembers});
+ queue.put(new MembershipChange(oldMembers, newMembers));
}
catch (InterruptedException e)
{
@@ -786,7 +796,8 @@
{
if (t == null || !t.isAlive())
{
- t = new Thread(this, "AsyncViewChangeHandlerThread-" + threadId.increment());
+ t = new Thread(this);
+ t.setName("AsyncViewChangeHandlerThread-" + threadId.getAndIncrement());
t.setDaemon(true);
t.start();
}
@@ -818,10 +829,10 @@
private void handleEnqueuedViewChange() throws Exception
{
log.trace("Handling queued view change");
- List[] members = (List[]) queue.take(); // 2 element array - 0 - oldMembers, 1 - newMembers
+ MembershipChange members = queue.take();
// always refresh buddy list.
- reassignBuddies(members[1]);
+ reassignBuddies(members.newMembers);
if (config.getBuddyPoolName() != null)
{
More information about the jboss-cvs-commits
mailing list