Skip to content
Browse files

local updates now also trigger updates to the backup coord(s)

  • Loading branch information...
1 parent 3e4f5a8 commit 33e0473516ee98c3538637b47d033380ec6348fe @belaban committed Oct 5, 2011
Showing with 19 additions and 6 deletions.
  1. +19 −6 src/org/jgroups/protocols/COUNTER.java
View
25 src/org/jgroups/protocols/COUNTER.java
@@ -226,7 +226,7 @@ protected void handleRequest(Request req, Address sender) {
counters.remove(((SimpleRequest)req).name);
break;
case SET:
- if(!local_addr.equals(coord))
+ if(!local_addr.equals(coord) || discard_requests)
return;
val=counters.get(((SimpleRequest)req).name);
if(val == null) {
@@ -648,7 +648,10 @@ public long get() {
@Override
public void set(long new_value) {
if(local_addr.equals(coord)) {
- getCounter(name).set(new_value);
+ VersionedValue val=getCounter(name);
+ val.set(new_value);
+ if(backup_coords != null)
+ updateBackups(name, val.value, val.version);
return;
}
Owner owner=getOwner();
@@ -667,8 +670,13 @@ public void set(long new_value) {
@Override
public boolean compareAndSet(long expect, long update) {
- if(local_addr.equals(coord))
- return getCounter(name).compareAndSet(expect, update) != null;
+ if(local_addr.equals(coord)) {
+ VersionedValue val=getCounter(name);
+ boolean retval=val.compareAndSet(expect, update) != null;
+ if(backup_coords != null)
+ updateBackups(name, val.value, val.version);
+ return retval;
+ }
Owner owner=getOwner();
Request req=new CompareAndSetRequest(owner, name, expect, update);
Promise<long[]> promise=new Promise<long[]>();
@@ -698,8 +706,13 @@ public long decrementAndGet() {
@Override
public long addAndGet(long delta) {
- if(local_addr.equals(coord))
- return getCounter(name).addAndGet(delta)[0];
+ if(local_addr.equals(coord)) {
+ VersionedValue val=getCounter(name);
+ long retval=val.addAndGet(delta)[0];
+ if(backup_coords != null)
+ updateBackups(name, val.value, val.version);
+ return retval;
+ }
Owner owner=getOwner();
Request req=new AddAndGetRequest(owner, name, delta);
Promise<long[]> promise=new Promise<long[]>();

0 comments on commit 33e0473

Please sign in to comment.
Something went wrong with that request. Please try again.