|
| 1 | +/* |
| 2 | + * Copyright 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 com.datastax.driver.core.ConsistencyLevel; |
| 19 | +import com.datastax.driver.core.EndPoint; |
| 20 | + |
| 21 | +public class CASWriteUnknownException extends QueryConsistencyException { |
| 22 | + |
| 23 | + private static final long serialVersionUID = 0; |
| 24 | + |
| 25 | + /** |
| 26 | + * This constructor should only be used internally by the driver when decoding error responses. |
| 27 | + */ |
| 28 | + public CASWriteUnknownException(ConsistencyLevel consistency, int received, int required) { |
| 29 | + this(null, consistency, received, required); |
| 30 | + } |
| 31 | + |
| 32 | + public CASWriteUnknownException( |
| 33 | + EndPoint endPoint, ConsistencyLevel consistency, int received, int required) { |
| 34 | + super( |
| 35 | + endPoint, |
| 36 | + String.format( |
| 37 | + "CAS operation result is unknown - proposal was not accepted by a quorum. (%d / %d)", |
| 38 | + received, required), |
| 39 | + consistency, |
| 40 | + received, |
| 41 | + required); |
| 42 | + } |
| 43 | + |
| 44 | + private CASWriteUnknownException( |
| 45 | + EndPoint endPoint, |
| 46 | + String msg, |
| 47 | + Throwable cause, |
| 48 | + ConsistencyLevel consistency, |
| 49 | + int received, |
| 50 | + int required) { |
| 51 | + super(endPoint, msg, cause, consistency, received, required); |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + public CASWriteUnknownException copy() { |
| 56 | + return new CASWriteUnknownException( |
| 57 | + getEndPoint(), |
| 58 | + getMessage(), |
| 59 | + this, |
| 60 | + getConsistencyLevel(), |
| 61 | + getReceivedAcknowledgements(), |
| 62 | + getRequiredAcknowledgements()); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Create a copy of this exception with a nicer stack trace, and including the coordinator address |
| 67 | + * that caused this exception to be raised. |
| 68 | + * |
| 69 | + * <p>This method is mainly intended for internal use by the driver and exists mainly because: |
| 70 | + * |
| 71 | + * <ol> |
| 72 | + * <li>the original exception was decoded from a response frame and at that time, the |
| 73 | + * coordinator address was not available; and |
| 74 | + * <li>the newly-created exception will refer to the current thread in its stack trace, which |
| 75 | + * generally yields a more user-friendly stack trace that the original one. |
| 76 | + * </ol> |
| 77 | + * |
| 78 | + * @param endPoint The full address of the host that caused this exception to be thrown. |
| 79 | + * @return a copy/clone of this exception, but with the given host address instead of the original |
| 80 | + * one. |
| 81 | + */ |
| 82 | + public CASWriteUnknownException copy(EndPoint endPoint) { |
| 83 | + return new CASWriteUnknownException( |
| 84 | + endPoint, |
| 85 | + getMessage(), |
| 86 | + this, |
| 87 | + getConsistencyLevel(), |
| 88 | + getReceivedAcknowledgements(), |
| 89 | + getRequiredAcknowledgements()); |
| 90 | + } |
| 91 | +} |
0 commit comments