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=fd322c6bbd49aabd10187501d630f2db762a2204;hpb=684ac768ff69c436aefd2b07fc94cc61a1e5bdb8;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 fd322c6b..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()); @@ -252,7 +261,7 @@ public class Container extends AbstractComponent { + "' required by system '" + aComponent + "' matches multiple services provided by other systems: " - + Arrays.asList(filtered)); + + getServers(filtered)); } else { // filtered.length == 0 if ( !descriptor.isOptional()) { @@ -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); } } @@ -281,6 +292,22 @@ public class Container extends AbstractComponent { private void warn(String aMsg) { LOG.warn(getQualifiedName() + ": " + aMsg); } + + private String getServers(ProvidedInterface[] aProvidedList ) { + String result = ""; + for (ProvidedInterface provided: aProvidedList) { + result += "(components "; + for (Component component: _components) { + for (ProvidedInterface provided2: component.getProvidedInterfaces()) { + if ( provided.equals(provided2)) { + result += component + " "; + } + } + } + result += ", interface " + provided + ")"; + } + return result; + } private List getClients(RequiredInterface aRequirement) { List clients = new ArrayList();