kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | d9212e557ba8cbb3963fade828fce454376344120c500fa6eeffa70f759f4442 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2015-03-12 17:27 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-03-16 11:28 +01:00 |
| Parents | b7478ead5d93 |
8 files changed
modified .gitignore +1 −0
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | .classpath |
| 6 | 6 | .project |
| 7 | 7 | doc |
| 8 | +docs | |
| 8 | 9 | notes |
| 9 | 10 | .DS_Store |
| 10 | 11 |
added README.md +103 −0
| @@ -0,0 +1,103 @@ | ||
| 1 | +# Datastax Java Driver for Apache Cassandra | |
| 2 | + | |
| 3 | +*If you're reading this on GitHub, please note that this is the readme | |
| 4 | +for the development version and that some features described here might | |
| 5 | +not yet have been released. You can find the documentation for latest | |
| 6 | +version through [Java driver | |
| 7 | +docs](http://datastax.github.io/java-driver/) or via the release tags, | |
| 8 | +[e.g. | |
| 9 | +2.1.5](https://github.com/datastax/java-driver/tree/2.1.5).* | |
| 10 | + | |
| 11 | +A Java client driver for Apache Cassandra. This driver works exclusively with | |
| 12 | +the Cassandra Query Language version 3 (CQL3) and Cassandra's binary protocol. | |
| 13 | + | |
| 14 | +- JIRA: https://datastax-oss.atlassian.net/browse/JAVA | |
| 15 | +- MAILING LIST: https://groups.google.com/a/lists.datastax.com/forum/#!forum/java-driver-user | |
| 16 | +- IRC: #datastax-drivers on [irc.freenode.net](http://freenode.net) | |
| 17 | +- TWITTER: Follow the latest news about DataStax Drivers - [@olim7t](http://twitter.com/olim7t), [@mfiguiere](http://twitter.com/mfiguiere) | |
| 18 | +- DOCS: http://www.datastax.com/documentation/developer/java-driver/2.1/index.html | |
| 19 | +- API: http://www.datastax.com/drivers/java/2.1 | |
| 20 | +- CHANGELOG: https://github.com/datastax/java-driver/blob/2.1/driver-core/CHANGELOG.rst | |
| 21 | + | |
| 22 | +The driver architecture is based on layers. At the bottom lies the driver core. | |
| 23 | +This core handles everything related to the connections to a Cassandra | |
| 24 | +cluster (for example, connection pool, discovering new nodes, etc.) and exposes a simple, | |
| 25 | +relatively low-level API on top of which higher level layer can be built. | |
| 26 | + | |
| 27 | +The driver contains the following modules: | |
| 28 | + | |
| 29 | +- driver-core: the core layer. | |
| 30 | +- driver-mapping: the object mapper. | |
| 31 | +- driver-examples: example applications using the other modules which are | |
| 32 | + only meant for demonstration purposes. | |
| 33 | + | |
| 34 | +Please refer to the README of each module for more information. | |
| 35 | + | |
| 36 | +## Maven | |
| 37 | + | |
| 38 | +The last release of the driver is available on Maven Central. You can install | |
| 39 | +it in your application using the following Maven dependency: | |
| 40 | + | |
| 41 | + <dependency> | |
| 42 | + <groupId>com.datastax.cassandra</groupId> | |
| 43 | + <artifactId>cassandra-driver-core</artifactId> | |
| 44 | + <version>2.1.5</version> | |
| 45 | + </dependency> | |
| 46 | + | |
| 47 | +Note that the object mapper is published as a separate artifact: | |
| 48 | + | |
| 49 | + <dependency> | |
| 50 | + <groupId>com.datastax.cassandra</groupId> | |
| 51 | + <artifactId>cassandra-driver-mapping</artifactId> | |
| 52 | + <version>2.1.5</version> | |
| 53 | + </dependency> | |
| 54 | + | |
| 55 | +We also provide a [shaded JAR](http://datastax.github.io/java-driver/features/shaded_jar/) | |
| 56 | +to avoid the explicit dependency to Netty. | |
| 57 | + | |
| 58 | +## Compatibility | |
| 59 | + | |
| 60 | +The Java client driver 2.1 ([branch 2.1](https://github.com/datastax/java-driver/tree/2.1)) is compatible with Apache | |
| 61 | +Cassandra 1.2, 2.0 and 2.1. | |
| 62 | + | |
| 63 | +UDT and tuple support is available only when using Apache Cassandra 2.1 (see [CQL improvements in Cassandra 2.1](http://www.datastax.com/dev/blog/cql-in-2-1)). | |
| 64 | + | |
| 65 | +Other features are available only when using Apache Cassandra 2.0 or higher (e.g. result set paging, | |
| 66 | +[BatchStatement](https://github.com/datastax/java-driver/blob/2.1/driver-core/src/main/java/com/datastax/driver/core/BatchStatement.java), | |
| 67 | +[lightweight transactions](http://www.datastax.com/documentation/cql/3.1/cql/cql_using/use_ltweight_transaction_t.html) | |
| 68 | +-- see [What's new in Cassandra 2.0](http://www.datastax.com/documentation/cassandra/2.0/cassandra/features/features_key_c.html)). | |
| 69 | +Trying to use these with a cluster running Cassandra 1.2 will result in | |
| 70 | +an [UnsupportedFeatureException](https://github.com/datastax/java-driver/blob/2.1/driver-core/src/main/java/com/datastax/driver/core/exceptions/UnsupportedFeatureException.java) being thrown. | |
| 71 | + | |
| 72 | + | |
| 73 | +## Upgrading from previous versions | |
| 74 | + | |
| 75 | +If you are upgrading from the 2.0.x branch of the driver, be sure to have a look at | |
| 76 | +the [upgrade guide](https://github.com/datastax/java-driver/blob/2.1/driver-core/Upgrade_guide_to_2.1.rst). | |
| 77 | + | |
| 78 | +If you are upgrading from the 1.x branch, follow the [upgrade guide to 2.0](https://github.com/datastax/java-driver/blob/2.0/driver-core/Upgrade_guide_to_2.0.rst), | |
| 79 | +and then the above document. | |
| 80 | + | |
| 81 | + | |
| 82 | +### Troubleshooting | |
| 83 | + | |
| 84 | +If you are having issues connecting to the cluster (seeing `NoHostAvailableConnection` exceptions) please check the | |
| 85 | +[connection requirements](https://github.com/datastax/java-driver/wiki/Connection-requirements). | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | +## License | |
| 91 | +Copyright 2012-2014, DataStax | |
| 92 | + | |
| 93 | +Licensed under the Apache License, Version 2.0 (the "License"); | |
| 94 | +you may not use this file except in compliance with the License. | |
| 95 | +You may obtain a copy of the License at | |
| 96 | + | |
| 97 | +http://www.apache.org/licenses/LICENSE-2.0 | |
| 98 | + | |
| 99 | +Unless required by applicable law or agreed to in writing, software | |
| 100 | +distributed under the License is distributed on an "AS IS" BASIS, | |
| 101 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 102 | +See the License for the specific language governing permissions and | |
| 103 | +limitations under the License. |
deleted README.rst +0 −99
| @@ -1,99 +0,0 @@ | ||
| 1 | -DataStax Java Driver for Apache Cassandra | |
| 2 | -========================================= | |
| 3 | - | |
| 4 | -A Java client driver for Apache Cassandra. This driver works exclusively with | |
| 5 | -the Cassandra Query Language version 3 (CQL3) and Cassandra's binary protocol. | |
| 6 | - | |
| 7 | -- JIRA: https://datastax-oss.atlassian.net/browse/JAVA | |
| 8 | -- MAILING LIST: https://groups.google.com/a/lists.datastax.com/forum/#!forum/java-driver-user | |
| 9 | -- IRC: #datastax-drivers on `irc.freenode.net <http://freenode.net>`_ | |
| 10 | -- TWITTER: Follow the latest news about DataStax Drivers - `@olim7t <http://twitter.com/olim7t>`_, `@mfiguiere <http://twitter.com/mfiguiere>`_ | |
| 11 | -- DOCS: http://www.datastax.com/documentation/developer/java-driver/2.1/index.html | |
| 12 | -- API: http://www.datastax.com/drivers/java/2.1 | |
| 13 | -- CHANGELOG: https://github.com/datastax/java-driver/blob/2.1/driver-core/CHANGELOG.rst | |
| 14 | - | |
| 15 | - | |
| 16 | -The driver architecture is based on layers. At the bottom lies the driver core. | |
| 17 | -This core handles everything related to the connections to a Cassandra | |
| 18 | -cluster (for example, connection pool, discovering new nodes, etc.) and exposes a simple, | |
| 19 | -relatively low-level API on top of which higher level layer can be built. | |
| 20 | - | |
| 21 | -The driver contains the following modules: | |
| 22 | - - driver-core: the core layer. | |
| 23 | - - driver-mapping: the object mapper. | |
| 24 | - - driver-examples: example applications using the other modules which are | |
| 25 | - only meant for demonstration purposes. | |
| 26 | - | |
| 27 | -Please refer to the README of each module for more information. | |
| 28 | - | |
| 29 | - | |
| 30 | -Maven | |
| 31 | ------ | |
| 32 | - | |
| 33 | -The last release of the driver is available on Maven Central. You can install | |
| 34 | -it in your application using the following Maven dependency:: | |
| 35 | - | |
| 36 | - <dependency> | |
| 37 | - <groupId>com.datastax.cassandra</groupId> | |
| 38 | - <artifactId>cassandra-driver-core</artifactId> | |
| 39 | - <version>2.1.4</version> | |
| 40 | - </dependency> | |
| 41 | - | |
| 42 | -Note that the object mapper is published as a separate artifact:: | |
| 43 | - | |
| 44 | - <dependency> | |
| 45 | - <groupId>com.datastax.cassandra</groupId> | |
| 46 | - <artifactId>cassandra-driver-mapping</artifactId> | |
| 47 | - <version>2.1.4</version> | |
| 48 | - </dependency> | |
| 49 | - | |
| 50 | -Compatibility | |
| 51 | -------------- | |
| 52 | - | |
| 53 | -The Java client driver 2.1 (`branch 2.1 <https://github.com/datastax/java-driver/tree/2.1>`_) is compatible with Apache | |
| 54 | -Cassandra 1.2, 2.0 and 2.1. | |
| 55 | - | |
| 56 | -UDT and tuple support is available only when using Apache Cassandra 2.1 (see `CQL improvements in Cassandra 2.1 <http://www.datastax.com/dev/blog/cql-in-2-1>`_). | |
| 57 | - | |
| 58 | -Other features are available only when using Apache Cassandra 2.0 or higher (e.g. result set paging, | |
| 59 | -`BatchStatement <https://github.com/datastax/java-driver/blob/2.0/driver-core/src/main/java/com/datastax/driver/core/BatchStatement.java>`_, | |
| 60 | -`lightweight transactions <http://www.datastax.com/documentation/cql/3.1/cql/cql_using/use_ltweight_transaction_t.html>`_ | |
| 61 | --- see `What's new in Cassandra 2.0 <http://www.datastax.com/documentation/cassandra/2.0/cassandra/features/features_key_c.html>`_). | |
| 62 | -Trying to use these with a cluster running Cassandra 1.2 will result in | |
| 63 | -an `UnsupportedFeatureException <https://github.com/datastax/java-driver/blob/2.1/driver-core/src/main/java/com/datastax/driver/core/exceptions/UnsupportedFeatureException.java>`_ being thrown. | |
| 64 | - | |
| 65 | - | |
| 66 | -Upgrading from previous versions | |
| 67 | --------------------------------- | |
| 68 | - | |
| 69 | -If you are upgrading from the 2.0.x branch of the driver, be sure to have a look at | |
| 70 | -the `upgrade guide <https://github.com/datastax/java-driver/blob/2.1/driver-core/Upgrade_guide_to_2.1.rst>`_. | |
| 71 | - | |
| 72 | -If you are upgrading from the 1.x branch, follow the `upgrade guide to 2.0 <https://github.com/datastax/java-driver/blob/2.0/driver-core/Upgrade_guide_to_2.0.rst>`_, | |
| 73 | -and then the above document. | |
| 74 | - | |
| 75 | - | |
| 76 | -Troubleshooting | |
| 77 | -~~~~~~~~~~~~~~~ | |
| 78 | - | |
| 79 | -If you are having issues connecting to the cluster (seeing ``NoHostAvailableConnection`` exceptions) please check the | |
| 80 | -`connection requirements <https://github.com/datastax/java-driver/wiki/Connection-requirements>`_. | |
| 81 | - | |
| 82 | - | |
| 83 | - | |
| 84 | - | |
| 85 | -License | |
| 86 | -------- | |
| 87 | -Copyright 2012-2014, DataStax | |
| 88 | - | |
| 89 | -Licensed under the Apache License, Version 2.0 (the "License"); | |
| 90 | -you may not use this file except in compliance with the License. | |
| 91 | -You may obtain a copy of the License at | |
| 92 | - | |
| 93 | -http://www.apache.org/licenses/LICENSE-2.0 | |
| 94 | - | |
| 95 | -Unless required by applicable law or agreed to in writing, software | |
| 96 | -distributed under the License is distributed on an "AS IS" BASIS, | |
| 97 | -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 98 | -See the License for the specific language governing permissions and | |
| 99 | -limitations under the License. |
added docs.yaml +25 −0
| @@ -0,0 +1,25 @@ | ||
| 1 | +title: Java Driver for Apache Cassandra | |
| 2 | +summary: High performance Java client for Apache Cassandra | |
| 3 | +homepage: http://datastax.github.io/java-driver/ | |
| 4 | +sections: | |
| 5 | + - title: Features | |
| 6 | + prefix: /features | |
| 7 | + sources: | |
| 8 | + - type: markdown | |
| 9 | + files: 'features/**/*.md' | |
| 10 | +links: | |
| 11 | + - title: Code | |
| 12 | + href: https://github.com/datastax/java-driver/ | |
| 13 | + - title: Docs | |
| 14 | + href: http://datastax.github.io/java-driver/ | |
| 15 | + - title: Issues | |
| 16 | + href: https://datastax-oss.atlassian.net/browse/JAVA/ | |
| 17 | + - title: Mailing List | |
| 18 | + href: https://groups.google.com/a/lists.datastax.com/forum/#!forum/java-driver-user | |
| 19 | + - title: IRC Channel | |
| 20 | + href: irc://irc.freenode.net/datastax-drivers | |
| 21 | + - title: Releases | |
| 22 | + href: https://github.com/datastax/java-driver/releases | |
| 23 | +#versions: | |
| 24 | +# - name: 2.1.5 | |
| 25 | +# ref: '2.1.5' |
added features/README.md +7 −0
| @@ -0,0 +1,7 @@ | ||
| 1 | +## Features | |
| 2 | + | |
| 3 | +This documentation is a work in progress. Use the "Read More" menu on the right hand side to browse currently documented features. | |
| 4 | + | |
| 5 | +You can also refer to the | |
| 6 | +[user documentation](http://www.datastax.com/documentation/developer/java-driver/2.1/java-driver/whatsNew2.html) | |
| 7 | +on the DataStax website. | |
| No newline at the end of the file |
added features/address_resolution/README.md +58 −0
| @@ -0,0 +1,58 @@ | ||
| 1 | +## Address resolution | |
| 2 | + | |
| 3 | +The driver auto-detects new Cassandra nodes added to the cluster through server | |
| 4 | +side push notifications and through checking the system tables. | |
| 5 | + | |
| 6 | +For each node, the address the driver will receive will correspond to the address set as | |
| 7 | +`rpc_address` in the node's `cassandra.yaml` file. In most cases, this is the correct value. | |
| 8 | +However, sometimes the addresses received through this mechanism will either not be | |
| 9 | +reachable directly by the driver, or should not be the preferred address to use | |
| 10 | +(for instance, it might be a private IP, but some clients may have to use a public IP, or | |
| 11 | +go through a router). | |
| 12 | + | |
| 13 | +### The `AddressTranslater` interface | |
| 14 | + | |
| 15 | +This interface allows you to deal with such cases, by transforming the address sent by a | |
| 16 | +Cassandra node to another address to be used by the driver for connection. | |
| 17 | + | |
| 18 | + public class MyAddressTranslater implements AddressTranslater { | |
| 19 | + public InetSocketAddress translate(InetSocketAddress address) { | |
| 20 | + ... // your custom translation logic | |
| 21 | + } | |
| 22 | + } | |
| 23 | + | |
| 24 | + Cluster cluster = Cluster.builder() | |
| 25 | + .addContactPoint("1.2.3.4") | |
| 26 | + .withAddressTranslater(new MyAddressTranslater()) | |
| 27 | + .build(); | |
| 28 | + | |
| 29 | +Notes: | |
| 30 | + | |
| 31 | +* the contact points provided while creating the `Cluster` are not translated, only addresses | |
| 32 | + retrieved from or sent by Cassandra nodes are; | |
| 33 | +* you might want to implement `CloseableAddressTranslater` if your implementation has state that | |
| 34 | + should be cleaned up when the `Cluster` shuts down. This is provided as a separate interface for | |
| 35 | + historical reasons, the `close()` method will be merged in `AddressTranslater` in a future | |
| 36 | + release. | |
| 37 | + | |
| 38 | + | |
| 39 | +### EC2 multi-region | |
| 40 | + | |
| 41 | +`EC2MultiRegionAddressTranslater` is provided out of the box. It helps optimize network costs when | |
| 42 | +your infrastructure (both Cassandra nodes *and* clients) is distributed across multiple Amazon EC2 | |
| 43 | +regions: | |
| 44 | + | |
| 45 | +* a client communicating with a Cassandra node *in the same EC2 region* should use the node's | |
| 46 | + private IP (which is less expensive); | |
| 47 | +* a client communicating with a node in a different region should use the public IP. | |
| 48 | + | |
| 49 | +To use this implementation, provide an instance when initializing the `Cluster`: | |
| 50 | + | |
| 51 | + Cluster cluster = Cluster.builder() | |
| 52 | + .addContactPoint("1.2.3.4") | |
| 53 | + .withAddressTranslater(new EC2MultiRegionAddressTranslater()) | |
| 54 | + .build(); | |
| 55 | + | |
| 56 | +This class performs a reverse DNS lookup of the origin address, to find the domain name of the | |
| 57 | +target instance. Then it performs a forward DNS lookup of the domain name; the EC2 DNS does the | |
| 58 | +private/public switch automatically based on location. | |
| No newline at the end of the file |
added features/heartbeat/README.md +38 −0
| @@ -0,0 +1,38 @@ | ||
| 1 | +## Connection heartbeat | |
| 2 | + | |
| 3 | +If connections stay idle for too long, they might be dropped by | |
| 4 | +intermediate network devices (routers, firewalls...). Normally, TCP | |
| 5 | +keepalive should take care of this; but tweaking low-level keepalive | |
| 6 | +settings might be impractical in some environments. | |
| 7 | + | |
| 8 | +The driver provides application-side keepalive in the form of a | |
| 9 | +connection heartbeat: when a connection has been idle for a given amount | |
| 10 | +of time, the driver will simulate activity by writing a dummy request to | |
| 11 | +it. | |
| 12 | + | |
| 13 | +This feature is enabled by default. The default heartbeat interval is 30 | |
| 14 | +seconds, it can be customized through `PoolingOptions`: | |
| 15 | + | |
| 16 | + cluster.getConfiguration().getPoolingOptions() | |
| 17 | + .setHeartbeatIntervalSeconds(60); | |
| 18 | + | |
| 19 | +This can be changed at runtime, but only connections created after that | |
| 20 | +will use the new interval. Most users will want to do this at startup: | |
| 21 | + | |
| 22 | + Cluster cluster = Cluster.builder() | |
| 23 | + .addContactPoint("127.0.0.1") | |
| 24 | + .withPoolingOptions(new PoolingOptions() | |
| 25 | + .setHeartbeatIntervalSeconds(60)) | |
| 26 | + .build(); | |
| 27 | + | |
| 28 | +The heartbeat interval should be set higher than | |
| 29 | +[SocketOptions.readTimeoutMillis](http://www.datastax.com/drivers/java/2.1/com/datastax/driver/core/SocketOptions.html#getReadTimeoutMillis()): | |
| 30 | +the read timeout is the maximum time that the driver waits for a regular | |
| 31 | +query to complete, therefore the connection should not be considered | |
| 32 | +idle before it has elapsed. | |
| 33 | + | |
| 34 | +To disable heartbeat, set the interval to 0. | |
| 35 | + | |
| 36 | +Implementation note: the dummy request sent by heartbeat is an | |
| 37 | +[OPTIONS](https://github.com/apache/cassandra/blob/trunk/doc/native_protocol_v3.spec#L278) | |
| 38 | +message. |
added features/shaded_jar/README.md +51 −0
| @@ -0,0 +1,51 @@ | ||
| 1 | +## Using the shaded JAR | |
| 2 | + | |
| 3 | +The default driver JAR depends on [Netty](http://netty.io/), which is | |
| 4 | +used internally for networking. | |
| 5 | + | |
| 6 | +This explicit dependency can be a problem if your application already | |
| 7 | +uses another Netty version. To avoid conflicts, we provide a "shaded" | |
| 8 | +version of the JAR, which bundles the Netty classes under a different | |
| 9 | +package name: | |
| 10 | + | |
| 11 | + <dependency> | |
| 12 | + <groupId>${project.groupId}</groupId> | |
| 13 | + <artifactId>cassandra-driver-core</artifactId> | |
| 14 | + <version>2.1.5</version> | |
| 15 | + <classifier>shaded</classifier> | |
| 16 | + <!-- Because the shaded JAR uses the original POM, you still need | |
| 17 | + to exclude this dependency explicitly: --> | |
| 18 | + <exclusions> | |
| 19 | + <exclusion> | |
| 20 | + <groupId>io.netty</groupId> | |
| 21 | + <artifactId>*</artifactId> | |
| 22 | + </exclusion> | |
| 23 | + </exclusions> | |
| 24 | + </dependency> | |
| 25 | + | |
| 26 | +If you also use the mapper, you need to remove its dependency to the | |
| 27 | +non-shaded JAR: | |
| 28 | + | |
| 29 | + <dependency> | |
| 30 | + <groupId>com.datastax.cassandra</groupId> | |
| 31 | + <artifactId>cassandra-driver-core</artifactId> | |
| 32 | + <version>2.1.5</version> | |
| 33 | + <classifier>shaded</classifier> | |
| 34 | + <exclusions> | |
| 35 | + <exclusion> | |
| 36 | + <groupId>io.netty</groupId> | |
| 37 | + <artifactId>*</artifactId> | |
| 38 | + </exclusion> | |
| 39 | + </exclusions> | |
| 40 | + </dependency> | |
| 41 | + <dependency> | |
| 42 | + <groupId>com.datastax.cassandra</groupId> | |
| 43 | + <artifactId>cassandra-driver-mapping</artifactId> | |
| 44 | + <version>2.1.5</version> | |
| 45 | + <exclusions> | |
| 46 | + <exclusion> | |
| 47 | + <groupId>com.datastax.cassandra</groupId> | |
| 48 | + <artifactId>cassandra-driver-core</artifactId> | |
| 49 | + </exclusion> | |
| 50 | + </exclusions> | |
| 51 | + </dependency> |