*
* @author Erik Brakkee
*/
-public class Container extends AbstractComponent {
+public class Container extends AbstractComponent<Scope> {
private static final Log LOG = LogFactory.getLog(Container.class);
}
}
}
+
+ public Scope start() {
+ return super.start(new DefaultScope(new ProvidedInterface[0]));
+ }
@Override
- protected void doStart() {
+ protected Scope doStart(Scope aExternalScope) {
LOG.info("Starting '" + getQualifiedName() + "'");
+
+ Scope scope = new DefaultScope(getProvidedInterfaces(),
+ aExternalScope);
+
List<ProvidedInterface> allProvided = new ArrayList<ProvidedInterface>();
// all interfaces from the required list of this container are
checkAllRequiredServicesAlreadyProvided(allProvided, component);
// Start the service.
- component.start();
+ Object runtime = component.start(scope);
+ scope.addRuntime(component, runtime);
started.add(component);
// add all provided services
} catch (RuntimeException e) {
LOG.error(getQualifiedName() + ": could not start '"
+ component.getQualifiedName() + "'", e);
- stopAlreadyStartedComponents(started);
+ stopAlreadyStartedComponents(started, scope);
throw e;
}
}
-
+ return scope;
}
- private void stopAlreadyStartedComponents(List<Component> aStarted) {
+ private void stopAlreadyStartedComponents(List<Component> aStarted, Scope aScope) {
// an exception occurred, stop the successfully started
// components
for (int i = aStarted.size() - 1; i >= 0; i--) {
try {
- aStarted.get(i).stop();
+ aStarted.get(i).stop(aScope);
} catch (Throwable t) {
LOG.error(getQualifiedName() + ": error stopping "
+ aStarted.get(i).getQualifiedName());
}
@Override
- protected void doStop() {
+ protected void doStop(Scope aScope) {
for (int i = _components.length - 1; i >= 0; i--) {
- _components[i].stop();
+ Component component = _components[i];
+ Object runtime = aScope.getRuntime(component);
+ component.stop(runtime);
}
}