BUG 2138: Introduce DistributedShardedDOMDataTree
[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 org.opendaylight.controller.cluster.access.concepts.MemberName;
14 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
15 import org.opendaylight.mdsal.dom.api.DOMDataTreeProducerException;
16 import org.opendaylight.mdsal.dom.api.DOMDataTreeShardingConflictException;
17 import org.opendaylight.yangtools.concepts.Registration;
18
19 /**
20  * A factory that handles addition of new clustered shard's based on a prefix. This factory is a QoL class that handles
21  * all the boilerplate that comes with registration of a new clustered shard into the system and creating the backend
22  * shard/replicas that come along with it.
23  */
24 @Beta
25 public interface DistributedShardFactory {
26
27     /**
28      * Register a new shard that is rooted at the desired prefix with replicas on the provided members.
29      * Note to register a shard without replicas you still need to provide at least one Member for the shard.
30      *
31      * @param prefix         Shard root
32      * @param replicaMembers Members that this shard is replicated on, has to have at least one Member even if the shard
33      *                       should not be replicated.
34      * @return ShardRegistration that should be closed if the shard should be destroyed
35      * @throws DOMDataTreeShardingConflictException If the prefix already has a shard registered
36      * @throws DOMDataTreeProducerException in case there is a problem closing the initial producer that is used to
37      *                                      register the shard into the ShardingService
38      */
39     DistributedShardRegistration createDistributedShard(DOMDataTreeIdentifier prefix,
40                                                         Collection<MemberName> replicaMembers)
41             throws DOMDataTreeShardingConflictException, DOMDataTreeProducerException,
42             DOMDataTreeShardCreationFailedException;
43
44     interface DistributedShardRegistration extends Registration {
45         @Override
46         void close();
47     }
48 }