You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jm...@apache.org on 2007/02/25 02:26:31 UTC

svn commit: r511397 - in /incubator/tuscany/java/sca/kernel/core/src: main/java/org/apache/tuscany/core/implementation/composite/ test/java/org/apache/tuscany/core/implementation/composite/ test/java/org/apache/tuscany/core/implementation/java/

Author: jmarino
Date: Sat Feb 24 17:26:30 2007
New Revision: 511397

URL: http://svn.apache.org/viewvc?view=rev&rev=511397
Log:
get rid of AbstractCompositeComponent

Removed:
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeComponent.java
Modified:
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeBuilder.java
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImpl.java
    incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplTestCase.java
    incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/DuplicateRegistrationTestCase.java
    incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderMetadataTestCase.java
    incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderReferenceTestCase.java

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeBuilder.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeBuilder.java?view=diff&rev=511397&r1=511396&r2=511397
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeBuilder.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeBuilder.java Sat Feb 24 17:26:30 2007
@@ -40,7 +40,7 @@
         CompositeImplementation implementation = componentDefinition.getImplementation();
         CompositeComponentType<?, ?, ?> componentType = implementation.getComponentType();
         URI name = componentDefinition.getUri();
-        CompositeComponentImpl component = new CompositeComponentImpl(name, null);
+        CompositeComponentImpl component = new CompositeComponentImpl(name);
 
         return build(parent, component, componentType, deploymentContext);
     }

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImpl.java?view=diff&rev=511397&r1=511396&r2=511397
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImpl.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImpl.java Sat Feb 24 17:26:30 2007
@@ -20,36 +20,35 @@
 
 import java.net.URI;
 import java.util.List;
-import java.util.Map;
-
-import org.w3c.dom.Document;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 
+import org.apache.tuscany.spi.event.Event;
+import org.apache.tuscany.spi.extension.CompositeComponentExtension;
 import org.apache.tuscany.spi.wire.Wire;
 
+import org.apache.tuscany.core.component.event.ComponentStop;
+
 /**
  * The standard implementation of a composite component. Autowiring is performed by delegating to the parent composite.
  *
  * @version $Rev$ $Date$
  */
