Elffuss BraidHub

kikocis/java-driver public

Make AbstractReconnectionHandler use a ListenableFuture.
Changeset8c0b4c94af46d1a127d5fd3951850bcc6eba2d4a4175f22a09397aaaf37384b3
Authorolim7t <omichallat+github@gmail.com> · 2014-10-14 21:45 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2014-10-14 21:47 +02:00
Parentsc47a44c17770

Browse the files at this changeset

4 files changed

modified driver-core/src/main/java/com/datastax/driver/core/AbstractReconnectionHandler.java +5 −4
@@ -18,6 +18,7 @@
1818 import java.util.concurrent.*;
1919 import java.util.concurrent.atomic.AtomicReference;
2020
21+import com.google.common.util.concurrent.ListenableFuture;
2122 import com.google.common.util.concurrent.AbstractFuture;
2223 import org.slf4j.Logger;
2324 import org.slf4j.LoggerFactory;
@@ -34,7 +35,7 @@
3435 /**
3536 * The future that is exposed to clients, representing completion of the current active handler
3637 */
37- private final AtomicReference<Future<?>> currentAttempt;
38+ private final AtomicReference<ListenableFuture<?>> currentAttempt;
3839
3940 private final HandlerFuture handlerFuture = new HandlerFuture();
4041
@@ -42,11 +43,11 @@
4243
4344 private volatile boolean isActive;
4445
45- public AbstractReconnectionHandler(ScheduledExecutorService executor, ReconnectionPolicy.ReconnectionSchedule schedule, AtomicReference<Future<?>> currentAttempt) {
46+ public AbstractReconnectionHandler(ScheduledExecutorService executor, ReconnectionPolicy.ReconnectionSchedule schedule, AtomicReference<ListenableFuture<?>> currentAttempt) {
4647 this(executor, schedule, currentAttempt, -1);
4748 }
4849
49- public AbstractReconnectionHandler(ScheduledExecutorService executor, ReconnectionPolicy.ReconnectionSchedule schedule, AtomicReference<Future<?>> currentAttempt, long initialDelayMs) {
50+ public AbstractReconnectionHandler(ScheduledExecutorService executor, ReconnectionPolicy.ReconnectionSchedule schedule, AtomicReference<ListenableFuture<?>> currentAttempt, long initialDelayMs) {
5051 this.executor = executor;
5152 this.schedule = schedule;
5253 this.currentAttempt = currentAttempt;
@@ -74,7 +75,7 @@
7475 handlerFuture.nextTry = executor.schedule(this, firstDelay, TimeUnit.MILLISECONDS);
7576
7677 while (true) {
77- Future<?> previous = currentAttempt.get();
78+ ListenableFuture<?> previous = currentAttempt.get();
7879 if (previous != null && !previous.isCancelled()) {
7980 logger.debug("Found another already active handler, cancelling");
8081 handlerFuture.cancel(false);
modified driver-core/src/main/java/com/datastax/driver/core/ControlConnection.java +3 −3
@@ -20,11 +20,11 @@
2020 import java.net.UnknownHostException;
2121 import java.util.*;
2222 import java.util.concurrent.ExecutionException;
23-import java.util.concurrent.Future;
2423 import java.util.concurrent.TimeUnit;
2524 import java.util.concurrent.atomic.AtomicReference;
2625
2726 import com.google.common.base.Objects;
27+import com.google.common.util.concurrent.ListenableFuture;
2828 import org.slf4j.Logger;
2929 import org.slf4j.LoggerFactory;
3030
@@ -63,7 +63,7 @@
6363
6464 private final Cluster.Manager cluster;
6565
66- private final AtomicReference<Future<?>> reconnectionAttempt = new AtomicReference<Future<?>>();
66+ private final AtomicReference<ListenableFuture<?>> reconnectionAttempt = new AtomicReference<ListenableFuture<?>>();
6767
6868 private volatile boolean isShutdown;
6969
@@ -85,7 +85,7 @@
8585 isShutdown = true;
8686
8787 // Cancel any reconnection attempt in progress
88- Future<?> r = reconnectionAttempt.get();
88+ ListenableFuture<?> r = reconnectionAttempt.get();
8989 if (r != null)
9090 r.cancel(false);
9191
modified driver-core/src/main/java/com/datastax/driver/core/Host.java +1 −2
@@ -17,7 +17,6 @@
1717
1818 import java.net.InetAddress;
1919 import java.net.InetSocketAddress;
20-import java.util.concurrent.Future;
2120 import java.util.concurrent.atomic.AtomicReference;
2221
2322 import com.google.common.collect.ImmutableList;
@@ -47,7 +46,7 @@
4746 final AtomicReference<ListenableFuture<?>> initialReconnectionAttempt = new AtomicReference<ListenableFuture<?>>(Futures.immediateFuture(null));
4847
4948 // Tracks later reconnection attempts to that host so we avoid adding multiple tasks.
50- final AtomicReference<Future<?>> reconnectionAttempt = new AtomicReference<Future<?>>();
49+ final AtomicReference<ListenableFuture<?>> reconnectionAttempt = new AtomicReference<ListenableFuture<?>>();
5150
5251 final ExecutionInfo defaultExecutionInfo;
5352
modified driver-core/src/test/java/com/datastax/driver/core/AbstractReconnectionHandlerTest.java +6 −2
@@ -1,10 +1,14 @@
11 package com.datastax.driver.core;
22
33 import java.net.InetSocketAddress;
4-import java.util.concurrent.*;
4+import java.util.concurrent.CyclicBarrier;
5+import java.util.concurrent.Executors;
6+import java.util.concurrent.ScheduledExecutorService;
7+import java.util.concurrent.TimeUnit;
58 import java.util.concurrent.atomic.AtomicReference;
69
710 import com.google.common.util.concurrent.Futures;
11+import com.google.common.util.concurrent.ListenableFuture;
812 import com.google.common.util.concurrent.SettableFuture;
913 import org.slf4j.Logger;
1014 import org.slf4j.LoggerFactory;
@@ -24,7 +28,7 @@
2428 ScheduledExecutorService executor;
2529 MockReconnectionSchedule schedule;
2630 MockReconnectionWork work;
27- final AtomicReference<Future<?>> future = new AtomicReference<Future<?>>();
31+ final AtomicReference<ListenableFuture<?>> future = new AtomicReference<ListenableFuture<?>>();
2832 AbstractReconnectionHandler handler;
2933
3034 @BeforeMethod(groups = "unit")