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.base.MoreObjects.ToStringHelper;
13 import java.io.Serial;
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 * @param <T> Target identifier type
22 * @param <C> Message class
24 public abstract class RequestFailure<T extends WritableIdentifier, C extends RequestFailure<T, C>>
25 extends Response<T, C> {
27 private static final long serialVersionUID = 1L;
29 private final @NonNull RequestException cause;
31 protected RequestFailure(final @NonNull C failure, final @NonNull ABIVersion version) {
32 super(failure, version);
33 this.cause = requireNonNull(failure.getCause());
36 protected RequestFailure(final @NonNull T target, final long sequence, final @NonNull RequestException cause) {
37 super(target, sequence);
38 this.cause = requireNonNull(cause);
42 * Return the failure cause.
44 * @return Failure cause.
46 public final @NonNull RequestException getCause() {
51 * Return an indication of whether this a hard failure. Hard failures must not be retried but need to be treated
52 * as authoritative response to a request.
54 * @return True if this represents a hard failure, false otherwise.
56 public final boolean isHardFailure() {
57 return !cause.isRetriable();
61 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
62 return super.addToStringAttributes(toStringHelper).add("cause", cause);
66 protected abstract AbstractRequestFailureProxy<T, C> externalizableProxy(ABIVersion version);