*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import org.opendaylight.controller.config.spi.ModuleFactory;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleEvent;
import org.opendaylight.controller.config.spi.ModuleFactory;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleEvent;
/**
* OSGi extender that listens for bundle activation events. Reads file
* META-INF/services/org.opendaylight.controller.config.spi.ModuleFactory, each
* line should contain an implementation of ModuleFactory interface. Creates new
* instance with default constructor and registers it into OSGi service
* registry. There is no need for listening for implementing removedBundle as
/**
* OSGi extender that listens for bundle activation events. Reads file
* META-INF/services/org.opendaylight.controller.config.spi.ModuleFactory, each
* line should contain an implementation of ModuleFactory interface. Creates new
* instance with default constructor and registers it into OSGi service
* registry. There is no need for listening for implementing removedBundle as
- * the services are unregistered automatically.
- * Code based on http://www.toedter.com/blog/?p=236
+ * the services are unregistered automatically. Code based on
+ * http://www.toedter.com/blog/?p=236
- logger.trace("Got addingBundle event of bundle {}, resource {}, event {}",
- bundle, resource, event);
+ LOG.trace("Got addingBundle event of bundle {}, resource {}, event {}", bundle, resource, event);
- try (InputStream inputStream = resource.openStream()) {
- List<String> lines = IOUtils.readLines(inputStream);
- for (String factoryClassName : lines) {
+ try {
+ for (String factoryClassName : Resources.readLines(resource, StandardCharsets.UTF_8)) {
- } catch (Exception e) {
- logger.error("Error while reading {}", resource, e);
+
+ return Boolean.TRUE;
+ } catch (final IOException e) {
+ LOG.error("Error while reading {}", resource, e);
- public void removedBundle(Bundle bundle, BundleEvent event, Object object) {
- // workaround for service tracker not getting removed service event
- blankTransactionServiceTracker.blankTransaction();
+ public void removedBundle(final Bundle bundle, final BundleEvent event, final Boolean hasFactory) {
+ if (hasFactory) {
+ // workaround for service tracker not getting removed service event
+ blankTransactionServiceTracker.blankTransactionSync();
+ }
String errorMessage;
Exception ex = null;
try {
Class<?> clazz = bundle.loadClass(factoryClassName);
if (ModuleFactory.class.isAssignableFrom(clazz)) {
try {
String errorMessage;
Exception ex = null;
try {
Class<?> clazz = bundle.loadClass(factoryClassName);
if (ModuleFactory.class.isAssignableFrom(clazz)) {
try {
- logger.debug("Registering {} in bundle {}",
- clazz.getName(), bundle);
- return bundle.getBundleContext().registerService(
- ModuleFactory.class.getName(), clazz.newInstance(),
+ LOG.debug("Registering {} in bundle {}", clazz.getName(), bundle);
+ return bundle.getBundleContext().registerService(ModuleFactory.class.getName(), clazz.newInstance(),
- } catch (InstantiationException e) {
- errorMessage = logMessage(
- "Could not instantiate {} in bundle {}, reason {}",
- factoryClassName, bundle, e);
+ } catch (final InstantiationException e) {
+ errorMessage = logMessage("Could not instantiate {} in bundle {}, reason {}", factoryClassName,
+ bundle, e);
- } catch (IllegalAccessException e) {
- errorMessage = logMessage(
- "Illegal access during instantiation of class {} in bundle {}, reason {}",
+ } catch (final IllegalAccessException e) {
+ errorMessage = logMessage("Illegal access during instantiation of class {} in bundle {}, reason {}",
- errorMessage = logMessage(
- "Class {} does not implement {} in bundle {}", clazz,
- ModuleFactory.class, bundle);
+ errorMessage = logMessage("Class {} does not implement {} in bundle {}", clazz, ModuleFactory.class,
+ bundle);
- } catch (ClassNotFoundException e) {
- errorMessage = logMessage(
- "Could not find class {} in bundle {}, reason {}",
- factoryClassName, bundle, e);
+ } catch (final ClassNotFoundException e) {
+ errorMessage = logMessage("Could not find class {} in bundle {}, reason {}", factoryClassName, bundle, e);
- public static String logMessage(String slfMessage, Object... params) {
- logger.info(slfMessage, params);
+ public static String logMessage(final String slfMessage, final Object... params) {
+ LOG.info(slfMessage, params);