private Status _status;
private String _name;
private ServiceRegistry _registry;
- private List<ProvidedInterfaceDescriptor> _provided;
- private List<RequiredInterfaceDescriptor> _required;
- private Map<ProvidedInterfaceDescriptor, Service> _running;
+ private List<ProvidedInterface> _provided;
+ private List<RequiredInterface> _required;
+ private Map<ProvidedInterface, Service> _running;
/**
* Constructs the subsystem.
* @param aRequired
* Required services.
*/
- protected AbstractComponent(String aName, ServiceRegistry aRegistry, ProvidedInterfaceDescriptor[] aProvided,
- RequiredInterfaceDescriptor[] aRequired) {
+ protected AbstractComponent(String aName, ServiceRegistry aRegistry, ProvidedInterface[] aProvided,
+ RequiredInterface[] aRequired) {
_status = Status.NOT_STARTED;
_name = aName;
_registry = aRegistry;
- _provided = new ArrayList<ProvidedInterfaceDescriptor>();
+ _provided = new ArrayList<ProvidedInterface>();
_provided.addAll(Arrays.asList(aProvided));
- _required = new ArrayList<RequiredInterfaceDescriptor>();
+ _required = new ArrayList<RequiredInterface>();
_required.addAll(Arrays.asList(aRequired));
- _running = new HashMap<ProvidedInterfaceDescriptor, Service>();
+ _running = new HashMap<ProvidedInterface, Service>();
}
@Override
}
@Override
- public final ProvidedInterfaceDescriptor[] getProvidedServices() {
- return _provided.toArray(new ProvidedInterfaceDescriptor[0]);
+ public final ProvidedInterface[] getProvidedServices() {
+ return _provided.toArray(new ProvidedInterface[0]);
}
@Override
- public final RequiredInterfaceDescriptor[] getRequiredServices() {
- return _required.toArray(new RequiredInterfaceDescriptor[0]);
+ public final RequiredInterface[] getRequiredServices() {
+ return _required.toArray(new RequiredInterface[0]);
}
@Override
* Service.
*/
protected final void addService(String aContext,
- ProvidedInterfaceDescriptor aDescriptor, Object aService) {
+ ProvidedInterface aDescriptor, Object aService) {
LOG.info(aContext + ": service '" + aService + "' started.");
Service svc = getRegistry().register(aDescriptor, aService);
_running.put(svc.getDescriptor(), svc);
* Gets a description of the provided interfaces.
* @return Provided interfaces.
*/
- ProvidedInterfaceDescriptor[] getProvidedServices();
+ ProvidedInterface[] getProvidedServices();
/**
* Gets a description of the required interfaces.
* @return Required interfaces.
*/
- RequiredInterfaceDescriptor[] getRequiredServices();
+ RequiredInterface[] getRequiredServices();
/**
* @param aRequired Required services by the system.
*/
public Container(String aName, ServiceRegistry aRegistry, Component[] aSystems,
- ProvidedInterfaceDescriptor[] aProvided, RequiredInterfaceDescriptor[] aRequired) {
+ ProvidedInterface[] aProvided, RequiredInterface[] aRequired) {
super(aName, aRegistry, aProvided, aRequired);
_systems = aSystems;
validate();
* Also logs a warning in case of superfluous requirements.
*/
private void validate() {
- List<ProvidedInterfaceDescriptor> provided = new ArrayList<ProvidedInterfaceDescriptor>();
+ List<ProvidedInterface> provided = new ArrayList<ProvidedInterface>();
for (Component system : _systems) {
provided.addAll(Arrays.asList(system.getProvidedServices()));
}
- List<RequiredInterfaceDescriptor> required = new ArrayList<RequiredInterfaceDescriptor>();
+ List<RequiredInterface> required = new ArrayList<RequiredInterface>();
for (Component system : _systems) {
required.addAll(Arrays.asList(system.getRequiredServices()));
}
- for (ProvidedInterfaceDescriptor service : getProvidedServices()) {
+ for (ProvidedInterface service : getProvidedServices()) {
if (!(provided.contains(service))) {
throw new SystemAssemblyException(getName() + ": Service '" + service
+ "' is not provided by any of the subsystems");
}
}
- for (RequiredInterfaceDescriptor service : getRequiredServices()) {
+ for (RequiredInterface service : getRequiredServices()) {
if (!(required.contains(service))) {
info("Service '"
+ service
}
}
- List<RequiredInterfaceDescriptor> reallyRequired = new ArrayList<RequiredInterfaceDescriptor>(
+ List<RequiredInterface> reallyRequired = new ArrayList<RequiredInterface>(
required);
- for (ProvidedInterfaceDescriptor service : provided) {
+ for (ProvidedInterface service : provided) {
reallyRequired.remove(service);
}
- for (RequiredInterfaceDescriptor service: getRequiredServices()) {
+ for (RequiredInterface service: getRequiredServices()) {
reallyRequired.remove(service);
}
String missingRequired = "";
- for (RequiredInterfaceDescriptor service: reallyRequired) {
+ for (RequiredInterface service: reallyRequired) {
missingRequired += service + "\n";
}
if ( missingRequired.length() > 0 ) {
@Override
protected void doStart(String aContext, Service[] aRequiredServices) {
- List<ProvidedInterfaceDescriptor> descriptors = new ArrayList<ProvidedInterfaceDescriptor>();
+ List<ProvidedInterface> descriptors = new ArrayList<ProvidedInterface>();
for (Service service : aRequiredServices) {
descriptors.add(service.getDescriptor());
}
SystemAssembler assembler = new SystemAssembler(aContext + "." + getName(), _systems,
- descriptors.toArray(new ProvidedInterfaceDescriptor[0]));
+ descriptors.toArray(new ProvidedInterface[0]));
assembler.start(getRegistry(), aRequiredServices);
}
*
* @author Erik Brakkee
*/
-public class DefaultProvidedInterfaceDescriptor implements ProvidedInterfaceDescriptor {
+public class DefaultProvidedInterfaceDescriptor implements ProvidedInterface {
private String _name;
private Class[] _interfaces;
package org.wamblee.system;
public class DefaultRequiredInterfaceDescriptor extends DefaultProvidedInterfaceDescriptor
- implements RequiredInterfaceDescriptor {
+ implements RequiredInterface {
public DefaultRequiredInterfaceDescriptor(String aName, Class aInterface) {
super(aName, aInterface);
}
@Override
- public boolean implementedBy(ProvidedInterfaceDescriptor aDescriptor) {
+ public boolean implementedBy(ProvidedInterface aDescriptor) {
Class[] provided = aDescriptor.getInterfaceTypes();
for (Class required : getInterfaceTypes()) {
if ( !serviceProvided(required, provided)) {
public class DefaultService implements Service {
private String _id;
- private ProvidedInterfaceDescriptor _descriptor;
+ private ProvidedInterface _descriptor;
private Object _service;
/**
* @param aService
* Service.
*/
- public DefaultService(String aId, ProvidedInterfaceDescriptor aDescriptor,
+ public DefaultService(String aId, ProvidedInterface aDescriptor,
Object aService) {
_id = aId;
_descriptor = aDescriptor;
}
@Override
- public ProvidedInterfaceDescriptor getDescriptor() {
+ public ProvidedInterface getDescriptor() {
return _descriptor;
}
}
@Override
- public synchronized Service register(ProvidedInterfaceDescriptor aDescriptor,
+ public synchronized Service register(ProvidedInterface aDescriptor,
Object aService) {
_count++;
String id = "" + _count;
*
* @author Erik Brakkee
*/
-public interface ProvidedInterfaceDescriptor {
+public interface ProvidedInterface {
/**
* Symbolic name for the service as used by the subsystem.
package org.wamblee.system;
-public interface RequiredInterfaceDescriptor {
+public interface RequiredInterface {
/**
* Name for the interface.
* @param aInterface Provided interface.
* @return
*/
- boolean implementedBy(ProvidedInterfaceDescriptor aInterface);
+ boolean implementedBy(ProvidedInterface aInterface);
}
* Gets the descriptor of the service.
* @return Descriptor.
*/
- ProvidedInterfaceDescriptor getDescriptor();
+ ProvidedInterface getDescriptor();
/**
* Returns a reference to the running service.
public interface ServiceRegistry {
- Service register(ProvidedInterfaceDescriptor aDescriptor, Object aService);
+ Service register(ProvidedInterface aDescriptor, Object aService);
void remove(Service aService);
private String _context;
private Component[] _systems;
- public static RequiredInterfaceDescriptor[] filterRequiredServices(
- ProvidedInterfaceDescriptor aProvided,
- Collection<RequiredInterfaceDescriptor> aDescriptors) {
- List<RequiredInterfaceDescriptor> required = new ArrayList<RequiredInterfaceDescriptor>();
- for (RequiredInterfaceDescriptor descriptor : aDescriptors) {
+ public static RequiredInterface[] filterRequiredServices(
+ ProvidedInterface aProvided,
+ Collection<RequiredInterface> aDescriptors) {
+ List<RequiredInterface> required = new ArrayList<RequiredInterface>();
+ for (RequiredInterface descriptor : aDescriptors) {
if (descriptor.implementedBy(aProvided)) {
required.add(descriptor);
}
}
- return required.toArray(new RequiredInterfaceDescriptor[0]);
+ return required.toArray(new RequiredInterface[0]);
}
- public static ProvidedInterfaceDescriptor[] filterProvidedServices(
- RequiredInterfaceDescriptor aRequired,
- Collection<ProvidedInterfaceDescriptor> aProvided) {
- List<ProvidedInterfaceDescriptor> provided = new ArrayList<ProvidedInterfaceDescriptor>();
- for (ProvidedInterfaceDescriptor descriptor : aProvided) {
+ public static ProvidedInterface[] filterProvidedServices(
+ RequiredInterface aRequired,
+ Collection<ProvidedInterface> aProvided) {
+ List<ProvidedInterface> provided = new ArrayList<ProvidedInterface>();
+ for (ProvidedInterface descriptor : aProvided) {
if (aRequired.implementedBy(descriptor)) {
provided.add(descriptor);
}
}
- return provided.toArray(new ProvidedInterfaceDescriptor[0]);
+ return provided.toArray(new ProvidedInterface[0]);
}
/**
* that this assembler manages.
*/
public SystemAssembler(Component[] aSystems,
- ProvidedInterfaceDescriptor[] aAvailableServices) {
+ ProvidedInterface[] aAvailableServices) {
this(ROOT_CONTEXT_NAME, aSystems, aAvailableServices);
}
* that this assembler manages.
*/
public SystemAssembler(String aContext, Component[] aSystems,
- ProvidedInterfaceDescriptor[] aAvailableServices) {
+ ProvidedInterface[] aAvailableServices) {
_context = aContext;
_systems = aSystems;
validate(aAvailableServices);
* Determines if the systems are ordered appropriately so that all
* dependencies are met.
*/
- private void validate(ProvidedInterfaceDescriptor[] aDescriptors)
+ private void validate(ProvidedInterface[] aDescriptors)
throws SystemAssemblyException {
- List<ProvidedInterfaceDescriptor> allProvided = new ArrayList<ProvidedInterfaceDescriptor>();
- for (ProvidedInterfaceDescriptor descriptor : aDescriptors) {
+ List<ProvidedInterface> allProvided = new ArrayList<ProvidedInterface>();
+ for (ProvidedInterface descriptor : aDescriptors) {
allProvided.add(descriptor);
}
for (Component system : _systems) {
// Check if all required services are already provided by earlier
// systems.
- RequiredInterfaceDescriptor[] required = system.getRequiredServices();
+ RequiredInterface[] required = system.getRequiredServices();
- for (RequiredInterfaceDescriptor descriptor : required) {
- ProvidedInterfaceDescriptor[] filtered = filterProvidedServices(
+ for (RequiredInterface descriptor : required) {
+ ProvidedInterface[] filtered = filterProvidedServices(
descriptor, allProvided);
if (filtered.length == 0) {
}
// add all provided services
- ProvidedInterfaceDescriptor[] provided = system.getProvidedServices();
+ ProvidedInterface[] provided = system.getProvidedServices();
allProvided.addAll(Arrays.asList(provided));
}
}
*/
public void start(ServiceRegistry aRegistry, Service[] aRequiredServices) {
LOG.info("Starting '" + _context + "'");
- Map<ProvidedInterfaceDescriptor, Service> allProvided = new HashMap<ProvidedInterfaceDescriptor, Service>();
+ Map<ProvidedInterface, Service> allProvided = new HashMap<ProvidedInterface, Service>();
for (Service service : aRequiredServices) {
allProvided.put(service.getDescriptor(), service);
// Compose a list of the required services required for the subsystem.
- RequiredInterfaceDescriptor[] descriptors = system
+ RequiredInterface[] descriptors = system
.getRequiredServices();
List<Service> services = new ArrayList<Service>();
- for (RequiredInterfaceDescriptor descriptor : descriptors) {
- ProvidedInterfaceDescriptor[] provided = filterProvidedServices(
+ for (RequiredInterface descriptor : descriptors) {
+ ProvidedInterface[] provided = filterProvidedServices(
descriptor, allProvided.keySet());
services.add(allProvided.get(provided[0]));
}
import javax.sql.DataSource;
public class Application extends AbstractComponent {
- private static final RequiredInterfaceDescriptor[] REQUIRED =
- new RequiredInterfaceDescriptor[] {
+ private static final RequiredInterface[] REQUIRED =
+ new RequiredInterface[] {
new DefaultRequiredInterfaceDescriptor("datasource", DataSource.class),
new DefaultRequiredInterfaceDescriptor("integer", Integer.class)
};
public Application(ServiceRegistry aRegistry) {
- super("application", aRegistry, new ProvidedInterfaceDescriptor[0], REQUIRED);
+ super("application", aRegistry, new ProvidedInterface[0], REQUIRED);
}
@Override
public class DefaultInterfaceDescriptorTest extends TestCase {
public void testOneRequiredOneProvidedMatch() {
- ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name", String.class);
- RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name", String.class);
+ ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name", String.class);
+ RequiredInterface 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);
+ ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name", Integer.class);
+ RequiredInterface 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);
+ ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name", String.class);
+ RequiredInterface required = new DefaultRequiredInterfaceDescriptor("name", Number.class);
assertFalse(required.implementedBy(provided));
}
public void testOneRequiredMultipleProvidedMatch() {
- ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name",
+ ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name",
new Class[] { String.class, Integer.class} );
- RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name", String.class);
+ RequiredInterface required = new DefaultRequiredInterfaceDescriptor("name", String.class);
assertTrue(required.implementedBy(provided));
}
}
public void testMultipleRequiredOneProvidedMatch() {
- ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name",
+ ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name",
MyMultiple.class );
- RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name",
+ RequiredInterface required = new DefaultRequiredInterfaceDescriptor("name",
new Class[] {Runnable.class, Serializable.class} );
assertTrue(required.implementedBy(provided));
}
public void testMultipleRequiredOneProvidedNoMatch() {
- ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name",
+ ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name",
MyMultiple.class );
- RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name",
+ RequiredInterface required = new DefaultRequiredInterfaceDescriptor("name",
new Class[] { String.class, Runnable.class} );
assertFalse(required.implementedBy(provided));
}
public void testMultipleRequiredMultipleProvidedMatch() {
- ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name",
+ ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name",
new Class[] { Runnable.class, Serializable.class, String.class} );
- RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name",
+ RequiredInterface required = new DefaultRequiredInterfaceDescriptor("name",
new Class[] {Runnable.class, Serializable.class} );
assertTrue(required.implementedBy(provided));
}
public class Environment extends AbstractComponent {
- private static final ProvidedInterfaceDescriptor[] PROVIDED =
- new ProvidedInterfaceDescriptor[] {
+ private static final ProvidedInterface[] PROVIDED =
+ new ProvidedInterface[] {
new DefaultProvidedInterfaceDescriptor("datasource", DataSource.class),
new DefaultProvidedInterfaceDescriptor("integer", Integer.class)
};
public Environment(ServiceRegistry aRegistry) {
- super("environment", aRegistry, PROVIDED, new RequiredInterfaceDescriptor[0]);
+ super("environment", aRegistry, PROVIDED, new RequiredInterface[0]);
}
@Override
}
public void testFilterProvided() {
- RequiredInterfaceDescriptor req1 = new DefaultRequiredInterfaceDescriptor(
+ RequiredInterface req1 = new DefaultRequiredInterfaceDescriptor(
"name", Runnable.class);
- RequiredInterfaceDescriptor req2 = new DefaultRequiredInterfaceDescriptor(
+ RequiredInterface req2 = new DefaultRequiredInterfaceDescriptor(
"name", Serializable.class);
- ProvidedInterfaceDescriptor prov1 = new DefaultProvidedInterfaceDescriptor(
+ ProvidedInterface prov1 = new DefaultProvidedInterfaceDescriptor(
"name", Runnable.class);
- ProvidedInterfaceDescriptor prov2 = new DefaultProvidedInterfaceDescriptor(
+ ProvidedInterface prov2 = new DefaultProvidedInterfaceDescriptor(
"name", Serializable.class);
- ProvidedInterfaceDescriptor prov3 = new DefaultProvidedInterfaceDescriptor(
+ ProvidedInterface prov3 = new DefaultProvidedInterfaceDescriptor(
"name", MyMultiple.class);
- AssertionUtils.assertEquals(new RequiredInterfaceDescriptor[] { req1 },
+ AssertionUtils.assertEquals(new RequiredInterface[] { req1 },
SystemAssembler.filterRequiredServices(prov1, Arrays
- .asList(new RequiredInterfaceDescriptor[] { req1 })));
- AssertionUtils.assertEquals(new RequiredInterfaceDescriptor[] { req1 },
+ .asList(new RequiredInterface[] { req1 })));
+ AssertionUtils.assertEquals(new RequiredInterface[] { req1 },
SystemAssembler.filterRequiredServices(prov1,
- Arrays.asList(new RequiredInterfaceDescriptor[] { req1,
+ Arrays.asList(new RequiredInterface[] { req1,
req2 })));
- AssertionUtils.assertEquals(new RequiredInterfaceDescriptor[] { req1,
+ AssertionUtils.assertEquals(new RequiredInterface[] { req1,
req2 }, SystemAssembler.filterRequiredServices(prov3, Arrays
- .asList(new RequiredInterfaceDescriptor[] { req1, req2 })));
+ .asList(new RequiredInterface[] { req1, req2 })));
AssertionUtils.assertEquals(
- new ProvidedInterfaceDescriptor[] { prov1 },
+ new ProvidedInterface[] { prov1 },
SystemAssembler.filterProvidedServices(req1, Arrays
- .asList(new ProvidedInterfaceDescriptor[] { prov1 })));
+ .asList(new ProvidedInterface[] { prov1 })));
AssertionUtils.assertEquals(
- new ProvidedInterfaceDescriptor[] { prov1 }, SystemAssembler
+ new ProvidedInterface[] { prov1 }, SystemAssembler
.filterProvidedServices(req1, Arrays
- .asList(new ProvidedInterfaceDescriptor[] {
+ .asList(new ProvidedInterface[] {
prov1, prov2 })));
- AssertionUtils.assertEquals(new ProvidedInterfaceDescriptor[] { prov1,
+ AssertionUtils.assertEquals(new ProvidedInterface[] { prov1,
prov3 }, SystemAssembler.filterProvidedServices(req1, Arrays
- .asList(new ProvidedInterfaceDescriptor[] { prov1, prov3 })));
+ .asList(new ProvidedInterface[] { prov1, prov3 })));
}
public void testEnvironmentApplication() {
Component environment = new Environment(_registry);
Component application = new Application(_registry);
SystemAssembler assembler = new SystemAssembler(new Component[] {
- environment, application }, new ProvidedInterfaceDescriptor[0]);
+ environment, application }, new ProvidedInterface[0]);
assembler.start(_registry, new Service[0]);
Service[] envServices = environment.getRunningServices();
assertEquals(2, envServices.length);
Component application = new Application(_registry);
SystemAssembler assembler = new SystemAssembler(new Component[] {
application, environment },
- new ProvidedInterfaceDescriptor[0]);
+ new ProvidedInterface[0]);
assembler.start(_registry, new Service[0]);
} catch (SystemAssemblyException e) {
// e.printStackTrace();
assertEquals(Status.NOT_STARTED, environment.getStatus());
assertEquals(Status.NOT_STARTED, application.getStatus());
Container system = new Container("all", _registry, new Component[] {
- environment, application }, new ProvidedInterfaceDescriptor[0],
- new RequiredInterfaceDescriptor[0]);
+ environment, application }, new ProvidedInterface[0],
+ new RequiredInterface[0]);
assertEquals(Status.NOT_STARTED, system.getStatus());
system.start("root", new Service[0]);
- RequiredInterfaceDescriptor[] required = system.getRequiredServices();
+ RequiredInterface[] required = system.getRequiredServices();
assertEquals(0, required.length);
- ProvidedInterfaceDescriptor[] provided = system.getProvidedServices();
+ ProvidedInterface[] provided = system.getProvidedServices();
assertEquals(0, provided.length);
assertEquals(Status.RUNNING, environment.getStatus());
assertEquals(Status.RUNNING, application.getStatus());
"all",
_registry,
new Component[] { environment, application },
- new ProvidedInterfaceDescriptor[] { new DefaultProvidedInterfaceDescriptor(
+ new ProvidedInterface[] { new DefaultProvidedInterfaceDescriptor(
"string", String.class) },
new DefaultRequiredInterfaceDescriptor[0]);
} catch (SystemAssemblyException e) {
"all",
_registry,
new Component[] { environment, application },
- new ProvidedInterfaceDescriptor[0],
- new RequiredInterfaceDescriptor[] { new DefaultRequiredInterfaceDescriptor(
+ new ProvidedInterface[0],
+ new RequiredInterface[] { new DefaultRequiredInterfaceDescriptor(
"string", String.class) });
system.start("root", new Service[0]);
- RequiredInterfaceDescriptor[] required = system.getRequiredServices();
+ RequiredInterface[] required = system.getRequiredServices();
assertEquals(1, required.length);
- ProvidedInterfaceDescriptor[] provided = system.getProvidedServices();
+ ProvidedInterface[] provided = system.getProvidedServices();
assertEquals(0, provided.length);
}
Component application = new Application(_registry);
Container system = new Container("all", _registry,
new Component[] { application },
- new ProvidedInterfaceDescriptor[0], application
+ new ProvidedInterface[0], application
.getRequiredServices());
system.start("root", new Service[0]);
} catch (SystemAssemblyException e) {
Component application = new Application(_registry);
Container system = new Container("all", _registry,
new Component[] { application },
- new ProvidedInterfaceDescriptor[0], application
+ new ProvidedInterface[0], application
.getRequiredServices());
Service[] envServices = environment.start("env", new Service[0]);
system.start("root", envServices);
- RequiredInterfaceDescriptor[] required = system.getRequiredServices();
+ RequiredInterface[] required = system.getRequiredServices();
assertEquals(2, required.length);
- ProvidedInterfaceDescriptor[] provided = system.getProvidedServices();
+ ProvidedInterface[] provided = system.getProvidedServices();
assertEquals(0, provided.length);
}
Component application = new Application(_registry);
SystemAssembler assembler = new SystemAssembler(new Component[] {
environment1, environment2, application },
- new ProvidedInterfaceDescriptor[0]);
+ new ProvidedInterface[0]);
assembler.start(_registry, new Service[0]);
} catch (SystemAssemblyException e) {
Component application = new Application(_registry);
Container system = new Container("all", _registry,
new Component[] { application },
- new ProvidedInterfaceDescriptor[0],
- new RequiredInterfaceDescriptor[0]);
+ new ProvidedInterface[0],
+ new RequiredInterface[0]);
system.start("root", new Service[0]);
} catch (SystemAssemblyException e) {
return;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.wamblee.system.AbstractComponent;
-import org.wamblee.system.ProvidedInterfaceDescriptor;
-import org.wamblee.system.RequiredInterfaceDescriptor;
+import org.wamblee.system.ProvidedInterface;
+import org.wamblee.system.RequiredInterface;
import org.wamblee.system.Service;
import org.wamblee.system.ServiceRegistry;
import org.wamblee.system.SystemAssembler;
private Properties _properties;
private String[] _configFiles;
- private Map<String, ProvidedInterfaceDescriptor> _provided;
- private Map<RequiredInterfaceDescriptor, String> _required;
+ private Map<String, ProvidedInterface> _provided;
+ private Map<RequiredInterface, String> _required;
/**
* Parent application context containing required services.
*/
* service.
*/
public SpringComponent(String aName, ServiceRegistry aRegistry, String[] aConfigFiles,
- Map<String, ProvidedInterfaceDescriptor> aProvided,
- Map<RequiredInterfaceDescriptor, String> aRequired) {
- super(aName, aRegistry, aProvided.values().toArray(new ProvidedInterfaceDescriptor[0]),
- aRequired.keySet().toArray(new RequiredInterfaceDescriptor[0]));
+ Map<String, ProvidedInterface> aProvided,
+ Map<RequiredInterface, String> aRequired) {
+ super(aName, aRegistry, aProvided.values().toArray(new ProvidedInterface[0]),
+ aRequired.keySet().toArray(new RequiredInterface[0]));
_properties = new Properties();
_configFiles = aConfigFiles;
_provided = aProvided;
for (Service svc: aRequiredServices) {
String id = svc.getId();
- ProvidedInterfaceDescriptor descriptor = svc.getDescriptor();
- RequiredInterfaceDescriptor[] requiredServices = SystemAssembler.filterRequiredServices(descriptor,
+ ProvidedInterface descriptor = svc.getDescriptor();
+ RequiredInterface[] requiredServices = SystemAssembler.filterRequiredServices(descriptor,
_required.keySet());
- for (RequiredInterfaceDescriptor required: requiredServices) {
+ for (RequiredInterface required: requiredServices) {
String beanName = _required.get(required);
ConstructorArgumentValues cargs = new ConstructorArgumentValues();
cargs.addGenericArgumentValue(id);
import org.wamblee.system.DefaultProvidedInterfaceDescriptor;
import org.wamblee.system.DefaultRequiredInterfaceDescriptor;
import org.wamblee.system.DefaultServiceRegistry;
-import org.wamblee.system.ProvidedInterfaceDescriptor;
-import org.wamblee.system.RequiredInterfaceDescriptor;
+import org.wamblee.system.ProvidedInterface;
+import org.wamblee.system.RequiredInterface;
import org.wamblee.system.Service;
import org.wamblee.system.ServiceRegistry;
import org.wamblee.system.SystemAssemblyException;
public void testBlackboxSystem() {
SpringComponent system = new SpringComponent("system", _registry,
new String[] { HELLO_SERVICE_SPRING_XML },
- new HashMap<String, ProvidedInterfaceDescriptor>(),
- new HashMap<RequiredInterfaceDescriptor, String>());
+ new HashMap<String, ProvidedInterface>(),
+ new HashMap<RequiredInterface, String>());
system.start("Hello", new Service[0]);
Service[] services = system.getRunningServices();
assertEquals(0, services.length);
}
public void testOneProvidedService() {
- Map<String, ProvidedInterfaceDescriptor> provided = new HashMap<String, ProvidedInterfaceDescriptor>();
+ Map<String, ProvidedInterface> provided = new HashMap<String, ProvidedInterface>();
provided.put("helloService", new DefaultProvidedInterfaceDescriptor(
"hello", HelloService.class));
SpringComponent system = new SpringComponent("system", _registry,
new String[] { HELLO_SERVICE_SPRING_XML }, provided,
- new HashMap<RequiredInterfaceDescriptor, String>());
+ new HashMap<RequiredInterface, String>());
system.start("Hello", new Service[0]);
Service[] services = system.getRunningServices();
assertEquals(1, services.length);
}
public void testWithProperties() throws IOException {
- Map<String, ProvidedInterfaceDescriptor> provided = new HashMap<String, ProvidedInterfaceDescriptor>();
+ Map<String, ProvidedInterface> provided = new HashMap<String, ProvidedInterface>();
provided.put("helloService", new DefaultProvidedInterfaceDescriptor(
"hello", HelloService.class));
SpringComponent system = new SpringComponent("system", _registry,
new String[] { HELLO_SERVICE_SPRING_WITH_PROPERTIES_XML },
provided,
- new HashMap<RequiredInterfaceDescriptor, String>());
+ new HashMap<RequiredInterface, String>());
Properties props = new Properties();
props.load(new ClassPathResource(PROPERTY_FILE).getInputStream());
system.addProperties(props);
try {
SpringComponent system = new SpringComponent("system", _registry,
new String[] { HELLO_SERVICE_SPRING_WITH_REQS_XML },
- new HashMap<String, ProvidedInterfaceDescriptor>(),
- new HashMap<RequiredInterfaceDescriptor, String>());
+ new HashMap<String, ProvidedInterface>(),
+ new HashMap<RequiredInterface, String>());
system.start("Bla", new Service[0]);
} catch (SystemAssemblyException e) {
//e.printStackTrace();
}
public void testWithRequirement() {
- Map<RequiredInterfaceDescriptor, String> required = new HashMap<RequiredInterfaceDescriptor, String>();
+ Map<RequiredInterface, String> required = new HashMap<RequiredInterface, String>();
required.put(new DefaultRequiredInterfaceDescriptor("hello", HelloService.class),
"helloService");
SpringComponent system = new SpringComponent("system", _registry,
new String[] { HELLO_SERVICE_SPRING_WITH_REQS_XML },
- new HashMap<String, ProvidedInterfaceDescriptor>(), required);
+ new HashMap<String, ProvidedInterface>(), required);
HelloService helloObject = new HelloService("ladida");
Service helloService = _registry.register(new DefaultProvidedInterfaceDescriptor("hello", HelloService.class), helloObject);
}
public void testWithRequirementAndProvidedService() {
- Map<RequiredInterfaceDescriptor, String> required = new HashMap<RequiredInterfaceDescriptor, String>();
+ Map<RequiredInterface, String> required = new HashMap<RequiredInterface, String>();
required.put(new DefaultRequiredInterfaceDescriptor("hello", HelloService.class),
"helloService");
- Map<String,ProvidedInterfaceDescriptor> provided = new HashMap<String, ProvidedInterfaceDescriptor>();
+ Map<String,ProvidedInterface> provided = new HashMap<String, ProvidedInterface>();
provided.put("blaService", new DefaultProvidedInterfaceDescriptor("bla",
BlaService.class));