Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / cds-access-client / src / main / java / org / opendaylight / controller / cluster / access / client / AbstractClientActorBehavior.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.access.client;
9
10 import static java.util.Objects.requireNonNull;
11
12 import akka.actor.ActorRef;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.eclipse.jdt.annotation.Nullable;
15
16 /**
17  * Base behavior attached to {@link AbstractClientActor}.
18  *
19  * @param <C> Type of associated context
20  */
21 public abstract class AbstractClientActorBehavior<C extends AbstractClientActorContext> implements AutoCloseable {
22     private final @NonNull C context;
23
24     AbstractClientActorBehavior(final @NonNull C context) {
25         // Hidden to prevent outside subclasses. Users instantiated this via ClientActorBehavior
26         this.context = requireNonNull(context);
27     }
28
29     /**
30      * Return an {@link AbstractClientActorContext} associated with this {@link AbstractClientActor}.
31      *
32      * @return A client actor context instance.
33      */
34     protected final @NonNull C context() {
35         return context;
36     }
37
38     /**
39      * Return the persistence identifier associated with this {@link AbstractClientActor}. This identifier should be
40      * used in logging to identify this actor.
41      *
42      * @return Persistence identifier
43      */
44     protected final @NonNull String persistenceId() {
45         return context.persistenceId();
46     }
47
48     /**
49      * Return an {@link ActorRef} of this ClientActor.
50      *
51      * @return Actor associated with this behavior
52      */
53     public final @NonNull ActorRef self() {
54         return context.self();
55     }
56
57     @Override
58     public void close() {
59         // No-op
60     }
61
62     /**
63      * Implementation-internal method for handling an incoming command message.
64      *
65      * @param command Command message
66      * @return Behavior which should be used with the next message. Return null if this actor should shut down.
67      */
68     abstract @Nullable AbstractClientActorBehavior<?> onReceiveCommand(@NonNull Object command);
69
70     /**
71      * Implementation-internal method for handling an incoming recovery message coming from persistence.
72      *
73      * @param recover Recover message
74      * @return Behavior which should be used with the next message. Return null if this actor should shut down.
75      */
76     abstract @Nullable AbstractClientActorBehavior<?> onReceiveRecover(@NonNull Object recover);
77 }