2 * Copyright (c) 2016, 2017 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 akka.actor.ActorRef;
11 import com.google.common.annotations.Beta;
12 import com.google.common.base.MoreObjects.ToStringHelper;
13 import com.google.common.base.Preconditions;
14 import javax.annotation.Nonnull;
15 import org.opendaylight.controller.cluster.access.ABIVersion;
16 import org.opendaylight.yangtools.concepts.WritableIdentifier;
19 * A request message concept. Upon receipt of this message, the recipient will respond with either
20 * a {@link RequestSuccess} or a {@link RequestFailure} message.
22 * @author Robert Varga
24 * @param <T> Target identifier type
25 * @param <C> Message type
28 public abstract class Request<T extends WritableIdentifier, C extends Request<T, C>> extends Message<T, C> {
29 private static final long serialVersionUID = 1L;
30 private final ActorRef replyTo;
32 protected Request(@Nonnull final T target, final long sequence, @Nonnull final ActorRef replyTo) {
33 super(target, sequence);
34 this.replyTo = Preconditions.checkNotNull(replyTo);
37 protected Request(@Nonnull final C request, @Nonnull final ABIVersion version) {
38 super(request, version);
39 this.replyTo = Preconditions.checkNotNull(request.getReplyTo());
43 * Return the return address where responses to this request should be directed to.
45 * @return Original requestor
48 public final ActorRef getReplyTo() {
53 * Return a {@link RequestFailure} for this request, caused by a {@link RequestException}.
55 * @param cause Failure cause
56 * @return {@link RequestFailure} corresponding to this request
59 public abstract RequestFailure<T, ?> toRequestFailure(@Nonnull RequestException cause);
62 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
63 return super.addToStringAttributes(toStringHelper).add("replyTo", replyTo);
67 protected abstract AbstractRequestProxy<T, C> externalizableProxy(@Nonnull ABIVersion version);