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;
25 private final YangStoreService yangStoreService;
26 private final ConfigRegistryJMXClient jmxClient;
28 private static final Logger logger = LoggerFactory.getLogger(NetconfOperationServiceFactoryImpl.class);
30 public NetconfOperationServiceFactoryImpl(YangStoreService yangStoreService) {
31 this(yangStoreService, ManagementFactory.getPlatformMBeanServer());
34 public NetconfOperationServiceFactoryImpl(YangStoreService yangStoreService, MBeanServer mBeanServer) {
35 this.yangStoreService = yangStoreService;
37 // Config registry might not be present yet, but will be eventually
40 final ConfigRegistryJMXClient configRegistryJMXClient;
42 configRegistryJMXClient = new ConfigRegistryJMXClient(mBeanServer);
43 } catch (IllegalStateException e) {
44 logger.debug("Jmx client could not be created, reattempting");
46 Thread.sleep(ATTEMPT_TIMEOUT_MS);
47 } catch (InterruptedException e1) {
48 Thread.currentThread().interrupt();
49 throw new RuntimeException(e1);
54 jmxClient = configRegistryJMXClient;
60 public NetconfOperationServiceImpl createService(long netconfSessionId, String netconfSessionIdForReporting) {
62 return new NetconfOperationServiceImpl(yangStoreService, jmxClient, netconfSessionIdForReporting);
63 } catch (YangStoreException e) {
64 throw new IllegalStateException(e);