2051e21d64cfe5efe178d8b5387b86e94ee1fa50
[controller.git] / opendaylight / md-sal / cds-dom-api / src / main / java / org / opendaylight / controller / cluster / dom / api / CDSShardAccess.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.dom.api;
9
10 import com.google.common.annotations.Beta;
11 import java.util.concurrent.CompletionStage;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
14
15 /**
16  * Unprivileged access interface to shard information. Provides read-only access to operational details about a CDS
17  * shard.
18  *
19  * @author Robert Varga
20  */
21 @Beta
22 public interface CDSShardAccess {
23     /**
24      * Return the shard identifier.
25      *
26      * @return Shard identifier.
27      * @throws IllegalStateException if the {@link CDSDataTreeProducer} from which the associated
28      *         {@link CDSDataTreeProducer} is no longer valid.
29      */
30     @NonNull DOMDataTreeIdentifier getShardIdentifier();
31
32     /**
33      * Return the shard leader location relative to the local node.
34      *
35      * @return Shard leader location.
36      * @throws IllegalStateException if the {@link CDSDataTreeProducer} from which the associated
37      *         {@link CDSDataTreeProducer} is no longer valid.
38      */
39     @NonNull LeaderLocation getLeaderLocation();
40
41     /**
42      * Request the shard leader to be moved to the local node. The request will be evaluated against shard state and
43      * satisfied if leader movement is possible. If current shard policy or state prevents the movement from happening,
44      * the returned {@link CompletionStage} will report an exception.
45      *
46      * <p>
47      * This is a one-time operation, which does not prevent further movement happening in future. Even if this request
48      * succeeds, there is no guarantee that the leader will remain local in face of failures, shutdown or any future
49      * movement requests from other nodes.
50      *
51      * <p>
52      * Note that due to asynchronous nature of CDS, the leader may no longer be local by the time the returned
53      * {@link CompletionStage} reports success.
54      *
55      * @return A {@link CompletionStage} representing the request.
56      * @throws IllegalStateException if the {@link CDSDataTreeProducer} from which the associated
57      *         {@link CDSDataTreeProducer} is no longer valid.
58      */
59     @NonNull CompletionStage<Void> makeLeaderLocal();
60
61     /**
62      * Register a listener to shard location changes. Each listener object can be registered at most once.
63      *
64      * @param listener Listener object
65      * @return A {@link LeaderLocationListenerRegistration} for the listener.
66      * @throws IllegalArgumentException if the specified listener is already registered.
67      * @throws IllegalStateException if the {@link CDSDataTreeProducer} from which the associated
68      *         {@link CDSDataTreeProducer} is no longer valid.
69      * @throws NullPointerException if listener is null.
70      */
71     @NonNull <L extends LeaderLocationListener> LeaderLocationListenerRegistration<L> registerLeaderLocationListener(
72             @NonNull L listener);
73 }