* in case of any validation problems.
*/
public void validate() {
- List<ProvidedInterface> provided = new ArrayList<ProvidedInterface>();
- for (Component component : _components) {
- provided.addAll(Arrays.asList(component.getProvidedInterfaces()));
- }
+ validateProvidedInterfacesArePresent();
- List<RequiredInterface> required = new ArrayList<RequiredInterface>();
- for (Component component : _components) {
- required.addAll(Arrays.asList(component.getRequiredInterfaces()));
- }
-
- validateProvidedInterfacesArePresent(provided);
-
- validateRequiredInterfaces(required);
+ validateRequiredInterfaces();
- addProvidersOfRequiredInterfaces(provided);
- validateRequiredProvidedMatch(provided, required);
+ doStartOptionalDryRun(null, true);
}
- /**
- *
- * @param aProvided
- * All provided interfaces.
- * @param aRequired
- * All required interfaces.
- * @return
- */
- private void validateRequiredProvidedMatch(
- List<ProvidedInterface> aProvided, List<RequiredInterface> aRequired) {
-
+ private void validateRequiredInterfaces() {
+ List<RequiredInterface> required = new ArrayList<RequiredInterface>();
for (Component component : _components) {
- initializeProvidersForRequiredInterfaces(aProvided, component, true);
+ required.addAll(Arrays.asList(component.getRequiredInterfaces()));
}
- }
- private void validateRequiredInterfaces(List<RequiredInterface> aRequired) {
for (RequiredInterface service : getRequiredInterfaces()) {
// TODO required interfaces by the component could be
// subclasses or implementations of the requirements
// of the contained components. The code below assumes
// an exact match.
- if (!(aRequired.contains(service))) {
+ if (!(required.contains(service))) {
info("Service '"
+ service
+ "' indicated as required is not actually required by any of the components");
// is optional whereas the internally required service is
// mandatory.
if (service.isOptional()) {
- for (RequiredInterface intf : aRequired) {
+ for (RequiredInterface intf : required) {
if (intf.equals(service) && !intf.isOptional()) {
warn("Required service '"
+ service
}
}
- private void validateProvidedInterfacesArePresent(
- List<ProvidedInterface> aProvided) {
+ private void validateProvidedInterfacesArePresent() {
+ List<ProvidedInterface> provided = new ArrayList<ProvidedInterface>();
+ for (Component component : _components) {
+ provided.addAll(Arrays.asList(component.getProvidedInterfaces()));
+ }
for (ProvidedInterface service : getProvidedInterfaces()) {
// TODO provided interfaces by components could be
// provide subclasses or implementations of the
// provided interfaces of the container.
// The code below assumes an exact match.
- if (!(aProvided.contains(service))) {
+ if (!(provided.contains(service))) {
throw new SystemAssemblyException(getName() + ": Service '"
+ service
+ "' is not provided by any of its components");
@Override
protected Scope doStart(Scope aExternalScope) {
+ return doStartOptionalDryRun(aExternalScope, false);
+ }
+
+ private Scope doStartOptionalDryRun(Scope aExternalScope, boolean aDryRun) {
LOG.info("Starting '" + getQualifiedName() + "'");
Scope scope = new DefaultScope(getProvidedInterfaces(), aExternalScope);
for (Component component : _components) {
try {
initializeProvidersForRequiredInterfaces(allProvided,
- component, false);
+ component, aDryRun);
// Start the service.
- Object runtime = component.start(scope);
- scope.addRuntime(component, runtime);
- started.add(component);
+ if (!aDryRun) {
+ Object runtime = component.start(scope);
+ scope.addRuntime(component, runtime);
+ started.add(component);
+ }
// add all provided services
ProvidedInterface[] provided = component
// components
for (int i = aStarted.size() - 1; i >= 0; i--) {
try {
- aStarted.get(i).stop(aScope);
+ Component component = aStarted.get(i);
+ aStarted.get(i).stop(aScope.getRuntime(component));
} catch (Throwable t) {
LOG.error(getQualifiedName() + ": error stopping "
+ aStarted.get(i).getQualifiedName());