Merge "Netconf-cli compilable and included in project"
[controller.git] / opendaylight / netconf / netconf-impl / src / main / java / org / opendaylight / controller / netconf / impl / osgi / NetconfOperationServiceSnapshotImpl.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.impl.osgi;
10
11 import java.util.Collections;
12 import java.util.HashSet;
13 import java.util.Set;
14 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService;
15 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
16 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceSnapshot;
17 import org.opendaylight.controller.netconf.util.CloseableUtil;
18
19 public class NetconfOperationServiceSnapshotImpl implements NetconfOperationServiceSnapshot {
20
21     private final Set<NetconfOperationService> services;
22     private final String netconfSessionIdForReporting;
23
24     public NetconfOperationServiceSnapshotImpl(Set<NetconfOperationServiceFactory> factories, String sessionIdForReporting) {
25         Set<NetconfOperationService> services = new HashSet<>();
26         netconfSessionIdForReporting = sessionIdForReporting;
27         for (NetconfOperationServiceFactory factory : factories) {
28             services.add(factory.createService(netconfSessionIdForReporting));
29         }
30         this.services = Collections.unmodifiableSet(services);
31     }
32
33
34
35     @Override
36     public String getNetconfSessionIdForReporting() {
37         return netconfSessionIdForReporting;
38     }
39
40     @Override
41     public Set<NetconfOperationService> getServices() {
42         return services;
43     }
44
45     @Override
46     public void close() throws Exception {
47         CloseableUtil.closeAll(services);
48     }
49
50     @Override
51     public String toString() {
52         return "NetconfOperationServiceSnapshotImpl{" + netconfSessionIdForReporting + '}';
53     }
54 }