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 com.google.common.annotations.Beta;
11 import com.google.common.base.MoreObjects.ToStringHelper;
12 import com.google.common.base.Preconditions;
13 import javax.annotation.Nonnull;
14 import org.opendaylight.controller.cluster.access.ABIVersion;
15 import org.opendaylight.yangtools.concepts.WritableIdentifier;
18 * A failure response to a {@link Request}. Contains a {@link RequestException} detailing the cause for this failure.
20 * @author Robert Varga
22 * @param <T> Target identifier type
23 * @param <C> Message class
26 public abstract class RequestFailure<T extends WritableIdentifier, C extends RequestFailure<T, C>> extends Response<T, C> {
27 private static final long serialVersionUID = 1L;
28 private final RequestException cause;
30 protected RequestFailure(final @Nonnull C failure, final @Nonnull ABIVersion version) {
31 super(failure, version);
32 this.cause = Preconditions.checkNotNull(failure.getCause());
35 protected RequestFailure(final @Nonnull T target, final long sequence, final long retry,
36 final @Nonnull RequestException cause) {
37 super(target, sequence, retry);
38 this.cause = Preconditions.checkNotNull(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(@Nonnull ABIVersion version);