/**
* Abstract subsystem class making it easy to implement new subsystems.
*/
-public abstract class AbstractSubSystem implements SubSystem {
+public abstract class AbstractComponent implements Component {
- private static final Log LOG = LogFactory.getLog(AbstractSubSystem.class);
+ private static final Log LOG = LogFactory.getLog(AbstractComponent.class);
private String _name;
private ServiceRegistry _registry;
- private List<ServiceDescriptor> _provided;
- private List<ServiceDescriptor> _required;
- private Map<ServiceDescriptor, Service> _running;
+ private List<InterfaceDescriptor> _provided;
+ private List<InterfaceDescriptor> _required;
+ private Map<InterfaceDescriptor, Service> _running;
/**
* Constructs the subsystem.
* @param aRequired
* Required services.
*/
- protected AbstractSubSystem(String aName, ServiceRegistry aRegistry, ServiceDescriptor[] aProvided,
- ServiceDescriptor[] aRequired) {
+ protected AbstractComponent(String aName, ServiceRegistry aRegistry, InterfaceDescriptor[] aProvided,
+ InterfaceDescriptor[] aRequired) {
_name = aName;
_registry = aRegistry;
- _provided = new ArrayList<ServiceDescriptor>();
+ _provided = new ArrayList<InterfaceDescriptor>();
_provided.addAll(Arrays.asList(aProvided));
- _required = new ArrayList<ServiceDescriptor>();
+ _required = new ArrayList<InterfaceDescriptor>();
_required.addAll(Arrays.asList(aRequired));
- _running = new HashMap<ServiceDescriptor, Service>();
+ _running = new HashMap<InterfaceDescriptor, Service>();
}
@Override
}
@Override
- public final ProvidedServiceDescriptor[] getProvidedServices() {
- return _provided.toArray(new ProvidedServiceDescriptor[0]);
+ public final ProvidedInterfaceDescriptor[] getProvidedServices() {
+ return _provided.toArray(new ProvidedInterfaceDescriptor[0]);
}
@Override
- public final RequiredServiceDescriptor[] getRequiredServices() {
- return _required.toArray(new RequiredServiceDescriptor[0]);
+ public final RequiredInterfaceDescriptor[] getRequiredServices() {
+ return _required.toArray(new RequiredInterfaceDescriptor[0]);
}
@Override
* Service.
*/
protected final void addService(String aContext,
- ProvidedServiceDescriptor aDescriptor, Object aService) {
+ ProvidedInterfaceDescriptor aDescriptor, Object aService) {
LOG.info(aContext + ": service '" + aService + "' started.");
Service svc = getRegistry().register(aDescriptor, aService);
_running.put(svc.getDescriptor(), svc);
*
* @author Erik Brakkee
*/
-public abstract class AbstractServiceDescriptor implements ServiceDescriptor {
+public abstract class AbstractInterfaceDescriptor implements InterfaceDescriptor {
private String _name;
private Class[] _interfaces;
* Constructs the descriptor.
* @param aInterface Type of service.
*/
- public AbstractServiceDescriptor(String aName, Class aInterface) {
+ public AbstractInterfaceDescriptor(String aName, Class aInterface) {
_name = aName;
_interfaces = new Class[] { aInterface };
}
- public AbstractServiceDescriptor(String aName, Class[] aInterfaces) {
+ public AbstractInterfaceDescriptor(String aName, Class[] aInterfaces) {
_name = aName;
_interfaces = Arrays.copyOf(aInterfaces, aInterfaces.length);
}
@Override
public boolean equals(Object obj) {
- if ( !(obj instanceof AbstractServiceDescriptor)) {
+ if ( !(obj instanceof AbstractInterfaceDescriptor)) {
return false;
}
- AbstractServiceDescriptor descr = (AbstractServiceDescriptor)obj;
+ AbstractInterfaceDescriptor descr = (AbstractInterfaceDescriptor)obj;
if ( _interfaces.length != descr._interfaces.length ) {
return false;
}
package org.wamblee.system;
/**
- * A sub system represents a part of a system that required a
- * number of services and provides a number of services.
+ * A component represents a part of a system that requires a
+ * number of interfaces and provides a number of interfaces.
*
* @author Erik Brakkee
*/
-public interface SubSystem {
+public interface Component {
/**
* Gets the name of the subsystem.
* Gets a description of the provided interfaces.
* @return Provided interfaces.
*/
- ProvidedServiceDescriptor[] getProvidedServices();
+ ProvidedInterfaceDescriptor[] getProvidedServices();
/**
* Gets a description of the required interfaces.
* @return Required interfaces.
*/
- RequiredServiceDescriptor[] getRequiredServices();
+ RequiredInterfaceDescriptor[] getRequiredServices();
/**
*
* @author Erik Brakkee
*/
-public class CompositeSystem extends AbstractSubSystem {
+public class CompositeSystem extends AbstractComponent {
private static final Log LOG = LogFactory.getLog(CompositeSystem.class);
- private SubSystem[] _systems;
+ private Component[] _systems;
/**
* Construcst the composite system.
* @param aProvided Provided services of the system.
* @param aRequired Required services by the system.
*/
- public CompositeSystem(String aName, ServiceRegistry aRegistry, SubSystem[] aSystems,
- ServiceDescriptor[] aProvided, ServiceDescriptor[] aRequired) {
+ public CompositeSystem(String aName, ServiceRegistry aRegistry, Component[] aSystems,
+ InterfaceDescriptor[] aProvided, InterfaceDescriptor[] aRequired) {
super(aName, aRegistry, aProvided, aRequired);
_systems = aSystems;
validate();
* Also logs a warning in case of superfluous requirements.
*/
private void validate() {
- List<ServiceDescriptor> provided = new ArrayList<ServiceDescriptor>();
- for (SubSystem system : _systems) {
+ List<InterfaceDescriptor> provided = new ArrayList<InterfaceDescriptor>();
+ for (Component system : _systems) {
provided.addAll(Arrays.asList(system.getProvidedServices()));
}
- List<ServiceDescriptor> required = new ArrayList<ServiceDescriptor>();
- for (SubSystem system : _systems) {
+ List<InterfaceDescriptor> required = new ArrayList<InterfaceDescriptor>();
+ for (Component system : _systems) {
required.addAll(Arrays.asList(system.getRequiredServices()));
}
- for (ServiceDescriptor service : getProvidedServices()) {
+ for (InterfaceDescriptor service : getProvidedServices()) {
if (!(provided.contains(service))) {
throw new SystemAssemblyException(getName() + ": Service '" + service
+ "' is not provided by any of the subsystems");
}
}
- for (ServiceDescriptor service : getRequiredServices()) {
+ for (InterfaceDescriptor service : getRequiredServices()) {
if (!(required.contains(service))) {
info("Service '"
+ service
}
}
- List<ServiceDescriptor> reallyRequired = new ArrayList<ServiceDescriptor>(
+ List<InterfaceDescriptor> reallyRequired = new ArrayList<InterfaceDescriptor>(
required);
- for (ServiceDescriptor service : provided) {
+ for (InterfaceDescriptor service : provided) {
reallyRequired.remove(service);
}
- for (ServiceDescriptor service: getRequiredServices()) {
+ for (InterfaceDescriptor service: getRequiredServices()) {
reallyRequired.remove(service);
}
- for (ServiceDescriptor service: reallyRequired) {
+ for (InterfaceDescriptor service: reallyRequired) {
throw new SystemAssemblyException(getName() + ": " + "Service '" + service + "' is not provided internally and is not indicated as required for this sub system");
}
}
@Override
protected void doStart(String aContext, Service[] aRequiredServices) {
- List<ProvidedServiceDescriptor> descriptors = new ArrayList<ProvidedServiceDescriptor>();
+ List<ProvidedInterfaceDescriptor> descriptors = new ArrayList<ProvidedInterfaceDescriptor>();
for (Service service : aRequiredServices) {
descriptors.add(service.getDescriptor());
}
SystemAssembler assembler = new SystemAssembler(aContext + "." + getName(), _systems,
- descriptors.toArray(new ProvidedServiceDescriptor[0]));
+ descriptors.toArray(new ProvidedInterfaceDescriptor[0]));
assembler.start(getRegistry(), aRequiredServices);
}
--- /dev/null
+package org.wamblee.system;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+
+public class DefaultProvidedInterfaceDescriptor extends AbstractInterfaceDescriptor implements
+ ProvidedInterfaceDescriptor {
+
+ public DefaultProvidedInterfaceDescriptor(String aName, Class aInterface) {
+ super(aName, aInterface);
+ }
+
+ public DefaultProvidedInterfaceDescriptor(String aName, Class[] aInterface) {
+ super(aName, aInterface);
+ }
+
+}
+++ /dev/null
-package org.wamblee.system;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-
-public class DefaultProvidedServiceDescriptor extends AbstractServiceDescriptor implements
- ProvidedServiceDescriptor {
-
- public DefaultProvidedServiceDescriptor(String aName, Class aInterface) {
- super(aName, aInterface);
- }
-
- public DefaultProvidedServiceDescriptor(String aName, Class[] aInterface) {
- super(aName, aInterface);
- }
-
-}
package org.wamblee.system;
-public class DefaultRequiredServiceDescriptor extends AbstractServiceDescriptor
- implements RequiredServiceDescriptor {
+public class DefaultRequiredInterfaceDescriptor extends AbstractInterfaceDescriptor
+ implements RequiredInterfaceDescriptor {
- public DefaultRequiredServiceDescriptor(String aName, Class aInterface) {
+ public DefaultRequiredInterfaceDescriptor(String aName, Class aInterface) {
super(aName, aInterface);
}
- public DefaultRequiredServiceDescriptor(String aName, Class[] aInterfaces) {
+ public DefaultRequiredInterfaceDescriptor(String aName, Class[] aInterfaces) {
super(aName, aInterfaces);
}
@Override
- public boolean implementedBy(ProvidedServiceDescriptor aDescriptor) {
+ public boolean implementedBy(ProvidedInterfaceDescriptor aDescriptor) {
Class[] provided = aDescriptor.getInterfaceTypes();
for (Class required : getInterfaceTypes()) {
if ( !serviceProvided(required, provided)) {
public class DefaultService implements Service {
private String _id;
- private ProvidedServiceDescriptor _descriptor;
+ private ProvidedInterfaceDescriptor _descriptor;
private Object _service;
/**
* @param aService
* Service.
*/
- public DefaultService(String aId, ProvidedServiceDescriptor aDescriptor,
+ public DefaultService(String aId, ProvidedInterfaceDescriptor aDescriptor,
Object aService) {
_id = aId;
_descriptor = aDescriptor;
}
@Override
- public ProvidedServiceDescriptor getDescriptor() {
+ public ProvidedInterfaceDescriptor getDescriptor() {
return _descriptor;
}
}
@Override
- public synchronized Service register(ProvidedServiceDescriptor aDescriptor,
+ public synchronized Service register(ProvidedInterfaceDescriptor aDescriptor,
Object aService) {
_count++;
String id = "" + _count;
*
* @author Erik Brakkee
*/
-public interface ServiceDescriptor {
+public interface InterfaceDescriptor {
/**
* Symbolic name for the service as used by the subsystem.
--- /dev/null
+package org.wamblee.system;
+
+import java.util.Collection;
+
+public interface ProvidedInterfaceDescriptor extends InterfaceDescriptor {
+ // Empty
+}
+++ /dev/null
-package org.wamblee.system;
-
-import java.util.Collection;
-
-public interface ProvidedServiceDescriptor extends ServiceDescriptor {
- // Empty
-}
--- /dev/null
+package org.wamblee.system;
+
+public interface RequiredInterfaceDescriptor extends InterfaceDescriptor {
+
+ boolean implementedBy(ProvidedInterfaceDescriptor aDescriptor);
+}
+++ /dev/null
-package org.wamblee.system;
-
-public interface RequiredServiceDescriptor extends ServiceDescriptor {
-
- boolean implementedBy(ProvidedServiceDescriptor aDescriptor);
-}
* Gets the descriptor of the service.
* @return Descriptor.
*/
- ProvidedServiceDescriptor getDescriptor();
+ ProvidedInterfaceDescriptor getDescriptor();
/**
* Returns a reference to the running service.
public interface ServiceRegistry {
- Service register(ProvidedServiceDescriptor aDescriptor, Object aService);
+ Service register(ProvidedInterfaceDescriptor aDescriptor, Object aService);
void remove(Service aService);
private static final String ROOT_CONTEXT_NAME = "root";
private String _context;
- private SubSystem[] _systems;
+ private Component[] _systems;
- public static RequiredServiceDescriptor[] filterRequiredServices(
- ProvidedServiceDescriptor aProvided,
- Collection<RequiredServiceDescriptor> aDescriptors) {
- List<RequiredServiceDescriptor> required = new ArrayList<RequiredServiceDescriptor>();
- for (RequiredServiceDescriptor descriptor : aDescriptors) {
+ public static RequiredInterfaceDescriptor[] filterRequiredServices(
+ ProvidedInterfaceDescriptor aProvided,
+ Collection<RequiredInterfaceDescriptor> aDescriptors) {
+ List<RequiredInterfaceDescriptor> required = new ArrayList<RequiredInterfaceDescriptor>();
+ for (RequiredInterfaceDescriptor descriptor : aDescriptors) {
if (descriptor.implementedBy(aProvided)) {
required.add(descriptor);
}
}
- return required.toArray(new RequiredServiceDescriptor[0]);
+ return required.toArray(new RequiredInterfaceDescriptor[0]);
}
- public static ProvidedServiceDescriptor[] filterProvidedServices(
- RequiredServiceDescriptor aRequired,
- Collection<ProvidedServiceDescriptor> aProvided) {
- List<ProvidedServiceDescriptor> provided = new ArrayList<ProvidedServiceDescriptor>();
- for (ProvidedServiceDescriptor descriptor : aProvided) {
+ public static ProvidedInterfaceDescriptor[] filterProvidedServices(
+ RequiredInterfaceDescriptor aRequired,
+ Collection<ProvidedInterfaceDescriptor> aProvided) {
+ List<ProvidedInterfaceDescriptor> provided = new ArrayList<ProvidedInterfaceDescriptor>();
+ for (ProvidedInterfaceDescriptor descriptor : aProvided) {
if (aRequired.implementedBy(descriptor)) {
provided.add(descriptor);
}
}
- return provided.toArray(new ProvidedServiceDescriptor[0]);
+ return provided.toArray(new ProvidedInterfaceDescriptor[0]);
}
/**
* Available services from other systems outside of the systems
* that this assembler manages.
*/
- public SystemAssembler(SubSystem[] aSystems,
- ProvidedServiceDescriptor[] aAvailableServices) {
+ public SystemAssembler(Component[] aSystems,
+ ProvidedInterfaceDescriptor[] aAvailableServices) {
this(ROOT_CONTEXT_NAME, aSystems, aAvailableServices);
}
* Available services from other systems outside of the systems
* that this assembler manages.
*/
- public SystemAssembler(String aContext, SubSystem[] aSystems,
- ProvidedServiceDescriptor[] aAvailableServices) {
+ public SystemAssembler(String aContext, Component[] aSystems,
+ ProvidedInterfaceDescriptor[] aAvailableServices) {
_context = aContext;
_systems = aSystems;
validate(aAvailableServices);
* Determines if the systems are ordered appropriately so that all
* dependencies are met.
*/
- private void validate(ProvidedServiceDescriptor[] aDescriptors)
+ private void validate(ProvidedInterfaceDescriptor[] aDescriptors)
throws SystemAssemblyException {
- List<ProvidedServiceDescriptor> allProvided = new ArrayList<ProvidedServiceDescriptor>();
- for (ProvidedServiceDescriptor descriptor : aDescriptors) {
+ List<ProvidedInterfaceDescriptor> allProvided = new ArrayList<ProvidedInterfaceDescriptor>();
+ for (ProvidedInterfaceDescriptor descriptor : aDescriptors) {
allProvided.add(descriptor);
}
- for (SubSystem system : _systems) {
+ for (Component system : _systems) {
// Check if all required services are already provided by earlier
// systems.
- RequiredServiceDescriptor[] required = system.getRequiredServices();
+ RequiredInterfaceDescriptor[] required = system.getRequiredServices();
- for (RequiredServiceDescriptor descriptor : required) {
- ProvidedServiceDescriptor[] filtered = filterProvidedServices(
+ for (RequiredInterfaceDescriptor descriptor : required) {
+ ProvidedInterfaceDescriptor[] filtered = filterProvidedServices(
descriptor, allProvided);
if (filtered.length == 0) {
}
// add all provided services
- ProvidedServiceDescriptor[] provided = system.getProvidedServices();
+ ProvidedInterfaceDescriptor[] provided = system.getProvidedServices();
allProvided.addAll(Arrays.asList(provided));
}
}
*/
public void start(ServiceRegistry aRegistry, Service[] aRequiredServices) {
LOG.info("Starting '" + _context + "'");
- Map<ProvidedServiceDescriptor, Service> allProvided = new HashMap<ProvidedServiceDescriptor, Service>();
+ Map<ProvidedInterfaceDescriptor, Service> allProvided = new HashMap<ProvidedInterfaceDescriptor, Service>();
for (Service service : aRequiredServices) {
allProvided.put(service.getDescriptor(), service);
}
- for (SubSystem system : _systems) {
+ for (Component system : _systems) {
// Compose a list of the required services required for the subsystem.
- RequiredServiceDescriptor[] descriptors = system
+ RequiredInterfaceDescriptor[] descriptors = system
.getRequiredServices();
List<Service> services = new ArrayList<Service>();
- for (RequiredServiceDescriptor descriptor : descriptors) {
- ProvidedServiceDescriptor[] provided = filterProvidedServices(
+ for (RequiredInterfaceDescriptor descriptor : descriptors) {
+ ProvidedInterfaceDescriptor[] provided = filterProvidedServices(
descriptor, allProvided.keySet());
services.add(allProvided.get(provided[0]));
}
import javax.sql.DataSource;
-public class Application extends AbstractSubSystem {
- private static final ServiceDescriptor[] REQUIRED =
- new ServiceDescriptor[] {
- new DefaultRequiredServiceDescriptor("datasource", DataSource.class),
- new DefaultRequiredServiceDescriptor("integer", Integer.class)
+public class Application extends AbstractComponent {
+ private static final InterfaceDescriptor[] REQUIRED =
+ new InterfaceDescriptor[] {
+ new DefaultRequiredInterfaceDescriptor("datasource", DataSource.class),
+ new DefaultRequiredInterfaceDescriptor("integer", Integer.class)
};
public Application(ServiceRegistry aRegistry) {
- super("application", aRegistry, new ServiceDescriptor[0], REQUIRED);
+ super("application", aRegistry, new InterfaceDescriptor[0], REQUIRED);
}
@Override
--- /dev/null
+package org.wamblee.system;
+
+import java.io.Serializable;
+
+import junit.framework.TestCase;
+
+public class DefaultInterfaceDescriptorTest extends TestCase {
+
+ public void testOneRequiredOneProvidedMatch() {
+ ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name", String.class);
+ RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name", String.class);
+ assertTrue(required.implementedBy(provided));
+ }
+
+ public void testOneRequiredOneProvidedMatchSubClass() {
+ ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name", Integer.class);
+ RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name", Number.class);
+ assertTrue(required.implementedBy(provided));
+ }
+
+ public void testOneRequiredOneProvidedNoMatch() {
+ ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name", String.class);
+ RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name", Number.class);
+ assertFalse(required.implementedBy(provided));
+ }
+
+ public void testOneRequiredMultipleProvidedMatch() {
+ ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name",
+ new Class[] { String.class, Integer.class} );
+ RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name", String.class);
+ assertTrue(required.implementedBy(provided));
+ }
+
+ private static class MyMultiple implements Runnable, Serializable {
+ @Override
+ public void run() {
+ // Empty
+ }
+ }
+
+ public void testMultipleRequiredOneProvidedMatch() {
+ ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name",
+ MyMultiple.class );
+ RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name",
+ new Class[] {Runnable.class, Serializable.class} );
+ assertTrue(required.implementedBy(provided));
+ }
+
+ public void testMultipleRequiredOneProvidedNoMatch() {
+ ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name",
+ MyMultiple.class );
+ RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name",
+ new Class[] { String.class, Runnable.class} );
+ assertFalse(required.implementedBy(provided));
+ }
+
+ public void testMultipleRequiredMultipleProvidedMatch() {
+ ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name",
+ new Class[] { Runnable.class, Serializable.class, String.class} );
+ RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name",
+ new Class[] {Runnable.class, Serializable.class} );
+ assertTrue(required.implementedBy(provided));
+ }
+
+
+}
+++ /dev/null
-package org.wamblee.system;
-
-import java.io.Serializable;
-
-import junit.framework.TestCase;
-
-public class DefaultServiceDescriptorTest extends TestCase {
-
- public void testOneRequiredOneProvidedMatch() {
- ProvidedServiceDescriptor provided = new DefaultProvidedServiceDescriptor("name", String.class);
- RequiredServiceDescriptor required = new DefaultRequiredServiceDescriptor("name", String.class);
- assertTrue(required.implementedBy(provided));
- }
-
- public void testOneRequiredOneProvidedMatchSubClass() {
- ProvidedServiceDescriptor provided = new DefaultProvidedServiceDescriptor("name", Integer.class);
- RequiredServiceDescriptor required = new DefaultRequiredServiceDescriptor("name", Number.class);
- assertTrue(required.implementedBy(provided));
- }
-
- public void testOneRequiredOneProvidedNoMatch() {
- ProvidedServiceDescriptor provided = new DefaultProvidedServiceDescriptor("name", String.class);
- RequiredServiceDescriptor required = new DefaultRequiredServiceDescriptor("name", Number.class);
- assertFalse(required.implementedBy(provided));
- }
-
- public void testOneRequiredMultipleProvidedMatch() {
- ProvidedServiceDescriptor provided = new DefaultProvidedServiceDescriptor("name",
- new Class[] { String.class, Integer.class} );
- RequiredServiceDescriptor required = new DefaultRequiredServiceDescriptor("name", String.class);
- assertTrue(required.implementedBy(provided));
- }
-
- private static class MyMultiple implements Runnable, Serializable {
- @Override
- public void run() {
- // Empty
- }
- }
-
- public void testMultipleRequiredOneProvidedMatch() {
- ProvidedServiceDescriptor provided = new DefaultProvidedServiceDescriptor("name",
- MyMultiple.class );
- RequiredServiceDescriptor required = new DefaultRequiredServiceDescriptor("name",
- new Class[] {Runnable.class, Serializable.class} );
- assertTrue(required.implementedBy(provided));
- }
-
- public void testMultipleRequiredOneProvidedNoMatch() {
- ProvidedServiceDescriptor provided = new DefaultProvidedServiceDescriptor("name",
- MyMultiple.class );
- RequiredServiceDescriptor required = new DefaultRequiredServiceDescriptor("name",
- new Class[] { String.class, Runnable.class} );
- assertFalse(required.implementedBy(provided));
- }
-
- public void testMultipleRequiredMultipleProvidedMatch() {
- ProvidedServiceDescriptor provided = new DefaultProvidedServiceDescriptor("name",
- new Class[] { Runnable.class, Serializable.class, String.class} );
- RequiredServiceDescriptor required = new DefaultRequiredServiceDescriptor("name",
- new Class[] {Runnable.class, Serializable.class} );
- assertTrue(required.implementedBy(provided));
- }
-
-
-}
import javax.sql.DataSource;
-public class Environment extends AbstractSubSystem {
+public class Environment extends AbstractComponent {
- private static final ProvidedServiceDescriptor[] PROVIDED =
- new ProvidedServiceDescriptor[] {
- new DefaultProvidedServiceDescriptor("datasource", DataSource.class),
- new DefaultProvidedServiceDescriptor("integer", Integer.class)
+ private static final ProvidedInterfaceDescriptor[] PROVIDED =
+ new ProvidedInterfaceDescriptor[] {
+ new DefaultProvidedInterfaceDescriptor("datasource", DataSource.class),
+ new DefaultProvidedInterfaceDescriptor("integer", Integer.class)
};
public Environment(ServiceRegistry aRegistry) {
- super("environment", aRegistry, PROVIDED, new ServiceDescriptor[0]);
+ super("environment", aRegistry, PROVIDED, new InterfaceDescriptor[0]);
}
@Override
}
public void testFilterProvided() {
- RequiredServiceDescriptor req1 = new DefaultRequiredServiceDescriptor(
+ RequiredInterfaceDescriptor req1 = new DefaultRequiredInterfaceDescriptor(
"name", Runnable.class);
- RequiredServiceDescriptor req2 = new DefaultRequiredServiceDescriptor(
+ RequiredInterfaceDescriptor req2 = new DefaultRequiredInterfaceDescriptor(
"name", Serializable.class);
- ProvidedServiceDescriptor prov1 = new DefaultProvidedServiceDescriptor(
+ ProvidedInterfaceDescriptor prov1 = new DefaultProvidedInterfaceDescriptor(
"name", Runnable.class);
- ProvidedServiceDescriptor prov2 = new DefaultProvidedServiceDescriptor(
+ ProvidedInterfaceDescriptor prov2 = new DefaultProvidedInterfaceDescriptor(
"name", Serializable.class);
- ProvidedServiceDescriptor prov3 = new DefaultProvidedServiceDescriptor(
+ ProvidedInterfaceDescriptor prov3 = new DefaultProvidedInterfaceDescriptor(
"name", MyMultiple.class);
- AssertionUtils.assertEquals(new RequiredServiceDescriptor[] { req1 },
+ AssertionUtils.assertEquals(new RequiredInterfaceDescriptor[] { req1 },
SystemAssembler.filterRequiredServices(prov1, Arrays
- .asList(new RequiredServiceDescriptor[] { req1 })));
- AssertionUtils.assertEquals(new RequiredServiceDescriptor[] { req1 },
+ .asList(new RequiredInterfaceDescriptor[] { req1 })));
+ AssertionUtils.assertEquals(new RequiredInterfaceDescriptor[] { req1 },
SystemAssembler
.filterRequiredServices(prov1, Arrays
- .asList(new RequiredServiceDescriptor[] { req1,
+ .asList(new RequiredInterfaceDescriptor[] { req1,
req2 })));
- AssertionUtils.assertEquals(new RequiredServiceDescriptor[] { req1,
+ AssertionUtils.assertEquals(new RequiredInterfaceDescriptor[] { req1,
req2 }, SystemAssembler.filterRequiredServices(prov3, Arrays
- .asList(new RequiredServiceDescriptor[] { req1, req2 })));
+ .asList(new RequiredInterfaceDescriptor[] { req1, req2 })));
- AssertionUtils.assertEquals(new ProvidedServiceDescriptor[] { prov1 },
+ AssertionUtils.assertEquals(new ProvidedInterfaceDescriptor[] { prov1 },
SystemAssembler.filterProvidedServices(req1, Arrays
- .asList(new ProvidedServiceDescriptor[] { prov1 })));
- AssertionUtils.assertEquals(new ProvidedServiceDescriptor[] { prov1 },
+ .asList(new ProvidedInterfaceDescriptor[] { prov1 })));
+ AssertionUtils.assertEquals(new ProvidedInterfaceDescriptor[] { prov1 },
SystemAssembler.filterProvidedServices(req1,
- Arrays.asList(new ProvidedServiceDescriptor[] { prov1,
+ Arrays.asList(new ProvidedInterfaceDescriptor[] { prov1,
prov2 })));
- AssertionUtils.assertEquals(new ProvidedServiceDescriptor[] { prov1,
+ AssertionUtils.assertEquals(new ProvidedInterfaceDescriptor[] { prov1,
prov3 }, SystemAssembler.filterProvidedServices(req1, Arrays
- .asList(new ProvidedServiceDescriptor[] { prov1, prov3 })));
+ .asList(new ProvidedInterfaceDescriptor[] { prov1, prov3 })));
}
public void testEnvironmentApplication() {
- SubSystem environment = new Environment(_registry);
- SubSystem application = new Application(_registry);
- SystemAssembler assembler = new SystemAssembler(new SubSystem[] {
- environment, application }, new ProvidedServiceDescriptor[0]);
+ Component environment = new Environment(_registry);
+ Component application = new Application(_registry);
+ SystemAssembler assembler = new SystemAssembler(new Component[] {
+ environment, application }, new ProvidedInterfaceDescriptor[0]);
assembler.start(_registry, new Service[0]);
Service[] envServices = environment.getRunningServices();
assertEquals(2, envServices.length);
public void testApplicationEnvironment() {
try {
- SubSystem environment = new Environment(_registry);
- SubSystem application = new Application(_registry);
- SystemAssembler assembler = new SystemAssembler(new SubSystem[] {
+ Component environment = new Environment(_registry);
+ Component application = new Application(_registry);
+ SystemAssembler assembler = new SystemAssembler(new Component[] {
application, environment },
- new ProvidedServiceDescriptor[0]);
+ new ProvidedInterfaceDescriptor[0]);
assembler.start(_registry, new Service[0]);
} catch (SystemAssemblyException e) {
// e.printStackTrace();
}
public void testComposite() {
- SubSystem environment = new Environment(_registry);
- SubSystem application = new Application(_registry);
+ Component environment = new Environment(_registry);
+ Component application = new Application(_registry);
CompositeSystem system = new CompositeSystem("all", _registry,
- new SubSystem[] { environment, application },
- new ServiceDescriptor[0], new ServiceDescriptor[0]);
+ new Component[] { environment, application },
+ new InterfaceDescriptor[0], new InterfaceDescriptor[0]);
system.start("root", new Service[0]);
- ServiceDescriptor[] required = system.getRequiredServices();
+ InterfaceDescriptor[] required = system.getRequiredServices();
assertEquals(0, required.length);
- ServiceDescriptor[] provided = system.getProvidedServices();
+ InterfaceDescriptor[] provided = system.getProvidedServices();
assertEquals(0, provided.length);
}
public void testCompositeWithWrongProvidedInfo() {
try {
- SubSystem environment = new Environment(_registry);
- SubSystem application = new Application(_registry);
+ Component environment = new Environment(_registry);
+ Component application = new Application(_registry);
CompositeSystem system = new CompositeSystem(
"all",
_registry,
- new SubSystem[] { environment, application },
- new ServiceDescriptor[] { new DefaultProvidedServiceDescriptor(
+ new Component[] { environment, application },
+ new InterfaceDescriptor[] { new DefaultProvidedInterfaceDescriptor(
"string", String.class) },
- new DefaultRequiredServiceDescriptor[0]);
+ new DefaultRequiredInterfaceDescriptor[0]);
} catch (SystemAssemblyException e) {
return;
}
}
public void testCompositeWithSuperfluousRequiredInfo() {
- SubSystem environment = new Environment(_registry);
- SubSystem application = new Application(_registry);
+ Component environment = new Environment(_registry);
+ Component application = new Application(_registry);
CompositeSystem system = new CompositeSystem("all", _registry,
- new SubSystem[] { environment, application },
- new ServiceDescriptor[0],
- new ServiceDescriptor[] { new DefaultRequiredServiceDescriptor(
+ new Component[] { environment, application },
+ new InterfaceDescriptor[0],
+ new InterfaceDescriptor[] { new DefaultRequiredInterfaceDescriptor(
"string", String.class) });
system.start("root", new Service[0]);
- ServiceDescriptor[] required = system.getRequiredServices();
+ InterfaceDescriptor[] required = system.getRequiredServices();
assertEquals(1, required.length);
- ServiceDescriptor[] provided = system.getProvidedServices();
+ InterfaceDescriptor[] provided = system.getProvidedServices();
assertEquals(0, provided.length);
}
public void testCompositeWithExternalDependencesNotProvided() {
try {
- SubSystem environment = new Environment(_registry);
- SubSystem application = new Application(_registry);
+ Component environment = new Environment(_registry);
+ Component application = new Application(_registry);
CompositeSystem system = new CompositeSystem("all", _registry,
- new SubSystem[] { application }, new ServiceDescriptor[0],
+ new Component[] { application }, new InterfaceDescriptor[0],
application.getRequiredServices());
system.start("root", new Service[0]);
} catch (SystemAssemblyException e) {
public void testCompositeWithExternalDependencesProvided() {
- SubSystem environment = new Environment(_registry);
- SubSystem application = new Application(_registry);
+ Component environment = new Environment(_registry);
+ Component application = new Application(_registry);
CompositeSystem system = new CompositeSystem("all", _registry,
- new SubSystem[] { application }, new ServiceDescriptor[0],
+ new Component[] { application }, new InterfaceDescriptor[0],
application.getRequiredServices());
Service[] envServices = environment.start("env", new Service[0]);
system.start("root", envServices);
- ServiceDescriptor[] required = system.getRequiredServices();
+ InterfaceDescriptor[] required = system.getRequiredServices();
assertEquals(2, required.length);
- ServiceDescriptor[] provided = system.getProvidedServices();
+ InterfaceDescriptor[] provided = system.getProvidedServices();
assertEquals(0, provided.length);
}
public void testAmbiguousInterfaces() {
try {
- SubSystem environment1 = new Environment(_registry);
- SubSystem environment2 = new Environment(_registry);
- SubSystem application = new Application(_registry);
- SystemAssembler assembler = new SystemAssembler(new SubSystem[] {
+ Component environment1 = new Environment(_registry);
+ Component environment2 = new Environment(_registry);
+ Component application = new Application(_registry);
+ SystemAssembler assembler = new SystemAssembler(new Component[] {
environment1, environment2, application },
- new ProvidedServiceDescriptor[0]);
+ new ProvidedInterfaceDescriptor[0]);
assembler.start(_registry, new Service[0]);
+
} catch (SystemAssemblyException e) {
return;
}
fail();
}
+
}
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
-import org.wamblee.system.AbstractSubSystem;
+import org.wamblee.system.AbstractComponent;
import org.wamblee.system.CompositeSystem;
-import org.wamblee.system.ProvidedServiceDescriptor;
-import org.wamblee.system.RequiredServiceDescriptor;
+import org.wamblee.system.ProvidedInterfaceDescriptor;
+import org.wamblee.system.RequiredInterfaceDescriptor;
import org.wamblee.system.Service;
-import org.wamblee.system.ServiceDescriptor;
+import org.wamblee.system.InterfaceDescriptor;
import org.wamblee.system.ServiceRegistry;
import org.wamblee.system.SystemAssembler;
import org.wamblee.system.SystemAssemblyException;
*
* @author Erik Brakkee
*/
-public class SpringSystem extends AbstractSubSystem {
+public class SpringSystem extends AbstractComponent {
/**
* Singleton access to the service registry. Required while starting up.
static ThreadLocal<ServiceRegistry> REGISTRY = new ThreadLocal<ServiceRegistry>();
private String[] _configFiles;
- private Map<String, ProvidedServiceDescriptor> _provided;
- private Map<RequiredServiceDescriptor, String> _required;
+ private Map<String, ProvidedInterfaceDescriptor> _provided;
+ private Map<RequiredInterfaceDescriptor, String> _required;
/**
* Parent application context containing required services.
*/
* service.
*/
public SpringSystem(String aName, ServiceRegistry aRegistry, String[] aConfigFiles,
- Map<String, ProvidedServiceDescriptor> aProvided,
- Map<RequiredServiceDescriptor, String> aRequired) {
- super(aName, aRegistry, aProvided.values().toArray(new ServiceDescriptor[0]),
- aRequired.keySet().toArray(new ServiceDescriptor[0]));
+ Map<String, ProvidedInterfaceDescriptor> aProvided,
+ Map<RequiredInterfaceDescriptor, String> aRequired) {
+ super(aName, aRegistry, aProvided.values().toArray(new InterfaceDescriptor[0]),
+ aRequired.keySet().toArray(new InterfaceDescriptor[0]));
_configFiles = aConfigFiles;
_provided = aProvided;
_required = aRequired;
for (Service svc: aRequiredServices) {
String id = svc.getId();
- ProvidedServiceDescriptor descriptor = svc.getDescriptor();
- RequiredServiceDescriptor[] requiredServices = SystemAssembler.filterRequiredServices(descriptor,
+ ProvidedInterfaceDescriptor descriptor = svc.getDescriptor();
+ RequiredInterfaceDescriptor[] requiredServices = SystemAssembler.filterRequiredServices(descriptor,
_required.keySet());
- for (RequiredServiceDescriptor required: requiredServices) {
+ for (RequiredInterfaceDescriptor required: requiredServices) {
String beanName = _required.get(required);
ConstructorArgumentValues cargs = new ConstructorArgumentValues();
cargs.addGenericArgumentValue(id);
import junit.framework.TestCase;
-import org.wamblee.system.AbstractServiceDescriptor;
-import org.wamblee.system.DefaultProvidedServiceDescriptor;
-import org.wamblee.system.DefaultRequiredServiceDescriptor;
+import org.wamblee.system.AbstractInterfaceDescriptor;
+import org.wamblee.system.DefaultProvidedInterfaceDescriptor;
+import org.wamblee.system.DefaultRequiredInterfaceDescriptor;
import org.wamblee.system.DefaultServiceRegistry;
-import org.wamblee.system.ProvidedServiceDescriptor;
-import org.wamblee.system.RequiredServiceDescriptor;
+import org.wamblee.system.ProvidedInterfaceDescriptor;
+import org.wamblee.system.RequiredInterfaceDescriptor;
import org.wamblee.system.Service;
-import org.wamblee.system.ServiceDescriptor;
+import org.wamblee.system.InterfaceDescriptor;
import org.wamblee.system.ServiceRegistry;
import org.wamblee.system.SystemAssemblyException;
public void testBlackboxSystem() {
SpringSystem system = new SpringSystem("system", _registry,
new String[] { HELLO_SERVICE_SPRING_XML },
- new HashMap<String, ProvidedServiceDescriptor>(),
- new HashMap<RequiredServiceDescriptor, String>());
+ new HashMap<String, ProvidedInterfaceDescriptor>(),
+ new HashMap<RequiredInterfaceDescriptor, String>());
system.start("Hello", new Service[0]);
Service[] services = system.getRunningServices();
assertEquals(0, services.length);
}
public void testOneProvidedService() {
- Map<String, ProvidedServiceDescriptor> provided = new HashMap<String, ProvidedServiceDescriptor>();
- provided.put("helloService", new DefaultProvidedServiceDescriptor(
+ Map<String, ProvidedInterfaceDescriptor> provided = new HashMap<String, ProvidedInterfaceDescriptor>();
+ provided.put("helloService", new DefaultProvidedInterfaceDescriptor(
"hello", HelloService.class));
SpringSystem system = new SpringSystem("system", _registry,
new String[] { HELLO_SERVICE_SPRING_XML }, provided,
- new HashMap<RequiredServiceDescriptor, String>());
+ new HashMap<RequiredInterfaceDescriptor, String>());
system.start("Hello", new Service[0]);
Service[] services = system.getRunningServices();
assertEquals(1, services.length);
try {
SpringSystem system = new SpringSystem("system", _registry,
new String[] { HELLO_SERVICE_SPRING_WITH_REQS_XML },
- new HashMap<String, ProvidedServiceDescriptor>(),
- new HashMap<RequiredServiceDescriptor, String>());
+ new HashMap<String, ProvidedInterfaceDescriptor>(),
+ new HashMap<RequiredInterfaceDescriptor, String>());
system.start("Bla", new Service[0]);
} catch (SystemAssemblyException e) {
//e.printStackTrace();
}
public void testWithRequirement() {
- Map<RequiredServiceDescriptor, String> required = new HashMap<RequiredServiceDescriptor, String>();
- required.put(new DefaultRequiredServiceDescriptor("hello", HelloService.class),
+ Map<RequiredInterfaceDescriptor, String> required = new HashMap<RequiredInterfaceDescriptor, String>();
+ required.put(new DefaultRequiredInterfaceDescriptor("hello", HelloService.class),
"helloService");
SpringSystem system = new SpringSystem("system", _registry,
new String[] { HELLO_SERVICE_SPRING_WITH_REQS_XML },
- new HashMap<String, ProvidedServiceDescriptor>(), required);
+ new HashMap<String, ProvidedInterfaceDescriptor>(), required);
HelloService helloObject = new HelloService("ladida");
- Service helloService = _registry.register(new DefaultProvidedServiceDescriptor("hello", HelloService.class), helloObject);
+ Service helloService = _registry.register(new DefaultProvidedInterfaceDescriptor("hello", HelloService.class), helloObject);
system.start("Bla", new Service[] { helloService } );
system.stop();
}
public void testWithRequirementAndProvidedService() {
- Map<RequiredServiceDescriptor, String> required = new HashMap<RequiredServiceDescriptor, String>();
- required.put(new DefaultRequiredServiceDescriptor("hello", HelloService.class),
+ Map<RequiredInterfaceDescriptor, String> required = new HashMap<RequiredInterfaceDescriptor, String>();
+ required.put(new DefaultRequiredInterfaceDescriptor("hello", HelloService.class),
"helloService");
- Map<String,ProvidedServiceDescriptor> provided = new HashMap<String, ProvidedServiceDescriptor>();
- provided.put("blaService", new DefaultProvidedServiceDescriptor("bla",
+ Map<String,ProvidedInterfaceDescriptor> provided = new HashMap<String, ProvidedInterfaceDescriptor>();
+ provided.put("blaService", new DefaultProvidedInterfaceDescriptor("bla",
BlaService.class));
SpringSystem system = new SpringSystem("system", _registry,
provided, required);
HelloService helloObject = new HelloService("ladida");
- Service helloService = _registry.register(new DefaultProvidedServiceDescriptor("hello", HelloService.class), helloObject);
+ Service helloService = _registry.register(new DefaultProvidedInterfaceDescriptor("hello", HelloService.class), helloObject);
Service[] services = system.start("Bla", new Service[] { helloService } );
assertEquals(1, services.length);