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.mdsal.dom.schema.osgi.impl;
10 import static com.google.common.base.Verify.verifyNotNull;
12 import com.google.common.annotations.VisibleForTesting;
13 import java.util.Dictionary;
15 import java.util.function.Consumer;
16 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
17 import org.osgi.framework.FrameworkUtil;
18 import org.osgi.service.component.annotations.Activate;
19 import org.osgi.service.component.annotations.Component;
20 import org.osgi.service.component.annotations.Deactivate;
23 * A Factory Component for OSGi SR manifestation of a {@code Consumer<EffectiveModelContext>}. Instances of this
24 * component are created through by {@link OSGiDOMSchemaService} each time a listener is registered.
26 @Component(factory = ModelContextListener.FACTORY_NAME, service = ModelContextListener.class)
27 public final class ModelContextListener {
28 static final String FACTORY_NAME = "org.opendaylight.mdsal.dom.schema.osgi.impl.SchemaSchemaContextListener";
31 static final String DELEGATE = "org.opendaylight.mdsal.dom.schema.osgi.SchemaSchemaContextListener";
33 private Consumer<EffectiveModelContext> delegate = null;
36 public ModelContextListener(final Map<String, ?> properties) {
37 delegate = (Consumer<EffectiveModelContext>) verifyNotNull(properties.get(DELEGATE));
45 void onModelContextUpdated(final EffectiveModelContext newModelContext) {
46 delegate.accept(newModelContext);
49 static Dictionary<String, ?> props(final Consumer<EffectiveModelContext> delegate) {
50 return FrameworkUtil.asDictionary(Map.of(DELEGATE, delegate));