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 org.eclipse.jdt.annotation.NonNull;
14 import org.eclipse.jdt.annotation.Nullable;
17 * Base behavior attached to {@link AbstractClientActor}.
19 * @param <C> Type of associated context
21 public abstract class AbstractClientActorBehavior<C extends AbstractClientActorContext> implements AutoCloseable {
22 private final @NonNull C context;
24 AbstractClientActorBehavior(final @NonNull C context) {
25 // Hidden to prevent outside subclasses. Users instantiated this via ClientActorBehavior
26 this.context = requireNonNull(context);
30 * Return an {@link AbstractClientActorContext} associated with this {@link AbstractClientActor}.
32 * @return A client actor context instance.
34 protected final @NonNull C context() {
39 * Return the persistence identifier associated with this {@link AbstractClientActor}. This identifier should be
40 * used in logging to identify this actor.
42 * @return Persistence identifier
44 protected final @NonNull String persistenceId() {
45 return context.persistenceId();
49 * Return an {@link ActorRef} of this ClientActor.
51 * @return Actor associated with this behavior
53 public final @NonNull ActorRef self() {
54 return context.self();
63 * Implementation-internal method for handling an incoming command message.
65 * @param command Command message
66 * @return Behavior which should be used with the next message. Return null if this actor should shut down.
68 abstract @Nullable AbstractClientActorBehavior<?> onReceiveCommand(@NonNull Object command);
71 * Implementation-internal method for handling an incoming recovery message coming from persistence.
73 * @param recover Recover message
74 * @return Behavior which should be used with the next message. Return null if this actor should shut down.
76 abstract @Nullable AbstractClientActorBehavior<?> onReceiveRecover(@NonNull Object recover);