Elffuss BraidHub

kikocis/java-driver public

JAVA-1006: Reorganize exceptions hierarchy.

This commit also promotes some package-private exceptions to top level, e,g, ConnectionException.
Changeset68ee5447be2a928e7e1359ef665d22123ad7fb7ad04c7a41f2e7b1954d53e5a2
AuthorAlexandre Dutra <alexandre.dutra@datastax.com> · 2015-12-01 15:25 +01:00
CommitterAlexandre Dutra <alexandre.dutra@datastax.com> · 2015-12-03 18:44 +01:00
Parentsb4554bb54c38

Browse the files at this changeset

48 files changed

modified driver-core/src/main/java/com/datastax/driver/core/AbstractReconnectionHandler.java +5 −3
@@ -25,6 +25,8 @@
2525 import org.slf4j.LoggerFactory;
2626
2727 import com.datastax.driver.core.exceptions.AuthenticationException;
28+import com.datastax.driver.core.exceptions.ConnectionException;
29+import com.datastax.driver.core.exceptions.UnsupportedProtocolVersionException;
2830 import com.datastax.driver.core.policies.ReconnectionPolicy;
2931
3032 /**
@@ -140,7 +142,7 @@
140142 if (onAuthenticationException(e, nextDelay)) {
141143 reschedule(nextDelay);
142144 } else {
143- logger.error("Retry against {} have been suspended. It won't be retried unless the node is restarted.", e.getHost());
145+ logger.error("Retries against {} have been suspended. It won't be retried unless the node is restarted.", e.getHost());
144146 currentAttempt.compareAndSet(handlerFuture, null);
145147 }
146148 } catch (InterruptedException e) {
@@ -151,7 +153,7 @@
151153 if (onUnsupportedProtocolVersionException(e, nextDelay)) {
152154 reschedule(nextDelay);
153155 } else {
154- logger.error("Retry against {} have been suspended. It won't be retried unless the node is restarted.", e.address);
156+ logger.error("Retries against {} have been suspended. It won't be retried unless the node is restarted.", e.getHost());
155157 currentAttempt.compareAndSet(handlerFuture, null);
156158 }
157159 } catch (ClusterNameMismatchException e) {
@@ -160,7 +162,7 @@
160162 if (onClusterNameMismatchException(e, nextDelay)) {
161163 reschedule(nextDelay);
162164 } else {
163- logger.error("Retry against {} have been suspended. It won't be retried unless the node is restarted.", e.address);
165+ logger.error("Retries against {} have been suspended. It won't be retried unless the node is restarted.", e.address.getAddress());
164166 currentAttempt.compareAndSet(handlerFuture, null);
165167 }
166168 } catch (Exception e) {
modified driver-core/src/main/java/com/datastax/driver/core/ArrayBackedResultSet.java +1 −0
@@ -28,6 +28,7 @@
2828 import org.slf4j.Logger;
2929 import org.slf4j.LoggerFactory;
3030
31+import com.datastax.driver.core.exceptions.ConnectionException;
3132 import com.datastax.driver.core.exceptions.DriverInternalError;
3233
3334 /**
deleted driver-core/src/main/java/com/datastax/driver/core/BusyConnectionException.java +0 −25
@@ -1,25 +0,0 @@
1-/*
2- * Copyright (C) 2012-2015 DataStax Inc.
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-package com.datastax.driver.core;
17-
18-class BusyConnectionException extends Exception
19-{
20- private static final long serialVersionUID = 0;
21-
22- public BusyConnectionException() {
23- super();
24- }
25-}
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +5 −8
@@ -34,10 +34,7 @@
3434 import org.slf4j.Logger;
3535 import org.slf4j.LoggerFactory;
3636
37-import com.datastax.driver.core.exceptions.AuthenticationException;
38-import com.datastax.driver.core.exceptions.DriverInternalError;
39-import com.datastax.driver.core.exceptions.InvalidQueryException;
40-import com.datastax.driver.core.exceptions.NoHostAvailableException;
37+import com.datastax.driver.core.exceptions.*;
4138 import com.datastax.driver.core.policies.*;
4239 import com.datastax.driver.core.utils.MoreFutures;
4340
@@ -1404,9 +1401,9 @@
14041401 try {
14051402 controlConnection.connect();
14061403 } catch (UnsupportedProtocolVersionException e) {
1407- logger.debug("Cannot connect with protocol {}, trying {}", e.unsupportedVersion, e.serverVersion);
1404+ logger.debug("Cannot connect with protocol {}, trying {}", e.getUnsupportedVersion(), e.getServerVersion());
14081405
1409- connectionFactory.protocolVersion = e.serverVersion;
1406+ connectionFactory.protocolVersion = e.getServerVersion();
14101407 try {
14111408 controlConnection.connect();
14121409 } catch (UnsupportedProtocolVersionException e1) {
@@ -1682,7 +1679,7 @@
16821679 Thread.currentThread().interrupt();
16831680 // Don't propagate because we don't want to prevent other listener to run
16841681 } catch (UnsupportedProtocolVersionException e) {
1685- logUnsupportedVersionProtocol(host, e.unsupportedVersion);
1682+ logUnsupportedVersionProtocol(host, e.getUnsupportedVersion());
16861683 return;
16871684 } catch (ClusterNameMismatchException e) {
16881685 logClusterNameMismatch(host, e.expectedClusterName, e.actualClusterName);
@@ -1969,7 +1966,7 @@
19691966 Thread.currentThread().interrupt();
19701967 // Don't propagate because we don't want to prevent other listener to run
19711968 } catch (UnsupportedProtocolVersionException e) {
1972- logUnsupportedVersionProtocol(host, e.unsupportedVersion);
1969+ logUnsupportedVersionProtocol(host, e.getUnsupportedVersion());
19731970 return;
19741971 } catch (ClusterNameMismatchException e) {
19751972 logClusterNameMismatch(host, e.expectedClusterName, e.actualClusterName);
modified driver-core/src/main/java/com/datastax/driver/core/Connection.java +3 −3
@@ -47,9 +47,7 @@
4747 import static io.netty.handler.timeout.IdleState.ALL_IDLE;
4848
4949 import com.datastax.driver.core.Responses.Result.SetKeyspace;
50-import com.datastax.driver.core.exceptions.AuthenticationException;
51-import com.datastax.driver.core.exceptions.DriverException;
52-import com.datastax.driver.core.exceptions.DriverInternalError;
50+import com.datastax.driver.core.exceptions.*;
5351 import com.datastax.driver.core.utils.MoreFutures;
5452
5553 import static com.datastax.driver.core.Message.Response.Type.ERROR;
@@ -1225,6 +1223,8 @@
12251223 public ResponseHandler(Connection connection, ResponseCallback callback) throws BusyConnectionException {
12261224 this.connection = connection;
12271225 this.streamId = connection.dispatcher.streamIdHandler.next();
1226+ if (streamId == -1)
1227+ throw new BusyConnectionException(connection.address);
12281228 this.callback = callback;
12291229 this.retryCount = callback.retryCount();
12301230
deleted driver-core/src/main/java/com/datastax/driver/core/ConnectionException.java +0 −42
@@ -1,42 +0,0 @@
1-/*
2- * Copyright (C) 2012-2015 DataStax Inc.
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-package com.datastax.driver.core;
17-
18-import java.net.InetSocketAddress;
19-
20-class ConnectionException extends Exception {
21-
22- private static final long serialVersionUID = 0;
23-
24- public final InetSocketAddress address;
25-
26- public ConnectionException(InetSocketAddress address, String msg, Throwable cause)
27- {
28- super(msg, cause);
29- this.address = address;
30- }
31-
32- public ConnectionException(InetSocketAddress address, String msg)
33- {
34- super(msg);
35- this.address = address;
36- }
37-
38- @Override
39- public String getMessage() {
40- return String.format("[%s] %s", address, super.getMessage());
41- }
42-}
modified driver-core/src/main/java/com/datastax/driver/core/ControlConnection.java +1 −3
@@ -28,9 +28,7 @@
2828 import org.slf4j.Logger;
2929 import org.slf4j.LoggerFactory;
3030
31-import com.datastax.driver.core.exceptions.DriverException;
32-import com.datastax.driver.core.exceptions.DriverInternalError;
33-import com.datastax.driver.core.exceptions.NoHostAvailableException;
31+import com.datastax.driver.core.exceptions.*;
3432
3533 import static com.datastax.driver.core.SchemaElement.*;
3634
modified driver-core/src/main/java/com/datastax/driver/core/HostConnectionPool.java +2 −0
@@ -34,6 +34,8 @@
3434 import org.slf4j.LoggerFactory;
3535
3636 import com.datastax.driver.core.exceptions.AuthenticationException;
37+import com.datastax.driver.core.exceptions.ConnectionException;
38+import com.datastax.driver.core.exceptions.UnsupportedProtocolVersionException;
3739 import com.datastax.driver.core.utils.MoreFutures;
3840
3941 import static com.datastax.driver.core.Connection.State.GONE;
deleted driver-core/src/main/java/com/datastax/driver/core/OperationTimedOutException.java +0 −28
@@ -1,28 +0,0 @@
1-/*
2- * Copyright (C) 2012-2015 DataStax Inc.
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-package com.datastax.driver.core;
17-
18-import java.net.InetSocketAddress;
19-
20-/**
21- * Thrown on a client-side timeout, i.e. when the client didn't hear back from the server within
22- * {@link SocketOptions#getReadTimeoutMillis()}.
23- */
24-class OperationTimedOutException extends ConnectionException {
25- public OperationTimedOutException(InetSocketAddress address) {
26- super(address, "Operation timed out");
27- }
28-}
modified driver-core/src/main/java/com/datastax/driver/core/RegularStatement.java +1 −0
@@ -18,6 +18,7 @@
1818 import java.nio.ByteBuffer;
1919
2020 import com.datastax.driver.core.exceptions.InvalidTypeException;
21+import com.datastax.driver.core.exceptions.UnsupportedProtocolVersionException;
2122
2223 /**
2324 * A regular (non-prepared and non batched) CQL statement.
modified driver-core/src/main/java/com/datastax/driver/core/RequestHandler.java +5 −8
@@ -505,8 +505,7 @@
505505 connection.release();
506506 // Try another node
507507 logger.warn("Host {} is overloaded, trying next host.", connection.address);
508- DriverException overloaded = new DriverException("Host overloaded");
509- logError(connection.address, overloaded);
508+ logError(connection.address, exceptionToReport);
510509 if (metricsEnabled())
511510 metrics().getErrorMetrics().getOthers().inc();
512511 retry(false, null);
@@ -515,9 +514,8 @@
515514 connection.release();
516515 // Defunct connection and try another node
517516 logger.warn("{} replied with server error ({}), trying next host.", connection.address, err.message);
518- DriverException exception = new DriverException("Host replied with server error: " + err.message);
519- logError(connection.address, exception);
520- connection.defunct(exception);
517+ logError(connection.address, exceptionToReport);
518+ connection.defunct(exceptionToReport);
521519 if (metricsEnabled())
522520 metrics().getErrorMetrics().getOthers().inc();
523521 retry(false, null);
@@ -526,8 +524,7 @@
526524 connection.release();
527525 // Try another node
528526 logger.error("Query sent to {} but it is bootstrapping. This shouldn't happen but trying next host.", connection.address);
529- DriverException bootstrapping = new DriverException("Host is bootstrapping");
530- logError(connection.address, bootstrapping);
527+ logError(connection.address, exceptionToReport);
531528 if (metricsEnabled())
532529 metrics().getErrorMetrics().getOthers().inc();
533530 retry(false, null);
@@ -678,7 +675,7 @@
678675 return false;
679676 }
680677 connection.release();
681- logError(connection.address, new DriverException("Timeout waiting for response to prepare message"));
678+ logError(connection.address, new OperationTimedOutException(connection.address, "Timeout waiting for response to prepare message"));
682679 retry(false, null);
683680 return true;
684681 }
modified driver-core/src/main/java/com/datastax/driver/core/SchemaParser.java +3 −0
@@ -23,6 +23,9 @@
2323 import org.slf4j.Logger;
2424 import org.slf4j.LoggerFactory;
2525
26+import com.datastax.driver.core.exceptions.BusyConnectionException;
27+import com.datastax.driver.core.exceptions.ConnectionException;
28+
2629 import static com.datastax.driver.core.SchemaElement.*;
2730
2831 abstract class SchemaParser {
modified driver-core/src/main/java/com/datastax/driver/core/SessionManager.java +2 −1
@@ -32,6 +32,7 @@
3232 import com.datastax.driver.core.exceptions.DriverInternalError;
3333 import com.datastax.driver.core.exceptions.InvalidQueryException;
3434 import com.datastax.driver.core.exceptions.UnsupportedFeatureException;
35+import com.datastax.driver.core.exceptions.UnsupportedProtocolVersionException;
3536 import com.datastax.driver.core.policies.LoadBalancingPolicy;
3637 import com.datastax.driver.core.policies.ReconnectionPolicy;
3738 import com.datastax.driver.core.policies.SpeculativeExecutionPolicy;
@@ -357,7 +358,7 @@
357358 @Override
358359 public void onFailure(Throwable t) {
359360 if (t instanceof UnsupportedProtocolVersionException) {
360- cluster.manager.logUnsupportedVersionProtocol(host, ((UnsupportedProtocolVersionException)t).unsupportedVersion);
361+ cluster.manager.logUnsupportedVersionProtocol(host, ((UnsupportedProtocolVersionException)t).getUnsupportedVersion());
361362 cluster.manager.triggerOnDown(host, false);
362363 } else if (t instanceof ClusterNameMismatchException) {
363364 ClusterNameMismatchException e = (ClusterNameMismatchException)t;
modified driver-core/src/main/java/com/datastax/driver/core/Statement.java +1 −0
@@ -21,6 +21,7 @@
2121 import com.google.common.collect.ImmutableMap;
2222
2323 import com.datastax.driver.core.exceptions.PagingStateException;
24+import com.datastax.driver.core.exceptions.UnsupportedProtocolVersionException;
2425 import com.datastax.driver.core.policies.RetryPolicy;
2526 import com.datastax.driver.core.querybuilder.BuiltStatement;
2627
modified driver-core/src/main/java/com/datastax/driver/core/StreamIdGenerator.java +2 −2
@@ -81,7 +81,7 @@
8181 offset = new AtomicInteger(bits.length() - 1);
8282 }
8383
84- public int next() throws BusyConnectionException {
84+ public int next() {
8585 int previousOffset, myOffset;
8686 do {
8787 previousOffset = offset.get();
@@ -95,7 +95,7 @@
9595 if (id >= 0)
9696 return id + (64 * j);
9797 }
98- throw new BusyConnectionException();
98+ return -1;
9999 }
100100
101101 public void release(int streamId) {
deleted driver-core/src/main/java/com/datastax/driver/core/TransportException.java +0 −37
@@ -1,37 +0,0 @@
1-/*
2- * Copyright (C) 2012-2015 DataStax Inc.
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-package com.datastax.driver.core;
17-
18-import java.net.InetSocketAddress;
19-
20-/**
21- * A connection exception that has to do with the transport itself, i.e. that
22- * suggests the node is down.
23- */
24-class TransportException extends ConnectionException
25-{
26- private static final long serialVersionUID = 0;
27-
28- public TransportException(InetSocketAddress address, String msg, Throwable cause)
29- {
30- super(address, msg, cause);
31- }
32-
33- public TransportException(InetSocketAddress address, String msg)
34- {
35- super(address, msg);
36- }
37-}
deleted driver-core/src/main/java/com/datastax/driver/core/UnsupportedProtocolVersionException.java +0 −39
@@ -1,39 +0,0 @@
1-/*
2- * Copyright (C) 2012-2015 DataStax Inc.
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-package com.datastax.driver.core;
17-
18-import java.net.InetSocketAddress;
19-
20-/**
21- * Indicates that we've attempted to connect to a 1.2 C* node with version 2 of
22- * the protocol.
23- */
24-class UnsupportedProtocolVersionException extends Exception {
25-
26- private static final long serialVersionUID = 0;
27-
28- public final InetSocketAddress address;
29- public final ProtocolVersion unsupportedVersion;
30- public final ProtocolVersion serverVersion;
31-
32- public UnsupportedProtocolVersionException(InetSocketAddress address, ProtocolVersion unsupportedVersion, ProtocolVersion serverVersion)
33- {
34- super(String.format("[%s] Host %s does not support protocol version %s but %s", address, address, unsupportedVersion, serverVersion));
35- this.address = address;
36- this.unsupportedVersion = unsupportedVersion;
37- this.serverVersion = serverVersion;
38- }
39-}
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/BootstrappingException.java +2 −6
@@ -19,13 +19,9 @@
1919 import java.net.InetSocketAddress;
2020
2121 /**
22- * Indicates that the contacted host was bootstrapping.
23- * This class is mainly intended for internal use;
24- * client applications are not expected to deal with this exception directly,
25- * because the driver would transparently retry the same query on another host;
26- * but such exceptions are likely to appear occasionally in the driver logs.
22+ * Indicates that the contacted host was bootstrapping when it received a read query.
2723 */
28-public class BootstrappingException extends DriverInternalError implements CoordinatorException {
24+public class BootstrappingException extends QueryExecutionException implements CoordinatorException {
2925
3026 private static final long serialVersionUID = 0;
3127
added driver-core/src/main/java/com/datastax/driver/core/exceptions/BusyConnectionException.java +55 −0
@@ -0,0 +1,55 @@
1+/*
2+ * Copyright (C) 2012-2015 DataStax Inc.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+package com.datastax.driver.core.exceptions;
17+
18+import java.net.InetAddress;
19+import java.net.InetSocketAddress;
20+
21+/**
22+ * Indicates that a connection has run out of stream IDs.
23+ */
24+public class BusyConnectionException extends DriverException implements CoordinatorException {
25+
26+ private static final long serialVersionUID = 0;
27+
28+ private final InetSocketAddress address;
29+
30+ public BusyConnectionException(InetSocketAddress address) {
31+ super(String.format("[%s] Connection has run out of stream IDs", address.getAddress()));
32+ this.address = address;
33+ }
34+
35+ public BusyConnectionException(InetSocketAddress address, Throwable cause) {
36+ super(String.format("[%s] Connection has run out of stream IDs", address.getAddress()), cause);
37+ this.address = address;
38+ }
39+
40+ @Override
41+ public InetAddress getHost() {
42+ return address.getAddress();
43+ }
44+
45+ @Override
46+ public InetSocketAddress getAddress() {
47+ return address;
48+ }
49+
50+ @Override
51+ public BusyConnectionException copy() {
52+ return new BusyConnectionException(address, this);
53+ }
54+
55+}
added driver-core/src/main/java/com/datastax/driver/core/exceptions/ConnectionException.java +65 −0
@@ -0,0 +1,65 @@
1+/*
2+ * Copyright (C) 2012-2015 DataStax Inc.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+package com.datastax.driver.core.exceptions;
17+
18+import java.net.InetAddress;
19+import java.net.InetSocketAddress;
20+
21+/**
22+ * Indicates that a connection to a host has encountered a problem
23+ * and that it should be closed.
24+ */
25+public class ConnectionException extends DriverException implements CoordinatorException {
26+
27+ private static final long serialVersionUID = 0;
28+
29+ public final InetSocketAddress address;
30+
31+ public ConnectionException(InetSocketAddress address, String msg, Throwable cause) {
32+ super(msg, cause);
33+ this.address = address;
34+ }
35+
36+ public ConnectionException(InetSocketAddress address, String msg) {
37+ super(msg);
38+ this.address = address;
39+ }
40+
41+ @Override
42+ public InetAddress getHost() {
43+ return address.getAddress();
44+ }
45+
46+ @Override
47+ public InetSocketAddress getAddress() {
48+ return address;
49+ }
50+
51+ @Override
52+ public String getMessage() {
53+ return String.format("[%s] %s", getHost(), getRawMessage());
54+ }
55+
56+ @Override
57+ public ConnectionException copy() {
58+ return new ConnectionException(address, getRawMessage(), this);
59+ }
60+
61+ String getRawMessage() {
62+ return super.getMessage();
63+ }
64+
65+}
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/CoordinatorException.java +5 −5
@@ -20,25 +20,25 @@
2020
2121 /**
2222 * An interface for exceptions that are able to report the address of the coordinator host
23- * that triggered the response error which caused the exception to be raised.
23+ * that was contacted.
2424 */
2525 public interface CoordinatorException {
2626
2727 /**
28- * The coordinator host that caused this exception to be raised.
28+ * The coordinator host that was contacted.
2929 * <p>
3030 * This is a shortcut for {@link InetSocketAddress#getAddress() getAddress().getAddress()}.
3131 *
32- * @return The coordinator host that caused this exception to be raised;
32+ * @return The coordinator host that was contacted;
3333 * may be {@code null} if the coordinator is not known.
3434 *
3535 */
3636 InetAddress getHost();
3737
3838 /**
39- * The full address of the coordinator host that caused this exception to be raised.
39+ * The full address of the coordinator host that was contacted.
4040 *
41- * @return the full address of the coordinator host that caused this exception to be raised;
41+ * @return the full address of the coordinator host that was contacted;
4242 * may be {@code null} if the coordinator is not known.
4343 */
4444 InetSocketAddress getAddress();
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/DriverException.java +1 −5
@@ -22,10 +22,6 @@
2222
2323 private static final long serialVersionUID = 0;
2424
25- DriverException() {
26- super();
27- }
28-
2925 public DriverException(String message) {
3026 super(message);
3127 }
@@ -41,7 +37,7 @@
4137 /**
4238 * Copy the exception.
4339 * <p>
44- * This return a new exception, equivalent to the original one, except that
40+ * This returns a new exception, equivalent to the original one, except that
4541 * because a new object is created in the current thread, the top-most
4642 * element in the stacktrace of the exception will refer to the current
4743 * thread (this is mainly intended for internal use by the driver). The cause of
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/DriverInternalError.java +1 −1
@@ -18,7 +18,7 @@
1818 /**
1919 * An unexpected error happened internally.
2020 *
21- * This should never be raise and indicates a bug (either in the driver or in
21+ * This should never be raised and indicates a bug (either in the driver or in
2222 * Cassandra).
2323 */
2424 public class DriverInternalError extends DriverException {
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/InvalidTypeException.java +8 −1
@@ -15,6 +15,13 @@
1515 */
1616 package com.datastax.driver.core.exceptions;
1717
18+/**
19+ * Thrown when a {@link com.datastax.driver.core.TypeCodec}
20+ * is unable to perform the requested operation (serialization,
21+ * deserialization, parsing or formatting) because the
22+ * object or the byte buffer content being processed does not
23+ * comply with the expected Java and/or CQL type.
24+ */
1825 public class InvalidTypeException extends DriverException {
1926
2027 private static final long serialVersionUID = 0;
@@ -28,7 +35,7 @@
2835 }
2936
3037 @Override
31- public DriverException copy() {
38+ public InvalidTypeException copy() {
3239 return new InvalidTypeException(getMessage(), this);
3340 }
3441 }
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/NoHostAvailableException.java +8 −8
@@ -22,17 +22,17 @@
2222 import java.util.Map;
2323
2424 /**
25- * Exception thrown when a query cannot be performed because no host are
25+ * Exception thrown when a query cannot be performed because no host is
2626 * available.
27- *
28- * This exception is thrown if
27+ * <p>
28+ * This exception is thrown if either:
2929 * <ul>
30- * <li>either there is no host live in the cluster at the moment of the query</li>
31- * <li>all host that have been tried have failed due to a connection problem</li>
30+ * <li>there is no host live in the cluster at the moment of the query;</li>
31+ * <li>all hosts that have been tried have failed.</li>
3232 * </ul>
3333 *
34- * For debugging purpose, the list of hosts that have been tried along with the
35- * failure cause can be retrieved using the {@link #errors} method.
34+ * For debugging purposes, the list of hosts that have been tried along with the
35+ * failure cause can be retrieved using the {@link #getErrors()} method.
3636 */
3737 public class NoHostAvailableException extends DriverException {
3838
@@ -80,7 +80,7 @@
8080 }
8181
8282 @Override
83- public DriverException copy() {
83+ public NoHostAvailableException copy() {
8484 return new NoHostAvailableException(getMessage(), this, errors);
8585 }
8686
added driver-core/src/main/java/com/datastax/driver/core/exceptions/OperationTimedOutException.java +47 −0
@@ -0,0 +1,47 @@
1+/*
2+ * Copyright (C) 2012-2015 DataStax Inc.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+package com.datastax.driver.core.exceptions;
17+
18+import java.net.InetSocketAddress;
19+
20+import com.datastax.driver.core.SocketOptions;
21+
22+/**
23+ * Thrown on a client-side timeout, i.e. when the client didn't hear back from the server within
24+ * {@link SocketOptions#getReadTimeoutMillis()}.
25+ */
26+public class OperationTimedOutException extends ConnectionException {
27+
28+ private static final long serialVersionUID = 0;
29+
30+ public OperationTimedOutException(InetSocketAddress address) {
31+ super(address, "Operation timed out");
32+ }
33+
34+ public OperationTimedOutException(InetSocketAddress address, String msg) {
35+ super(address, msg);
36+ }
37+
38+ public OperationTimedOutException(InetSocketAddress address, String msg, Throwable cause) {
39+ super(address, msg, cause);
40+ }
41+
42+ @Override
43+ public OperationTimedOutException copy() {
44+ return new OperationTimedOutException(address, getRawMessage(), this);
45+ }
46+
47+}
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/OverloadedException.java +1 −5
@@ -20,12 +20,8 @@
2020
2121 /**
2222 * Indicates that the contacted host reported itself being overloaded.
23- * This class is mainly intended for internal use;
24- * client applications are not expected to deal with this exception directly,
25- * because the driver would transparently retry the same query on another host;
26- * but such exceptions are likely to appear occasionally in the driver logs.
2723 */
28-public class OverloadedException extends DriverInternalError implements CoordinatorException {
24+public class OverloadedException extends QueryExecutionException implements CoordinatorException {
2925
3026 private static final long serialVersionUID = 0;
3127
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/PagingStateException.java +8 −1
@@ -15,6 +15,13 @@
1515 */
1616 package com.datastax.driver.core.exceptions;
1717
18+/**
19+ * Indicates an error while deserializing a (previously serialized)
20+ * {@link com.datastax.driver.core.PagingState} object,
21+ * or when a paging state does not match the statement being executed.
22+ *
23+ * @see com.datastax.driver.core.PagingState
24+ */
1825 public class PagingStateException extends DriverException {
1926
2027 private static final long serialVersionUID = 0;
@@ -27,4 +34,4 @@
2734 super(msg, cause);
2835 }
2936
30-}
No newline at the end of the file
37+}
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/QueryExecutionException.java +2 −2
@@ -17,8 +17,8 @@
1717
1818 /**
1919 * Exception related to the execution of a query.
20- *
21- * This correspond to the exception that Cassandra throw when a (valid) query
20+ * <p>
21+ * This corresponds to the exception that Cassandra throws when a (valid) query
2222 * cannot be executed (TimeoutException, UnavailableException, ...).
2323 */
2424 @SuppressWarnings("serial")
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/ReadFailureException.java +3 −3
@@ -80,12 +80,12 @@
8080 }
8181
8282 @Override
83- public DriverException copy() {
83+ public ReadFailureException copy() {
8484 return new ReadFailureException(getAddress(), getMessage(), this, getConsistencyLevel(), getReceivedAcknowledgements(),
8585 getRequiredAcknowledgements(), getFailures(), wasDataRetrieved());
8686 }
8787
88- public DriverException copy(InetSocketAddress address) {
88+ public ReadFailureException copy(InetSocketAddress address) {
8989 return new ReadFailureException(
9090 address,
9191 getMessage(),
@@ -96,4 +96,4 @@
9696 failed,
9797 dataPresent);
9898 }
99-}
No newline at the end of the file
99+}
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/ReadTimeoutException.java +1 −1
@@ -77,7 +77,7 @@
7777 }
7878
7979 @Override
80- public DriverException copy() {
80+ public ReadTimeoutException copy() {
8181 return new ReadTimeoutException(
8282 getAddress(),
8383 getMessage(),
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/ServerError.java +2 −1
@@ -19,7 +19,8 @@
1919 import java.net.InetSocketAddress;
2020
2121 /**
22- * Indicates that the contacted host reported un expected error.
22+ * Indicates that the contacted host reported an internal error.
23+ * This should be considered as a bug in Cassandra and reported as such.
2324 */
2425 public class ServerError extends DriverInternalError implements CoordinatorException {
2526
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/SyntaxError.java +1 −1
@@ -62,7 +62,7 @@
6262 }
6363
6464 @Override
65- public DriverException copy() {
65+ public SyntaxError copy() {
6666 return new SyntaxError(getAddress(), getMessage(), this);
6767 }
6868 }
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/TraceRetrievalException.java +1 −1
@@ -33,7 +33,7 @@
3333 }
3434
3535 @Override
36- public DriverException copy() {
36+ public TraceRetrievalException copy() {
3737 return new TraceRetrievalException(getMessage(), this);
3838 }
3939 }
added driver-core/src/main/java/com/datastax/driver/core/exceptions/TransportException.java +41 −0
@@ -0,0 +1,41 @@
1+/*
2+ * Copyright (C) 2012-2015 DataStax Inc.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+package com.datastax.driver.core.exceptions;
17+
18+import java.net.InetSocketAddress;
19+
20+/**
21+ * A connection exception that has to do with the transport itself, i.e. that
22+ * suggests the node is down.
23+ */
24+public class TransportException extends ConnectionException {
25+
26+ private static final long serialVersionUID = 0;
27+
28+ public TransportException(InetSocketAddress address, String msg, Throwable cause) {
29+ super(address, msg, cause);
30+ }
31+
32+ public TransportException(InetSocketAddress address, String msg) {
33+ super(address, msg);
34+ }
35+
36+ @Override
37+ public TransportException copy() {
38+ return new TransportException(address, getRawMessage(), this);
39+ }
40+
41+}
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/TruncateException.java +1 −1
@@ -62,7 +62,7 @@
6262 }
6363
6464 @Override
65- public DriverException copy() {
65+ public TruncateException copy() {
6666 return new TruncateException(getAddress(), getMessage(), this);
6767 }
6868 }
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/UnauthorizedException.java +1 −1
@@ -63,7 +63,7 @@
6363 }
6464
6565 @Override
66- public DriverException copy() {
66+ public UnauthorizedException copy() {
6767 return new UnauthorizedException(getAddress(), getMessage(), this);
6868 }
6969 }
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/UnavailableException.java +4 −4
@@ -21,7 +21,7 @@
2121 import com.datastax.driver.core.ConsistencyLevel;
2222
2323 /**
24- * Exception thrown when the coordinator knows there is not enough replica
24+ * Exception thrown when the coordinator knows there is not enough replicas
2525 * alive to perform a query with the requested consistency level.
2626 */
2727 public class UnavailableException extends QueryExecutionException implements CoordinatorException {
@@ -78,10 +78,10 @@
7878 }
7979
8080 /**
81- * The number of replica that were known to be alive by the Cassandra
81+ * The number of replicas that were known to be alive by the Cassandra
8282 * coordinator node when it tried to execute the operation.
8383 *
84- * @return The number of replica that were known to be alive by the Cassandra
84+ * @return The number of replicas that were known to be alive by the Cassandra
8585 * coordinator node when it tried to execute the operation.
8686 */
8787 public int getAliveReplicas() {
@@ -105,7 +105,7 @@
105105 }
106106
107107 @Override
108- public DriverException copy() {
108+ public UnavailableException copy() {
109109 return new UnavailableException(getAddress(), getMessage(), this, consistency, required, alive);
110110 }
111111
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/UnpreparedException.java +1 −5
@@ -20,12 +20,8 @@
2020
2121 /**
2222 * Indicates that the contacted host replied with an UNPREPARED error code.
23- * This class is mainly intended for internal use;
24- * client applications are not expected to deal with this exception directly,
25- * because the driver would transparently prepare the query and execute it again;
26- * but such exceptions are likely to appear occasionally in the driver logs.
2723 */
28-public class UnpreparedException extends DriverInternalError implements CoordinatorException {
24+public class UnpreparedException extends QueryValidationException implements CoordinatorException {
2925
3026 private static final long serialVersionUID = 0;
3127
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/UnresolvedUserTypeException.java +9 −2
@@ -17,8 +17,15 @@
1717
1818 /**
1919 * Thrown when a user type cannot be resolved.
20+ * <p>
21+ * This exception can be raised when the driver is rebuilding
22+ * its schema metadata, and a user-defined type cannot be completely
23+ * constructed due to some missing information.
24+ * It should only appear in the driver logs, never in client code.
25+ * It shouldn't be considered as a severe error as long as it only
26+ * appears occasionally.
2027 */
21-public class UnresolvedUserTypeException extends InvalidTypeException {
28+public class UnresolvedUserTypeException extends DriverException {
2229
2330 private final String keyspaceName;
2431
@@ -45,7 +52,7 @@
4552 }
4653
4754 @Override
48- public DriverException copy() {
55+ public UnresolvedUserTypeException copy() {
4956 return new UnresolvedUserTypeException(keyspaceName, name, this);
5057 }
5158
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/UnsupportedFeatureException.java +8 −0
@@ -25,7 +25,15 @@
2525
2626 private static final long serialVersionUID = 0;
2727
28+ private final ProtocolVersion currentVersion;
29+
2830 public UnsupportedFeatureException(ProtocolVersion currentVersion, String msg) {
2931 super("Unsupported feature with the native protocol " + currentVersion + " (which is currently in use): " + msg);
32+ this.currentVersion = currentVersion;
3033 }
34+
35+ public ProtocolVersion getCurrentVersion() {
36+ return currentVersion;
37+ }
38+
3139 }
added driver-core/src/main/java/com/datastax/driver/core/exceptions/UnsupportedProtocolVersionException.java +75 −0
@@ -0,0 +1,75 @@
1+/*
2+ * Copyright (C) 2012-2015 DataStax Inc.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+package com.datastax.driver.core.exceptions;
17+
18+import java.net.InetAddress;
19+import java.net.InetSocketAddress;
20+
21+import com.datastax.driver.core.ProtocolVersion;
22+
23+/**
24+ * Indicates that we've attempted to connect to a Cassandra node with a protocol version
25+ * that it cannot handle (e.g., connecting to a C* 1.2 node with protocol version 2).
26+ */
27+public class UnsupportedProtocolVersionException extends DriverException implements CoordinatorException {
28+
29+ private static final long serialVersionUID = 0;
30+
31+ private final InetSocketAddress address;
32+
33+ private final ProtocolVersion unsupportedVersion;
34+
35+ private final ProtocolVersion serverVersion;
36+
37+ public UnsupportedProtocolVersionException(InetSocketAddress address, ProtocolVersion unsupportedVersion, ProtocolVersion serverVersion) {
38+ super(String.format("[%s] Host does not support protocol version %s but %s", address, unsupportedVersion, serverVersion));
39+ this.address = address;
40+ this.unsupportedVersion = unsupportedVersion;
41+ this.serverVersion = serverVersion;
42+ }
43+
44+ public UnsupportedProtocolVersionException(InetSocketAddress address, ProtocolVersion unsupportedVersion, ProtocolVersion serverVersion, Throwable cause) {
45+ super(String.format("[%s] Host does not support protocol version %s but %s", address, unsupportedVersion, serverVersion), cause);
46+ this.address = address;
47+ this.unsupportedVersion = unsupportedVersion;
48+ this.serverVersion = serverVersion;
49+ }
50+
51+ @Override
52+ public InetAddress getHost() {
53+ return address.getAddress();
54+ }
55+
56+ @Override
57+ public InetSocketAddress getAddress() {
58+ return address;
59+ }
60+
61+ public ProtocolVersion getServerVersion() {
62+ return serverVersion;
63+ }
64+
65+ public ProtocolVersion getUnsupportedVersion() {
66+ return unsupportedVersion;
67+ }
68+
69+ @Override
70+ public UnsupportedProtocolVersionException copy() {
71+ return new UnsupportedProtocolVersionException(address, unsupportedVersion, serverVersion, this);
72+ }
73+
74+
75+}
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/WriteFailureException.java +2 −2
@@ -75,12 +75,12 @@
7575 }
7676
7777 @Override
78- public DriverException copy() {
78+ public WriteFailureException copy() {
7979 return new WriteFailureException(getAddress(), getMessage(), this, getConsistencyLevel(), getWriteType(),
8080 getReceivedAcknowledgements(), getRequiredAcknowledgements(), getFailures());
8181 }
8282
83- public DriverException copy(InetSocketAddress address) {
83+ public WriteFailureException copy(InetSocketAddress address) {
8484 return new WriteFailureException(
8585 address,
8686 getMessage(),
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/WriteTimeoutException.java +1 −1
@@ -62,7 +62,7 @@
6262 }
6363
6464 @Override
65- public DriverException copy() {
65+ public WriteTimeoutException copy() {
6666 return new WriteTimeoutException(
6767 getAddress(),
6868 getMessage(),
modified driver-core/src/test/java/com/datastax/driver/core/AbstractReconnectionHandlerTest.java +2 −0
@@ -40,6 +40,8 @@
4040
4141 import com.datastax.driver.core.AbstractReconnectionHandler.HandlerFuture;
4242 import com.datastax.driver.core.AbstractReconnectionHandlerTest.MockReconnectionWork.ReconnectBehavior;
43+import com.datastax.driver.core.exceptions.ConnectionException;
44+import com.datastax.driver.core.exceptions.UnsupportedProtocolVersionException;
4345 import com.datastax.driver.core.policies.ReconnectionPolicy.ReconnectionSchedule;
4446
4547 public class AbstractReconnectionHandlerTest {
modified driver-core/src/test/java/com/datastax/driver/core/HostConnectionPoolTest.java +2 −0
@@ -38,6 +38,8 @@
3838 import static org.scassandra.http.client.PrimingRequest.then;
3939 import static org.testng.Assert.fail;
4040
41+import com.datastax.driver.core.exceptions.BusyConnectionException;
42+import com.datastax.driver.core.exceptions.ConnectionException;
4143 import com.datastax.driver.core.policies.ConstantReconnectionPolicy;
4244
4345 import static com.datastax.driver.core.Assertions.assertThat;
modified driver-core/src/test/java/com/datastax/driver/core/QueryLoggerErrorsTest.java +2 −7
@@ -176,12 +176,7 @@
176176 assertThat(expectedException).isEqualTo(NoHostAvailableException.class);
177177 // ok
178178 Throwable error = ((NoHostAvailableException)e).getErrors().get(hostAddress);
179- assertThat(error).isNotNull();
180- if(loggedException.getSuperclass() == DriverInternalError.class) {
181- assertThat(error).isOfAnyClassIn(DriverException.class);
182- } else {
183- assertThat(error).isOfAnyClassIn(loggedException);
184- }
179+ assertThat(error).isNotNull().isOfAnyClassIn(loggedException);
185180 } else {
186181 assertThat(e).isInstanceOf(expectedException);
187182 }
@@ -196,4 +191,4 @@
196191 .contains(loggedException.getName());
197192 }
198193
199-}
No newline at the end of the file
194+}
modified driver-core/src/test/java/com/datastax/driver/core/StreamIdGeneratorTest.java +3 −6
@@ -19,6 +19,8 @@
1919 import static org.testng.Assert.assertEquals;
2020 import static org.testng.Assert.fail;
2121
22+import com.datastax.driver.core.exceptions.BusyConnectionException;
23+
2224 public class StreamIdGeneratorTest {
2325
2426 @Test(groups = "unit")
@@ -42,11 +44,6 @@
4244 generator.release(100);
4345 assertEquals(generator.next(), 100);
4446
45- try {
46- generator.next();
47- fail("No more streamId should be available");
48- } catch (BusyConnectionException e) {
49- // Ok, expected
50- }
47+ assertEquals(generator.next(), -1);
5148 }
5249 }