Eliminate some more references to SchemaService
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / md / sal / binding / impl / BindingDOMNotificationPublishServiceAdapter.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.md.sal.binding.impl;
9
10 import com.google.common.collect.ClassToInstanceMap;
11 import com.google.common.collect.ImmutableSet;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import java.util.Set;
14 import java.util.concurrent.TimeUnit;
15 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
16 import org.opendaylight.controller.md.sal.binding.impl.BindingDOMAdapterBuilder.Factory;
17 import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
18 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService;
19 import org.opendaylight.controller.md.sal.dom.api.DOMService;
20 import org.opendaylight.yangtools.yang.binding.Notification;
21
22 public class BindingDOMNotificationPublishServiceAdapter implements NotificationPublishService, AutoCloseable {
23
24     static final Factory<NotificationPublishService> BUILDER_FACTORY = Builder::new;
25
26     private final BindingToNormalizedNodeCodec codecRegistry;
27     private final DOMNotificationPublishService domPublishService;
28
29     public BindingDOMNotificationPublishServiceAdapter(final BindingToNormalizedNodeCodec codec, final DOMNotificationPublishService domPublishService) {
30         this.codecRegistry = codec;
31         this.domPublishService = domPublishService;
32     }
33
34     public BindingToNormalizedNodeCodec getCodecRegistry() {
35         return codecRegistry;
36     }
37
38     public DOMNotificationPublishService getDomPublishService() {
39         return domPublishService;
40     }
41
42     @Override
43     public void putNotification(final Notification notification) throws InterruptedException {
44         domPublishService.putNotification(toDomNotification(notification));
45     }
46
47     @Override
48     public ListenableFuture<?> offerNotification(final Notification notification) {
49         ListenableFuture<?> offerResult = domPublishService.offerNotification(toDomNotification(notification));
50         return DOMNotificationPublishService.REJECTED.equals(offerResult)
51                 ? NotificationPublishService.REJECTED
52                 : offerResult;
53     }
54
55     @Override
56     public ListenableFuture<?> offerNotification(final Notification notification, final int timeout, final TimeUnit unit) throws InterruptedException {
57         ListenableFuture<?> offerResult = domPublishService.offerNotification(toDomNotification(notification), timeout, unit);
58         return DOMNotificationPublishService.REJECTED.equals(offerResult)
59                 ? NotificationPublishService.REJECTED
60                 : offerResult;
61     }
62
63     private DOMNotification toDomNotification(final Notification notification) {
64         return LazySerializedDOMNotification.create(codecRegistry, notification);
65     }
66
67     @Override
68     public void close() throws Exception {
69
70     }
71
72     protected static class Builder extends BindingDOMAdapterBuilder<NotificationPublishService> {
73
74         @Override
75         public Set<Class<? extends DOMService>> getRequiredDelegates() {
76             return ImmutableSet.<Class<? extends DOMService>>of(DOMNotificationPublishService.class);
77         }
78
79         @Override
80         protected NotificationPublishService createInstance(final BindingToNormalizedNodeCodec codec,
81                 final ClassToInstanceMap<DOMService> delegates) {
82             final DOMNotificationPublishService domPublish = delegates.getInstance(DOMNotificationPublishService.class);
83             return new BindingDOMNotificationPublishServiceAdapter(codec, domPublish);
84         }
85
86     }
87 }