X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=system%2Fgeneral%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fsystem%2Fcore%2FContainer.java;h=1c19be341d874e10675fb465ee702b5a662845ea;hb=001d69a3cfa9c4d949963d222c05a3134b594ddb;hp=a0130f7cf3420094198d72b616f3b281a1973987;hpb=b7f387ca0178938325ce7107222188d3912fc1cb;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 a0130f7c..1c19be34 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 @@ -195,28 +195,13 @@ public class Container extends AbstractComponent { // provided interfaces of the container. // The code below assumes an exact match. if (!(provided.contains(service))) { - throw new SystemAssemblyException(getName() + ": Service '" + throw new SystemAssemblyException(getQualifiedName() + ": Service '" + service + "' is not provided by any of its components"); } } } - /** - * Starts the container. After the container is started, the container - * becomes sealed meaning that no further components, required or provided - * interfaces may be added. - * - * @return Scope. - */ - public Scope start() { - checkSealed(); - validate(); - Scope scope = super.start(new DefaultScope(new ProvidedInterface[0])); - seal(); - return scope; - } - /** * Seal the container, meaning that no further components or interfaces may * be added. @@ -233,17 +218,30 @@ public class Container extends AbstractComponent { public boolean isSealed() { return _sealed; } + + /** + * Utility method to start with an empty external scope. This is useful for + * top-level containers which are not part of another container. + * @return Scope. + */ + public Scope start() { + Scope scope = new DefaultScope(getProvidedInterfaces()); + return super.start(scope); + } @Override protected Scope doStart(Scope aExternalScope) { - return doStartOptionalDryRun(aExternalScope, false); + checkSealed(); + validate(); + Scope scope = new DefaultScope(getProvidedInterfaces(), aExternalScope); + doStartOptionalDryRun(scope, false); + seal(); + return scope; } - private Scope doStartOptionalDryRun(Scope aExternalScope, boolean aDryRun) { + private void doStartOptionalDryRun(Scope aScope, boolean aDryRun) { LOG.info("Starting '" + getQualifiedName() + "'"); - Scope scope = new DefaultScope(getProvidedInterfaces(), aExternalScope); - List> allProvided = new ArrayList>(); addProvidersOfRequiredInterfaces(allProvided); @@ -256,8 +254,8 @@ public class Container extends AbstractComponent { // Start the service. if (!aDryRun) { - Object runtime = component.start(scope); - scope.addRuntime(component, runtime); + Object runtime = component.start(aScope); + aScope.addRuntime(component, runtime); started.add(component); } @@ -272,11 +270,10 @@ public class Container extends AbstractComponent { } catch (RuntimeException e) { LOG.error(getQualifiedName() + ": could not start '" + component.getQualifiedName() + "'", e); - stopAlreadyStartedComponents(started, scope); + stopAlreadyStartedComponents(started, aScope); throw e; } } - return scope; } private void addProvidersOfRequiredInterfaces(