return _name;
}
+ @Override
+ public void addContext(String aContext) {
+ if (_context == null ) {
+ _context = aContext;
+ }
+ else {
+ _context = aContext + "." + _context;
+ }
+ }
+
@Override
public String getQualifiedName() {
if ( _context == null ) {
}
@Override
- public final void start(String aContext) {
- LOG.info("Initializing '" + aContext + "." + _name + "'");
- _context = aContext;
- doStart(aContext + "." + 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);
remaining.removeAll(_running);
- throw new SystemAssemblyException(aContext + "." + getName() + ": not all services were started, missing " + remaining);
+ throw new SystemAssemblyException(getQualifiedName() + ": not all services were started, missing " + remaining);
}
}
* Must be implemented for initializing the subsystem. The implementation
* must call {@link #addService(Service)} for each service that is started.
*/
- protected abstract void doStart(String aContext);
+ protected abstract void doStart();
/**
* Implementations must call this method to indicate that a new service has
* @param aService
* Service.
*/
- protected final void addService(String aContext,
+ protected final void addService(
ProvidedInterface aDescriptor, Object aService) {
- LOG.info(aContext + ": service '" + aService + "' started.");
+ LOG.info("Interface '" + getQualifiedName() + "." + aDescriptor.getName() + "' started.");
_running.add(aDescriptor);
aDescriptor.publish(aService);
}
*/
String getName();
+ /**
+ * Prepends the context with a super context.
+ */
+ void addContext(String aContext);
+
/**
* Gets the fully qualified name of the component which includes
* the context of the component.
/**
* Initialises the subsytem by starting all the services that
* it described as provided.
- * @param aContext Unique name for the subsystem.
*/
- void start(String aContext);
+ void start();
/**
* Stops a subsystem.
ProvidedInterface[] aProvided, RequiredInterface[] aRequired) {
super(aName, aProvided, aRequired);
_systems = aSystems;
+ for (Component component: aSystems) {
+ component.addContext(getQualifiedName());
+ }
validate(aRequired);
}
}
@Override
- protected void doStart(String aContext) {
+ protected void doStart() {
List<ProvidedInterface> provided = new ArrayList<ProvidedInterface>();
// all interfaces from the required list of this container are
for (RequiredInterface intf: required) {
ProvidedInterface provider = intf.getProvider();
if ( provider == null ) {
- throw new SystemAssemblyException(aContext + ": required interface '" + intf +"' is not provided");
+ throw new SystemAssemblyException(getQualifiedName() + ": required interface '" + intf +"' is not provided");
}
provided.add(intf.getProvider());
}
* started before.
*/
private void startImpl() {
- LOG.info("Starting '" + "'");
+ LOG.info("Starting '" + getQualifiedName() + "'");
List<ProvidedInterface> allProvided = new ArrayList<ProvidedInterface>();
// Add the provides of all externally required interfaces to the list of available
}
// Start the service.
- system.start(getQualifiedName());
+ system.start();
// add all provided services
ProvidedInterface[] provided = system.getProvidedServices();
}
@Override
- protected void doStart(String aContext) {
+ protected void doStart() {
track("start." + getName());
}
environment, application }, new ProvidedInterface[0],
new RequiredInterface[0]);
- container.start("top");
+ container.start();
AssertionUtils.assertEquals(new String[] { "start.environment",
"start.application" }, _tracker.getEvents(
Thread.currentThread()).toArray(new String[0]));
new Component[] {
application, environment },
new ProvidedInterface[0], new RequiredInterface[0]);
- container.start("top");
+ container.start();
} catch (SystemAssemblyException e) {
// e.printStackTrace();
return;
application }, new ProvidedInterface[0],
new RequiredInterface[0]);
assertEquals(Status.NOT_STARTED, system.getStatus());
- system.start("root");
+ system.start();
RequiredInterface[] required = system.getRequiredServices();
assertEquals(0, required.length);
ProvidedInterface[] provided = system.getProvidedServices();
environment, application }, new ProvidedInterface[0],
new RequiredInterface[] { new DefaultRequiredInterface(
"string", String.class) });
- system.start("root");
+ system.start();
} catch (SystemAssemblyException e) {
return;
}
"string", String.class) });
system.getRequiredServices()[0]
.setProvider(new DefaultProvidedInterface("hallo", String.class));
- system.start("root");
+ system.start();
RequiredInterface[] required = system.getRequiredServices();
assertEquals(1, required.length);
ProvidedInterface[] provided = system.getProvidedServices();
Container system = new Container("all",
new Component[] { application }, new ProvidedInterface[0],
application.getRequiredServices());
- system.start("root");
+ system.start();
} catch (SystemAssemblyException e) {
return;
}
Container system = new Container("all",
new Component[] { application }, new ProvidedInterface[0],
application.getRequiredServices());
- environment.start("env");
+ environment.start();
system.getRequiredServices()[0].setProvider(environment
.getProvidedServices()[0]);
system.getRequiredServices()[1].setProvider(environment
.getProvidedServices()[1]);
- system.start("root");
+ system.start();
RequiredInterface[] required = system.getRequiredServices();
assertEquals(2, required.length);
ProvidedInterface[] provided = system.getProvidedServices();
Container container = new Container("root", new Component[] {
environment1, environment2, application },
new ProvidedInterface[0], new RequiredInterface[0]);
- container.start("top");
+ container.start();
} catch (SystemAssemblyException e) {
return;
Container system = new Container("all",
new Component[] { application }, new ProvidedInterface[0],
new RequiredInterface[0]);
- system.start("root");
+ system.start();
} catch (SystemAssemblyException e) {
return;
}
}
@Override
- protected void doStart(String aContext) {
- addService(aContext, getProvidedServices()[0], new Integer(1));
- addService(aContext, getProvidedServices()[1], new Integer(2));
+ protected void doStart() {
+ addService(getProvidedServices()[0], new Integer(1));
+ addService(getProvidedServices()[1], new Integer(2));
track("start." + getName());
}
}
@Override
- protected void doStart(String aContext) {
+ protected void doStart() {
SpringComponent old = THIS.get();
THIS.set(this);
.addBeanFactoryPostProcessor(new PropertySetter(_properties));
_context.refresh();
- exposeProvidedServices(aContext);
+ exposeProvidedServices();
} catch (Exception e) {
throw new SystemAssemblyException(
"Failed to assemble spring system", e);
}
}
- private void exposeProvidedServices(String aContext) {
+ private void exposeProvidedServices() {
// Call addService for each provided service.
for (String name : _provided.keySet()) {
Object svc = _context.getBean(name);
if (svc == null) {
- throw new IllegalArgumentException(aContext + ": service '"
+ throw new IllegalArgumentException(getQualifiedName() + ": service '"
+ name + "' is null");
}
- addService(aContext, _provided.get(name), svc);
+ addService(_provided.get(name), svc);
}
}
new String[] { HELLO_SERVICE_SPRING_XML },
new HashMap<String, ProvidedInterface>(),
new HashMap<RequiredInterface, String>());
- system.start("Hello");
+ system.start();
ProvidedInterface[] services = system.getRunningServices();
assertEquals(0, services.length);
SpringComponent system = new SpringComponent("system",
new String[] { HELLO_SERVICE_SPRING_XML }, provided,
new HashMap<RequiredInterface, String>());
- system.start("Hello");
+ system.start();
ProvidedInterface[] services = system.getRunningServices();
assertEquals(1, services.length);
assertTrue(services[0].getImplementation() instanceof HelloService);
props.load(new ClassPathResource(PROPERTY_FILE).getInputStream());
system.addProperties(props);
- system.start("Hello");
+ system.start();
ProvidedInterface[] services = system.getRunningServices();
assertEquals("Property Value",
((HelloService)services[0].getImplementation()).say());
new String[] { HELLO_SERVICE_SPRING_WITH_REQS_XML },
new HashMap<String, ProvidedInterface>(),
new HashMap<RequiredInterface, String>());
- system.start("Bla");
+ system.start();
} catch (SystemAssemblyException e) {
//e.printStackTrace();
return;
helloService.publish(helloObject);
system.getRequiredServices()[0].setProvider(helloService);
- system.start("Bla");
+ system.start();
system.stop();
}
new DefaultProvidedInterface("hello", HelloService.class);
helloService.publish(helloObject);
system.getRequiredServices()[0].setProvider(helloService);
- system.start("Bla");
+ system.start();
ProvidedInterface started = system.getProvidedServices()[0];
assertNotNull(started.getImplementation());