2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.access.concepts;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import com.google.common.base.MoreObjects.ToStringHelper;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.controller.cluster.access.ABIVersion;
16 import org.opendaylight.yangtools.concepts.WritableIdentifier;
19 * A failure response to a {@link Request}. Contains a {@link RequestException} detailing the cause for this failure.
21 * @author Robert Varga
23 * @param <T> Target identifier type
24 * @param <C> Message class
27 public abstract class RequestFailure<T extends WritableIdentifier, C extends RequestFailure<T, C>>
28 extends Response<T, C> {
29 private static final long serialVersionUID = 1L;
31 private final @NonNull RequestException cause;
33 protected RequestFailure(final @NonNull C failure, final @NonNull ABIVersion version) {
34 super(failure, version);
35 this.cause = requireNonNull(failure.getCause());
38 protected RequestFailure(final @NonNull T target, final long sequence, final @NonNull RequestException cause) {
39 super(target, sequence);
40 this.cause = requireNonNull(cause);
44 * Return the failure cause.
46 * @return Failure cause.
48 public final @NonNull RequestException getCause() {
53 * Return an indication of whether this a hard failure. Hard failures must not be retried but need to be treated
54 * as authoritative response to a request.
56 * @return True if this represents a hard failure, false otherwise.
58 public final boolean isHardFailure() {
59 return !cause.isRetriable();
63 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
64 return super.addToStringAttributes(toStringHelper).add("cause", cause);
68 protected abstract AbstractRequestFailureProxy<T, C> externalizableProxy(ABIVersion version);