*
* @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());
+ "' required by system '"
+ aComponent
+ "' matches multiple services provided by other systems: "
- + Arrays.asList(filtered));
+ + getServers(filtered));
} else {
// filtered.length == 0
if ( !descriptor.isOptional()) {
}
@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);
}
}
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<Component> getClients(RequiredInterface aRequirement) {
List<Component> clients = new ArrayList<Component>();