Bump versions to 4.0.0-SNAPSHOT
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / sharding / OSGiDistributedShardedDOMDataTree.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.sharding;
9
10 import com.google.common.collect.ClassToInstanceMap;
11 import java.util.Collection;
12 import java.util.concurrent.CompletionStage;
13 import org.opendaylight.controller.cluster.ActorSystemProvider;
14 import org.opendaylight.controller.cluster.access.concepts.MemberName;
15 import org.opendaylight.controller.cluster.datastore.DistributedDataStoreInterface;
16 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
17 import org.opendaylight.mdsal.dom.api.DOMDataTreeListener;
18 import org.opendaylight.mdsal.dom.api.DOMDataTreeLoopException;
19 import org.opendaylight.mdsal.dom.api.DOMDataTreeProducer;
20 import org.opendaylight.mdsal.dom.api.DOMDataTreeService;
21 import org.opendaylight.mdsal.dom.api.DOMDataTreeServiceExtension;
22 import org.opendaylight.mdsal.dom.api.DOMDataTreeShard;
23 import org.opendaylight.mdsal.dom.api.DOMDataTreeShardingConflictException;
24 import org.opendaylight.mdsal.dom.api.DOMDataTreeShardingService;
25 import org.opendaylight.yangtools.concepts.ListenerRegistration;
26 import org.osgi.service.component.annotations.Activate;
27 import org.osgi.service.component.annotations.Component;
28 import org.osgi.service.component.annotations.Deactivate;
29 import org.osgi.service.component.annotations.Reference;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 @Component(immediate = true, property = "type=default")
34 @Deprecated(forRemoval = true)
35 public final class OSGiDistributedShardedDOMDataTree
36         implements DOMDataTreeService, DOMDataTreeShardingService, DistributedShardFactory {
37     private static final Logger LOG = LoggerFactory.getLogger(OSGiDistributedShardedDOMDataTree.class);
38
39     @Reference
40     ActorSystemProvider actorSystemProvider = null;
41     @Reference(target = "(type=distributed-config)")
42     DistributedDataStoreInterface configDatastore = null;
43     @Reference(target = "(type=distributed-operational)")
44     DistributedDataStoreInterface operDatastore = null;
45
46     private DistributedShardedDOMDataTree delegate;
47
48     @Override
49     public DOMDataTreeProducer createProducer(final Collection<DOMDataTreeIdentifier> subtrees) {
50         return delegate.createProducer(subtrees);
51     }
52
53     @Override
54     public ClassToInstanceMap<DOMDataTreeServiceExtension> getExtensions() {
55         return delegate.getExtensions();
56     }
57
58     @Override
59     public CompletionStage<DistributedShardRegistration> createDistributedShard(final DOMDataTreeIdentifier prefix,
60             final Collection<MemberName> replicaMembers) throws DOMDataTreeShardingConflictException {
61         return delegate.createDistributedShard(prefix, replicaMembers);
62     }
63
64     @Override
65     public <T extends DOMDataTreeShard> ListenerRegistration<T> registerDataTreeShard(
66             final DOMDataTreeIdentifier prefix, final T shard, final DOMDataTreeProducer producer)
67             throws DOMDataTreeShardingConflictException {
68         return delegate.registerDataTreeShard(prefix, shard, producer);
69     }
70
71     @Override
72     public <T extends DOMDataTreeListener> ListenerRegistration<T> registerListener(final T listener,
73             final Collection<DOMDataTreeIdentifier> subtrees, final boolean allowRxMerges,
74             final Collection<DOMDataTreeProducer> producers) throws DOMDataTreeLoopException {
75         return delegate.registerListener(listener, subtrees, allowRxMerges, producers);
76     }
77
78     @Activate
79     void activate() {
80         LOG.info("Distributed DOM Data Tree Service starting");
81         delegate = new DistributedShardedDOMDataTree(actorSystemProvider, operDatastore, configDatastore);
82         delegate.init();
83         LOG.info("Distributed DOM Data Tree Service started");
84     }
85
86     @Deactivate
87     void deactivate() {
88         LOG.info("Distributed DOM Data Tree Service stopping");
89         // TODO: this needs a shutdown hook, I think
90         delegate = null;
91         LOG.info("Distributed DOM Data Tree Service stopped");
92     }
93 }