git://wamblee.org
/
utils
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
66cabd4
)
Better solution for setting the context. The context is now known as soon as componen...
author
erik
<erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Wed, 9 Apr 2008 18:25:37 +0000
(18:25 +0000)
committer
erik
<erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Wed, 9 Apr 2008 18:25:37 +0000
(18:25 +0000)
system/general/src/main/java/org/wamblee/system/AbstractComponent.java
patch
|
blob
|
history
system/general/src/main/java/org/wamblee/system/Component.java
patch
|
blob
|
history
system/general/src/main/java/org/wamblee/system/Container.java
patch
|
blob
|
history
system/general/src/test/java/org/wamblee/system/Application.java
patch
|
blob
|
history
system/general/src/test/java/org/wamblee/system/ContainerTest.java
patch
|
blob
|
history
system/general/src/test/java/org/wamblee/system/Environment.java
patch
|
blob
|
history
system/spring/src/main/java/org/wamblee/system/spring/SpringComponent.java
patch
|
blob
|
history
system/spring/src/test/java/org/wamblee/system/spring/SpringComponentTest.java
patch
|
blob
|
history
diff --git
a/system/general/src/main/java/org/wamblee/system/AbstractComponent.java
b/system/general/src/main/java/org/wamblee/system/AbstractComponent.java
index 3b4725835155e3cfc558fd370967e3fd4467ebd2..8b6109f233a951cf72edae3a6eb5765abc320e2a 100644
(file)
--- a/
system/general/src/main/java/org/wamblee/system/AbstractComponent.java
+++ b/
system/general/src/main/java/org/wamblee/system/AbstractComponent.java
@@
-70,6
+70,16
@@
public abstract class AbstractComponent implements Component {
return _name;
}
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 String getQualifiedName() {
if ( _context == null ) {
@@
-89,16
+99,15
@@
public abstract class AbstractComponent implements Component {
}
@Override
}
@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);
_status = Status.RUNNING;
if ( _running.size() != _provided.size()) {
List<ProvidedInterface> remaining =
new ArrayList<ProvidedInterface>(_provided);
remaining.removeAll(_running);
- throw new SystemAssemblyException(
aContext + "." + get
Name() + ": not all services were started, missing " + remaining);
+ throw new SystemAssemblyException(
getQualified
Name() + ": not all services were started, missing " + remaining);
}
}
}
}
@@
-106,7
+115,7
@@
public abstract class AbstractComponent implements Component {
* Must be implemented for initializing the subsystem. The implementation
* must call {@link #addService(Service)} for each service that is started.
*/
* 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
/**
* Implementations must call this method to indicate that a new service has
@@
-115,9
+124,9
@@
public abstract class AbstractComponent implements Component {
* @param aService
* Service.
*/
* @param aService
* Service.
*/
- protected final void addService(
String aContext,
+ protected final void addService(
ProvidedInterface aDescriptor, Object aService) {
ProvidedInterface aDescriptor, Object aService) {
- LOG.info(
aContext + ": service '" + aService
+ "' started.");
+ LOG.info(
"Interface '" + getQualifiedName() + "." + aDescriptor.getName()
+ "' started.");
_running.add(aDescriptor);
aDescriptor.publish(aService);
}
_running.add(aDescriptor);
aDescriptor.publish(aService);
}
diff --git
a/system/general/src/main/java/org/wamblee/system/Component.java
b/system/general/src/main/java/org/wamblee/system/Component.java
index 0234005f958be3922c8eb719ccf27323a47fda38..e06532669ce5a49c179fc5d54c0214c9b5e20d45 100644
(file)
--- a/
system/general/src/main/java/org/wamblee/system/Component.java
+++ b/
system/general/src/main/java/org/wamblee/system/Component.java
@@
-39,6
+39,11
@@
public interface Component {
*/
String getName();
*/
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.
/**
* Gets the fully qualified name of the component which includes
* the context of the component.
@@
-63,9
+68,8
@@
public interface Component {
/**
* Initialises the subsytem by starting all the services that
* it described as provided.
/**
* 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.
/**
* Stops a subsystem.
diff --git
a/system/general/src/main/java/org/wamblee/system/Container.java
b/system/general/src/main/java/org/wamblee/system/Container.java
index bd059902d5f2a5995c5bfe6cf283fbe95f315536..65d10f06e2960d74eff34b5ed63cd560d6fa1337 100644
(file)
--- a/
system/general/src/main/java/org/wamblee/system/Container.java
+++ b/
system/general/src/main/java/org/wamblee/system/Container.java
@@
-72,6
+72,9
@@
public class Container extends AbstractComponent {
ProvidedInterface[] aProvided, RequiredInterface[] aRequired) {
super(aName, aProvided, aRequired);
_systems = aSystems;
ProvidedInterface[] aProvided, RequiredInterface[] aRequired) {
super(aName, aProvided, aRequired);
_systems = aSystems;
+ for (Component component: aSystems) {
+ component.addContext(getQualifiedName());
+ }
validate(aRequired);
}
validate(aRequired);
}
@@
-130,7
+133,7
@@
public class Container extends AbstractComponent {
}
@Override
}
@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
List<ProvidedInterface> provided = new ArrayList<ProvidedInterface>();
// all interfaces from the required list of this container are
@@
-139,7
+142,7
@@
public class Container extends AbstractComponent {
for (RequiredInterface intf: required) {
ProvidedInterface provider = intf.getProvider();
if ( provider == null ) {
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());
}
}
provided.add(intf.getProvider());
}
@@
-155,7
+158,7
@@
public class Container extends AbstractComponent {
* started before.
*/
private void startImpl() {
* 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
List<ProvidedInterface> allProvided = new ArrayList<ProvidedInterface>();
// Add the provides of all externally required interfaces to the list of available
@@
-194,7
+197,7
@@
public class Container extends AbstractComponent {
}
// Start the service.
}
// Start the service.
- system.start(
getQualifiedName()
);
+ system.start();
// add all provided services
ProvidedInterface[] provided = system.getProvidedServices();
// add all provided services
ProvidedInterface[] provided = system.getProvidedServices();
diff --git
a/system/general/src/test/java/org/wamblee/system/Application.java
b/system/general/src/test/java/org/wamblee/system/Application.java
index 5bc6240151c410f0b0c9c07dc209d722291435a1..cb177f20259de7de21512c6576d4e30ce4f37540 100644
(file)
--- a/
system/general/src/test/java/org/wamblee/system/Application.java
+++ b/
system/general/src/test/java/org/wamblee/system/Application.java
@@
-40,7
+40,7
@@
public class Application extends AbstractComponent {
}
@Override
}
@Override
- protected void doStart(
String aContext
) {
+ protected void doStart() {
track("start." + getName());
}
track("start." + getName());
}
diff --git
a/system/general/src/test/java/org/wamblee/system/ContainerTest.java
b/system/general/src/test/java/org/wamblee/system/ContainerTest.java
index 33f3c00da080b6b42945fffbd9ba8098ae11b907..775e80064af58f5e797d4e45c0285efb166964a8 100644
(file)
--- a/
system/general/src/test/java/org/wamblee/system/ContainerTest.java
+++ b/
system/general/src/test/java/org/wamblee/system/ContainerTest.java
@@
-82,7
+82,7
@@
public class ContainerTest extends TestCase {
environment, application }, new ProvidedInterface[0],
new RequiredInterface[0]);
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]));
AssertionUtils.assertEquals(new String[] { "start.environment",
"start.application" }, _tracker.getEvents(
Thread.currentThread()).toArray(new String[0]));
@@
-102,7
+102,7
@@
public class ContainerTest extends TestCase {
new Component[] {
application, environment },
new ProvidedInterface[0], new RequiredInterface[0]);
new Component[] {
application, environment },
new ProvidedInterface[0], new RequiredInterface[0]);
- container.start(
"top"
);
+ container.start();
} catch (SystemAssemblyException e) {
// e.printStackTrace();
return;
} catch (SystemAssemblyException e) {
// e.printStackTrace();
return;
@@
-121,7
+121,7
@@
public class ContainerTest extends TestCase {
application }, new ProvidedInterface[0],
new RequiredInterface[0]);
assertEquals(Status.NOT_STARTED, system.getStatus());
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();
RequiredInterface[] required = system.getRequiredServices();
assertEquals(0, required.length);
ProvidedInterface[] provided = system.getProvidedServices();
@@
-170,7
+170,7
@@
public class ContainerTest extends TestCase {
environment, application }, new ProvidedInterface[0],
new RequiredInterface[] { new DefaultRequiredInterface(
"string", String.class) });
environment, application }, new ProvidedInterface[0],
new RequiredInterface[] { new DefaultRequiredInterface(
"string", String.class) });
- system.start(
"root"
);
+ system.start();
} catch (SystemAssemblyException e) {
return;
}
} catch (SystemAssemblyException e) {
return;
}
@@
-186,7
+186,7
@@
public class ContainerTest extends TestCase {
"string", String.class) });
system.getRequiredServices()[0]
.setProvider(new DefaultProvidedInterface("hallo", String.class));
"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();
RequiredInterface[] required = system.getRequiredServices();
assertEquals(1, required.length);
ProvidedInterface[] provided = system.getProvidedServices();
@@
-200,7
+200,7
@@
public class ContainerTest extends TestCase {
Container system = new Container("all",
new Component[] { application }, new ProvidedInterface[0],
application.getRequiredServices());
Container system = new Container("all",
new Component[] { application }, new ProvidedInterface[0],
application.getRequiredServices());
- system.start(
"root"
);
+ system.start();
} catch (SystemAssemblyException e) {
return;
}
} catch (SystemAssemblyException e) {
return;
}
@@
-215,13
+215,13
@@
public class ContainerTest extends TestCase {
Container system = new Container("all",
new Component[] { application }, new ProvidedInterface[0],
application.getRequiredServices());
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.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();
RequiredInterface[] required = system.getRequiredServices();
assertEquals(2, required.length);
ProvidedInterface[] provided = system.getProvidedServices();
@@
-237,7
+237,7
@@
public class ContainerTest extends TestCase {
Container container = new Container("root", new Component[] {
environment1, environment2, application },
new ProvidedInterface[0], new RequiredInterface[0]);
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;
} catch (SystemAssemblyException e) {
return;
@@
-251,7
+251,7
@@
public class ContainerTest extends TestCase {
Container system = new Container("all",
new Component[] { application }, new ProvidedInterface[0],
new RequiredInterface[0]);
Container system = new Container("all",
new Component[] { application }, new ProvidedInterface[0],
new RequiredInterface[0]);
- system.start(
"root"
);
+ system.start();
} catch (SystemAssemblyException e) {
return;
}
} catch (SystemAssemblyException e) {
return;
}
diff --git
a/system/general/src/test/java/org/wamblee/system/Environment.java
b/system/general/src/test/java/org/wamblee/system/Environment.java
index 1fdc079e08908222604e1e4952ea4251e781ca4e..07a2814d49327314607ec2f8e957926b725d58b5 100644
(file)
--- a/
system/general/src/test/java/org/wamblee/system/Environment.java
+++ b/
system/general/src/test/java/org/wamblee/system/Environment.java
@@
-41,9
+41,9
@@
public class Environment extends AbstractComponent {
}
@Override
}
@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());
}
track("start." + getName());
}
diff --git
a/system/spring/src/main/java/org/wamblee/system/spring/SpringComponent.java
b/system/spring/src/main/java/org/wamblee/system/spring/SpringComponent.java
index 763875f6072f770df99312748e120c9bb2b34f44..0e54deaec72ff12b194348704632f9bb8fdf7c4e 100644
(file)
--- a/
system/spring/src/main/java/org/wamblee/system/spring/SpringComponent.java
+++ b/
system/spring/src/main/java/org/wamblee/system/spring/SpringComponent.java
@@
-100,7
+100,7
@@
public class SpringComponent extends AbstractComponent {
}
@Override
}
@Override
- protected void doStart(
String aContext
) {
+ protected void doStart() {
SpringComponent old = THIS.get();
THIS.set(this);
SpringComponent old = THIS.get();
THIS.set(this);
@@
-117,7
+117,7
@@
public class SpringComponent extends AbstractComponent {
.addBeanFactoryPostProcessor(new PropertySetter(_properties));
_context.refresh();
.addBeanFactoryPostProcessor(new PropertySetter(_properties));
_context.refresh();
- exposeProvidedServices(
aContext
);
+ exposeProvidedServices();
} catch (Exception e) {
throw new SystemAssemblyException(
"Failed to assemble spring system", e);
} catch (Exception e) {
throw new SystemAssemblyException(
"Failed to assemble spring system", e);
@@
-126,16
+126,16
@@
public class SpringComponent extends AbstractComponent {
}
}
}
}
- 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) {
// 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");
}
+ name + "' is null");
}
- addService(
aContext,
_provided.get(name), svc);
+ addService(_provided.get(name), svc);
}
}
}
}
diff --git
a/system/spring/src/test/java/org/wamblee/system/spring/SpringComponentTest.java
b/system/spring/src/test/java/org/wamblee/system/spring/SpringComponentTest.java
index 97e0417e9ec9f7db9a6d55455c2cae9b28d1b790..72912fe9fa32e9b68a1244e70341f2a6cada7933 100644
(file)
--- a/
system/spring/src/test/java/org/wamblee/system/spring/SpringComponentTest.java
+++ b/
system/spring/src/test/java/org/wamblee/system/spring/SpringComponentTest.java
@@
-46,7
+46,7
@@
public class SpringComponentTest extends TestCase {
new String[] { HELLO_SERVICE_SPRING_XML },
new HashMap<String, ProvidedInterface>(),
new HashMap<RequiredInterface, String>());
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);
ProvidedInterface[] services = system.getRunningServices();
assertEquals(0, services.length);
@@
-61,7
+61,7
@@
public class SpringComponentTest extends TestCase {
SpringComponent system = new SpringComponent("system",
new String[] { HELLO_SERVICE_SPRING_XML }, provided,
new HashMap<RequiredInterface, String>());
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);
ProvidedInterface[] services = system.getRunningServices();
assertEquals(1, services.length);
assertTrue(services[0].getImplementation() instanceof HelloService);
@@
-82,7
+82,7
@@
public class SpringComponentTest extends TestCase {
props.load(new ClassPathResource(PROPERTY_FILE).getInputStream());
system.addProperties(props);
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());
ProvidedInterface[] services = system.getRunningServices();
assertEquals("Property Value",
((HelloService)services[0].getImplementation()).say());
@@
-94,7
+94,7
@@
public class SpringComponentTest extends TestCase {
new String[] { HELLO_SERVICE_SPRING_WITH_REQS_XML },
new HashMap<String, ProvidedInterface>(),
new HashMap<RequiredInterface, String>());
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;
} catch (SystemAssemblyException e) {
//e.printStackTrace();
return;
@@
-115,7
+115,7
@@
public class SpringComponentTest extends TestCase {
helloService.publish(helloObject);
system.getRequiredServices()[0].setProvider(helloService);
helloService.publish(helloObject);
system.getRequiredServices()[0].setProvider(helloService);
- system.start(
"Bla"
);
+ system.start();
system.stop();
}
system.stop();
}
@@
-136,7
+136,7
@@
public class SpringComponentTest extends TestCase {
new DefaultProvidedInterface("hello", HelloService.class);
helloService.publish(helloObject);
system.getRequiredServices()[0].setProvider(helloService);
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());
ProvidedInterface started = system.getProvidedServices()[0];
assertNotNull(started.getImplementation());