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.config.yang.store.api.YangStoreException;
13 import org.opendaylight.controller.config.yang.store.api.YangStoreService;
14 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
18 import javax.management.MBeanServer;
19 import java.lang.management.ManagementFactory;
21 public class NetconfOperationServiceFactoryImpl implements NetconfOperationServiceFactory {
23 public static final int ATTEMPT_TIMEOUT_MS = 1000;
24 private static final int SILENT_ATTEMPTS = 30;
26 private final YangStoreService yangStoreService;
27 private final ConfigRegistryJMXClient jmxClient;
29 private static final Logger logger = LoggerFactory.getLogger(NetconfOperationServiceFactoryImpl.class);
31 public NetconfOperationServiceFactoryImpl(YangStoreService yangStoreService) {
32 this(yangStoreService, ManagementFactory.getPlatformMBeanServer());
35 public NetconfOperationServiceFactoryImpl(YangStoreService yangStoreService, MBeanServer mBeanServer) {
36 this.yangStoreService = yangStoreService;
38 ConfigRegistryJMXClient configRegistryJMXClient;
40 // Config registry might not be present yet, but will be eventually
44 configRegistryJMXClient = new ConfigRegistryJMXClient(mBeanServer);
46 } catch (IllegalStateException e) {
48 if (i > SILENT_ATTEMPTS) {
49 logger.info("JMX client not created after {} attempts, still trying", i, e);
51 logger.debug("JMX client could not be created, reattempting, try {}", i, e);
54 Thread.sleep(ATTEMPT_TIMEOUT_MS);
55 } catch (InterruptedException e1) {
56 Thread.currentThread().interrupt();
57 throw new RuntimeException("Interrupted while reattempting connection", e1);
62 jmxClient = configRegistryJMXClient;
63 if (i > SILENT_ATTEMPTS) {
64 logger.info("Created JMX client after {} attempts", i);
66 logger.debug("Created JMX client after {} attempts", i);
71 public NetconfOperationServiceImpl createService(long netconfSessionId, String netconfSessionIdForReporting) {
73 return new NetconfOperationServiceImpl(yangStoreService, jmxClient, netconfSessionIdForReporting);
74 } catch (YangStoreException e) {
75 throw new IllegalStateException(e);