X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=system%2Fgeneral%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fsystem%2FAbstractSubSystem.java;h=6ae6f3cc566fc7f29cf01ca1fd74a3b7476a9b8b;hb=cd54b07b42712775ea414fd3cc60d332948e96a2;hp=7a6724f32ea8af702df9d9f45527f1dc53b09c98;hpb=fe01768589f67e25c16254bf27a8631ceb78afe0;p=utils diff --git a/system/general/src/main/java/org/wamblee/system/AbstractSubSystem.java b/system/general/src/main/java/org/wamblee/system/AbstractSubSystem.java index 7a6724f3..6ae6f3cc 100644 --- a/system/general/src/main/java/org/wamblee/system/AbstractSubSystem.java +++ b/system/general/src/main/java/org/wamblee/system/AbstractSubSystem.java @@ -17,6 +17,7 @@ public abstract class AbstractSubSystem implements SubSystem { private static final Log LOG = LogFactory.getLog(AbstractSubSystem.class); private String _name; + private ServiceRegistry _registry; private List _provided; private List _required; private Map _running; @@ -33,9 +34,10 @@ public abstract class AbstractSubSystem implements SubSystem { * @param aRequired * Required services. */ - protected AbstractSubSystem(String aName, ServiceDescriptor[] aProvided, + protected AbstractSubSystem(String aName, ServiceRegistry aRegistry, ServiceDescriptor[] aProvided, ServiceDescriptor[] aRequired) { _name = aName; + _registry = aRegistry; _provided = new ArrayList(); _provided.addAll(Arrays.asList(aProvided)); _required = new ArrayList(); @@ -47,6 +49,10 @@ public abstract class AbstractSubSystem implements SubSystem { public final String getName() { return _name; } + + public ServiceRegistry getRegistry() { + return _registry; + } @Override public final ServiceDescriptor[] getProvidedServices() { @@ -59,25 +65,23 @@ public abstract class AbstractSubSystem implements SubSystem { } @Override - public final Service[] start(String aContext, ServiceRegistry aRegistry, + public final Service[] start(String aContext, Service[] aRequiredServices) { LOG.info("Initializing '" + aContext + "." + _name + "' with " + Arrays.asList(aRequiredServices)); - doStart(aContext + "." + getName(), aRegistry, aRequiredServices); + doStart(aContext + "." + getName(), aRequiredServices); return _running.values().toArray(new Service[0]); } /** * Must be implemented for initializing the subsystem. The implementation * must call {@link #addService(Service)} for each service that is started. - * - * @param aRegistry Service registry. + * * @param aRequiredServices * Services that are already running from other subsystems that * may be used. */ protected abstract void doStart(String aContext, - ServiceRegistry aRegistry, Service[] aRequiredServices); /** @@ -88,10 +92,9 @@ public abstract class AbstractSubSystem implements SubSystem { * Service. */ protected final void addService(String aContext, - ServiceRegistry aRegistry, ServiceDescriptor aDescriptor, Object aService) { LOG.info(aContext + ": service '" + aService + "' started."); - Service svc = aRegistry.register(aDescriptor, aService); + Service svc = getRegistry().register(aDescriptor, aService); _running.put(svc.getDescriptor(), svc); } @@ -101,14 +104,14 @@ public abstract class AbstractSubSystem implements SubSystem { } @Override - public void stop(String aContext, ServiceRegistry aRegistry) { - doStop(aContext); + public void stop() { + doStop(); for (Service svc: _running.values()) { - aRegistry.remove(svc); + getRegistry().remove(svc); } } - protected abstract void doStop(String aContext); + protected abstract void doStop(); @Override public String toString() {