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.aaa.impl.password.service;
10 import com.google.common.annotations.Beta;
11 import com.google.common.collect.Iterables;
12 import java.util.Collection;
13 import org.checkerframework.checker.lock.qual.Holding;
14 import org.opendaylight.mdsal.binding.api.ClusteredDataTreeChangeListener;
15 import org.opendaylight.mdsal.binding.api.DataBroker;
16 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
17 import org.opendaylight.mdsal.binding.api.DataTreeModification;
18 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.aaa.password.service.config.rev170619.PasswordServiceConfig;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.aaa.password.service.config.rev170619.PasswordServiceConfigBuilder;
21 import org.opendaylight.yangtools.concepts.ListenerRegistration;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.osgi.service.component.ComponentFactory;
24 import org.osgi.service.component.ComponentInstance;
25 import org.osgi.service.component.annotations.Activate;
26 import org.osgi.service.component.annotations.Component;
27 import org.osgi.service.component.annotations.Deactivate;
28 import org.osgi.service.component.annotations.Reference;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 @Component(immediate = true)
34 public final class OSGiPasswordServiceConfigBootstrap
35 implements ClusteredDataTreeChangeListener<PasswordServiceConfig> {
36 private static final Logger LOG = LoggerFactory.getLogger(OSGiPasswordServiceConfigBootstrap.class);
39 DataBroker dataBroker = null;
41 @Reference(target = "(component.factory=" + OSGiPasswordServiceConfig.FACTORY_NAME + ")")
42 ComponentFactory configFactory = null;
44 private ListenerRegistration<?> registration;
45 private ComponentInstance instance;
48 synchronized void activate() {
49 registration = dataBroker.registerDataTreeChangeListener(
50 DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
51 InstanceIdentifier.create(PasswordServiceConfig.class)), this);
52 LOG.info("Listening for password service configuration");
56 synchronized void deactivate() {
59 if (instance != null) {
63 LOG.info("No longer listening for password service configuration");
67 public synchronized void onInitialData() {
72 public synchronized void onDataTreeChanged(final Collection<DataTreeModification<PasswordServiceConfig>> changes) {
73 // FIXME: at this point we need to populate default values -- from the XML file
74 updateInstance(Iterables.getLast(changes).getRootNode().getDataAfter());
78 private void updateInstance(final PasswordServiceConfig config) {
79 if (registration != null) {
80 final ComponentInstance newInstance = configFactory.newInstance(
81 OSGiPasswordServiceConfig.props(config != null ? config : new PasswordServiceConfigBuilder().build()));
82 if (instance != null) {
85 instance = newInstance;