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