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.controller.md.sal.binding.impl;
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.util.concurrent.TimeUnit;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
14 import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
15 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService;
16 import org.opendaylight.yangtools.binding.data.codec.api.BindingNormalizedNodeSerializer;
17 import org.opendaylight.yangtools.yang.binding.Notification;
18 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
19 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
21 public class ForwardedNotificationPublishService implements NotificationPublishService, AutoCloseable {
22 private final BindingNormalizedNodeSerializer codecRegistry;
23 private final DOMNotificationPublishService domPublishService;
25 public ForwardedNotificationPublishService(BindingNormalizedNodeSerializer codecRegistry, DOMNotificationPublishService domPublishService) {
26 this.codecRegistry = codecRegistry;
27 this.domPublishService = domPublishService;
31 public void putNotification(final Notification notification) throws InterruptedException {
32 domPublishService.putNotification(toDomNotification(notification));
36 public boolean offerNotification(final Notification notification) {
37 final ListenableFuture<?> listenableFuture = domPublishService.offerNotification(toDomNotification(notification));
38 return !DOMNotificationPublishService.REJECTED.equals(listenableFuture);
42 public boolean offerNotification(final Notification notification, final int timeout, final TimeUnit unit) throws InterruptedException {
43 final ListenableFuture<?> listenableFuture =
44 domPublishService.offerNotification(toDomNotification(notification), timeout, unit);
45 return !DOMNotificationPublishService.REJECTED.equals(listenableFuture);
48 private DOMNotification toDomNotification(final Notification notification) {
49 final ContainerNode domNotification = codecRegistry.toNormalizedNodeNotification(notification);
50 return new DOMNotificationImpl(domNotification);
54 public void close() throws Exception {
58 private static class DOMNotificationImpl implements DOMNotification {
60 private final SchemaPath type;
61 private final ContainerNode body;
63 public DOMNotificationImpl(final ContainerNode body) {
64 this.type = SchemaPath.create(true, body.getIdentifier().getNodeType());
70 public SchemaPath getType() {
76 public ContainerNode getBody() {