Skip to Content.
Sympa Menu

notify-dpml - r1793 - in trunk/tutorials: . components components/unit components/unit/etc components/unit/etc/data components/unit/src components/unit/src/main components/unit/src/main/acme components/unit/src/test components/unit/src/test/acme components/unit/src/test/acme/test

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: r1793 - in trunk/tutorials: . components components/unit components/unit/etc components/unit/etc/data components/unit/src components/unit/src/main components/unit/src/main/acme components/unit/src/test components/unit/src/test/acme components/unit/src/test/acme/test
  • Date: Sun, 3 Dec 2006 06:57:23 +0100

Author: mcconnell
Date: 2006-12-03 06:57:18 +0100 (Sun, 03 Dec 2006)
New Revision: 1793

Added:
trunk/tutorials/components/unit/
trunk/tutorials/components/unit/build.xml
trunk/tutorials/components/unit/etc/
trunk/tutorials/components/unit/etc/data/
trunk/tutorials/components/unit/etc/data/logging.properties
trunk/tutorials/components/unit/src/
trunk/tutorials/components/unit/src/main/
trunk/tutorials/components/unit/src/main/acme/
trunk/tutorials/components/unit/src/main/acme/Child.java
trunk/tutorials/components/unit/src/main/acme/ChildImpl.java
trunk/tutorials/components/unit/src/main/acme/Container.java
trunk/tutorials/components/unit/src/main/acme/ContainerImpl.java
trunk/tutorials/components/unit/src/test/
trunk/tutorials/components/unit/src/test/acme/
trunk/tutorials/components/unit/src/test/acme/test/
trunk/tutorials/components/unit/src/test/acme/test/ExampleTest.java
Modified:
trunk/tutorials/module.xml
Log:
add sample testcase dealing with formal decommissioning of a component via
Metro management APIs


Property changes on: trunk/tutorials/components/unit
___________________________________________________________________
Name: svn:ignore
+ target


Added: trunk/tutorials/components/unit/build.xml
===================================================================
--- trunk/tutorials/components/unit/build.xml 2006-12-03 02:38:37 UTC (rev
1792)
+++ trunk/tutorials/components/unit/build.xml 2006-12-03 05:57:18 UTC (rev
1793)
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<project default="install"
+ xmlns:transit="antlib:net.dpml.transit"
+ xmlns:depot="dpml:depot" >
+
+ <transit:import uri="local:template:dpml/tools/standard"/>
+
+ <target name="init" depends="standard.init">
+ <depot:plugin uri="link:part:dpml/metro/dpml-metro-tools"
urn="metro"/>
+ </target>
+
+ <target name="prepare" depends="standard.prepare">
+ <depot:plugin uri="link:part:dpml/depot/dpml-depot-convert">
+ <task name="convert" class="de.java2html.anttasks.Java2HtmlTask"/>
+ </depot:plugin>
+ <convert srcdir="target/build/main" destdir="target/reports/src"/>
+ <convert srcdir="target/build/test" destdir="target/reports/src"/>
+ </target>
+
+ <target name="build" depends="standard.build">
+ <echo message="Building Service Components" />
+
+ <type xmlns="metro"
+ name="container" class="acme.ContainerImpl" threadsafe="true"
lifestyle="singleton">
+ <services>
+ <service class="acme.Container" />
+ </services>
+ <state>
+ <trigger event="initialization">
+ <transition name="start" target="started">
+ <operation name="startup" method="start"/>
+ </transition>
+ </trigger>
+ <state name="started">
+ <transition name="stop" target="../stopped">
+ <operation name="stop" method="stop"/>
+ </transition>
+ <trigger event="termination">
+ <apply id="stop"/>
+ </trigger>
+ </state>
+ <state name="stopped">
+ <transition name="start" target="../started">
+ <operation name="start" method="start"/>
+ </transition>
+ </state>
+ </state>
+ </type>
+
+ <type xmlns="metro" name="configurable" class="acme.ChildImpl"
+ threadsafe="true" lifestyle="singleton" >
+ <services>
+ <service class="acme.Child" />
+ </services>
+ </type>
+
+ </target>
+
+</project>
\ No newline at end of file

