atomic-storage: remove type dependency at segment level I/O
[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 @Deprecated(forRemoval = true)
23 public class BindingDOMNotificationPublishServiceAdapter implements NotificationPublishService, AutoCloseable {
24
25     static final Factory<NotificationPublishService> BUILDER_FACTORY = Builder::new;
26
27     private final BindingToNormalizedNodeCodec codecRegistry;
28     private final DOMNotificationPublishService domPublishService;
29
30     public BindingDOMNotificationPublishServiceAdapter(final BindingToNormalizedNodeCodec codec,
31             final DOMNotificationPublishService domPublishService) {
32         this.codecRegistry = codec;
33         this.domPublishService = domPublishService;
34     }
35
36     public BindingToNormalizedNodeCodec getCodecRegistry() {
37         return codecRegistry;
38     }
39
40     public DOMNotificationPublishService getDomPublishService() {
41         return domPublishService;
42     }
43
44     @Override
45     public void putNotification(final Notification notification) throws InterruptedException {
46         domPublishService.putNotification(toDomNotification(notification));
47     }
48
49     @Override
50     public ListenableFuture<?> offerNotification(final Notification notification) {
51         ListenableFuture<?> offerResult = domPublishService.offerNotification(toDomNotification(notification));
52         return DOMNotificationPublishService.REJECTED.equals(offerResult)
53                 ? NotificationPublishService.REJECTED
54                 : offerResult;
55     }
56
57     @Override
58     public ListenableFuture<?> offerNotification(final Notification notification, final int timeout,
59             final TimeUnit unit) throws InterruptedException {
60         ListenableFuture<?> offerResult = domPublishService.offerNotification(toDomNotification(notification),
61                 timeout, unit);
62         return DOMNotificationPublishService.REJECTED.equals(offerResult)
63                 ? NotificationPublishService.REJECTED
64                 : offerResult;
65     }
66
67     private DOMNotification toDomNotification(final Notification notification) {
68         return LazySerializedDOMNotification.create(codecRegistry, notification);
69     }
70
71     @Override
72     public void close() {
73
74     }
75
76     protected static class Builder extends BindingDOMAdapterBuilder<NotificationPublishService> {
77
78         @Override
79         public Set<Class<? extends DOMService>> getRequiredDelegates() {
80             return ImmutableSet.<Class<? extends DOMService>>of(DOMNotificationPublishService.class);
81         }
82
83         @Override
84         protected NotificationPublishService createInstance(final BindingToNormalizedNodeCodec codec,
85                 final ClassToInstanceMap<DOMService> delegates) {
86             final DOMNotificationPublishService domPublish = delegates.getInstance(DOMNotificationPublishService.class);
87             return new BindingDOMNotificationPublishServiceAdapter(codec, domPublish);
88         }
89     }
90 }