fef38d1c90c64ca128173cede26c16ed4b04c895
[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
22             netconfNotificationRegistry) {
23         this.netconfOperations = Collections.singleton(new CreateSubscription(netconfSessionIdForReporting,
24                 netconfNotificationRegistry));
25     }
26
27
28     @Override
29     public Set<NetconfOperation> getNetconfOperations() {
30         return netconfOperations;
31     }
32
33     @SuppressWarnings("checkstyle:IllegalCatch")
34     @Override
35     public void close() {
36         for (NetconfOperation netconfOperation : netconfOperations) {
37             if (netconfOperation instanceof AutoCloseable) {
38                 try {
39                     ((AutoCloseable) netconfOperation).close();
40                 } catch (Exception e) {
41                     throw new IllegalStateException("Exception while closing " + netconfOperation, e);
42                 }
43             }
44         }
45     }
46 }