b770b99871d79aaf95daea317a179e73fcf58bb5
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / actors / client / ClientActorBehavior.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.datastore.actors.client;
9
10 import com.google.common.annotations.Beta;
11 import javax.annotation.Nonnull;
12 import javax.annotation.Nullable;
13 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
14 import org.opendaylight.yangtools.concepts.Identifiable;
15
16 /**
17  * A behavior, which handles messages sent to a {@link AbstractClientActor}.
18  *
19  * @param <T> Frontend type
20  *
21  * @author Robert Varga
22  */
23 @Beta
24 public abstract class ClientActorBehavior extends RecoveredClientActorBehavior<ClientActorContext>
25         implements Identifiable<ClientIdentifier> {
26     protected ClientActorBehavior(final @Nonnull ClientActorContext context) {
27         super(context);
28     }
29
30     @Override
31     final ClientActorBehavior onReceiveCommand(final Object command) {
32         // TODO: any client-common logic (such as validation and common dispatch) needs to go here
33         return onCommand(command);
34     }
35
36     @Override
37     public final @Nonnull ClientIdentifier getIdentifier() {
38         return context().getIdentifier();
39     }
40
41     /**
42      * Override this method to handle any command which is not handled by the base behavior.
43      *
44      * @param command
45      * @return Next behavior to use, null if this actor should shut down.
46      */
47     protected abstract @Nullable ClientActorBehavior onCommand(@Nonnull Object command);
48 }