2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.sharding;
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;
33 @Component(immediate = true, property = "type=default")
34 public final class OSGiDistributedShardedDOMDataTree
35 implements DOMDataTreeService, DOMDataTreeShardingService, DistributedShardFactory {
36 private static final Logger LOG = LoggerFactory.getLogger(OSGiDistributedShardedDOMDataTree.class);
39 ActorSystemProvider actorSystemProvider = null;
40 @Reference(target = "(type=distributed-config)")
41 DistributedDataStoreInterface configDatastore = null;
42 @Reference(target = "(type=distributed-operational)")
43 DistributedDataStoreInterface operDatastore = null;
45 private DistributedShardedDOMDataTree delegate;
48 public DOMDataTreeProducer createProducer(final Collection<DOMDataTreeIdentifier> subtrees) {
49 return delegate.createProducer(subtrees);
53 public ClassToInstanceMap<DOMDataTreeServiceExtension> getExtensions() {
54 return delegate.getExtensions();
58 public CompletionStage<DistributedShardRegistration> createDistributedShard(final DOMDataTreeIdentifier prefix,
59 final Collection<MemberName> replicaMembers) throws DOMDataTreeShardingConflictException {
60 return delegate.createDistributedShard(prefix, replicaMembers);
64 public <T extends DOMDataTreeShard> ListenerRegistration<T> registerDataTreeShard(
65 final DOMDataTreeIdentifier prefix, final T shard, final DOMDataTreeProducer producer)
66 throws DOMDataTreeShardingConflictException {
67 return delegate.registerDataTreeShard(prefix, shard, producer);
71 public <T extends DOMDataTreeListener> ListenerRegistration<T> registerListener(final T listener,
72 final Collection<DOMDataTreeIdentifier> subtrees, final boolean allowRxMerges,
73 final Collection<DOMDataTreeProducer> producers) throws DOMDataTreeLoopException {
74 return delegate.registerListener(listener, subtrees, allowRxMerges, producers);
79 LOG.info("Distributed DOM Data Tree Service starting");
80 delegate = new DistributedShardedDOMDataTree(actorSystemProvider, operDatastore, configDatastore);
82 LOG.info("Distributed DOM Data Tree Service started");
87 LOG.info("Distributed DOM Data Tree Service stopping");
88 // TODO: this needs a shutdown hook, I think
90 LOG.info("Distributed DOM Data Tree Service stopped");