[ARTEMIS-708] small improvements on remove call from DelayedAddRedistributor

This commit is contained in:
Clebert Suconic 2016-10-19 15:34:37 -04:00
parent 028f92ffa5
commit ac69fed4e7
1 changed files with 13 additions and 11 deletions

View File

@ -768,11 +768,7 @@ public class QueueImpl implements Queue {
@Override @Override
public synchronized void addRedistributor(final long delay) { public synchronized void addRedistributor(final long delay) {
if (redistributorFuture != null) { clearRedistributorFuture();
redistributorFuture.cancel(false);
futures.remove(redistributorFuture);
}
if (redistributor != null) { if (redistributor != null) {
// Just prompt delivery // Just prompt delivery
@ -792,6 +788,16 @@ public class QueueImpl implements Queue {
} }
} }
private void clearRedistributorFuture() {
ScheduledFuture<?> future = redistributorFuture;
redistributorFuture = null;
if (future != null) {
future.cancel(false);
futures.remove(future);
}
}
@Override @Override
public synchronized void cancelRedistributor() throws Exception { public synchronized void cancelRedistributor() throws Exception {
if (redistributor != null) { if (redistributor != null) {
@ -802,11 +808,7 @@ public class QueueImpl implements Queue {
removeConsumer(redistributorToRemove); removeConsumer(redistributorToRemove);
} }
if (redistributorFuture != null) { clearRedistributorFuture();
redistributorFuture.cancel(false);
redistributorFuture = null;
}
} }
@Override @Override
@ -2709,7 +2711,7 @@ public class QueueImpl implements Queue {
synchronized (QueueImpl.this) { synchronized (QueueImpl.this) {
internalAddRedistributor(executor1); internalAddRedistributor(executor1);
futures.remove(redistributorFuture); clearRedistributorFuture();
} }
} }
} }