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.confignetconfconnector.osgi;
11 import org.opendaylight.controller.config.util.ConfigRegistryJMXClient;
12 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
16 import javax.management.MBeanServer;
17 import java.lang.management.ManagementFactory;
19 public class NetconfOperationServiceFactoryImpl implements NetconfOperationServiceFactory {
21 public static final int ATTEMPT_TIMEOUT_MS = 1000;
22 private static final int SILENT_ATTEMPTS = 30;
24 private final YangStoreService yangStoreService;
25 private final ConfigRegistryJMXClient jmxClient;
27 private static final Logger logger = LoggerFactory.getLogger(NetconfOperationServiceFactoryImpl.class);
29 public NetconfOperationServiceFactoryImpl(YangStoreService yangStoreService) {
30 this(yangStoreService, ManagementFactory.getPlatformMBeanServer());
33 public NetconfOperationServiceFactoryImpl(YangStoreService yangStoreService, MBeanServer mBeanServer) {
34 this.yangStoreService = yangStoreService;
36 ConfigRegistryJMXClient configRegistryJMXClient;
38 // Config registry might not be present yet, but will be eventually
42 configRegistryJMXClient = new ConfigRegistryJMXClient(mBeanServer);
44 } catch (IllegalStateException e) {
46 if (i > SILENT_ATTEMPTS) {
47 logger.info("JMX client not created after {} attempts, still trying", i, e);
49 logger.debug("JMX client could not be created, reattempting, try {}", i, e);
52 Thread.sleep(ATTEMPT_TIMEOUT_MS);
53 } catch (InterruptedException e1) {
54 Thread.currentThread().interrupt();
55 throw new RuntimeException("Interrupted while reattempting connection", e1);
60 jmxClient = configRegistryJMXClient;
61 if (i > SILENT_ATTEMPTS) {
62 logger.info("Created JMX client after {} attempts", i);
64 logger.debug("Created JMX client after {} attempts", i);
69 public NetconfOperationServiceImpl createService(String netconfSessionIdForReporting) {
71 return new NetconfOperationServiceImpl(yangStoreService, jmxClient, netconfSessionIdForReporting);
72 } catch (YangStoreException e) {
73 throw new IllegalStateException(e);