Added: trunk/tutorials/components/unit/etc/data/logging.properties
===================================================================
--- trunk/tutorials/components/unit/etc/data/logging.properties 2006-12-03
02:38:37 UTC (rev 1792)
+++ trunk/tutorials/components/unit/etc/data/logging.properties 2006-12-03
05:57:18 UTC (rev 1793)
@@ -0,0 +1,2 @@
+container.level=FINE
+

Added: trunk/tutorials/components/unit/src/main/acme/Child.java
===================================================================
--- trunk/tutorials/components/unit/src/main/acme/Child.java 2006-12-03
02:38:37 UTC (rev 1792)
+++ trunk/tutorials/components/unit/src/main/acme/Child.java 2006-12-03
05:57:18 UTC (rev 1793)
@@ -0,0 +1,9 @@
+package acme;
+
+import java.net.URI;
+
+public interface Child
+{
+ public void start( URI configurationURI ) throws Exception;
+ public void stop() throws Exception;
+}

Added: trunk/tutorials/components/unit/src/main/acme/ChildImpl.java
===================================================================
--- trunk/tutorials/components/unit/src/main/acme/ChildImpl.java
2006-12-03 02:38:37 UTC (rev 1792)
+++ trunk/tutorials/components/unit/src/main/acme/ChildImpl.java
2006-12-03 05:57:18 UTC (rev 1793)
@@ -0,0 +1,35 @@
+package acme;
+
+import java.net.URI;
+import java.util.logging.Logger;
+
+public class ChildImpl implements Child
+{
+ private boolean started;
+ private Logger logger;
+
+ public ChildImpl( Logger logger )
+ {
+ this.started = false;
+ this.logger = logger;
+ }
+
+ public void start( URI configurationURI ) throws Exception {
+ if ( !this.started ){
+ this.started = true;
+ this.logger.info( "starting with: " + configurationURI );
+ } else {
+ throw new Exception( "already started!" );
+ }
+ }
+
+ public void stop() throws Exception {
+ if ( this.started ){
+ this.started = false;
+ this.logger.info( "stopping" );
+ } else {
+ throw new Exception("not started!" );
+ }
+ }
+
+}

Added: trunk/tutorials/components/unit/src/main/acme/Container.java
===================================================================
--- trunk/tutorials/components/unit/src/main/acme/Container.java
2006-12-03 02:38:37 UTC (rev 1792)
+++ trunk/tutorials/components/unit/src/main/acme/Container.java
2006-12-03 05:57:18 UTC (rev 1793)
@@ -0,0 +1,5 @@
+package acme;
+
+public interface Container
+{
+}

Added: trunk/tutorials/components/unit/src/main/acme/ContainerImpl.java
===================================================================
--- trunk/tutorials/components/unit/src/main/acme/ContainerImpl.java
2006-12-03 02:38:37 UTC (rev 1792)
+++ trunk/tutorials/components/unit/src/main/acme/ContainerImpl.java
2006-12-03 05:57:18 UTC (rev 1793)
@@ -0,0 +1,45 @@
+package acme;
+
+import java.net.URI;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class ContainerImpl implements Container {
+
+ public interface Context
+ {
+ public URI getConfigurationURI();
+ }
+
+ public interface Parts
+ {
+ public Child getChild( boolean proxy );
+ }
+
+ private URI m_uri;
+ private Child m_child;
+
+ private Logger m_logger;
+ private Context m_context;
+
+ public ContainerImpl( final Logger logger, final Context context, final
Parts parts )
+ {
+ m_logger = logger;
+ m_uri = context.getConfigurationURI();
+ m_logger.info( "configuration uri: " + m_uri );
+ m_child = parts.getChild( false );
+ }
+
+ public void start() throws Exception
+ {
+ m_logger.info( "starting" );
+ m_child.start( m_uri );
+ m_logger.info( "configurable service started successfully" );
+ }
+
+ public synchronized void stop() throws Exception
+ {
+ m_logger.info( "stopping" );
+ m_child.stop();
+ }
+}

