From 35d50d7b5b69ebb08c753a699bf0aa1e645027fe Mon Sep 17 00:00:00 2001 From: Jan Hajnar Date: Tue, 17 Feb 2015 16:47:54 +0100 Subject: [PATCH] Bug 2578 - Added Binding Adapters for new Notification Broker Implement and integrate Binding to DOM Notification adapters * implemented forwarded notification broker * added simple test for forwarded notification broker * added configuration of new modules and services to md-sal config Change-Id: I259c971f0dc61bc1b00cbaad2956c3d8b37ff780 Signed-off-by: Jan Hajnar --- .../src/main/resources/initial/01-md-sal.xml | 42 +++++++ .../BindingNotificationAdapterModule.java | 40 +++++++ ...ndingNotificationAdapterModuleFactory.java | 11 ++ ...ndingNotificationPublishAdapterModule.java | 39 ++++++ ...tificationPublishAdapterModuleFactory.java | 11 ++ .../sal/binding/impl/DummyNoopProvider.java | 27 +++++ .../impl/NotificationBrokerImplModule.java | 10 +- .../impl/BindingToNormalizedNodeCodec.java | 7 +- .../ForwardedNotificationPublishService.java | 80 +++++++++++++ .../impl/ForwardedNotificationService.java | 95 +++++++++++++++ ...iumNotificationProviderServiceAdapter.java | 59 +++++++++ .../HeliumNotificationServiceAdapter.java | 39 ++++++ .../opendaylight-binding-broker-impl.yang | 47 +++++++- ...wardsCompatibleNotificationBrokerTest.java | 84 +++++++++++++ .../ForwardedNotificationAdapterTest.java | 113 ++++++++++++++++++ .../test/AbstractNotificationBrokerTest.java | 52 ++++++++ .../binding/test/AbstractSchemaAwareTest.java | 4 +- .../test/DataBrokerTestCustomizer.java | 23 +++- .../yang/opendaylight-md-sal-binding.yang | 8 +- .../api/DOMNotificationPublishService.java | 3 +- .../sal/dom/api/DOMNotificationService.java | 3 +- .../md/sal/dom/impl/DomBrokerImplModule.java | 9 ++ .../sal/dom/broker/osgi/ProxyFactory.java | 14 +-- .../yang/opendaylight-mdsal-list-test.yang | 6 +- 24 files changed, 801 insertions(+), 25 deletions(-) create mode 100644 opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/BindingNotificationAdapterModule.java create mode 100644 opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/BindingNotificationAdapterModuleFactory.java create mode 100644 opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/BindingNotificationPublishAdapterModule.java create mode 100644 opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/BindingNotificationPublishAdapterModuleFactory.java create mode 100644 opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/DummyNoopProvider.java create mode 100644 opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/ForwardedNotificationPublishService.java create mode 100644 opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/ForwardedNotificationService.java create mode 100644 opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/compat/HeliumNotificationProviderServiceAdapter.java create mode 100644 opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/compat/HeliumNotificationServiceAdapter.java create mode 100644 opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/BackwardsCompatibleNotificationBrokerTest.java create mode 100644 opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/ForwardedNotificationAdapterTest.java create mode 100644 opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/test/AbstractNotificationBrokerTest.java diff --git a/opendaylight/md-sal/md-sal-config/src/main/resources/initial/01-md-sal.xml b/opendaylight/md-sal/md-sal-config/src/main/resources/initial/01-md-sal.xml index b9159dccd1..8b645274db 100644 --- a/opendaylight/md-sal/md-sal-config/src/main/resources/initial/01-md-sal.xml +++ b/opendaylight/md-sal/md-sal-config/src/main/resources/initial/01-md-sal.xml @@ -20,6 +20,34 @@ prefix:runtime-generated-mapping runtime-mapping-singleton + + prefix:binding-notification-adapter + binding-notification-adapter + + + binding:binding-dom-mapping-service + runtime-mapping-singleton + + + dom:dom-broker-osgi-registry + dom-broker + + + + + prefix:binding-notification-publish-adapter + binding-notification-publish-adapter + + + binding:binding-dom-mapping-service + runtime-mapping-singleton + + + dom:dom-broker-osgi-registry + dom-broker + + + prefix:binding-notification-broker binding-notification-broker @@ -184,6 +212,20 @@ /modules/module[type='runtime-generated-mapping'][name='runtime-mapping-singleton'] + + binding-impl:binding-new-notification-service + + binding-notification-adapter + /modules/module[type='binding-notification-adapter'][name='binding-notification-adapter'] + + + + binding-impl:binding-new-notification-publish-service + + binding-notification-publish-adapter + /modules/module[type='binding-notification-publish-adapter'][name='binding-notification-publish-adapter'] + + binding:binding-notification-service diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/BindingNotificationAdapterModule.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/BindingNotificationAdapterModule.java new file mode 100644 index 0000000000..e786151299 --- /dev/null +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/BindingNotificationAdapterModule.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.config.yang.md.sal.binding.impl; + +import org.opendaylight.controller.config.api.DependencyResolver; +import org.opendaylight.controller.config.api.ModuleIdentifier; +import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec; +import org.opendaylight.controller.md.sal.binding.impl.ForwardedNotificationService; +import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService; +import org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder; +import org.opendaylight.controller.sal.core.api.Broker; + +public class BindingNotificationAdapterModule extends AbstractBindingNotificationAdapterModule { + public BindingNotificationAdapterModule(ModuleIdentifier identifier, DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public BindingNotificationAdapterModule(ModuleIdentifier identifier, DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.md.sal.binding.impl.BindingNotificationAdapterModule oldModule, java.lang.AutoCloseable oldInstance) { + super(identifier, dependencyResolver, oldModule, oldInstance); + } + + @Override + public void customValidation() { + // add custom validation form module attributes here. + } + + @Override + public java.lang.AutoCloseable createInstance() { + final BindingToNormalizedNodeCodec codec = getBindingMappingServiceDependency(); + final Broker.ProviderSession session = getDomAsyncBrokerDependency().registerProvider(new DummyDOMProvider()); + final DOMNotificationService notifService = session.getService(DOMNotificationService.class); + return new ForwardedNotificationService(codec.getCodecRegistry(), notifService, SingletonHolder.INVOKER_FACTORY); + } + +} diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/BindingNotificationAdapterModuleFactory.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/BindingNotificationAdapterModuleFactory.java new file mode 100644 index 0000000000..0a5cb91433 --- /dev/null +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/BindingNotificationAdapterModuleFactory.java @@ -0,0 +1,11 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.config.yang.md.sal.binding.impl; +public class BindingNotificationAdapterModuleFactory extends org.opendaylight.controller.config.yang.md.sal.binding.impl.AbstractBindingNotificationAdapterModuleFactory { + +} diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/BindingNotificationPublishAdapterModule.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/BindingNotificationPublishAdapterModule.java new file mode 100644 index 0000000000..bdac710ecb --- /dev/null +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/BindingNotificationPublishAdapterModule.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.config.yang.md.sal.binding.impl; + +import org.opendaylight.controller.config.api.DependencyResolver; +import org.opendaylight.controller.config.api.ModuleIdentifier; +import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec; +import org.opendaylight.controller.md.sal.binding.impl.ForwardedNotificationPublishService; +import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService; +import org.opendaylight.controller.sal.core.api.Broker; + +public class BindingNotificationPublishAdapterModule extends AbstractBindingNotificationPublishAdapterModule { + public BindingNotificationPublishAdapterModule(ModuleIdentifier identifier, DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public BindingNotificationPublishAdapterModule(ModuleIdentifier identifier, DependencyResolver dependencyResolver, BindingNotificationPublishAdapterModule oldModule, java.lang.AutoCloseable oldInstance) { + super(identifier, dependencyResolver, oldModule, oldInstance); + } + + @Override + public void customValidation() { + // add custom validation form module attributes here. + } + + @Override + public java.lang.AutoCloseable createInstance() { + final BindingToNormalizedNodeCodec codec = getBindingMappingServiceDependency(); + final Broker.ProviderSession session = getDomAsyncBrokerDependency().registerProvider(new DummyDOMProvider()); + final DOMNotificationPublishService publishService = session.getService(DOMNotificationPublishService.class); + return new ForwardedNotificationPublishService(codec.getCodecRegistry(), publishService); + } + +} diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/BindingNotificationPublishAdapterModuleFactory.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/BindingNotificationPublishAdapterModuleFactory.java new file mode 100644 index 0000000000..e9a3df6a5f --- /dev/null +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/BindingNotificationPublishAdapterModuleFactory.java @@ -0,0 +1,11 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.config.yang.md.sal.binding.impl; +public class BindingNotificationPublishAdapterModuleFactory extends org.opendaylight.controller.config.yang.md.sal.binding.impl.AbstractBindingNotificationPublishAdapterModuleFactory { + +} diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/DummyNoopProvider.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/DummyNoopProvider.java new file mode 100644 index 0000000000..ca3054e692 --- /dev/null +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/DummyNoopProvider.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.config.yang.md.sal.binding.impl; + +import java.util.Collection; +import java.util.Collections; +import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; +import org.opendaylight.controller.sal.core.api.Provider; + +class DummyDOMProvider implements Provider { + + @Override + @Deprecated + public Collection getProviderFunctionality() { + return Collections.emptyList(); + } + + @Override + public void onSessionInitiated(ProviderSession session) { + // NOOP + } +} diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/NotificationBrokerImplModule.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/NotificationBrokerImplModule.java index b6c27a6332..415c9783da 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/NotificationBrokerImplModule.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/NotificationBrokerImplModule.java @@ -7,11 +7,10 @@ */ package org.opendaylight.controller.config.yang.md.sal.binding.impl; +import com.google.common.util.concurrent.ListeningExecutorService; import org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder; import org.opendaylight.controller.sal.binding.impl.NotificationBrokerImpl; -import com.google.common.util.concurrent.ListeningExecutorService; - /** * */ @@ -37,6 +36,13 @@ public final class NotificationBrokerImplModule extends @Override public java.lang.AutoCloseable createInstance() { + + /* + * FIXME: Switch to new broker (which has different threading model) + * once this change is communicated with downstream users or + * we will have adapter implementation which will honor Helium + * threading model for notifications. + */ ListeningExecutorService listeningExecutor = SingletonHolder.getDefaultNotificationExecutor(); NotificationBrokerImpl broker = new NotificationBrokerImpl(listeningExecutor); return broker; diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToNormalizedNodeCodec.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToNormalizedNodeCodec.java index d7314e5362..a973e67739 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToNormalizedNodeCodec.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToNormalizedNodeCodec.java @@ -9,12 +9,9 @@ package org.opendaylight.controller.md.sal.binding.impl; import com.google.common.base.Function; import com.google.common.base.Optional; - import java.util.Iterator; import java.util.Map.Entry; - import javax.annotation.Nonnull; - import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException; import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationOperation; import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizer; @@ -143,6 +140,10 @@ public class BindingToNormalizedNodeCodec implements SchemaContextListener,AutoC return bindingToLegacy; } + public BindingNormalizedNodeCodecRegistry getCodecRegistry() { + return codecRegistry; + } + @Override public void close() { // NOOP Intentionally diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/ForwardedNotificationPublishService.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/ForwardedNotificationPublishService.java new file mode 100644 index 0000000000..14d6713a6c --- /dev/null +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/ForwardedNotificationPublishService.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.md.sal.binding.impl; + +import com.google.common.util.concurrent.ListenableFuture; +import java.util.concurrent.TimeUnit; +import javax.annotation.Nonnull; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.controller.md.sal.dom.api.DOMNotification; +import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService; +import org.opendaylight.yangtools.binding.data.codec.api.BindingNormalizedNodeSerializer; +import org.opendaylight.yangtools.yang.binding.Notification; +import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; +import org.opendaylight.yangtools.yang.model.api.SchemaPath; + +public class ForwardedNotificationPublishService implements NotificationPublishService, AutoCloseable { + private final BindingNormalizedNodeSerializer codecRegistry; + private final DOMNotificationPublishService domPublishService; + + public ForwardedNotificationPublishService(BindingNormalizedNodeSerializer codecRegistry, DOMNotificationPublishService domPublishService) { + this.codecRegistry = codecRegistry; + this.domPublishService = domPublishService; + } + + @Override + public void putNotification(final Notification notification) throws InterruptedException { + domPublishService.putNotification(toDomNotification(notification)); + } + + @Override + public boolean offerNotification(final Notification notification) { + final ListenableFuture listenableFuture = domPublishService.offerNotification(toDomNotification(notification)); + return !DOMNotificationPublishService.REJECTED.equals(listenableFuture); + } + + @Override + public boolean offerNotification(final Notification notification, final int timeout, final TimeUnit unit) throws InterruptedException { + final ListenableFuture listenableFuture = + domPublishService.offerNotification(toDomNotification(notification), timeout, unit); + return !DOMNotificationPublishService.REJECTED.equals(listenableFuture); + } + + private DOMNotification toDomNotification(final Notification notification) { + final ContainerNode domNotification = codecRegistry.toNormalizedNodeNotification(notification); + return new DOMNotificationImpl(domNotification); + } + + @Override + public void close() throws Exception { + + } + + private static class DOMNotificationImpl implements DOMNotification { + + private final SchemaPath type; + private final ContainerNode body; + + public DOMNotificationImpl(final ContainerNode body) { + this.type = SchemaPath.create(true, body.getIdentifier().getNodeType()); + this.body = body; + } + + @Nonnull + @Override + public SchemaPath getType() { + return this.type; + } + + @Nonnull + @Override + public ContainerNode getBody() { + return this.body; + } + } +} diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/ForwardedNotificationService.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/ForwardedNotificationService.java new file mode 100644 index 0000000000..fc7a742d5e --- /dev/null +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/ForwardedNotificationService.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.md.sal.binding.impl; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Set; +import javax.annotation.Nonnull; +import org.opendaylight.controller.md.sal.binding.api.NotificationService; +import org.opendaylight.controller.md.sal.dom.api.DOMNotification; +import org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener; +import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService; +import org.opendaylight.controller.sal.binding.spi.NotificationInvokerFactory; +import org.opendaylight.yangtools.binding.data.codec.api.BindingNormalizedNodeSerializer; +import org.opendaylight.yangtools.concepts.AbstractListenerRegistration; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.Notification; +import org.opendaylight.yangtools.yang.binding.NotificationListener; +import org.opendaylight.yangtools.yang.binding.util.BindingReflections; +import org.opendaylight.yangtools.yang.model.api.SchemaPath; + +public class ForwardedNotificationService implements NotificationService, AutoCloseable { + + private final BindingNormalizedNodeSerializer codec; + private final DOMNotificationService domNotifService; + private final NotificationInvokerFactory notificationInvokerFactory; + + public ForwardedNotificationService(BindingNormalizedNodeSerializer codec, DOMNotificationService domNotifService, NotificationInvokerFactory notificationInvokerFactory) { + this.codec = codec; + this.domNotifService = domNotifService; + this.notificationInvokerFactory = notificationInvokerFactory; + } + + @Override + public ListenerRegistration registerNotificationListener(T listener) { + final NotificationInvokerFactory.NotificationInvoker invoker = notificationInvokerFactory.invokerFor(listener); + final DOMNotificationListener domListener = new NotificationInvokerImpl(invoker); + final Collection schemaPaths = convertNotifTypesToSchemaPath(invoker.getSupportedNotifications()); + final ListenerRegistration domRegistration = + domNotifService.registerNotificationListener(domListener, schemaPaths); + return new ListenerRegistrationImpl<>(listener, domRegistration); + } + + + + private Collection convertNotifTypesToSchemaPath(Set> notificationTypes) { + final List schemaPaths = new ArrayList<>(); + for (Class notificationType : notificationTypes) { + schemaPaths.add(SchemaPath.create(true, BindingReflections.findQName(notificationType))); + } + return schemaPaths; + } + + @Override + public void close() throws Exception { + + } + + private static class ListenerRegistrationImpl extends AbstractListenerRegistration { + private final ListenerRegistration listenerRegistration; + + public ListenerRegistrationImpl(T listener, ListenerRegistration listenerRegistration) { + super(listener); + this.listenerRegistration = listenerRegistration; + } + + @Override + protected void removeRegistration() { + listenerRegistration.close(); + } + } + + private class NotificationInvokerImpl implements DOMNotificationListener { + private final NotificationInvokerFactory.NotificationInvoker invoker; + + public NotificationInvokerImpl(NotificationInvokerFactory.NotificationInvoker invoker) { + this.invoker = invoker; + } + + @Override + public void onNotification(@Nonnull DOMNotification notification) { + final Notification baNotification = + codec.fromNormalizedNodeNotification(notification.getType(), notification.getBody()); + invoker.getInvocationProxy().onNotification(baNotification); + + } + } + +} diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/compat/HeliumNotificationProviderServiceAdapter.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/compat/HeliumNotificationProviderServiceAdapter.java new file mode 100644 index 0000000000..e0aedb265c --- /dev/null +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/compat/HeliumNotificationProviderServiceAdapter.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.md.sal.binding.impl.compat; + +import java.util.concurrent.ExecutorService; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.controller.md.sal.binding.api.NotificationService; +import org.opendaylight.controller.sal.binding.api.NotificationProviderService; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.Notification; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class HeliumNotificationProviderServiceAdapter extends HeliumNotificationServiceAdapter implements NotificationProviderService, AutoCloseable { + private static final Logger LOG = LoggerFactory.getLogger(HeliumNotificationProviderServiceAdapter.class); + + private final NotificationPublishService notificationPublishService; + + public HeliumNotificationProviderServiceAdapter(NotificationPublishService notificationPublishService, + NotificationService notificationService) { + super(notificationService); + this.notificationPublishService = notificationPublishService; + } + + @Override + public void publish(final Notification notification) { + try { + notificationPublishService.putNotification(notification); + } catch (InterruptedException e) { + LOG.error("Notification publication was interupted: " + e); + } + } + + @Override + public void publish(final Notification notification, final ExecutorService executor) { + try { + notificationPublishService.putNotification(notification); + } catch (InterruptedException e) { + LOG.error("Notification publication was interupted: " + e); + } + } + + @Override + public ListenerRegistration registerInterestListener( + NotificationInterestListener interestListener) { + throw new UnsupportedOperationException("InterestListener is not supported."); + } + + @Override + public void close() throws Exception { + + } + +} diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/compat/HeliumNotificationServiceAdapter.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/compat/HeliumNotificationServiceAdapter.java new file mode 100644 index 0000000000..d68ea1c1ca --- /dev/null +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/compat/HeliumNotificationServiceAdapter.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.md.sal.binding.impl.compat; + +import org.opendaylight.controller.md.sal.binding.api.NotificationService; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.Notification; +import org.opendaylight.yangtools.yang.binding.NotificationListener; + +public class HeliumNotificationServiceAdapter implements org.opendaylight.controller.sal.binding.api.NotificationService, AutoCloseable { + + private final NotificationService notificationService; + + public HeliumNotificationServiceAdapter(NotificationService notificationService) { + this.notificationService = notificationService; + } + + @Override + public ListenerRegistration> registerNotificationListener( + final Class notificationType, final org.opendaylight.controller.sal.binding.api.NotificationListener listener) { + throw new UnsupportedOperationException("Not supported type of listener."); + } + + @Override + public ListenerRegistration registerNotificationListener( + final NotificationListener listener) { + return notificationService.registerNotificationListener(listener); + } + + @Override + public void close() throws Exception { + + } +} diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/yang/opendaylight-binding-broker-impl.yang b/opendaylight/md-sal/sal-binding-broker/src/main/yang/opendaylight-binding-broker-impl.yang index de8ab63c0a..8e2808936c 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/yang/opendaylight-binding-broker-impl.yang +++ b/opendaylight/md-sal/sal-binding-broker/src/main/yang/opendaylight-binding-broker-impl.yang @@ -21,6 +21,18 @@ module opendaylight-sal-binding-broker-impl { config:java-class "org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec"; } + /* FIXME: move to opendaylight-md-sal-binding (cannot be there due to Class name confict with old implementation)*/ + identity binding-new-notification-service { + base config:service-type; + config:java-class "org.opendaylight.controller.md.sal.binding.api.NotificationService"; + } + + /* TODO: move to opendaylight-md-sal-binding (cannot be there due to Class name confict with old implementation)*/ + identity binding-new-notification-publish-service { + base config:service-type; + config:java-class "org.opendaylight.controller.md.sal.binding.api.NotificationPublishService"; + } + identity binding-broker-impl { base config:module-type; config:provided-service sal:binding-broker-osgi-registry; @@ -34,7 +46,7 @@ module opendaylight-sal-binding-broker-impl { config:provided-service sal:binding-data-consumer-broker; config:java-name-prefix ForwardedCompatibleDataBrokerImpl; } - + identity binding-forwarded-data-broker { base config:module-type; config:provided-service sal:binding-async-data-broker; @@ -60,6 +72,18 @@ module opendaylight-sal-binding-broker-impl { config:java-name-prefix RuntimeMapping; } + identity binding-notification-adapter { + base config:module-type; + config:provided-service binding-new-notification-service; + config:java-name-prefix BindingNotificationAdapter; + } + + identity binding-notification-publish-adapter { + base config:module-type; + config:provided-service binding-new-notification-publish-service; + config:java-name-prefix BindingNotificationPublishAdapter; + } + grouping dom-forwarding-component { container dom-async-broker { uses config:service-ref { @@ -130,7 +154,7 @@ module opendaylight-sal-binding-broker-impl { uses dom-forwarding-component; } } - + augment "/config:modules/config:module/config:configuration" { case binding-forwarded-data-broker { when "/config:modules/config:module/config:type = 'binding-forwarded-data-broker'"; @@ -178,10 +202,29 @@ module opendaylight-sal-binding-broker-impl { uses common:rpc-state; } } + augment "/config:modules/config:module/config:state" { case binding-notification-broker { when "/config:modules/config:module/config:type = 'binding-notification-broker'"; uses common:notification-state; } } + + augment "/config:modules/config:module/config:configuration" { + case binding-notification-adapter { + when "/config:modules/config:module/config:type = 'binding-notification-adapter'"; + container binding-notification-adapter { + uses dom-forwarding-component; + } + } + } + + augment "/config:modules/config:module/config:configuration" { + case binding-notification-publish-adapter { + when "/config:modules/config:module/config:type = 'binding-notification-publish-adapter'"; + container binding-notification-publish-adapter { + uses dom-forwarding-component; + } + } + } } diff --git a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/BackwardsCompatibleNotificationBrokerTest.java b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/BackwardsCompatibleNotificationBrokerTest.java new file mode 100644 index 0000000000..6da16338d9 --- /dev/null +++ b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/BackwardsCompatibleNotificationBrokerTest.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.md.sal.binding.impl.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import com.google.common.collect.ImmutableList; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.controller.md.sal.binding.api.NotificationService; +import org.opendaylight.controller.md.sal.binding.impl.compat.HeliumNotificationProviderServiceAdapter; +import org.opendaylight.controller.md.sal.binding.test.AbstractNotificationBrokerTest; +import org.opendaylight.controller.sal.binding.api.NotificationProviderService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.OpendaylightMdsalListTestListener; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.TwoLevelListChanged; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.TwoLevelListChangedBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.NotificationListener; + +public class BackwardsCompatibleNotificationBrokerTest extends AbstractNotificationBrokerTest { + + private NotificationProviderService notificationProviderService; + + @Before + public void initTest() { + final NotificationService notificationService = getNotificationService(); + final NotificationPublishService notificationPublishService = getNotificationPublishService(); + notificationProviderService = new HeliumNotificationProviderServiceAdapter(notificationPublishService, notificationService); + } + + private TwoLevelListChanged createTestData() { + final TwoLevelListChangedBuilder tb = new TwoLevelListChangedBuilder(); + tb.setTopLevelList(ImmutableList.of(new TopLevelListBuilder().setKey(new TopLevelListKey("test")).build())); + return tb.build(); + } + + @Test + public void testNotifSubscriptionForwarded() throws InterruptedException { + final CountDownLatch latch = new CountDownLatch(1); + final TwoLevelListChanged testData = createTestData(); + + final NotifTestListener testNotifListener = new NotifTestListener(latch); + final ListenerRegistration listenerRegistration = + notificationProviderService.registerNotificationListener(testNotifListener); + notificationProviderService.publish(testData); + + latch.await(); + assertTrue(testNotifListener.getReceivedNotifications().size() == 1); + assertEquals(testData, testNotifListener.getReceivedNotifications().get(0)); + listenerRegistration.close(); + } + + private static class NotifTestListener implements OpendaylightMdsalListTestListener { + private List receivedNotifications = new ArrayList<>(); + private CountDownLatch latch; + + public NotifTestListener(CountDownLatch latch) { + this.latch = latch; + } + + @Override + public void onTwoLevelListChanged(TwoLevelListChanged notification) { + receivedNotifications.add(notification); + latch.countDown(); + } + + public List getReceivedNotifications() { + return receivedNotifications; + } + } + +} diff --git a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/ForwardedNotificationAdapterTest.java b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/ForwardedNotificationAdapterTest.java new file mode 100644 index 0000000000..c2cdc0caaa --- /dev/null +++ b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/ForwardedNotificationAdapterTest.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.md.sal.binding.impl.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import org.junit.Test; +import org.opendaylight.controller.md.sal.binding.test.AbstractNotificationBrokerTest; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.OpendaylightMdsalListTestListener; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.TwoLevelListChanged; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.TwoLevelListChangedBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.YangModuleInfo; +import org.opendaylight.yangtools.yang.binding.util.BindingReflections; + +public class ForwardedNotificationAdapterTest extends AbstractNotificationBrokerTest { + + @Override + protected Iterable getModuleInfos() throws Exception { + return ImmutableSet.of(BindingReflections.getModuleInfo(TwoLevelListChanged.class)); + + } + + private TwoLevelListChanged createTestData() { + final TwoLevelListChangedBuilder tb = new TwoLevelListChangedBuilder(); + tb.setTopLevelList(ImmutableList.of(new TopLevelListBuilder().setKey(new TopLevelListKey("test")).build())); + return tb.build(); + } + + @Test + public void testNotifSubscription() throws InterruptedException { + final CountDownLatch latch = new CountDownLatch(1); + final TwoLevelListChanged testData = createTestData(); + + final TestNotifListener testNotifListener = new TestNotifListener(latch); + final ListenerRegistration listenerRegistration = getNotificationService() + .registerNotificationListener(testNotifListener); + getNotificationPublishService().putNotification(testData); + + latch.await(); + assertTrue(testNotifListener.getReceivedNotifications().size() == 1); + assertEquals(testData, testNotifListener.getReceivedNotifications().get(0)); + + listenerRegistration.close(); + } + + @Test + public void testNotifSubscription2() throws InterruptedException { + final CountDownLatch latch = new CountDownLatch(1); + final TwoLevelListChanged testData = createTestData(); + + final TestNotifListener testNotifListener = new TestNotifListener(latch); + final ListenerRegistration listenerRegistration = getNotificationService() + .registerNotificationListener(testNotifListener); + assertTrue(getNotificationPublishService().offerNotification(testData)); + + latch.await(); + assertTrue(testNotifListener.getReceivedNotifications().size() == 1); + assertEquals(testData, testNotifListener.getReceivedNotifications().get(0)); + + listenerRegistration.close(); + } + + @Test + public void testNotifSubscription3() throws InterruptedException { + final CountDownLatch latch = new CountDownLatch(1); + final TwoLevelListChanged testData = createTestData(); + + final TestNotifListener testNotifListener = new TestNotifListener(latch); + final ListenerRegistration listenerRegistration = getNotificationService() + .registerNotificationListener(testNotifListener); + assertTrue(getNotificationPublishService().offerNotification(testData, 5, TimeUnit.SECONDS)); + + latch.await(); + assertTrue(testNotifListener.getReceivedNotifications().size() == 1); + assertEquals(testData, testNotifListener.getReceivedNotifications().get(0)); + + listenerRegistration.close(); + } + + private static class TestNotifListener implements OpendaylightMdsalListTestListener { + private List receivedNotifications = new ArrayList<>(); + private CountDownLatch latch; + + public TestNotifListener(CountDownLatch latch) { + this.latch = latch; + } + + @Override + public void onTwoLevelListChanged(TwoLevelListChanged notification) { + receivedNotifications.add(notification); + latch.countDown(); + } + + public List getReceivedNotifications() { + return receivedNotifications; + } + } +} diff --git a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/test/AbstractNotificationBrokerTest.java b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/test/AbstractNotificationBrokerTest.java new file mode 100644 index 0000000000..60309830e5 --- /dev/null +++ b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/test/AbstractNotificationBrokerTest.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.md.sal.binding.test; + +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.controller.md.sal.binding.api.NotificationService; +import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec; +import org.opendaylight.controller.md.sal.dom.broker.impl.DOMNotificationRouter; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; + +public class AbstractNotificationBrokerTest extends AbstractSchemaAwareTest{ + private BindingToNormalizedNodeCodec bindingToNormalizedNodeCodec; + private DOMNotificationRouter domNotificationRouter; + private NotificationService notificationService; + private NotificationPublishService notificationPublishService; + + + @Override + protected void setupWithSchema(final SchemaContext context) { + final DataBrokerTestCustomizer testCustomizer = createDataBrokerTestCustomizer(); + domNotificationRouter = testCustomizer.getDomNotificationRouter(); + notificationService = testCustomizer.createNotificationService(); + notificationPublishService = testCustomizer.createNotificationPublishService(); + bindingToNormalizedNodeCodec = testCustomizer.getBindingToNormalized(); + testCustomizer.updateSchema(context); + } + + protected DataBrokerTestCustomizer createDataBrokerTestCustomizer() { + return new DataBrokerTestCustomizer(); + } + + public NotificationService getNotificationService() { + return notificationService; + } + + public NotificationPublishService getNotificationPublishService() { + return notificationPublishService; + } + + public DOMNotificationRouter getDomNotificationRouter() { + return domNotificationRouter; + } + + public BindingToNormalizedNodeCodec getBindingToNormalizedNodeCodec() { + return bindingToNormalizedNodeCodec; + } +} diff --git a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/test/AbstractSchemaAwareTest.java b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/test/AbstractSchemaAwareTest.java index 78febb50f7..6d758aa7bd 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/test/AbstractSchemaAwareTest.java +++ b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/test/AbstractSchemaAwareTest.java @@ -19,13 +19,13 @@ public abstract class AbstractSchemaAwareTest { private SchemaContext schemaContext; - protected Iterable getModuleInfos() { + protected Iterable getModuleInfos() throws Exception { return BindingReflections.loadModuleInfos(); } @Before - public final void setup() { + public final void setup() throws Exception { moduleInfos = getModuleInfos(); ModuleInfoBackedContext moduleContext = ModuleInfoBackedContext.create(); moduleContext.addModuleInfos(moduleInfos); diff --git a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/test/DataBrokerTestCustomizer.java b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/test/DataBrokerTestCustomizer.java index 38b36b3338..bf0cd6be3b 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/test/DataBrokerTestCustomizer.java +++ b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/test/DataBrokerTestCustomizer.java @@ -12,12 +12,18 @@ import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; import javassist.ClassPool; import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.controller.md.sal.binding.api.NotificationService; import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec; import org.opendaylight.controller.md.sal.binding.impl.ForwardedBindingDataBroker; +import org.opendaylight.controller.md.sal.binding.impl.ForwardedNotificationPublishService; +import org.opendaylight.controller.md.sal.binding.impl.ForwardedNotificationService; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.controller.md.sal.dom.broker.impl.DOMNotificationRouter; import org.opendaylight.controller.md.sal.dom.broker.impl.SerializedDOMDataBroker; import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore; +import org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder; import org.opendaylight.controller.sal.binding.test.util.MockSchemaService; import org.opendaylight.controller.sal.core.api.model.SchemaService; import org.opendaylight.controller.sal.core.spi.data.DOMStore; @@ -32,10 +38,11 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext; public class DataBrokerTestCustomizer { private DOMDataBroker domDataBroker; + private DOMNotificationRouter domNotificationRouter; private final RuntimeGeneratedMappingServiceImpl mappingService; private final MockSchemaService schemaService; private ImmutableMap datastores; - private final BindingToNormalizedNodeCodec bindingToNormalized ; + private final BindingToNormalizedNodeCodec bindingToNormalized; public ImmutableMap createDatastores() { return ImmutableMap.builder() @@ -53,6 +60,7 @@ public class DataBrokerTestCustomizer { GeneratedClassLoadingStrategy loading = GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(); bindingToNormalized = new BindingToNormalizedNodeCodec(loading, mappingService, codecRegistry); schemaService.registerSchemaContextListener(bindingToNormalized); + domNotificationRouter = DOMNotificationRouter.create(16); } public DOMStore createConfigurationDatastore() { @@ -71,6 +79,16 @@ public class DataBrokerTestCustomizer { return new SerializedDOMDataBroker(getDatastores(), getCommitCoordinatorExecutor()); } + public NotificationService createNotificationService() { + return new ForwardedNotificationService(bindingToNormalized.getCodecRegistry(), domNotificationRouter, + SingletonHolder.INVOKER_FACTORY); + } + + public NotificationPublishService createNotificationPublishService() { + return new ForwardedNotificationPublishService(bindingToNormalized.getCodecRegistry(), domNotificationRouter); + } + + public ListeningExecutorService getCommitCoordinatorExecutor() { return MoreExecutors.sameThreadExecutor(); } @@ -106,4 +124,7 @@ public class DataBrokerTestCustomizer { mappingService.onGlobalContextUpdated(ctx); } + public DOMNotificationRouter getDomNotificationRouter() { + return domNotificationRouter; + } } diff --git a/opendaylight/md-sal/sal-binding-config/src/main/yang/opendaylight-md-sal-binding.yang b/opendaylight/md-sal/sal-binding-config/src/main/yang/opendaylight-md-sal-binding.yang index 8636ff613b..fcfd6fa3cf 100644 --- a/opendaylight/md-sal/sal-binding-config/src/main/yang/opendaylight-md-sal-binding.yang +++ b/opendaylight/md-sal/sal-binding-config/src/main/yang/opendaylight-md-sal-binding.yang @@ -4,10 +4,10 @@ module opendaylight-md-sal-binding { prefix "md-sal-binding"; import config { prefix config; revision-date 2013-04-05; } - + description "Service definition for Binding Aware MD-SAL."; - + revision "2013-10-28" { description "Initial revision"; @@ -22,7 +22,7 @@ module opendaylight-md-sal-binding { base "config:service-type"; config:java-class "org.opendaylight.controller.sal.binding.api.data.DataProviderService"; } - + identity binding-async-data-broker { base "config:service-type"; config:java-class "org.opendaylight.controller.md.sal.binding.api.DataBroker"; @@ -48,4 +48,4 @@ module opendaylight-md-sal-binding { config:java-class "org.opendaylight.controller.sal.binding.api.NotificationService"; } -} \ No newline at end of file +} diff --git a/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMNotificationPublishService.java b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMNotificationPublishService.java index 8a845e8729..dc2ced7807 100644 --- a/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMNotificationPublishService.java +++ b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMNotificationPublishService.java @@ -12,6 +12,7 @@ import com.google.common.util.concurrent.ListenableFuture; import java.util.concurrent.TimeUnit; import javax.annotation.Nonnegative; import javax.annotation.Nonnull; +import org.opendaylight.controller.sal.core.api.BrokerService; /** * A {@link DOMService} which allows its user to send {@link DOMNotification}s. It @@ -23,7 +24,7 @@ import javax.annotation.Nonnull; * the caller to specify that it should never wait, or put an upper bound on how * long it is going to wait. */ -public interface DOMNotificationPublishService extends DOMService { +public interface DOMNotificationPublishService extends DOMService, BrokerService { /** * Well-known value indicating that the implementation is currently not * able to accept a notification. diff --git a/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMNotificationService.java b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMNotificationService.java index 4b9f8ca7fc..036ea24cb1 100644 --- a/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMNotificationService.java +++ b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMNotificationService.java @@ -9,6 +9,7 @@ package org.opendaylight.controller.md.sal.dom.api; import java.util.Collection; import javax.annotation.Nonnull; +import org.opendaylight.controller.sal.core.api.BrokerService; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.model.api.SchemaPath; @@ -16,7 +17,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath; * A {@link DOMService} which allows its users to subscribe to receive * {@link DOMNotification}s. */ -public interface DOMNotificationService { +public interface DOMNotificationService extends DOMService, BrokerService { /** * Register a {@link DOMNotificationListener} to receive a set of notifications. As with * other ListenerRegistration-based interfaces, registering an instance multiple times diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/dom/impl/DomBrokerImplModule.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/dom/impl/DomBrokerImplModule.java index b8861b3465..4fd6403461 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/dom/impl/DomBrokerImplModule.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/dom/impl/DomBrokerImplModule.java @@ -11,6 +11,9 @@ import com.google.common.collect.ClassToInstanceMap; import com.google.common.collect.MutableClassToInstanceMap; import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; +import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService; +import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService; +import org.opendaylight.controller.md.sal.dom.broker.impl.DOMNotificationRouter; import org.opendaylight.controller.md.sal.dom.broker.impl.compat.BackwardsCompatibleDataBroker; import org.opendaylight.controller.md.sal.dom.broker.impl.mount.DOMMountPointServiceImpl; import org.opendaylight.controller.sal.core.api.BrokerService; @@ -51,6 +54,12 @@ public final class DomBrokerImplModule extends org.opendaylight.controller.confi final ClassToInstanceMap services = MutableClassToInstanceMap.create(); + // TODO: retrieve from config subsystem + int queueDepth = 1024; + + final DOMNotificationRouter domNotificationRouter = DOMNotificationRouter.create(queueDepth); + services.putInstance(DOMNotificationService.class, domNotificationRouter); + services.putInstance(DOMNotificationPublishService.class, domNotificationRouter); final SchemaService schemaService = getSchemaServiceImpl(); services.putInstance(SchemaService.class, schemaService); diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/ProxyFactory.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/ProxyFactory.java index ebb923c375..c0eb5d55da 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/ProxyFactory.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/ProxyFactory.java @@ -8,18 +8,17 @@ package org.opendaylight.controller.sal.dom.broker.osgi; import java.util.Arrays; - +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; import org.opendaylight.controller.sal.core.api.BrokerService; -import org.osgi.framework.ServiceReference; +import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry; import org.opendaylight.controller.sal.core.api.data.DataBrokerService; import org.opendaylight.controller.sal.core.api.data.DataProviderService; -import org.opendaylight.controller.sal.core.api.notify.NotificationPublishService; -import org.opendaylight.controller.sal.core.api.notify.NotificationService; import org.opendaylight.controller.sal.core.api.model.SchemaService; import org.opendaylight.controller.sal.core.api.mount.MountProvisionService; -import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry; -import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.controller.sal.core.api.notify.NotificationPublishService; +import org.opendaylight.controller.sal.core.api.notify.NotificationService; +import org.osgi.framework.ServiceReference; @SuppressWarnings("unchecked") public class ProxyFactory { @@ -101,8 +100,7 @@ public class ProxyFactory { private static Object _createProxyImpl(final ServiceReference reference, final BrokerService service) { - throw new IllegalArgumentException("Not supported class: " - + service.getClass().getName()); + return service; } private static Object createProxyImpl(final ServiceReference ref, diff --git a/opendaylight/md-sal/sal-test-model/src/main/yang/opendaylight-mdsal-list-test.yang b/opendaylight/md-sal/sal-test-model/src/main/yang/opendaylight-mdsal-list-test.yang index 48666e1689..d4775afe54 100644 --- a/opendaylight/md-sal/sal-test-model/src/main/yang/opendaylight-mdsal-list-test.yang +++ b/opendaylight/md-sal/sal-test-model/src/main/yang/opendaylight-mdsal-list-test.yang @@ -43,9 +43,13 @@ module opendaylight-mdsal-list-test { uses two-level-list; } + notification two-level-list-changed { + uses two-level-list; + } + rpc put-top { input { uses two-level-list; } } -} \ No newline at end of file +} -- 2.36.6