-public class CompositeComponentImpl extends AbstractCompositeComponent {
-
-    /**
-     * Constructor specifying property values
-     *
-     * @param name           the name of this Component
-     * @param propertyValues this composite's Property values
-     */
-    public CompositeComponentImpl(URI name, Map<String, Document> propertyValues) {
-        super(name, propertyValues);
-    }
+public class CompositeComponentImpl extends CompositeComponentExtension {
+    public static final int DEFAULT_WAIT = 1000 * 60;
+    // Blocking latch to ensure the composite is initialized exactly once prior to servicing requests
+    protected CountDownLatch initializeLatch = new CountDownLatch(1);
+    protected final Object lock = new Object();
+    // Indicates whether the composite context has been initialized
+    protected boolean initialized;
 
     /**
-     * Constructor specifying if the composite is a system composite
+     * Constructor
      *
      * @param name the name of this Component
      */
     public CompositeComponentImpl(URI name) {
-        super(name, null);
+        super(name);
     }
 
     public void attachWire(Wire wire) {
@@ -67,4 +66,56 @@
     public void attachCallbackWire(Wire wire) {
         throw new UnsupportedOperationException();
     }
+
+    public void start() {
+        synchronized (lock) {
+            if (lifecycleState != UNINITIALIZED && lifecycleState != STOPPED) {
+                throw new IllegalStateException("Composite not in UNINITIALIZED state");
+            }
+            initializeLatch.countDown();
+            initialized = true;
+            lifecycleState = INITIALIZED;
+        }
+    }
+
+    public void stop() {
+        if (lifecycleState == STOPPED) {
+            return;
+        }
+
+        publish(new ComponentStop(this, getUri()));
+        // need to block a start until reset is complete
+        initializeLatch = new CountDownLatch(2);
+        lifecycleState = STOPPING;
+        initialized = false;
+        // allow initialized to be called
+        initializeLatch.countDown();
+        lifecycleState = STOPPED;
+    }
+
+    public void publish(Event event) {
+        if (lifecycleState == STOPPED) {
+            return;
+        }
+        checkInit();
+        super.publish(event);
+    }
+
+    /**
+     * Blocks until the composite context has been initialized
+     */
+    protected void checkInit() throws ComponentTimeoutException {
+        if (!initialized) {
+            try {
+                /* block until the composite has initialized */
+                boolean success = initializeLatch.await(DEFAULT_WAIT, TimeUnit.MILLISECONDS);
+                if (!success) {
+                    throw new ComponentTimeoutException("Timeout waiting for context to initialize");
+                }
+            } catch (InterruptedException e) { // should not happen
+            }
+        }
+
+    }
+
 }

Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplTestCase.java?view=diff&rev=511397&r1=511396&r2=511397
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplTestCase.java Sat Feb 24 17:26:30 2007
@@ -41,26 +41,26 @@
 public class CompositeComponentImplTestCase extends TestCase {
 
     public void testGetScope() {
-        Component composite = new CompositeComponentImpl(URI.create("parent"), null);
+        Component composite = new CompositeComponentImpl(URI.create("parent"));
         Assert.assertEquals(Scope.SYSTEM, composite.getScope());
     }
 
     public void testRegisterService() throws Exception {
-        Component composite = new CompositeComponentImpl(URI.create("parent"), null);
+        Component composite = new CompositeComponentImpl(URI.create("parent"));
         Service service = new ServiceImpl(URI.create("foo#service"), null);
         composite.register(service);
         assertNotNull(composite.getService("service"));
     }
 
     public void testRegisterReference() throws Exception {
-        Component composite = new CompositeComponentImpl(URI.create("parent"), null);
+        Component composite = new CompositeComponentImpl(URI.create("parent"));
         Reference reference = new ReferenceImpl(URI.create("foo#reference"), null);
         composite.register(reference);
         assertNotNull(composite.getReference("reference"));
     }
 
     public void testOnEvent() {
-        CompositeComponentImpl composite = new CompositeComponentImpl(URI.create("parent"), null);
+        CompositeComponentImpl composite = new CompositeComponentImpl(URI.create("parent"));
         Event event = new Event() {
             public Object getSource() {
                 return null;

Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/DuplicateRegistrationTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/DuplicateRegistrationTestCase.java?view=diff&rev=511397&r1=511396&r2=511397
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/DuplicateRegistrationTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/DuplicateRegistrationTestCase.java Sat Feb 24 17:26:30 2007
@@ -36,7 +36,7 @@
 public class DuplicateRegistrationTestCase extends TestCase {
 
     public void testDuplicateServiceRegistration() throws Exception {
-        Component parent = new CompositeComponentImpl(URI.create("parent"), null);
+        Component parent = new CompositeComponentImpl(URI.create("parent"));
         parent.start();
 
         Service service1 = EasyMock.createMock(Service.class);
@@ -60,7 +60,7 @@
     }
 
     public void testDuplicateReferenceRegistration() throws Exception {
-        Component parent = new CompositeComponentImpl(URI.create("parent"), null);
+        Component parent = new CompositeComponentImpl(URI.create("parent"));
         parent.start();
 
         Reference reference1 = EasyMock.createMock(Reference.class);
@@ -85,7 +85,7 @@
     }
 
     public void testDuplicateServiceReferenceRegistration() throws Exception {
-        Component parent = new CompositeComponentImpl(URI.create("parent"), null);
+        Component parent = new CompositeComponentImpl(URI.create("parent"));
         parent.start();
 
         Service service1 = EasyMock.createMock(Service.class);

Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderMetadataTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderMetadataTestCase.java?view=diff&rev=511397&r1=511396&r2=511397
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderMetadataTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderMetadataTestCase.java Sat Feb 24 17:26:30 2007
@@ -74,7 +74,7 @@
 
     protected void setUp() throws Exception {
         super.setUp();
-        parent = new CompositeComponentImpl(URI.create("parent"), null);
+        parent = new CompositeComponentImpl(URI.create("parent"));
         constructor = SourceImpl.class.getConstructor((Class[]) null);
         createDeploymentContext();
         createComponentDefinitionAndType();

Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderReferenceTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderReferenceTestCase.java?view=diff&rev=511397&r1=511396&r2=511397
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderReferenceTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderReferenceTestCase.java Sat Feb 24 17:26:30 2007
@@ -95,7 +95,7 @@
     protected void setUp() throws Exception {
         super.setUp();
         proxyService = new JDKProxyService();
-        parent = new CompositeComponentImpl(URI.create("parent"), null);
+        parent = new CompositeComponentImpl(URI.create("parent"));
         constructor = SourceImpl.class.getConstructor((Class[]) null);
         createDeploymentContext();
         createWire();



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org