Author: jboynes
Date: Mon Apr 24 03:56:40 2006
New Revision: 396511

URL: http://svn.apache.org/viewcvs?rev=396511&view=rev
Log:
separate Lifecycle from Context

Added:
    
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/Lifecycle.java
   (with props)
Modified:
    
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/Context.java
    
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractCompositeContext.java
    
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/ModuleScopeContext.java
    
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/RequestScopeContext.java
    
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/SessionScopeContext.java
    
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/StatelessScopeContext.java
    
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/runtime/RuntimeBootTestCase.java
    
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/runtime/RuntimeContextImplTestCase.java

Modified: 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/Context.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/Context.java?rev=396511&r1=396510&r2=396511&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/Context.java
 (original)
+++ 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/Context.java
 Mon Apr 24 03:56:40 2006
@@ -19,93 +19,43 @@
 /**
  * An entity that provides an execution context for a runtime artifact or 
artifacts. A <code>Context</code> may
  * be a composite, managing child contexts or it may be an atomic, i.e. leaf, 
context.
- * 
+ *
  * @version $Rev$ $Date$
  */
-public interface Context extends EventPublisher{
+public interface Context extends EventPublisher, Lifecycle {
 
-        /* A configuration error state */
-        public static final int CONFIG_ERROR = -1;
+    /* A configuration error state */
+    public static final int CONFIG_ERROR = -1;
 
-        /* Has not been initialized */
-        public static final int UNINITIALIZED = 0;
-
-        /* In the process of being configured and initialized */
-        public static final int INITIALIZING = 1;
-
-        /* Instantiated and configured */
-        public static final int INITIALIZED = 2;
-
-         /* Started */
-         public static final int STARTED = 4;
-
-        /* Configured and initialized */
-        public static final int RUNNING = 4;
-
-        /* In the process of being shutdown */
-        public static final int STOPPING = 5;
-
-        /* Has been shutdown and removed from the module */
-        public static final int STOPPED = 6;
-
-        /* In an error state */
-        public static final int ERROR = 7;
-
-        /**
-         * Returns the name of the context
-         */
-        public String getName();
-
-        /**
-         * Sets the name of the context
-         */
-        public void setName(String name);
-
-        /**
-         * Returns the lifecycle state
-         *
-         * @see #UNINITIALIZED
-         * @see #INITIALIZING
-         * @see #INITIALIZED
-         * @see #RUNNING
-         * @see #STOPPING
-         * @see #STOPPED
-         */
-        public int getLifecycleState();
-
-        /**
-         * Starts the container
-         *
-         * @throws CoreRuntimeException
-         */
-        public void start() throws CoreRuntimeException;
-
-        /**
-         * Stops the container
-         *
-         * @throws CoreRuntimeException
-         */
-        public void stop() throws CoreRuntimeException;
-
-
-        /**
-         * Returns the instance associated with the requested name, which may 
be in a atomic or composite form. Atomic (i.e.
-         * leaf) contexts will return an instance associated with the service 
name part of the compound name, which may be
-         * null.
-         * <p>
-         * Composite contexts will return an instance (likely a proxy) of a 
contained entry point context. In this case, the
-         * port name on the qualified name will correspond to the composite 
context name and the part name will be used to
-         * retrieve the contained entry point context. The latter may be null. 
If the contained context is not an entry
-         * point context, an exception will be thrown.
-         *
-         * @param qName a qualified name of the requested instance
-         * @return the implementation instance or a proxy to it
-         * @throws org.apache.tuscany.core.context.TargetException if an error 
occurs retrieving the instance or the requested component is not an entry
-         *         point.
-         *
-         * @see org.apache.tuscany.core.context.CompositeContext
-         * @see org.apache.tuscany.model.assembly.EntryPoint
-         */
-        public Object getInstance(QualifiedName qName) throws TargetException;
+    /**
+     * Returns the name of the context
+     */
+    public String getName();
+
+    /**
+     * Sets the name of the context
+     */
+    public void setName(String name);
+
+
+    /**
+     * Returns the instance associated with the requested name, which may be 
in a atomic or composite form. Atomic (i.e.
+     * leaf) contexts will return an instance associated with the service name 
part of the compound name, which may be
+     * null.
+     * <p/>
+     * Composite contexts will return an instance (likely a proxy) of a 
contained entry point context. In this case, the
+     * port name on the qualified name will correspond to the composite 
context name and the part name will be used to
+     * retrieve the contained entry point context. The latter may be null. If 
the contained context is not an entry
+     * point context, an exception will be thrown.
+     *
+     * @param qName a qualified name of the requested instance
+     * @return the implementation instance or a proxy to it
+     * @throws TargetException
+     *          if an error occurs retrieving the instance or the requested 
component is not an entry
+     *          point.
+     * @see CompositeContext
+     * @see org.apache.tuscany.model.assembly.EntryPoint
+     */
+    public Object getInstance(QualifiedName qName) throws TargetException;
 
 }

Added: 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/Lifecycle.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/Lifecycle.java?rev=396511&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/Lifecycle.java
 (added)
+++ 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/Lifecycle.java
 Mon Apr 24 03:56:40 2006
@@ -0,0 +1,65 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors as applicable
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.tuscany.core.context;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface Lifecycle {
+    /* Has not been initialized */
+    int UNINITIALIZED = 0;
+    /* In the process of being configured and initialized */
+    int INITIALIZING = 1;
+    /* Instantiated and configured */
+    int INITIALIZED = 2;
+    /* Started */
+    int STARTED = 4;
+    /* Configured and initialized */
+    int RUNNING = 4;
+    /* In the process of being shutdown */
+    int STOPPING = 5;
+    /* Has been shutdown and removed from the module */
+    int STOPPED = 6;
+    /* In an error state */
+    int ERROR = 7;
+
+    /**
+     * Returns the lifecycle state
+     *
+     * @see #UNINITIALIZED
+     * @see #INITIALIZING
+     * @see #INITIALIZED
+     * @see #RUNNING
+     * @see #STOPPING
+     * @see #STOPPED
+     */
+    int getLifecycleState();
+
+    /**
+     * Starts the container
+     *
+     * @throws org.apache.tuscany.core.context.CoreRuntimeException
+     */
+    void start() throws CoreRuntimeException;
+
+    /**
+     * Stops the container
+     *
+     * @throws org.apache.tuscany.core.context.CoreRuntimeException
+     */
+    void stop() throws CoreRuntimeException;
+}

Propchange: 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/Lifecycle.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/Lifecycle.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Modified: 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractCompositeContext.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractCompositeContext.java?rev=396511&r1=396510&r2=396511&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractCompositeContext.java
 (original)
+++ 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractCompositeContext.java
 Mon Apr 24 03:56:40 2006
@@ -36,6 +36,7 @@
 import org.apache.tuscany.core.context.ProxyConfigurationException;
 import org.apache.tuscany.core.context.MissingScopeException;
 import org.apache.tuscany.core.context.AutowireResolutionException;
+import org.apache.tuscany.core.context.Lifecycle;
 import org.apache.tuscany.core.context.event.RequestEnd;
 import org.apache.tuscany.core.context.event.Event;
 import org.apache.tuscany.core.context.event.SessionBound;
@@ -224,7 +225,7 @@
         initialized = false;
         if (scopeContexts != null) {
             for (ScopeContext scopeContext : scopeContexts.values()) {
-                if (scopeContext.getLifecycleState() == Context.RUNNING) {
+                if (scopeContext.getLifecycleState() == Lifecycle.RUNNING) {
                     scopeContext.stop();
                 }
             }

Modified: 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/ModuleScopeContext.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/ModuleScopeContext.java?rev=396511&r1=396510&r2=396511&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/ModuleScopeContext.java
 (original)
+++ 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/ModuleScopeContext.java
 Mon Apr 24 03:56:40 2006
@@ -22,6 +22,7 @@
 import org.apache.tuscany.core.context.CoreRuntimeException;
 import org.apache.tuscany.core.context.EventContext;
 import org.apache.tuscany.core.context.TargetException;
+import org.apache.tuscany.core.context.Lifecycle;
 import org.apache.tuscany.core.context.event.InstanceCreated;
 import org.apache.tuscany.core.context.event.Event;
 import org.apache.tuscany.core.context.event.ModuleStart;
@@ -133,7 +134,7 @@
         // shutdown destroyable instances in reverse instantiation order
         ListIterator<Context> iter = 
destroyQueue.listIterator(destroyQueue.size());
         while(iter.hasPrevious()){
-            Context context = iter.previous();
+            Lifecycle context = iter.previous();
             if (context.getLifecycleState() == RUNNING) {
                 try {
                     if (context instanceof AtomicContext){
@@ -147,7 +148,7 @@
         if (contexts == null){
             return;
         }
-        for(Context context: contexts.values()) {
+        for(Lifecycle context: contexts.values()) {
             try {
                 if (context.getLifecycleState() == RUNNING) {
                     context.stop();

Modified: 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/RequestScopeContext.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/RequestScopeContext.java?rev=396511&r1=396510&r2=396511&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/RequestScopeContext.java
 (original)
+++ 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/RequestScopeContext.java
 Mon Apr 24 03:56:40 2006
@@ -22,6 +22,7 @@
 import org.apache.tuscany.core.context.EventContext;
 import org.apache.tuscany.core.context.AtomicContext;
 import org.apache.tuscany.core.context.TargetException;
+import org.apache.tuscany.core.context.Lifecycle;
 import org.apache.tuscany.core.context.event.InstanceCreated;
 import org.apache.tuscany.core.context.event.Event;
 import org.apache.tuscany.core.context.event.RequestEnd;
@@ -199,7 +200,7 @@
               // shutdown destroyable instances in reverse instantiation order
               ListIterator<Context> iter = 
destroyQueue.listIterator(destroyQueue.size());
               while(iter.hasPrevious()){
-                  Context context = iter.previous();
+                  Lifecycle context = iter.previous();
                   if (context.getLifecycleState() == RUNNING) {
                       try {
                           if (context instanceof AtomicContext){
@@ -216,7 +217,7 @@
           if (currentContexts == null){
              return;
           }
-          for (Context context: currentContexts.values()){
+          for (Lifecycle context: currentContexts.values()){
               if (context.getLifecycleState() == RUNNING) {
                   context.stop();
               }

Modified: 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/SessionScopeContext.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/SessionScopeContext.java?rev=396511&r1=396510&r2=396511&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/SessionScopeContext.java
 (original)
+++ 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/SessionScopeContext.java
 Mon Apr 24 03:56:40 2006
@@ -23,6 +23,7 @@
 import org.apache.tuscany.core.context.EventContext;
 import org.apache.tuscany.core.context.ScopeRuntimeException;
 import org.apache.tuscany.core.context.TargetException;
+import org.apache.tuscany.core.context.Lifecycle;
 import org.apache.tuscany.core.context.event.Event;
 import org.apache.tuscany.core.context.event.HttpSessionEvent;
 import org.apache.tuscany.core.context.event.InstanceCreated;
@@ -230,7 +231,7 @@
         ListIterator<Context> iter = 
destroyQueue.listIterator(destroyQueue.size());
         synchronized (destroyQueue) {
             while (iter.hasPrevious()) {
-                Context context = iter.previous();
+                Lifecycle context = iter.previous();
                 if (context.getLifecycleState() == RUNNING) {
                     try {
                         if (context instanceof AtomicContext) {
@@ -247,7 +248,7 @@
         if (currentContexts == null) {
             return;
         }
-        for (Context context : currentContexts.values()) {
+        for (Lifecycle context : currentContexts.values()) {
             if (context.getLifecycleState() == RUNNING) {
                 context.stop();
             }

Modified: 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/StatelessScopeContext.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/StatelessScopeContext.java?rev=396511&r1=396510&r2=396511&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/StatelessScopeContext.java
 (original)
+++ 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/StatelessScopeContext.java
 Mon Apr 24 03:56:40 2006
@@ -20,6 +20,7 @@
 import org.apache.tuscany.core.context.EventContext;
 import org.apache.tuscany.core.context.Context;
 import org.apache.tuscany.core.context.CoreRuntimeException;
+import org.apache.tuscany.core.context.Lifecycle;
 import org.apache.tuscany.core.context.event.Event;
 import org.apache.tuscany.core.context.event.ModuleStop;
 
@@ -114,7 +115,7 @@
         if (contexts == null){
             return;
         }
-        for(Context context: contexts.values()) {
+        for(Lifecycle context: contexts.values()) {
             try {
                 if (context.getLifecycleState() == RUNNING) {
                     context.stop();

Modified: 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/runtime/RuntimeBootTestCase.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/runtime/RuntimeBootTestCase.java?rev=396511&r1=396510&r2=396511&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/runtime/RuntimeBootTestCase.java
 (original)
+++ 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/runtime/RuntimeBootTestCase.java
 Mon Apr 24 03:56:40 2006
@@ -21,7 +21,7 @@
 import org.apache.tuscany.core.builder.impl.DefaultWireBuilder;
 import org.apache.tuscany.core.client.BootstrapHelper;
 import org.apache.tuscany.core.context.CompositeContext;
-import org.apache.tuscany.core.context.Context;
+import org.apache.tuscany.core.context.Lifecycle;
 import org.apache.tuscany.core.context.event.ModuleStart;
 import org.apache.tuscany.core.context.event.ModuleStop;
 import org.apache.tuscany.core.mock.MockFactory;
@@ -52,13 +52,13 @@
     }
 
     public void testRuntimeLifecycle() {
-        assertEquals(Context.RUNNING, runtime.getLifecycleState());
+        assertEquals(Lifecycle.RUNNING, runtime.getLifecycleState());
         runtime.stop();
 
-        assertEquals(Context.STOPPED, runtime.getLifecycleState());
+        assertEquals(Lifecycle.STOPPED, runtime.getLifecycleState());
 
         runtime.start();
-        assertEquals(Context.RUNNING, runtime.getLifecycleState());
+        assertEquals(Lifecycle.RUNNING, runtime.getLifecycleState());
     }
 
     public void testIncrementalBoot() throws Exception{
@@ -81,7 +81,7 @@
 
         system.publish(new ModuleStop(this));
         runtimeContext.stop();
-        Assert.assertEquals(Context.STOPPED,system.getLifecycleState());
+        Assert.assertEquals(Lifecycle.STOPPED,system.getLifecycleState());
     }
 
     protected void setUp() throws Exception {

Modified: 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/runtime/RuntimeContextImplTestCase.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/runtime/RuntimeContextImplTestCase.java?rev=396511&r1=396510&r2=396511&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/runtime/RuntimeContextImplTestCase.java
 (original)
+++ 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/runtime/RuntimeContextImplTestCase.java
 Mon Apr 24 03:56:40 2006
@@ -24,7 +24,7 @@
 import org.apache.tuscany.core.client.BootstrapHelper;
 import org.apache.tuscany.core.config.ConfigurationException;
 import org.apache.tuscany.core.context.CompositeContext;
-import org.apache.tuscany.core.context.Context;
+import org.apache.tuscany.core.context.Lifecycle;
 import org.apache.tuscany.core.context.event.ModuleStart;
 import org.apache.tuscany.core.context.event.ModuleStop;
 import org.apache.tuscany.core.context.impl.CompositeContextImpl;
@@ -63,7 +63,7 @@
     public void testSystemExplicitWiring() throws Exception {
         CompositeContext root = runtime.getRootContext();
         Assert.assertNotNull(root);
-        Assert.assertTrue(root.getLifecycleState() == Context.RUNNING);
+        Assert.assertTrue(root.getLifecycleState() == Lifecycle.RUNNING);
 
         CompositeContext system = runtime.getSystemContext();
         Assert.assertNotNull(system);
@@ -108,7 +108,7 @@
     public void testSystemAutoWiring() throws Exception {
         CompositeContext root = runtime.getRootContext();
         Assert.assertNotNull(root);
-        Assert.assertTrue(root.getLifecycleState() == Context.RUNNING);
+        Assert.assertTrue(root.getLifecycleState() == Lifecycle.RUNNING);
 
         CompositeContext system = runtime.getSystemContext();
         Assert.assertNotNull(system);


Reply via email to