Skip to content

Commit

Permalink
Merge branch '1.0' into 2.0
Browse files Browse the repository at this point in the history
Conflicts:
	driver-core/CHANGELOG.rst
  • Loading branch information
Sylvain Lebresne committed Mar 3, 2014
2 parents 4614d9d + 06eacf5 commit 606943e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions driver-core/CHANGELOG.rst
Expand Up @@ -14,6 +14,7 @@ CHANGELOG
Merged from 1.0 branch:

- [bug] LatencyAwarePolicy.Builder#withScale doesn't set the scale (JAVA-275)
- [new] Add methods to check if a Cluster/Session instance has been closed already (JAVA-114)


2.0.0:
Expand Down
16 changes: 16 additions & 0 deletions driver-core/src/main/java/com/datastax/driver/core/Cluster.java
Expand Up @@ -401,6 +401,22 @@ public void close() {
}
}

/**
* Whether this Cluster instance has been closed.
* <p>
* Note that this method returns true as soon as one of the close methods
* ({@link closeAsync} or {@link close}) has been called, it does not guarantee
* that the closing is done. If you want to guarantee that the closing is done,
* you can call {@code close()} and wait until it returns (or call the get method
* on {@code closeAsync()} with a very short timeout and check this doesn't timeout).
*
* @return {@code true} if this Cluster instance has been closed, {@code false}
* otherwise.
*/
public boolean isClosed() {
return manager.closeFuture.get() != null;
}

/**
* Initializer for {@link Cluster} instances.
* <p>
Expand Down
14 changes: 14 additions & 0 deletions driver-core/src/main/java/com/datastax/driver/core/Session.java
Expand Up @@ -306,6 +306,20 @@ public interface Session extends Closeable {
*/
public void close();

/**
* Whether this Session instance has been closed.
* <p>
* Note that this method returns true as soon as one closing this Session
* has started but it does not guarantee that the closing is done. If you
* want to guarantee that the closing is done, you can call {@code close()}
* and wait until it returns (or call the get method on {@code closeAsync()}
* with a very short timeout and check this doesn't timeout).
*
* @return {@code true} if this Session instance has been closed, {@code false}
* otherwise.
*/
public boolean isClosed();

/**
* Returns the {@code Cluster} object this session is part of.
*
Expand Down
Expand Up @@ -162,6 +162,10 @@ public CloseFuture closeAsync() {
: closeFuture.get(); // We raced, it's ok, return the future that was actually set
}

public boolean isClosed() {
return closeFuture.get() != null;
}

public void close() {
try {
closeAsync().get();
Expand Down Expand Up @@ -234,10 +238,6 @@ ListeningExecutorService blockingExecutor() {
return cluster.manager.blockingTasksExecutor;
}

boolean isClosed() {
return closeFuture.get() != null;
}

ListenableFuture<Boolean> addOrRenewPool(final Host host, final boolean isHostAddition) {
final HostDistance distance = cluster.manager.loadBalancingPolicy().distance(host);
if (distance == HostDistance.IGNORED)
Expand Down

0 comments on commit 606943e

Please sign in to comment.