private boolean beginVolunteering() { synchronized (BucketAdvisor.this) { if (Thread.currentThread().equals(this.volunteeringThread)) { return true; // this thread is already volunteering or reserved } if (this.volunteeringThread != null) { // another thread is already volunteering return false; } this.volunteeringThread = Thread.currentThread(); boolean changedState = false; try { if (isAggressive()) { changedState = setBecoming(); } else { changedState = setVolunteering(); } return changedState; } finally { if (!changedState) { this.aggressive = false; this.volunteeringThread = null; } } } }
protected void acquirePrimaryForRestOfTheBucket() { List<FixedPartitionAttributesImpl> fpas = this.pRegion.getFixedPartitionAttributesImpl(); if (fpas != null) { int bucketId = getBucket().getId(); for (FixedPartitionAttributesImpl fpa : fpas) { if (fpa.getStartingBucketID() == bucketId) { for (int i = bucketId + 1; i <= fpa.getLastBucketID();) { Bucket b = regionAdvisor.getBucket(i++); if (b != null) { BucketAdvisor ba = b.getBucketAdvisor(); ba.primaryMoveWriteLock.lock(); try { if (ba.isHosting()) { if (!ba.isPrimary()) { ba.setVolunteering(); ba.acquiredPrimaryLock(); } } } finally { ba.primaryMoveWriteLock.unlock(); } } } } else { continue; } } } }
if (isPrimary()) { if (!childBA.isPrimary()) { childBA.setVolunteering(); boolean acquired = childBA.acquiredPrimaryLock(); acquireForChild = true;