Fix CS warnings in cds-access-client and enable enforcement
[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 akka.actor.ActorRef;
11 import com.google.common.annotations.Beta;
12 import com.google.common.base.Preconditions;
13 import javax.annotation.Nonnull;
14 import javax.annotation.Nullable;
15
16 /**
17  * Base behavior attached to {@link AbstractClientActor}.
18  *
19  * @param <C> Type of associated context
20  *
21  * @author Robert Varga
22  */
23 @Beta
24 public abstract class AbstractClientActorBehavior<C extends AbstractClientActorContext> {
25     private final C context;
26
27     AbstractClientActorBehavior(@Nonnull final C context) {
28         // Hidden to prevent outside subclasses. Users instantiated this via ClientActorBehavior
29         this.context = Preconditions.checkNotNull(context);
30     }
31
32     /**
33      * Return an {@link AbstractClientActorContext} associated with this {@link AbstractClientActor}.
34      *
35      * @return A client actor context instance.
36      */
37     @Nonnull
38     protected final C context() {
39         return context;
40     }
41
42     /**
43      * Return the persistence identifier associated with this {@link AbstractClientActor}. This identifier should be
44      * used in logging to identify this actor.
45      *
46      * @return Persistence identifier
47      */
48     @Nonnull
49     protected final String persistenceId() {
50         return context.persistenceId();
51     }
52
53     /**
54      * Return an {@link ActorRef} of this ClientActor.
55      *
56      * @return Actor associated with this behavior
57      */
58     @Nonnull
59     public final ActorRef self() {
60         return context.self();
61     }
62
63     /**
64      * Implementation-internal method for handling an incoming command message.
65      *
66      * @param command Command message
67      * @return Behavior which should be used with the next message. Return null if this actor should shut down.
68      */
69     @Nullable
70     abstract AbstractClientActorBehavior<?> onReceiveCommand(@Nonnull Object command);
71
72     /**
73      * Implementation-internal method for handling an incoming recovery message coming from persistence.
74      *
75      * @param recover Recover message
76      * @return Behavior which should be used with the next message. Return null if this actor should shut down.
77      */
78     @Nullable
79     abstract AbstractClientActorBehavior<?> onReceiveRecover(@Nonnull Object recover);
80 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.