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.client;
10 import static java.util.Objects.requireNonNull;
12 import akka.actor.ActorRef;
13 import com.google.common.annotations.Beta;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.Nullable;
18 * Base behavior attached to {@link AbstractClientActor}.
20 * @param <C> Type of associated context
22 * @author Robert Varga
25 public abstract class AbstractClientActorBehavior<C extends AbstractClientActorContext> implements AutoCloseable {
26 private final @NonNull C context;
28 AbstractClientActorBehavior(final @NonNull C context) {
29 // Hidden to prevent outside subclasses. Users instantiated this via ClientActorBehavior
30 this.context = requireNonNull(context);
34 * Return an {@link AbstractClientActorContext} associated with this {@link AbstractClientActor}.
36 * @return A client actor context instance.
38 protected final @NonNull C context() {
43 * Return the persistence identifier associated with this {@link AbstractClientActor}. This identifier should be
44 * used in logging to identify this actor.
46 * @return Persistence identifier
48 protected final @NonNull String persistenceId() {
49 return context.persistenceId();
53 * Return an {@link ActorRef} of this ClientActor.
55 * @return Actor associated with this behavior
57 public final @NonNull ActorRef self() {
58 return context.self();
66 * Implementation-internal method for handling an incoming command message.
68 * @param command Command message
69 * @return Behavior which should be used with the next message. Return null if this actor should shut down.
71 abstract @Nullable AbstractClientActorBehavior<?> onReceiveCommand(@NonNull Object command);
74 * Implementation-internal method for handling an incoming recovery message coming from persistence.
76 * @param recover Recover message
77 * @return Behavior which should be used with the next message. Return null if this actor should shut down.
79 abstract @Nullable AbstractClientActorBehavior<?> onReceiveRecover(@NonNull Object recover);