added spring subsystem implementation.
[utils] / system / general / src / main / java / org / wamblee / system / AbstractSubSystem.java
index 7a6724f32ea8af702df9d9f45527f1dc53b09c98..6ae6f3cc566fc7f29cf01ca1fd74a3b7476a9b8b 100644 (file)
@@ -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<ServiceDescriptor> _provided;
        private List<ServiceDescriptor> _required;
        private Map<ServiceDescriptor, Service> _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<ServiceDescriptor>();
                _provided.addAll(Arrays.asList(aProvided));
                _required = new ArrayList<ServiceDescriptor>();
@@ -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() {