kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 390663e21058d7912f97a401fe72a48f672554b7f301800ba41187d006990801 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2014-10-31 23:34 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2014-11-03 11:32 +01:00 |
| Parents | a8e90ec9201c |
1 file changed
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +13 −4
| @@ -1289,9 +1289,9 @@ | ||
| 1289 | 1289 | |
| 1290 | 1290 | // If we're shutting down, there is no point in waiting on scheduled reconnections, nor on notifications |
| 1291 | 1291 | // delivery or blocking tasks so we use shutdownNow |
| 1292 | - reconnectionExecutor.shutdownNow(); | |
| 1293 | - scheduledTasksExecutor.shutdownNow(); | |
| 1294 | - blockingExecutor.shutdownNow(); | |
| 1292 | + shutdownNow(reconnectionExecutor); | |
| 1293 | + shutdownNow(scheduledTasksExecutor); | |
| 1294 | + shutdownNow(blockingExecutor); | |
| 1295 | 1295 | |
| 1296 | 1296 | // but for the worker executor, we want to let submitted tasks finish unless the shutdown is forced. |
| 1297 | 1297 | executor.shutdown(); |
| @@ -1319,6 +1319,15 @@ | ||
| 1319 | 1319 | : closeFuture.get(); // We raced, it's ok, return the future that was actually set |
| 1320 | 1320 | } |
| 1321 | 1321 | |
| 1322 | + private void shutdownNow(ExecutorService executor) { | |
| 1323 | + List<Runnable> pendingTasks = executor.shutdownNow(); | |
| 1324 | + // If some tasks were submitted to this executor but not yet commenced, make sure the corresponding futures complete | |
| 1325 | + for (Runnable pendingTask : pendingTasks) { | |
| 1326 | + if (pendingTask instanceof FutureTask<?>) | |
| 1327 | + ((FutureTask<?>)pendingTask).cancel(false); | |
| 1328 | + } | |
| 1329 | + } | |
| 1330 | + | |
| 1322 | 1331 | void logUnsupportedVersionProtocol(Host host) { |
| 1323 | 1332 | logger.warn("Detected added or restarted Cassandra host {} but ignoring it since it does not support the version 2 of the native " |
| 1324 | 1333 | + "protocol which is currently in use. If you want to force the use of the version 1 of the native protocol, use " |
| @@ -2096,7 +2105,7 @@ | ||
| 2096 | 2105 | @Override |
| 2097 | 2106 | public CloseFuture force() { |
| 2098 | 2107 | // The only ExecutorService we haven't forced yet is executor |
| 2099 | - executor.shutdownNow(); | |
| 2108 | + shutdownNow(executor); | |
| 2100 | 2109 | return super.force(); |
| 2101 | 2110 | } |
| 2102 | 2111 |