private static final Log LOG = LogFactory.getLog(AbstractComponent.class);
- private Status _status;
private String _context;
private String _name;
private List<ProvidedInterface> _provided;
*/
protected AbstractComponent(String aName, ProvidedInterface[] aProvided,
RequiredInterface[] aRequired) {
- _status = Status.NOT_STARTED;
_context = null;
_name = aName;
_provided = new ArrayList<ProvidedInterface>();
_required.addAll(Arrays.asList(aRequired));
_running = new HashSet<ProvidedInterface>();
}
-
- @Override
- public Status getStatus() {
- return _status;
- }
@Override
public final String 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);
* @param aService
* Service.
*/
- protected final void addService(
+ protected final void addInterface(
ProvidedInterface aDescriptor, Object aService) {
LOG.info("Interface '" + getQualifiedName() + "." + aDescriptor.getName() + "' started.");
_running.add(aDescriptor);
}
@Override
- public ProvidedInterface[] getRunningServices() {
+ public ProvidedInterface[] getRunningInterfaces() {
return _running.toArray(new ProvidedInterface[0]);
}
@Override
public void stop() {
- doStop();
- _status = Status.STOPPED;
+ doStop();
+ if ( _running.size() > 0 ) {
+ // programming error.
+ throw new RuntimeException(getQualifiedName() + ": still services running after the stop call.");
+ }
}
- protected abstract void doStop();
+ protected abstract void doStop();
+
+ /**
+ * Implementations must call this method to indicate that a running service has
+ * been stopped.
+ *
+ * @param aService
+ * Service.
+ */
+ protected final void removeInterface(
+ ProvidedInterface aDescriptor) {
+ LOG.info("Interface '" + getQualifiedName() + "." + aDescriptor.getName() + "' stopped.");
+ _running.remove(aDescriptor);
+ aDescriptor.publish(null);
+ }
@Override
public String toString() {
- return _name;
+ return getQualifiedName();
}
}