+/*
+ * Copyright 2007 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.wamblee.system;
import java.util.ArrayList;
private static final Log LOG = LogFactory.getLog(AbstractComponent.class);
- private Status _status;
+ private Status _status;
+ private String _context;
private String _name;
private List<ProvidedInterface> _provided;
private List<RequiredInterface> _required;
protected AbstractComponent(String aName, ProvidedInterface[] aProvided,
RequiredInterface[] aRequired) {
_status = Status.NOT_STARTED;
+ _context = null;
_name = aName;
_provided = new ArrayList<ProvidedInterface>();
_provided.addAll(Arrays.asList(aProvided));
public final String getName() {
return _name;
}
+
+ @Override
+ public void addContext(String aContext) {
+ if (_context == null ) {
+ _context = aContext;
+ }
+ else {
+ _context = aContext + "." + _context;
+ }
+ }
+
+ @Override
+ public String getQualifiedName() {
+ if ( _context == null ) {
+ return getName();
+ }
+ return _context + "." + getName();
+ }
@Override
public final ProvidedInterface[] getProvidedServices() {
}
@Override
- public final void start(String aContext) {
- LOG.info("Initializing '" + aContext + "." + _name + "'");
- doStart(aContext + "." + getName());
+ public final void start() {
+ LOG.info("Initializing '" + getQualifiedName() + "'");
+ doStart();
_status = Status.RUNNING;
+ if ( _running.size() != _provided.size()) {
+ List<ProvidedInterface> remaining =
+ new ArrayList<ProvidedInterface>(_provided);
+ remaining.removeAll(_running);
+ throw new SystemAssemblyException(getQualifiedName() + ": not all services were started, missing " + remaining);
+ }
}
/**
* Must be implemented for initializing the subsystem. The implementation
* must call {@link #addService(Service)} for each service that is started.
*/
- protected abstract void doStart(String aContext);
+ protected abstract void doStart();
/**
* Implementations must call this method to indicate that a new service has
* @param aService
* Service.
*/
- protected final void addService(String aContext,
+ protected final void addService(
ProvidedInterface aDescriptor, Object aService) {
- LOG.info(aContext + ": service '" + aService + "' started.");
+ LOG.info("Interface '" + getQualifiedName() + "." + aDescriptor.getName() + "' started.");
_running.add(aDescriptor);
aDescriptor.publish(aService);
}