Added: trunk/tutorials/components/unit/src/test/acme/test/ExampleTest.java
===================================================================
--- trunk/tutorials/components/unit/src/test/acme/test/ExampleTest.java
2006-12-03 02:38:37 UTC (rev 1792)
+++ trunk/tutorials/components/unit/src/test/acme/test/ExampleTest.java
2006-12-03 05:57:18 UTC (rev 1793)
@@ -0,0 +1,85 @@
+package acme.test;
+
+import java.io.File;
+import java.net.URI;
+import java.util.logging.Logger;
+
+import junit.framework.TestCase;
+
+import net.dpml.component.Component;
+import net.dpml.component.Disposable;
+import net.dpml.component.Provider;
+import net.dpml.lang.Part;
+
+import acme.ContainerImpl;
+
+public class ExampleTest extends TestCase
+{
+ private Logger m_logger;
+ private Component m_component;
+
+ /**
+ * Load up the part from the tasrget/deliverables directory,
+ * and get the component handler which we will use to (a)
+ * establish an instance and (b) handle the formal end-of-life
+ * processing.
+ *
+ * @exception Exception if not everything goes according to plan
+ */
+ public void setUp() throws Exception
+ {
+ m_logger = Logger.getLogger( "test" );
+ m_logger.info( "commissioning" );
+ URI uri = getPartURI();
+ Part part = Part.load( uri );
+ m_component = (Component) part.getContent( new
Class[]{Component.class} );
+ }
+
+ /**
+ * Handle formal decommissioning of the component.
+ *
+ * @exception Exception if not everything goes according to plan
+ */
+ public void tearDown() throws Exception
+ {
+ m_logger.info( "decommissioning" );
+ Disposable disposable = (Disposable) m_component;
+ disposable.dispose();
+ System.gc();
+ }
+
+ /**
+ * The Component instance exposes a buch of management operations. One
+ * of these is the operation getProvider() which gives us access to
+ * the manager of one instance of the class specificed by the component
+ * type. The provider exposes the operation getValue( boolean ) which
+ * is where we actually get a fully initialized instance (and keep
+ * in mind here that full-initialized means that all initialization
+ * actions (such as state transitions) have alrady been successfully
+ * completed.
+ *
+ * @exception Exception if a test related error occurs
+ */
+ public void testExampleComponent() throws Exception
+ {
+ m_logger.info( "testing" );
+ Provider provider = m_component.getProvider();
+ ContainerImpl container = (ContainerImpl) provider.getValue( false );
+
+ // Any tests dealing with the instance would go here.
+ }
+
+ /**
+ * Internal utility to get a URI to the part definition in the
+ * project target/deliverables directory.
+ *
+ * @return the part uri
+ * @exception Exception if an error occurs
+ */
+ private URI getPartURI() throws Exception
+ {
+ String path = System.getProperty( "project.deliverable.part.path" );
+ File file = new File( path );
+ return file.toURI();
+ }
+}

Modified: trunk/tutorials/module.xml
===================================================================
--- trunk/tutorials/module.xml 2006-12-03 02:38:37 UTC (rev 1792)
+++ trunk/tutorials/module.xml 2006-12-03 05:57:18 UTC (rev 1793)
@@ -478,6 +478,32 @@
<feature ref="dpmlx/tutorials/components/acme-clock-demo" token="PART"
id="uri" type="part"/>
</filters>
</project>
+
+ <project name="acme-unit" basedir="unit">
+ <properties>
+ <property name="java.util.logging.config.class" value="dpml"/>
+ <property name="example.uri"
value="local:properties:acme/examples/services/configuration"/>
+ </properties>
+ <types>
+ <type id="jar" />
+ <component xmlns="link:xsd:dpml/lang/dpml-component#1.0"
+ type="acme.ContainerImpl"
+ name="container" alias="true" collection="hard">
+ <context>
+ <entry key="configurationURI" value="${example.uri}" />
+ </context>
+ <parts>
+ <component key="child" type="acme.ChildImpl" collection="hard"/>
+ </parts>
+ </component>
+ </types>
+ <dependencies>
+ <test>
+ <include ref="ant/ant-junit" />
+ <include ref="dpml/metro/dpml-metro-model" />
+ </test>
+ </dependencies>
+ </project>

</module>





  • r1793 - in trunk/tutorials: . components components/unit components/unit/etc components/unit/etc/data components/unit/src components/unit/src/main components/unit/src/main/acme components/unit/src/test components/unit/src/test/acme components/unit/src/test/acme/test, mcconnell at BerliOS, 12/03/2006

Archive powered by MHonArc 2.6.24.

Top of Page