// #3 This bundle's state is set to {@code STARTING}.
setState(State.STARTING);
// #4 A module event of type {@link ModuleEvent#STARTING} is fired.
RuntimeEventsManager eventHandler = getRuntime().adapt(RuntimeEventsManager.class);
eventHandler.fireModuleEvent(this, ModuleEvent.STARTING);
// Create the {@link ModuleContext}
createModuleContext();
// #5 The {@link ModuleActivator#start(ModuleContext)} method if one is specified, is called.
try {
Boolean graviaEnabled = Boolean.parseBoolean(getHeaders().get(Constants.GRAVIA_ENABLED));
String moduleActivatorName = getHeaders().get(Constants.MODULE_ACTIVATOR);
String bundleActivatorName = getHeaders().get("Bundle-Activator");
if (moduleActivatorName != null || bundleActivatorName != null) {
ModuleActivator moduleActivator;
synchronized (MODULE_ACTIVATOR_KEY) {
moduleActivator = getAttachment(MODULE_ACTIVATOR_KEY);
if (moduleActivator == null) {
if (moduleActivatorName != null) {
Object result = loadClass(moduleActivatorName).newInstance();
moduleActivator = (ModuleActivator) result;
putAttachment(MODULE_ACTIVATOR_KEY, moduleActivator);
} else if (bundleActivatorName != null && graviaEnabled) {
Object result = loadClass(bundleActivatorName).newInstance();
moduleActivator = new ModuleActivatorBridge((BundleActivator) result);
putAttachment(MODULE_ACTIVATOR_KEY, moduleActivator);
}
}
}
if (moduleActivator != null) {
moduleActivator.start(getModuleContext());
}
}
}
// If the {@code ModuleActivator} is invalid or throws an exception then:
catch (Throwable th) {
// This module's state is set to {@code STOPPING}.
setState(State.STOPPING);
// A module event of type {@link BundleEvent#STOPPING} is fired.
eventHandler.fireModuleEvent(this, ModuleEvent.STOPPING);
// [TODO] Any services registered by this module must be unregistered.
// [TODO] Any services used by this module must be released.
// [TODO] Any listeners registered by this module must be removed.
// This module's state is set to {@code INSTALLED}.
setState(State.INSTALLED);
// A module event of type {@link BundleEvent#STOPPED} is fired.
eventHandler.fireModuleEvent(this, ModuleEvent.STOPPED);
// Destroy the {@link ModuleContext}
destroyModuleContext();
// A {@code ModuleException} is then thrown.
throw new ModuleException("Cannot start module: " + this, th);
}
// #6 This bundle's state is set to {@code ACTIVE}.
setState(State.ACTIVE);
// #7 A module event of type {@link ModuleEvent#STARTED} is fired.
eventHandler.fireModuleEvent(this, ModuleEvent.STARTED);
LOGGER.info("Started: {}", this);
} catch (InterruptedException ex) {
throw ModuleException.launderThrowable(ex);
} finally {