2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.netconf.impl.osgi;
11 import java.util.Collections;
12 import java.util.HashSet;
15 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService;
16 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 public class NetconfOperationServiceSnapshot implements AutoCloseable {
21 private static final Logger logger = LoggerFactory.getLogger(NetconfOperationServiceSnapshot.class);
23 private final Set<NetconfOperationService> services;
24 private final String netconfSessionIdForReporting;
26 public NetconfOperationServiceSnapshot(Set<NetconfOperationServiceFactory> factories, long sessionId) {
27 Set<NetconfOperationService> services = new HashSet<>();
28 netconfSessionIdForReporting = getNetconfSessionIdForReporting(sessionId);
29 for (NetconfOperationServiceFactory factory : factories) {
30 services.add(factory.createService(sessionId, netconfSessionIdForReporting));
32 this.services = Collections.unmodifiableSet(services);
35 private static String getNetconfSessionIdForReporting(long sessionId) {
36 return "netconf session id " + sessionId;
39 public String getNetconfSessionIdForReporting() {
40 return netconfSessionIdForReporting;
43 public Set<NetconfOperationService> getServices() {
49 RuntimeException firstException = null;
50 for (NetconfOperationService service : services) {
53 } catch (RuntimeException e) {
54 logger.warn("Got exception while closing {}", service, e);
55 if (firstException == null) {
58 firstException.addSuppressed(e);
62 if (firstException != null) {
68 public String toString() {
69 return "NetconfOperationServiceSnapshot{" + netconfSessionIdForReporting + '}';