X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fconfig-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fconfignetconfconnector%2Fosgi%2FNetconfOperationServiceFactoryImpl.java;fp=opendaylight%2Fnetconf%2Fconfig-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fconfignetconfconnector%2Fosgi%2FNetconfOperationServiceFactoryImpl.java;h=35695f75102870a00c31f631ca6f26a3b7e5320f;hb=a92d9d6a21a0f6ca8d2153795721f500eaf29ee9;hp=0000000000000000000000000000000000000000;hpb=fbc3092ca33990f0fc4a47f008786a416c484488;p=controller.git diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/NetconfOperationServiceFactoryImpl.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/NetconfOperationServiceFactoryImpl.java new file mode 100644 index 0000000000..35695f7510 --- /dev/null +++ b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/NetconfOperationServiceFactoryImpl.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.netconf.confignetconfconnector.osgi; + +import org.opendaylight.controller.config.util.ConfigRegistryJMXClient; +import org.opendaylight.controller.config.yang.store.api.YangStoreException; +import org.opendaylight.controller.config.yang.store.api.YangStoreService; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.management.MBeanServer; +import java.lang.management.ManagementFactory; + +public class NetconfOperationServiceFactoryImpl implements NetconfOperationServiceFactory { + + public static final int ATTEMPT_TIMEOUT_MS = 1000; + + private final YangStoreService yangStoreService; + private final ConfigRegistryJMXClient jmxClient; + + private static final Logger logger = LoggerFactory.getLogger(NetconfOperationServiceFactoryImpl.class); + + public NetconfOperationServiceFactoryImpl(YangStoreService yangStoreService) { + this(yangStoreService, ManagementFactory.getPlatformMBeanServer()); + } + + public NetconfOperationServiceFactoryImpl(YangStoreService yangStoreService, MBeanServer mBeanServer) { + this.yangStoreService = yangStoreService; + + // Config registry might not be present yet, but will be eventually + while(true) { + + final ConfigRegistryJMXClient configRegistryJMXClient; + try { + configRegistryJMXClient = new ConfigRegistryJMXClient(mBeanServer); + } catch (IllegalStateException e) { + logger.debug("Jmx client could not be created, reattempting"); + try { + Thread.sleep(ATTEMPT_TIMEOUT_MS); + } catch (InterruptedException e1) { + throw new RuntimeException(e1); + } + continue; + } + + jmxClient = configRegistryJMXClient; + break; + } + } + + @Override + public NetconfOperationServiceImpl createService(long netconfSessionId, String netconfSessionIdForReporting) { + try { + return new NetconfOperationServiceImpl(yangStoreService, jmxClient, netconfSessionIdForReporting); + } catch (YangStoreException e) { + throw new IllegalStateException(e); + } + } +}