X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=system%2Fgeneral%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fsystem%2Fcore%2FContainer.java;h=f1b8b1ec0380fe4204f7f2021dd97c9bf8e53de9;hb=fc10e15e031cf409146b04cbb5e98b649c6ccddc;hp=df92c0d099dcb4a61e219bb6047a7b5bea672783;hpb=d89a08c127770dfe9b25e88495c7545bbcc938fa;p=utils diff --git a/system/general/src/main/java/org/wamblee/system/core/Container.java b/system/general/src/main/java/org/wamblee/system/core/Container.java index df92c0d0..f1b8b1ec 100644 --- a/system/general/src/main/java/org/wamblee/system/core/Container.java +++ b/system/general/src/main/java/org/wamblee/system/core/Container.java @@ -29,7 +29,7 @@ import org.apache.commons.logging.LogFactory; * * @author Erik Brakkee */ -public class Container extends AbstractComponent { +public class Container extends AbstractComponent { private static final Log LOG = LogFactory.getLog(Container.class); @@ -176,10 +176,18 @@ public class Container extends AbstractComponent { } } } + + 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 allProvided = new ArrayList(); // all interfaces from the required list of this container are @@ -203,7 +211,8 @@ public class Container extends AbstractComponent { checkAllRequiredServicesAlreadyProvided(allProvided, component); // Start the service. - component.start(); + Object runtime = component.start(scope); + scope.addRuntime(component, runtime); started.add(component); // add all provided services @@ -214,19 +223,19 @@ public class Container extends AbstractComponent { } 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 aStarted) { + private void stopAlreadyStartedComponents(List 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()); @@ -268,9 +277,11 @@ public class Container extends AbstractComponent { } @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); } }