Elffuss BraidHub

kikocis/java-driver public

Merge branch '2.1' into 3.0
Changeseta3674bcf4e77af2015d3e89e354f7611b0b1864430d2a9d7932a9d799fe062ca
Authorolim7t <omichallat+github@gmail.com> · 2015-12-07 18:41 +01:00
Committerolim7t <omichallat+github@gmail.com> · 2015-12-07 18:41 +01:00
Parentse795c27abebd, 727384fa3b03

Browse the files at this changeset

4 files changed

modified changelog/README.md +1 −3
@@ -16,6 +16,7 @@
1616
1717 - [improvement] JAVA-989: Include keyspace name when invalid replication found when generating token map.
1818 - [improvement] JAVA-664: Reduce heap consumption for TokenMap.
19+- [bug] JAVA-994: Don't call on(Up|Down|Add|Remove) methods if Cluster is closed/closing.
1920
2021
2122 ### 3.0.0-alpha5
@@ -249,7 +250,6 @@
249250 Merged from 2.0 branch:
250251
251252 - [bug] JAVA-994: Don't call on(Up|Down|Add|Remove) methods if Cluster is closed/closing.
252-- [bug] JAVA-995: Defunct connection even if initializing.
253253
254254
255255 ### 2.1.9
@@ -574,8 +574,6 @@
574574 ### 2.0.13 (in progress)
575575
576576 - [bug] JAVA-994: Don't call on(Up|Down|Add|Remove) methods if Cluster is closed/closing.
577-- [bug] JAVA-995: Defunct connection even if initializing.
578-
579577
580578 ### 2.0.12
581579
modified driver-core/src/main/java/com/datastax/driver/core/Connection.java +1 −1
@@ -1063,7 +1063,7 @@
10631063 public void operationComplete(ChannelFuture future) throws Exception {
10641064 // If we've closed the channel client side then we don't really want to defunct the connection, but
10651065 // if there is remaining thread waiting on us, we still want to wake them up
1066- if (isClosed()) {
1066+ if (!isInitialized || isClosed()) {
10671067 dispatcher.errorOutAllHandler(new TransportException(address, "Channel has been closed"));
10681068 // we still want to force so that the future completes
10691069 Connection.this.closeAsync().force();
modified features/async/README.md +48 −0
@@ -42,6 +42,54 @@
4242 });
4343 ```
4444
45+### Async paging
46+
47+If you consume a `ResultSet` in a callback, be aware that iterating the
48+rows will trigger synchronous queries as you page through the results.
49+To avoid this, use [getAvailableWithoutFetching] to limit the iteration
50+to the current page, and [fetchMoreResults] to get a future to the next
51+page (see also the section on [paging](../paging/)).
52+Here is a full example:
53+
54+[getAvailableWithoutFetching]: http://docs.datastax.com/en/drivers/java/3.0/com/datastax/driver/core/ResultSet.html#getAvailableWithoutFetching--
55+[fetchMoreResults]: http://docs.datastax.com/en/drivers/java/3.0/com/datastax/driver/core/ResultSet.html#fetchMoreResults--
56+
57+```java
58+Statement statement = new SimpleStatement("select * from foo").setFetchSize(20);
59+ListenableFuture<ResultSet> future = Futures.transform(
60+ session.executeAsync(statement),
61+ iterate(1));
62+
63+private static AsyncFunction<ResultSet, ResultSet> iterate(final int page) {
64+ return new AsyncFunction<ResultSet, ResultSet>() {
65+ @Override
66+ public ListenableFuture<ResultSet> apply(ResultSet rs) throws Exception {
67+
68+ // How far we can go without triggering the blocking fetch:
69+ int remainingInPage = rs.getAvailableWithoutFetching();
70+
71+ System.out.printf("Starting page %d (%d rows)%n", page, remainingInPage);
72+
73+ for (Row row : rs) {
74+ System.out.printf("[page %d - %d] row = %s%n", page, remainingInPage, row);
75+ if (--remainingInPage == 0)
76+ break;
77+ }
78+ System.out.printf("Done page %d%n", page);
79+
80+ boolean wasLastPage = rs.getExecutionInfo().getPagingState() == null;
81+ if (wasLastPage) {
82+ System.out.println("Done iterating");
83+ return Futures.immediateFuture(rs);
84+ } else {
85+ ListenableFuture<ResultSet> future = rs.fetchMoreResults();
86+ return Futures.transform(future, iterate(page + 1));
87+ }
88+ }
89+ };
90+}
91+```
92+
4593 ### Good practices
4694
4795 If your callback is slow, consider providing a separate executor.
modified features/paging/README.md +5 −0
@@ -93,6 +93,11 @@
9393 }
9494 ```
9595
96+If you use paging with the async API, you'll also want to use those
97+methods to avoid triggering synchronous fetches unintentionally; see
98+[async paging](../async/#async-paging).
99+
100+
96101 ### Saving and reusing the paging state
97102
98103 Sometimes it is convenient to save the paging state in order to restore