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 java.lang.management.ManagementFactory;
12 import javax.management.MBeanServer;
13 import org.opendaylight.controller.config.util.ConfigRegistryJMXClient;
14 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
18 public class NetconfOperationServiceFactoryImpl implements NetconfOperationServiceFactory {
20 public static final int ATTEMPT_TIMEOUT_MS = 1000;
21 private static final int SILENT_ATTEMPTS = 30;
23 private final YangStoreService yangStoreService;
24 private final ConfigRegistryJMXClient jmxClient;
26 private static final Logger LOG = LoggerFactory.getLogger(NetconfOperationServiceFactoryImpl.class);
28 public NetconfOperationServiceFactoryImpl(YangStoreService yangStoreService) {
29 this(yangStoreService, ManagementFactory.getPlatformMBeanServer());
32 public NetconfOperationServiceFactoryImpl(YangStoreService yangStoreService, MBeanServer mBeanServer) {
33 this.yangStoreService = yangStoreService;
35 ConfigRegistryJMXClient configRegistryJMXClient;
37 // Config registry might not be present yet, but will be eventually
41 configRegistryJMXClient = new ConfigRegistryJMXClient(mBeanServer);
43 } catch (IllegalStateException e) {
45 if (i > SILENT_ATTEMPTS) {
46 LOG.info("JMX client not created after {} attempts, still trying", i, e);
48 LOG.debug("JMX client could not be created, reattempting, try {}", i, e);
51 Thread.sleep(ATTEMPT_TIMEOUT_MS);
52 } catch (InterruptedException e1) {
53 Thread.currentThread().interrupt();
54 throw new IllegalStateException("Interrupted while reattempting connection", e1);
59 jmxClient = configRegistryJMXClient;
60 if (i > SILENT_ATTEMPTS) {
61 LOG.info("Created JMX client after {} attempts", i);
63 LOG.debug("Created JMX client after {} attempts", i);
68 public NetconfOperationServiceImpl createService(String netconfSessionIdForReporting) {
70 return new NetconfOperationServiceImpl(yangStoreService, jmxClient, netconfSessionIdForReporting);
71 } catch (YangStoreException e) {
72 throw new IllegalStateException(e);