/* * 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.mdsal.binding.dom.adapter; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ClassToInstanceMap; import com.google.common.collect.ImmutableSet; import com.google.common.util.concurrent.ListenableFuture; import java.time.Instant; import java.util.Set; import java.util.concurrent.TimeUnit; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.mdsal.binding.api.NotificationPublishService; import org.opendaylight.mdsal.binding.dom.adapter.BindingDOMAdapterBuilder.Factory; import org.opendaylight.mdsal.dom.api.DOMNotification; import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService; import org.opendaylight.mdsal.dom.api.DOMService; import org.opendaylight.yangtools.yang.binding.EventInstantAware; import org.opendaylight.yangtools.yang.binding.Notification; @VisibleForTesting // FIXME: 10.0.0: make this class final public class BindingDOMNotificationPublishServiceAdapter extends AbstractBindingAdapter implements NotificationPublishService { static final Factory BUILDER_FACTORY = Builder::new; public BindingDOMNotificationPublishServiceAdapter(final AdapterContext adapterContext, final DOMNotificationPublishService domPublishService) { super(adapterContext, domPublishService); } @Deprecated(forRemoval = true, since = "9.0.2") public DOMNotificationPublishService getDomPublishService() { return getDelegate(); } @Override public void putNotification(final Notification notification) throws InterruptedException { getDelegate().putNotification(toDomNotification(notification)); } @Override public ListenableFuture offerNotification(final Notification notification) { return toBindingResult(getDelegate().offerNotification(toDomNotification(notification))); } @Override public ListenableFuture offerNotification(final Notification notification, final int timeout, final TimeUnit unit) throws InterruptedException { return toBindingResult(getDelegate().offerNotification(toDomNotification(notification), timeout, unit)); } private @NonNull DOMNotification toDomNotification(final Notification notification) { final Instant instant = notification instanceof EventInstantAware ? ((EventInstantAware) notification).eventInstant() : Instant.now(); return LazySerializedDOMNotification.create(currentSerializer(), notification, instant); } private static @NonNull ListenableFuture toBindingResult( final @NonNull ListenableFuture domResult) { return DOMNotificationPublishService.REJECTED.equals(domResult) ? NotificationPublishService.REJECTED : domResult; } // FIXME: 10.0.0: hide this class and make it final protected static class Builder extends BindingDOMAdapterBuilder { Builder(final AdapterContext adapterContext) { super(adapterContext); } @Override public Set> getRequiredDelegates() { return ImmutableSet.of(DOMNotificationPublishService.class); } @Override protected NotificationPublishService createInstance(final ClassToInstanceMap delegates) { return new BindingDOMNotificationPublishServiceAdapter(adapterContext(), delegates.getInstance(DOMNotificationPublishService.class)); } } }