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.annotations.VisibleForTesting;
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.eclipse.jdt.annotation.NonNull;
17 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
18 import org.opendaylight.mdsal.binding.dom.adapter.BindingDOMAdapterBuilder.Factory;
19 import org.opendaylight.mdsal.dom.api.DOMNotification;
20 import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService;
21 import org.opendaylight.mdsal.dom.api.DOMService;
22 import org.opendaylight.yangtools.yang.binding.Notification;
25 public final class BindingDOMNotificationPublishServiceAdapter
26 extends AbstractBindingAdapter<DOMNotificationPublishService> implements NotificationPublishService {
27 static final Factory<NotificationPublishService> BUILDER_FACTORY = Builder::new;
29 public BindingDOMNotificationPublishServiceAdapter(final AdapterContext adapterContext,
30 final DOMNotificationPublishService domPublishService) {
31 super(adapterContext, domPublishService);
35 public void putNotification(final Notification<?> notification) throws InterruptedException {
36 getDelegate().putNotification(toDomNotification(notification));
40 public ListenableFuture<? extends Object> offerNotification(final Notification<?> notification) {
41 return toBindingResult(getDelegate().offerNotification(toDomNotification(notification)));
45 public ListenableFuture<? extends Object> offerNotification(final Notification<?> notification, final int timeout,
46 final TimeUnit unit) throws InterruptedException {
47 return toBindingResult(getDelegate().offerNotification(toDomNotification(notification), timeout, unit));
50 private @NonNull DOMNotification toDomNotification(final Notification<?> notification) {
51 return new LazySerializedNotification(currentSerializer(), notification);
54 private static @NonNull ListenableFuture<? extends Object> toBindingResult(
55 final @NonNull ListenableFuture<? extends Object> domResult) {
56 return DOMNotificationPublishService.REJECTED.equals(domResult) ? NotificationPublishService.REJECTED
60 private static final class Builder extends BindingDOMAdapterBuilder<NotificationPublishService> {
61 Builder(final AdapterContext adapterContext) {
62 super(adapterContext);
66 public Set<Class<? extends DOMService<?, ?>>> getRequiredDelegates() {
67 return ImmutableSet.of(DOMNotificationPublishService.class);
71 protected NotificationPublishService createInstance(final ClassToInstanceMap<DOMService<?, ?>> delegates) {
72 return new BindingDOMNotificationPublishServiceAdapter(adapterContext(),
73 delegates.getInstance(DOMNotificationPublishService.class));