BUG-2138: Make DistributedShardFactory return Futures.
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / sharding / DistributedShardFactory.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
9 package org.opendaylight.controller.cluster.sharding;
10
11 import com.google.common.annotations.Beta;
12 import java.util.Collection;
13 import java.util.concurrent.CompletionStage;
14 import org.opendaylight.controller.cluster.access.concepts.MemberName;
15 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
16 import org.opendaylight.mdsal.dom.api.DOMDataTreeShardingConflictException;
17
18 /**
19  * A factory that handles addition of new clustered shard's based on a prefix. This factory is a QoL class that handles
20  * all the boilerplate that comes with registration of a new clustered shard into the system and creating the backend
21  * shard/replicas that come along with it.
22  */
23 @Beta
24 public interface DistributedShardFactory {
25
26     /**
27      * Register a new shard that is rooted at the desired prefix with replicas on the provided members.
28      * Note to register a shard without replicas you still need to provide at least one Member for the shard.
29      *
30      * @param prefix         Shard root
31      * @param replicaMembers Members that this shard is replicated on, has to have at least one Member even if the shard
32      *                       should not be replicated.
33      * @return A future that will be completed with a DistributedShardRegistration once the backend and frontend shards
34      *         are spawned.
35      * @throws DOMDataTreeShardingConflictException If the initial check for a conflict on the local node fails, the
36      *         sharding configuration won't be updated if this exception is thrown.
37      */
38     CompletionStage<DistributedShardRegistration>
39         createDistributedShard(DOMDataTreeIdentifier prefix, Collection<MemberName> replicaMembers)
40             throws DOMDataTreeShardingConflictException;
41
42     /**
43      * Registration of the CDS shard that allows you to remove the shard from the system by closing the registration.
44      * This removal is done asynchronously.
45      */
46     interface DistributedShardRegistration {
47
48         /**
49          *  Removes the shard from the system, this removal is done asynchronously, the future completes once the
50          *  backend shard is no longer present.
51          */
52         CompletionStage<Void> close();
53     }
54 }

©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.