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.datastore.actors.client;
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.controller.cluster.access.concepts.RequestException;
15 import org.opendaylight.controller.cluster.access.concepts.RequestFailure;
16 import org.opendaylight.controller.cluster.access.concepts.RetiredGenerationException;
17 import org.opendaylight.yangtools.concepts.Identifiable;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
22 * A behavior, which handles messages sent to a {@link AbstractClientActor}.
24 * @param <T> Frontend type
26 * @author Robert Varga
29 public abstract class ClientActorBehavior extends RecoveredClientActorBehavior<ClientActorContext>
30 implements Identifiable<ClientIdentifier> {
31 private static final Logger LOG = LoggerFactory.getLogger(ClientActorBehavior.class);
33 protected ClientActorBehavior(final @Nonnull ClientActorContext context) {
38 final ClientActorBehavior onReceiveCommand(final Object command) {
39 if (command instanceof InternalCommand) {
40 return ((InternalCommand) command).execute();
41 } else if (command instanceof RequestFailure) {
42 final RequestFailure<?, ?> failure = (RequestFailure<?, ?>) command;
43 final RequestException cause = failure.getCause();
44 if (cause instanceof RetiredGenerationException) {
45 LOG.error("{}: current generation {} has been superseded", persistenceId(), getIdentifier(), cause);
51 // TODO: any client-common logic (such as validation and common dispatch) needs to go here
52 return onCommand(command);
56 public final @Nonnull ClientIdentifier getIdentifier() {
57 return context().getIdentifier();
61 * Halt And Catch Fire.
63 * Halt processing on this client. Implementations need to ensure they initiate state flush procedures. No attempt
64 * to use this instance should be made after this method returns. Any such use may result in undefined behavior.
66 * @param cause Failure cause
68 protected abstract void haltClient(@Nonnull Throwable cause);
71 * Override this method to handle any command which is not handled by the base behavior.
74 * @return Next behavior to use, null if this actor should shut down.
76 protected abstract @Nullable ClientActorBehavior onCommand(@Nonnull Object command);
79 * Override this method to provide a backend resolver instance.
83 protected abstract @Nonnull BackendInfoResolver<?> resolver();