Fix sal-netconf-connector's pom.xml
[controller.git] / opendaylight / netconf / config-persister-impl / src / main / java / org / opendaylight / controller / netconf / persist / impl / Util.java
1 /*
2  * Copyright (c) 2013 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.controller.netconf.persist.impl;
10
11 import org.opendaylight.controller.netconf.client.NetconfClient;
12 import org.opendaylight.controller.netconf.client.NetconfClientDispatcher;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15
16 import java.util.Set;
17
18 public final class Util {
19     private static final Logger logger = LoggerFactory.getLogger(Util.class);
20
21
22     public static boolean isSubset(NetconfClient netconfClient, Set<String> expectedCaps) {
23         return isSubset(netconfClient.getCapabilities(), expectedCaps);
24
25     }
26
27     private static boolean isSubset(Set<String> currentCapabilities, Set<String> expectedCaps) {
28         for (String exCap : expectedCaps) {
29             if (currentCapabilities.contains(exCap) == false)
30                 return false;
31         }
32         return true;
33     }
34
35     public static void closeClientAndDispatcher(NetconfClient client) {
36         NetconfClientDispatcher dispatcher = client.getNetconfClientDispatcher();
37         Exception fromClient = null;
38         try {
39             client.close();
40         } catch (Exception e) {
41             fromClient = e;
42         } finally {
43             try {
44                 dispatcher.close();
45             } catch (Exception e) {
46                 if (fromClient != null) {
47                     e.addSuppressed(fromClient);
48                 }
49                 throw new RuntimeException("Error closing temporary client ", e);
50             }
51         }
52     }
53 }