Reduce JSR305 proliferation
[controller.git] / opendaylight / md-sal / cds-access-client / src / main / java / org / opendaylight / controller / cluster / access / client / BackendInfoResolver.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 java.util.concurrent.CompletionStage;
12 import java.util.function.Consumer;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.concepts.Registration;
15
16 /**
17  * Caching resolver which resolves a cookie to a leader {@link ActorRef}. This class needs to be specialized by the
18  * client. It is used by {@link ClientActorBehavior} for request dispatch. Results are cached until they are invalidated
19  * by either the client actor (when a message timeout is detected) and by the specific frontend (on explicit
20  * invalidation or when updated information becomes available).
21  *
22  * <p>
23  * If the completion stage returned by this interface's methods fails with a
24  * {@link org.opendaylight.controller.cluster.access.concepts.RequestException}, it will be forwarded to all
25  * outstanding requests towards the leader. If it fails with a {@link java.util.concurrent.TimeoutException},
26  * resolution process will be retried. If it fails with any other cause, it will we wrapped as a
27  * {@link org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException} wrapping that cause.
28  *
29  * @author Robert Varga
30  */
31 public abstract class BackendInfoResolver<T extends BackendInfo> implements AutoCloseable {
32     /**
33      * Request resolution of a particular backend identified by a cookie. This request can be satisfied from the cache.
34      *
35      * @param cookie Backend cookie
36      * @return A {@link CompletionStage} resulting in information about the backend
37      */
38     public abstract @NonNull CompletionStage<? extends T> getBackendInfo(@NonNull Long cookie);
39
40     /**
41      * Request re-resolution of a particular backend identified by a cookie, indicating a particular information as
42      * being stale. If the implementation's cache holds the stale information, it should be purged.
43      *
44      * @param cookie Backend cookie
45      * @param staleInfo Stale backend information
46      * @return A {@link CompletionStage} resulting in information about the backend
47      */
48     public abstract @NonNull CompletionStage<? extends T> refreshBackendInfo(@NonNull Long cookie,
49             @NonNull T staleInfo);
50
51     /**
52      * Registers a callback to be notified when BackendInfo that may have been previously obtained is now stale and
53      * should be refreshed.
54      *
55      * @param callback the callback that takes the backend cookie whose BackendInfo is now stale.
56      * @return a Registration
57      */
58     public abstract @NonNull Registration notifyWhenBackendInfoIsStale(Consumer<Long> callback);
59
60     public abstract @NonNull String resolveCookieName(Long cookie);
61
62     @Override
63     public void close() {
64     }
65 }