kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 8c0b4c94af46d1a127d5fd3951850bcc6eba2d4a4175f22a09397aaaf37384b3 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2014-10-14 21:45 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2014-10-14 21:47 +02:00 |
| Parents | c47a44c17770 |
4 files changed
modified driver-core/src/main/java/com/datastax/driver/core/AbstractReconnectionHandler.java +5 −4
| @@ -18,6 +18,7 @@ | ||
| 18 | 18 | import java.util.concurrent.*; |
| 19 | 19 | import java.util.concurrent.atomic.AtomicReference; |
| 20 | 20 | |
| 21 | +import com.google.common.util.concurrent.ListenableFuture; | |
| 21 | 22 | import com.google.common.util.concurrent.AbstractFuture; |
| 22 | 23 | import org.slf4j.Logger; |
| 23 | 24 | import org.slf4j.LoggerFactory; |
| @@ -34,7 +35,7 @@ | ||
| 34 | 35 | /** |
| 35 | 36 | * The future that is exposed to clients, representing completion of the current active handler |
| 36 | 37 | */ |
| 37 | - private final AtomicReference<Future<?>> currentAttempt; | |
| 38 | + private final AtomicReference<ListenableFuture<?>> currentAttempt; | |
| 38 | 39 | |
| 39 | 40 | private final HandlerFuture handlerFuture = new HandlerFuture(); |
| 40 | 41 | |
| @@ -42,11 +43,11 @@ | ||
| 42 | 43 | |
| 43 | 44 | private volatile boolean isActive; |
| 44 | 45 | |
| 45 | - public AbstractReconnectionHandler(ScheduledExecutorService executor, ReconnectionPolicy.ReconnectionSchedule schedule, AtomicReference<Future<?>> currentAttempt) { | |
| 46 | + public AbstractReconnectionHandler(ScheduledExecutorService executor, ReconnectionPolicy.ReconnectionSchedule schedule, AtomicReference<ListenableFuture<?>> currentAttempt) { | |
| 46 | 47 | this(executor, schedule, currentAttempt, -1); |
| 47 | 48 | } |
| 48 | 49 | |
| 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) { | |
| 50 | 51 | this.executor = executor; |
| 51 | 52 | this.schedule = schedule; |
| 52 | 53 | this.currentAttempt = currentAttempt; |
| @@ -74,7 +75,7 @@ | ||
| 74 | 75 | handlerFuture.nextTry = executor.schedule(this, firstDelay, TimeUnit.MILLISECONDS); |
| 75 | 76 | |
| 76 | 77 | while (true) { |
| 77 | - Future<?> previous = currentAttempt.get(); | |
| 78 | + ListenableFuture<?> previous = currentAttempt.get(); | |
| 78 | 79 | if (previous != null && !previous.isCancelled()) { |
| 79 | 80 | logger.debug("Found another already active handler, cancelling"); |
| 80 | 81 | handlerFuture.cancel(false); |
modified driver-core/src/main/java/com/datastax/driver/core/ControlConnection.java +3 −3
| @@ -20,11 +20,11 @@ | ||
| 20 | 20 | import java.net.UnknownHostException; |
| 21 | 21 | import java.util.*; |
| 22 | 22 | import java.util.concurrent.ExecutionException; |
| 23 | -import java.util.concurrent.Future; | |
| 24 | 23 | import java.util.concurrent.TimeUnit; |
| 25 | 24 | import java.util.concurrent.atomic.AtomicReference; |
| 26 | 25 | |
| 27 | 26 | import com.google.common.base.Objects; |
| 27 | +import com.google.common.util.concurrent.ListenableFuture; | |
| 28 | 28 | import org.slf4j.Logger; |
| 29 | 29 | import org.slf4j.LoggerFactory; |
| 30 | 30 | |
| @@ -63,7 +63,7 @@ | ||
| 63 | 63 | |
| 64 | 64 | private final Cluster.Manager cluster; |
| 65 | 65 | |
| 66 | - private final AtomicReference<Future<?>> reconnectionAttempt = new AtomicReference<Future<?>>(); | |
| 66 | + private final AtomicReference<ListenableFuture<?>> reconnectionAttempt = new AtomicReference<ListenableFuture<?>>(); | |
| 67 | 67 | |
| 68 | 68 | private volatile boolean isShutdown; |
| 69 | 69 | |
| @@ -85,7 +85,7 @@ | ||
| 85 | 85 | isShutdown = true; |
| 86 | 86 | |
| 87 | 87 | // Cancel any reconnection attempt in progress |
| 88 | - Future<?> r = reconnectionAttempt.get(); | |
| 88 | + ListenableFuture<?> r = reconnectionAttempt.get(); | |
| 89 | 89 | if (r != null) |
| 90 | 90 | r.cancel(false); |
| 91 | 91 |
modified driver-core/src/main/java/com/datastax/driver/core/Host.java +1 −2
| @@ -17,7 +17,6 @@ | ||
| 17 | 17 | |
| 18 | 18 | import java.net.InetAddress; |
| 19 | 19 | import java.net.InetSocketAddress; |
| 20 | -import java.util.concurrent.Future; | |
| 21 | 20 | import java.util.concurrent.atomic.AtomicReference; |
| 22 | 21 | |
| 23 | 22 | import com.google.common.collect.ImmutableList; |
| @@ -47,7 +46,7 @@ | ||
| 47 | 46 | final AtomicReference<ListenableFuture<?>> initialReconnectionAttempt = new AtomicReference<ListenableFuture<?>>(Futures.immediateFuture(null)); |
| 48 | 47 | |
| 49 | 48 | // 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<?>>(); | |
| 51 | 50 | |
| 52 | 51 | final ExecutionInfo defaultExecutionInfo; |
| 53 | 52 |
modified driver-core/src/test/java/com/datastax/driver/core/AbstractReconnectionHandlerTest.java +6 −2
| @@ -1,10 +1,14 @@ | ||
| 1 | 1 | package com.datastax.driver.core; |
| 2 | 2 | |
| 3 | 3 | 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; | |
| 5 | 8 | import java.util.concurrent.atomic.AtomicReference; |
| 6 | 9 | |
| 7 | 10 | import com.google.common.util.concurrent.Futures; |
| 11 | +import com.google.common.util.concurrent.ListenableFuture; | |
| 8 | 12 | import com.google.common.util.concurrent.SettableFuture; |
| 9 | 13 | import org.slf4j.Logger; |
| 10 | 14 | import org.slf4j.LoggerFactory; |
| @@ -24,7 +28,7 @@ | ||
| 24 | 28 | ScheduledExecutorService executor; |
| 25 | 29 | MockReconnectionSchedule schedule; |
| 26 | 30 | MockReconnectionWork work; |
| 27 | - final AtomicReference<Future<?>> future = new AtomicReference<Future<?>>(); | |
| 31 | + final AtomicReference<ListenableFuture<?>> future = new AtomicReference<ListenableFuture<?>>(); | |
| 28 | 32 | AbstractReconnectionHandler handler; |
| 29 | 33 | |
| 30 | 34 | @BeforeMethod(groups = "unit") |