BUG 2676 : Use custom client-dispatcher when configured
[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 com.google.common.collect.ImmutableSet;
12 import com.google.common.collect.ImmutableSet.Builder;
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(final Set<NetconfOperationServiceFactory> factories, final String sessionIdForReporting) {
25         final Builder<NetconfOperationService> b = ImmutableSet.builder();
26         netconfSessionIdForReporting = sessionIdForReporting;
27         for (NetconfOperationServiceFactory factory : factories) {
28             b.add(factory.createService(netconfSessionIdForReporting));
29         }
30         this.services = b.build();
31     }
32
33     @Override
34     public String getNetconfSessionIdForReporting() {
35         return netconfSessionIdForReporting;
36     }
37
38     @Override
39     public Set<NetconfOperationService> getServices() {
40         return services;
41     }
42
43     @Override
44     public void close() throws Exception {
45         CloseableUtil.closeAll(services);
46     }
47
48     @Override
49     public String toString() {
50         return "NetconfOperationServiceSnapshotImpl{" + netconfSessionIdForReporting + '}';
51     }
52 }