2 * Copyright (c) 2015 Cisco Systems, Inc. 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.dom.adapter;
10 import com.google.common.collect.ClassToInstanceMap;
11 import com.google.common.collect.ImmutableSet;
12 import com.google.common.util.concurrent.ListenableFuture;
14 import java.util.concurrent.TimeUnit;
15 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
16 import org.opendaylight.mdsal.binding.dom.adapter.BindingDOMAdapterBuilder.Factory;
17 import org.opendaylight.mdsal.dom.api.DOMNotification;
18 import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService;
19 import org.opendaylight.mdsal.dom.api.DOMService;
20 import org.opendaylight.yangtools.yang.binding.Notification;
22 public class BindingDOMNotificationPublishServiceAdapter implements NotificationPublishService {
24 static final Factory<NotificationPublishService> BUILDER_FACTORY = Builder::new;
26 private final BindingToNormalizedNodeCodec codecRegistry;
27 private final DOMNotificationPublishService domPublishService;
29 public BindingDOMNotificationPublishServiceAdapter(final BindingToNormalizedNodeCodec codec,
30 final DOMNotificationPublishService domPublishService) {
31 this.codecRegistry = codec;
32 this.domPublishService = domPublishService;
35 public BindingToNormalizedNodeCodec getCodecRegistry() {
39 public DOMNotificationPublishService getDomPublishService() {
40 return domPublishService;
44 public void putNotification(final Notification notification) throws InterruptedException {
45 domPublishService.putNotification(toDomNotification(notification));
49 public ListenableFuture<? extends Object> offerNotification(final Notification notification) {
50 ListenableFuture<?> offerResult = domPublishService.offerNotification(toDomNotification(notification));
51 return DOMNotificationPublishService.REJECTED.equals(offerResult)
52 ? NotificationPublishService.REJECTED
57 public ListenableFuture<? extends Object> offerNotification(final Notification notification,
58 final int timeout, final TimeUnit unit) throws InterruptedException {
59 ListenableFuture<?> offerResult = domPublishService.offerNotification(
60 toDomNotification(notification), timeout, unit);
61 return DOMNotificationPublishService.REJECTED.equals(offerResult)
62 ? NotificationPublishService.REJECTED
66 private DOMNotification toDomNotification(final Notification notification) {
67 return LazySerializedDOMNotification.create(codecRegistry, notification);
70 protected static class Builder extends BindingDOMAdapterBuilder<NotificationPublishService> {
73 public Set<Class<? extends DOMService>> getRequiredDelegates() {
74 return ImmutableSet.of(DOMNotificationPublishService.class);
78 protected NotificationPublishService createInstance(final BindingToNormalizedNodeCodec codec,
79 final ClassToInstanceMap<DOMService> delegates) {
80 final DOMNotificationPublishService domPublish = delegates.getInstance(DOMNotificationPublishService.class);
81 return new BindingDOMNotificationPublishServiceAdapter(codec, domPublish);