From: erik Date: Fri, 4 Apr 2008 22:11:06 +0000 (+0000) Subject: (no commit message) X-Git-Tag: wamblee-utils-0.2~1^2~199 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=6110f13b29c47ba0fe8039194ee2c4a992911e3b;p=utils --- 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 074e3ab0..93f62c1e 100644 --- a/system/general/src/main/java/org/wamblee/system/AbstractComponent.java +++ b/system/general/src/main/java/org/wamblee/system/AbstractComponent.java @@ -68,6 +68,12 @@ public abstract class AbstractComponent implements Component { LOG.info("Initializing '" + aContext + "." + _name + "'"); doStart(aContext + "." + getName()); _status = Status.RUNNING; + if ( _running.size() != _provided.size()) { + List remaining = + new ArrayList(_provided); + remaining.removeAll(_running); + throw new SystemAssemblyException(aContext + "." + getName() + ": not all services were started, missing " + remaining); + } } /** diff --git a/system/general/src/main/java/org/wamblee/system/DefaultProvidedInterfaceDescriptor.java b/system/general/src/main/java/org/wamblee/system/DefaultProvidedInterface.java similarity index 80% rename from system/general/src/main/java/org/wamblee/system/DefaultProvidedInterfaceDescriptor.java rename to system/general/src/main/java/org/wamblee/system/DefaultProvidedInterface.java index 3b38be7a..e80547c5 100644 --- a/system/general/src/main/java/org/wamblee/system/DefaultProvidedInterfaceDescriptor.java +++ b/system/general/src/main/java/org/wamblee/system/DefaultProvidedInterface.java @@ -7,7 +7,7 @@ import java.util.Arrays; * * @author Erik Brakkee */ -public class DefaultProvidedInterfaceDescriptor implements ProvidedInterface { +public class DefaultProvidedInterface implements ProvidedInterface { private String _name; private Class[] _interfaces; @@ -17,12 +17,12 @@ public class DefaultProvidedInterfaceDescriptor implements ProvidedInterface { * Constructs the descriptor. * @param aInterface Type of service. */ - public DefaultProvidedInterfaceDescriptor(String aName, Class aInterface) { + public DefaultProvidedInterface(String aName, Class aInterface) { _name = aName; _interfaces = new Class[] { aInterface }; } - public DefaultProvidedInterfaceDescriptor(String aName, Class[] aInterfaces) { + public DefaultProvidedInterface(String aName, Class[] aInterfaces) { _name = aName; _interfaces = Arrays.copyOf(aInterfaces, aInterfaces.length); } @@ -49,10 +49,10 @@ public class DefaultProvidedInterfaceDescriptor implements ProvidedInterface { @Override public boolean equals(Object obj) { - if ( !(obj instanceof DefaultProvidedInterfaceDescriptor)) { + if ( !(obj instanceof DefaultProvidedInterface)) { return false; } - DefaultProvidedInterfaceDescriptor descr = (DefaultProvidedInterfaceDescriptor)obj; + DefaultProvidedInterface descr = (DefaultProvidedInterface)obj; if ( _interfaces.length != descr._interfaces.length ) { return false; } diff --git a/system/general/src/main/java/org/wamblee/system/DefaultRequiredInterfaceDescriptor.java b/system/general/src/main/java/org/wamblee/system/DefaultRequiredInterface.java similarity index 84% rename from system/general/src/main/java/org/wamblee/system/DefaultRequiredInterfaceDescriptor.java rename to system/general/src/main/java/org/wamblee/system/DefaultRequiredInterface.java index 580b390b..2f06247d 100644 --- a/system/general/src/main/java/org/wamblee/system/DefaultRequiredInterfaceDescriptor.java +++ b/system/general/src/main/java/org/wamblee/system/DefaultRequiredInterface.java @@ -2,17 +2,17 @@ package org.wamblee.system; import java.util.Arrays; -public class DefaultRequiredInterfaceDescriptor implements RequiredInterface { +public class DefaultRequiredInterface implements RequiredInterface { private String _name; private Class[] _required; private ProvidedInterface _provider; - public DefaultRequiredInterfaceDescriptor(String aName, Class aInterface) { + public DefaultRequiredInterface(String aName, Class aInterface) { this(aName, new Class[] { aInterface }); } - public DefaultRequiredInterfaceDescriptor(String aName, Class[] aInterfaces) { + public DefaultRequiredInterface(String aName, Class[] aInterfaces) { _name = aName; _required = aInterfaces; } @@ -69,10 +69,10 @@ public class DefaultRequiredInterfaceDescriptor implements RequiredInterface { @Override public boolean equals(Object obj) { - if ( !(obj instanceof DefaultRequiredInterfaceDescriptor)) { + if ( !(obj instanceof DefaultRequiredInterface)) { return false; } - DefaultRequiredInterfaceDescriptor descr = (DefaultRequiredInterfaceDescriptor)obj; + DefaultRequiredInterface descr = (DefaultRequiredInterface)obj; if ( _required.length != descr._required.length ) { return false; } 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 b84ca5e2..6e9eb675 100644 --- a/system/general/src/test/java/org/wamblee/system/Application.java +++ b/system/general/src/test/java/org/wamblee/system/Application.java @@ -6,8 +6,8 @@ public class Application extends AbstractComponent { private static RequiredInterface[] required() { return new RequiredInterface[] { - new DefaultRequiredInterfaceDescriptor("datasource", DataSource.class), - new DefaultRequiredInterfaceDescriptor("integer", Integer.class) + new DefaultRequiredInterface("datasource", DataSource.class), + new DefaultRequiredInterface("integer", Integer.class) }; } diff --git a/system/general/src/test/java/org/wamblee/system/DefaultInterfaceDescriptorTest.java b/system/general/src/test/java/org/wamblee/system/DefaultInterfaceDescriptorTest.java index f74557be..b6a5eb8b 100644 --- a/system/general/src/test/java/org/wamblee/system/DefaultInterfaceDescriptorTest.java +++ b/system/general/src/test/java/org/wamblee/system/DefaultInterfaceDescriptorTest.java @@ -7,27 +7,27 @@ import junit.framework.TestCase; public class DefaultInterfaceDescriptorTest extends TestCase { public void testOneRequiredOneProvidedMatch() { - ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name", String.class); - RequiredInterface required = new DefaultRequiredInterfaceDescriptor("name", String.class); + ProvidedInterface provided = new DefaultProvidedInterface("name", String.class); + RequiredInterface required = new DefaultRequiredInterface("name", String.class); assertTrue(required.implementedBy(provided)); } public void testOneRequiredOneProvidedMatchSubClass() { - ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name", Integer.class); - RequiredInterface required = new DefaultRequiredInterfaceDescriptor("name", Number.class); + ProvidedInterface provided = new DefaultProvidedInterface("name", Integer.class); + RequiredInterface required = new DefaultRequiredInterface("name", Number.class); assertTrue(required.implementedBy(provided)); } public void testOneRequiredOneProvidedNoMatch() { - ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name", String.class); - RequiredInterface required = new DefaultRequiredInterfaceDescriptor("name", Number.class); + ProvidedInterface provided = new DefaultProvidedInterface("name", String.class); + RequiredInterface required = new DefaultRequiredInterface("name", Number.class); assertFalse(required.implementedBy(provided)); } public void testOneRequiredMultipleProvidedMatch() { - ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name", + ProvidedInterface provided = new DefaultProvidedInterface("name", new Class[] { String.class, Integer.class} ); - RequiredInterface required = new DefaultRequiredInterfaceDescriptor("name", String.class); + RequiredInterface required = new DefaultRequiredInterface("name", String.class); assertTrue(required.implementedBy(provided)); } @@ -39,25 +39,25 @@ public class DefaultInterfaceDescriptorTest extends TestCase { } public void testMultipleRequiredOneProvidedMatch() { - ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name", + ProvidedInterface provided = new DefaultProvidedInterface("name", MyMultiple.class ); - RequiredInterface required = new DefaultRequiredInterfaceDescriptor("name", + RequiredInterface required = new DefaultRequiredInterface("name", new Class[] {Runnable.class, Serializable.class} ); assertTrue(required.implementedBy(provided)); } public void testMultipleRequiredOneProvidedNoMatch() { - ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name", + ProvidedInterface provided = new DefaultProvidedInterface("name", MyMultiple.class ); - RequiredInterface required = new DefaultRequiredInterfaceDescriptor("name", + RequiredInterface required = new DefaultRequiredInterface("name", new Class[] { String.class, Runnable.class} ); assertFalse(required.implementedBy(provided)); } public void testMultipleRequiredMultipleProvidedMatch() { - ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name", + ProvidedInterface provided = new DefaultProvidedInterface("name", new Class[] { Runnable.class, Serializable.class, String.class} ); - RequiredInterface required = new DefaultRequiredInterfaceDescriptor("name", + RequiredInterface required = new DefaultRequiredInterface("name", new Class[] {Runnable.class, Serializable.class} ); assertTrue(required.implementedBy(provided)); } 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 27537e0a..300adf5c 100644 --- a/system/general/src/test/java/org/wamblee/system/Environment.java +++ b/system/general/src/test/java/org/wamblee/system/Environment.java @@ -7,8 +7,8 @@ public class Environment extends AbstractComponent { private static final ProvidedInterface[] provided() { return new ProvidedInterface[] { - new DefaultProvidedInterfaceDescriptor("datasource", DataSource.class), - new DefaultProvidedInterfaceDescriptor("integer", Integer.class) + new DefaultProvidedInterface("datasource", DataSource.class), + new DefaultProvidedInterface("integer", Integer.class) }; } diff --git a/system/general/src/test/java/org/wamblee/system/SystemAssemblerTest.java b/system/general/src/test/java/org/wamblee/system/SystemAssemblerTest.java index 9412caee..d862b15e 100644 --- a/system/general/src/test/java/org/wamblee/system/SystemAssemblerTest.java +++ b/system/general/src/test/java/org/wamblee/system/SystemAssemblerTest.java @@ -24,15 +24,15 @@ public class SystemAssemblerTest extends TestCase { } public void testFilterProvided() { - RequiredInterface req1 = new DefaultRequiredInterfaceDescriptor("name", + RequiredInterface req1 = new DefaultRequiredInterface("name", Runnable.class); - RequiredInterface req2 = new DefaultRequiredInterfaceDescriptor("name", + RequiredInterface req2 = new DefaultRequiredInterface("name", Serializable.class); - ProvidedInterface prov1 = new DefaultProvidedInterfaceDescriptor( + ProvidedInterface prov1 = new DefaultProvidedInterface( "name", Runnable.class); - ProvidedInterface prov2 = new DefaultProvidedInterfaceDescriptor( + ProvidedInterface prov2 = new DefaultProvidedInterface( "name", Serializable.class); - ProvidedInterface prov3 = new DefaultProvidedInterfaceDescriptor( + ProvidedInterface prov3 = new DefaultProvidedInterface( "name", MyMultiple.class); AssertionUtils.assertEquals(new RequiredInterface[] { req1 }, @@ -117,9 +117,9 @@ public class SystemAssemblerTest extends TestCase { Container system = new Container( "all", new Component[] { environment, application }, - new ProvidedInterface[] { new DefaultProvidedInterfaceDescriptor( + new ProvidedInterface[] { new DefaultProvidedInterface( "string", String.class) }, - new DefaultRequiredInterfaceDescriptor[0]); + new DefaultRequiredInterface[0]); } catch (SystemAssemblyException e) { return; } @@ -134,7 +134,7 @@ public class SystemAssemblerTest extends TestCase { "all", new Component[] { environment, application }, new ProvidedInterface[0], - new RequiredInterface[] { new DefaultRequiredInterfaceDescriptor( + new RequiredInterface[] { new DefaultRequiredInterface( "string", String.class) }); system.start("root"); } catch (SystemAssemblyException e) { @@ -150,10 +150,10 @@ public class SystemAssemblerTest extends TestCase { "all", new Component[] { environment, application }, new ProvidedInterface[0], - new RequiredInterface[] { new DefaultRequiredInterfaceDescriptor( + new RequiredInterface[] { new DefaultRequiredInterface( "string", String.class) }); system.getRequiredServices()[0].setProvider( - new DefaultProvidedInterfaceDescriptor("hallo", String.class)); + new DefaultProvidedInterface("hallo", String.class)); system.start("root"); RequiredInterface[] required = system.getRequiredServices(); assertEquals(1, required.length); 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 0b0921e6..f7177759 100644 --- a/system/spring/src/main/java/org/wamblee/system/spring/SpringComponent.java +++ b/system/spring/src/main/java/org/wamblee/system/spring/SpringComponent.java @@ -13,8 +13,6 @@ import org.springframework.context.support.GenericApplicationContext; import org.wamblee.system.AbstractComponent; import org.wamblee.system.ProvidedInterface; import org.wamblee.system.RequiredInterface; -import org.wamblee.system.Service; -import org.wamblee.system.SystemAssembler; import org.wamblee.system.SystemAssemblyException; /** 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 0b4ffb08..2da7a235 100644 --- a/system/spring/src/test/java/org/wamblee/system/spring/SpringComponentTest.java +++ b/system/spring/src/test/java/org/wamblee/system/spring/SpringComponentTest.java @@ -8,12 +8,10 @@ import java.util.Properties; import junit.framework.TestCase; import org.wamblee.io.ClassPathResource; -import org.wamblee.system.DefaultProvidedInterfaceDescriptor; -import org.wamblee.system.DefaultRequiredInterfaceDescriptor; -import org.wamblee.system.DefaultService; +import org.wamblee.system.DefaultProvidedInterface; +import org.wamblee.system.DefaultRequiredInterface; import org.wamblee.system.ProvidedInterface; import org.wamblee.system.RequiredInterface; -import org.wamblee.system.Service; import org.wamblee.system.SystemAssemblyException; public class SpringComponentTest extends TestCase { @@ -42,7 +40,7 @@ public class SpringComponentTest extends TestCase { public void testOneProvidedService() { Map provided = new HashMap(); - provided.put("helloService", new DefaultProvidedInterfaceDescriptor( + provided.put("helloService", new DefaultProvidedInterface( "hello", HelloService.class)); SpringComponent system = new SpringComponent("system", @@ -59,7 +57,7 @@ public class SpringComponentTest extends TestCase { public void testWithProperties() throws IOException { Map provided = new HashMap(); - provided.put("helloService", new DefaultProvidedInterfaceDescriptor( + provided.put("helloService", new DefaultProvidedInterface( "hello", HelloService.class)); SpringComponent system = new SpringComponent("system", new String[] { HELLO_SERVICE_SPRING_WITH_PROPERTIES_XML }, @@ -91,14 +89,14 @@ public class SpringComponentTest extends TestCase { public void testWithRequirement() { Map required = new HashMap(); - required.put(new DefaultRequiredInterfaceDescriptor("hello", HelloService.class), + required.put(new DefaultRequiredInterface("hello", HelloService.class), "helloService"); SpringComponent system = new SpringComponent("system", new String[] { HELLO_SERVICE_SPRING_WITH_REQS_XML }, new HashMap(), required); HelloService helloObject = new HelloService("ladida"); - ProvidedInterface helloService = new DefaultProvidedInterfaceDescriptor("hello", HelloService.class); + ProvidedInterface helloService = new DefaultProvidedInterface("hello", HelloService.class); helloService.publish(helloObject); system.getRequiredServices()[0].setProvider(helloService); @@ -108,10 +106,10 @@ public class SpringComponentTest extends TestCase { public void testWithRequirementAndProvidedService() { Map required = new HashMap(); - required.put(new DefaultRequiredInterfaceDescriptor("hello", HelloService.class), + required.put(new DefaultRequiredInterface("hello", HelloService.class), "helloService"); Map provided = new HashMap(); - provided.put("blaService", new DefaultProvidedInterfaceDescriptor("bla", + provided.put("blaService", new DefaultProvidedInterface("bla", BlaService.class)); SpringComponent system = new SpringComponent("system", @@ -120,7 +118,7 @@ public class SpringComponentTest extends TestCase { HelloService helloObject = new HelloService("ladida"); ProvidedInterface helloService = - new DefaultProvidedInterfaceDescriptor("hello", HelloService.class); + new DefaultProvidedInterface("hello", HelloService.class); helloService.publish(helloObject); system.getRequiredServices()[0].setProvider(helloService); system.start("Bla");