Merge "Bug 3866: Support for Restconf HTTP Patch"
[netconf.git] / netconf / mdsal-netconf-notification / src / main / java / org / opendaylight / netconf / mdsal / notification / NetconfNotificationOperationService.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
9 package org.opendaylight.netconf.mdsal.notification;
10
11 import java.util.Collections;
12 import java.util.Set;
13 import org.opendaylight.netconf.mapping.api.NetconfOperation;
14 import org.opendaylight.netconf.mapping.api.NetconfOperationService;
15 import org.opendaylight.netconf.notifications.NetconfNotificationRegistry;
16 import org.opendaylight.netconf.notifications.impl.ops.CreateSubscription;
17
18 public class NetconfNotificationOperationService implements NetconfOperationService {
19     private final Set<NetconfOperation> netconfOperations;
20
21     public NetconfNotificationOperationService(String netconfSessionIdForReporting, NetconfNotificationRegistry netconfNotificationRegistry) {
22         this.netconfOperations = Collections.<NetconfOperation>singleton(new CreateSubscription(netconfSessionIdForReporting, netconfNotificationRegistry));
23     }
24
25
26     @Override
27     public Set<NetconfOperation> getNetconfOperations() {
28         return netconfOperations;
29     }
30
31     @Override
32     public void close() {
33         for (NetconfOperation netconfOperation : netconfOperations) {
34             if (netconfOperation instanceof AutoCloseable) {
35                 try {
36                     ((AutoCloseable) netconfOperation).close();
37                 } catch (Exception e) {
38                     throw new IllegalStateException("Exception while closing " + netconfOperation, e);
39                 }
40             }
41         }
42     }
43 }