2 * Copyright (c) 2017 Pantheon Technologies 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.binding.javav2.dom.adapter.impl.notification;
10 import com.google.common.annotations.Beta;
11 import com.google.common.collect.ClassToInstanceMap;
12 import com.google.common.collect.ImmutableSet;
13 import com.google.common.util.concurrent.ListenableFuture;
15 import java.util.concurrent.TimeUnit;
16 import org.opendaylight.mdsal.binding.javav2.api.NotificationPublishService;
17 import org.opendaylight.mdsal.binding.javav2.dom.adapter.spi.builder.BindingDOMAdapterBuilder;
18 import org.opendaylight.mdsal.binding.javav2.dom.adapter.spi.builder.BindingDOMAdapterBuilder.Factory;
19 import org.opendaylight.mdsal.binding.javav2.dom.codec.impl.BindingToNormalizedNodeCodec;
20 import org.opendaylight.mdsal.binding.javav2.dom.codec.serialized.LazySerializedDOMNotification;
21 import org.opendaylight.mdsal.binding.javav2.spec.base.Notification;
22 import org.opendaylight.mdsal.dom.api.DOMNotification;
23 import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService;
24 import org.opendaylight.mdsal.dom.api.DOMService;
27 * Adapter for notification publisher service.
30 public class BindingDOMNotificationPublishServiceAdapter implements NotificationPublishService, AutoCloseable {
32 public static final Factory<NotificationPublishService> BUILDER_FACTORY = Builder::new;
34 private final BindingToNormalizedNodeCodec codecRegistry;
35 private final DOMNotificationPublishService domPublishService;
37 public BindingDOMNotificationPublishServiceAdapter(final BindingToNormalizedNodeCodec codec,
38 final DOMNotificationPublishService domPublishService) {
39 this.codecRegistry = codec;
40 this.domPublishService = domPublishService;
43 public BindingToNormalizedNodeCodec getCodecRegistry() {
47 public DOMNotificationPublishService getDomPublishService() {
48 return domPublishService;
52 public void putNotification(final Notification<?> notification) throws InterruptedException {
53 domPublishService.putNotification(toDomNotification(notification));
57 public ListenableFuture<? extends Object> offerNotification(final Notification<?> notification) {
58 final ListenableFuture<?> offerResult = domPublishService.offerNotification(toDomNotification(notification));
59 return DOMNotificationPublishService.REJECTED.equals(offerResult) ? NotificationPublishService.REJECTED
64 public ListenableFuture<? extends Object> offerNotification(final Notification<?> notification, final int timeout,
65 final TimeUnit unit) throws InterruptedException {
66 final ListenableFuture<?> offerResult =
67 domPublishService.offerNotification(toDomNotification(notification), timeout, unit);
68 return DOMNotificationPublishService.REJECTED.equals(offerResult) ? NotificationPublishService.REJECTED
72 private DOMNotification toDomNotification(final Notification<?> notification) {
73 return LazySerializedDOMNotification.create(codecRegistry, notification);
77 public void close() throws Exception {
81 private static class Builder extends BindingDOMAdapterBuilder<NotificationPublishService> {
84 public Set<Class<? extends DOMService>> getRequiredDelegates() {
85 return ImmutableSet.of(DOMNotificationPublishService.class);
89 protected NotificationPublishService createInstance(final BindingToNormalizedNodeCodec codec,
90 final ClassToInstanceMap<DOMService> delegates) {
91 final DOMNotificationPublishService domPublish = delegates.getInstance(DOMNotificationPublishService.class);
92 return new BindingDOMNotificationPublishServiceAdapter(codec, domPublish);