Skip to content

Commit ed9c2ee

Browse files
committed
JAVA-994: Don't call on(Up|Down|Add|Remove) if Cluster is closed.
1 parent 4866324 commit ed9c2ee

2 files changed

Lines changed: 44 additions & 24 deletions

File tree

changelog/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Changelog
22

3+
### 2.0.13 (in progress)
4+
5+
- [bug] JAVA-994: Don't call on(Up|Down|Add|Remove) methods if Cluster is closed/closing.
6+
37
### 2.0.12
48

59
- [bug] JAVA-950: Fix Cluster.connect with a case-sensitive keyspace.

driver-core/src/main/java/com/datastax/driver/core/Cluster.java

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,12 +1608,16 @@ void logClusterNameMismatch(Host host, String expectedClusterName, String actual
16081608
}
16091609

16101610
public ListenableFuture<?> triggerOnUp(final Host host) {
1611-
return executor.submit(new ExceptionCatchingRunnable() {
1612-
@Override
1613-
public void runMayThrow() throws InterruptedException, ExecutionException {
1614-
onUp(host, null);
1615-
}
1616-
});
1611+
if (!isClosed()) {
1612+
return executor.submit(new ExceptionCatchingRunnable() {
1613+
@Override
1614+
public void runMayThrow() throws InterruptedException, ExecutionException {
1615+
onUp(host, null);
1616+
}
1617+
});
1618+
} else {
1619+
return MoreFutures.VOID_SUCCESS;
1620+
}
16171621
}
16181622

16191623
// Use triggerOnUp unless you're sure you want to run this on the current thread.
@@ -1723,12 +1727,16 @@ public ListenableFuture<?> triggerOnDown(final Host host, boolean startReconnect
17231727
}
17241728

17251729
public ListenableFuture<?> triggerOnDown(final Host host, final boolean isHostAddition, final boolean startReconnection) {
1726-
return executor.submit(new ExceptionCatchingRunnable() {
1727-
@Override
1728-
public void runMayThrow() throws InterruptedException, ExecutionException {
1729-
onDown(host, isHostAddition, startReconnection);
1730-
}
1731-
});
1730+
if(!isClosed()) {
1731+
return executor.submit(new ExceptionCatchingRunnable() {
1732+
@Override
1733+
public void runMayThrow() throws InterruptedException, ExecutionException {
1734+
onDown(host, isHostAddition, startReconnection);
1735+
}
1736+
});
1737+
} else {
1738+
return MoreFutures.VOID_SUCCESS;
1739+
}
17321740
}
17331741

17341742
// Use triggerOnDown unless you're sure you want to run this on the current thread.
@@ -1883,12 +1891,16 @@ protected boolean onAuthenticationException(AuthenticationException e, long next
18831891
}
18841892

18851893
public ListenableFuture<?> triggerOnAdd(final Host host) {
1886-
return executor.submit(new ExceptionCatchingRunnable() {
1887-
@Override
1888-
public void runMayThrow() throws InterruptedException, ExecutionException {
1889-
onAdd(host, null);
1890-
}
1891-
});
1894+
if (!isClosed()) {
1895+
return executor.submit(new ExceptionCatchingRunnable() {
1896+
@Override
1897+
public void runMayThrow() throws InterruptedException, ExecutionException {
1898+
onAdd(host, null);
1899+
}
1900+
});
1901+
} else {
1902+
return MoreFutures.VOID_SUCCESS;
1903+
}
18921904
}
18931905

18941906
// Use triggerOnAdd unless you're sure you want to run this on the current thread.
@@ -1988,12 +2000,16 @@ private void onAdd(final Host host, Connection reusedConnection) throws Interrup
19882000
}
19892001

19902002
public ListenableFuture<?> triggerOnRemove(final Host host) {
1991-
return executor.submit(new ExceptionCatchingRunnable() {
1992-
@Override
1993-
public void runMayThrow() throws InterruptedException, ExecutionException {
1994-
onRemove(host);
1995-
}
1996-
});
2003+
if (!isClosed()) {
2004+
return executor.submit(new ExceptionCatchingRunnable() {
2005+
@Override
2006+
public void runMayThrow() throws InterruptedException, ExecutionException {
2007+
onRemove(host);
2008+
}
2009+
});
2010+
} else {
2011+
return MoreFutures.VOID_SUCCESS;
2012+
}
19972013
}
19982014

19992015
// Use triggerOnRemove unless you're sure you want to run this on the current thread.

0 commit comments

Comments
 (0)