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 org.opendaylight.mdsal.binding.api.NotificationPublishService;
12 import org.opendaylight.mdsal.binding.dom.adapter.BindingDOMAdapterBuilder.Factory;
13 import com.google.common.collect.ClassToInstanceMap;
14 import com.google.common.collect.ImmutableSet;
15 import com.google.common.util.concurrent.ListenableFuture;
17 import java.util.concurrent.TimeUnit;
18 import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
19 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService;
20 import org.opendaylight.controller.md.sal.dom.api.DOMService;
21 import org.opendaylight.yangtools.yang.binding.Notification;
23 public class BindingDOMNotificationPublishServiceAdapter implements NotificationPublishService, AutoCloseable {
25 static final Factory<NotificationPublishService> BUILDER_FACTORY = new BindingDOMAdapterBuilder.Factory<NotificationPublishService>() {
28 public BindingDOMAdapterBuilder<NotificationPublishService> newBuilder() {
34 private final BindingToNormalizedNodeCodec codecRegistry;
35 private final DOMNotificationPublishService domPublishService;
37 public BindingDOMNotificationPublishServiceAdapter(final BindingToNormalizedNodeCodec codec, final DOMNotificationPublishService domPublishService) {
38 this.codecRegistry = codec;
39 this.domPublishService = domPublishService;
42 public BindingToNormalizedNodeCodec getCodecRegistry() {
46 public DOMNotificationPublishService getDomPublishService() {
47 return domPublishService;
51 public void putNotification(final Notification notification) throws InterruptedException {
52 domPublishService.putNotification(toDomNotification(notification));
56 public ListenableFuture<? extends Object> offerNotification(final Notification notification) {
57 ListenableFuture<?> offerResult = domPublishService.offerNotification(toDomNotification(notification));
58 return DOMNotificationPublishService.REJECTED.equals(offerResult)
59 ? NotificationPublishService.REJECTED
64 public ListenableFuture<? extends Object> offerNotification(final Notification notification, final int timeout, final TimeUnit unit) throws InterruptedException {
65 ListenableFuture<?> offerResult = domPublishService.offerNotification(toDomNotification(notification), timeout, unit);
66 return DOMNotificationPublishService.REJECTED.equals(offerResult)
67 ? NotificationPublishService.REJECTED
71 private DOMNotification toDomNotification(final Notification notification) {
72 return LazySerializedDOMNotification.create(codecRegistry, notification);
76 public void close() throws Exception {
80 protected static class Builder extends BindingDOMAdapterBuilder<NotificationPublishService> {
83 public Set<Class<? extends DOMService>> getRequiredDelegates() {
84 return ImmutableSet.<Class<? extends DOMService>>of(DOMNotificationPublishService.class);
88 protected NotificationPublishService createInstance(final BindingToNormalizedNodeCodec codec,
89 final ClassToInstanceMap<DOMService> delegates) {
90 final DOMNotificationPublishService domPublish = delegates.getInstance(DOMNotificationPublishService.class);
91 return new BindingDOMNotificationPublishServiceAdapter(codec, domPublish);