tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmar...@apache.org
Subject svn commit: r392156 - in /incubator/tuscany/java/sca: containers/container.java/src/main/java/org/apache/tuscany/container/java/context/ containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/ containers/container.js/src/main/ja...
Date Fri, 07 Apr 2006 02:03:15 GMT
Author: jmarino
Date: Thu Apr  6 19:03:13 2006
New Revision: 392156

URL: http://svn.apache.org/viewcvs?rev=392156&view=rev
Log:
merge of listener types to RuntimeEventListener

Removed:
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/LifecycleEventListener.java
Modified:
    incubator/tuscany/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/context/JavaComponentContext.java
    incubator/tuscany/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockScopeContext.java
    incubator/tuscany/java/sca/containers/container.js/src/main/java/org/apache/tuscany/container/js/context/JavaScriptComponentContext.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/AbstractContext.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/AggregateContext.java
    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/EventContext.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractAggregateContext.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/HttpSessionScopeContext.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/StatelessScopeContext.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeContextImpl.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemAggregateContextImpl.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemComponentContext.java
    incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/MockScopeContext.java

Modified: incubator/tuscany/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/context/JavaComponentContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/context/JavaComponentContext.java?rev=392156&r1=392155&r2=392156&view=diff
==============================================================================
--- incubator/tuscany/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/context/JavaComponentContext.java
(original)
+++ incubator/tuscany/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/context/JavaComponentContext.java
Thu Apr  6 19:03:13 2006
@@ -96,11 +96,11 @@
                 Object instance = objectFactory.getInstance();
                 startInstance(instance);
                 if (notify) {
-                    for (LifecycleEventListener aContextListener : contextListener) {
-                        aContextListener.onInstanceCreate(this);
+                    for (RuntimeEventListener listener : listeners) {
+                        listener.onEvent(EventContext.CONTEXT_CREATED,this);
                     }
                 }
-                setLifecycleState(RUNNING);
+                lifecycleState = RUNNING;
                 if (stateless) {
                     return instance;
                 } else {
@@ -109,7 +109,7 @@
                     return cachedTargetInstance;
                 }
             } catch (ObjectCreationException e) {
-                setLifecycleState(Context.ERROR);
+                lifecycleState = ERROR;
                 TargetException te = new TargetException("Error creating instance for component",
e);
                 te.setIdentifier(getName());
                 throw te;
@@ -136,16 +136,16 @@
             throw new IllegalStateException("Context must be in UNINITIALIZED state [" +
getLifecycleState() + "]");
         }
         if (objectFactory == null) {
-            setLifecycleState(ERROR);
+            lifecycleState = ERROR;
             ContextInitException e = new ContextInitException("Object factory not found");
             e.setIdentifier(getName());
             throw e;
         }
-        setLifecycleState(INITIALIZED);
+        lifecycleState = INITIALIZED;
     }
 
     public void stop() {
-        setLifecycleState(STOPPING);
+        lifecycleState = STOPPING;
         if (cachedTargetInstance != null) {
             if (destroyInvoker != null) {
                 try {
@@ -157,7 +157,7 @@
                 }
             }
         }
-        setLifecycleState(STOPPED);
+        lifecycleState = STOPPED;
     }
 
     private void startInstance(Object instance) throws TargetException {

Modified: incubator/tuscany/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockScopeContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockScopeContext.java?rev=392156&r1=392155&r2=392156&view=diff
==============================================================================
--- incubator/tuscany/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockScopeContext.java
(original)
+++ incubator/tuscany/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockScopeContext.java
Thu Apr  6 19:03:13 2006
@@ -16,22 +16,15 @@
  */
 package org.apache.tuscany.container.java.mock;
 
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
 import org.apache.tuscany.container.java.invocation.mock.SimpleTargetImpl;
 import org.apache.tuscany.core.builder.ContextFactory;
-import org.apache.tuscany.core.context.InstanceContext;
-import org.apache.tuscany.core.context.EventException;
-import org.apache.tuscany.core.context.QualifiedName;
-import org.apache.tuscany.core.context.LifecycleEventListener;
-import org.apache.tuscany.core.context.ScopeContext;
-import org.apache.tuscany.core.context.ScopeRuntimeException;
-import org.apache.tuscany.core.context.SimpleComponentContext;
-import org.apache.tuscany.core.context.TargetException;
+import org.apache.tuscany.core.context.*;
 import org.apache.tuscany.model.assembly.SimpleComponent;
 
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 public class MockScopeContext implements ScopeContext {
 
     Map<String, Object> components;
@@ -53,6 +46,12 @@
     public void stop() {
     }
 
+    public void addListener(RuntimeEventListener listener) throws ContextRuntimeException
{
+    }
+
+    public void removeListener(RuntimeEventListener listener) throws ContextRuntimeException
{
+    }
+
     public String getName() {
         return "Mock Scope Container";
     }
@@ -110,14 +109,6 @@
 
 
     public void setName(String name) {
-    }
-
-
-    public void addContextListener(LifecycleEventListener listener) {
-    }
-
-
-    public void removeContextListener(LifecycleEventListener listener) {
     }
 
 

Modified: incubator/tuscany/java/sca/containers/container.js/src/main/java/org/apache/tuscany/container/js/context/JavaScriptComponentContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/containers/container.js/src/main/java/org/apache/tuscany/container/js/context/JavaScriptComponentContext.java?rev=392156&r1=392155&r2=392156&view=diff
==============================================================================
--- incubator/tuscany/java/sca/containers/container.js/src/main/java/org/apache/tuscany/container/js/context/JavaScriptComponentContext.java
(original)
+++ incubator/tuscany/java/sca/containers/container.js/src/main/java/org/apache/tuscany/container/js/context/JavaScriptComponentContext.java
Thu Apr  6 19:03:13 2006
@@ -16,22 +16,16 @@
  */
 package org.apache.tuscany.container.js.context;
 
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
 import org.apache.tuscany.container.js.rhino.RhinoScript;
-import org.apache.tuscany.core.context.AbstractContext;
-import org.apache.tuscany.core.context.CoreRuntimeException;
-import org.apache.tuscany.core.context.LifecycleEventListener;
-import org.apache.tuscany.core.context.QualifiedName;
-import org.apache.tuscany.core.context.SimpleComponentContext;
-import org.apache.tuscany.core.context.TargetException;
+import org.apache.tuscany.core.context.*;
 import org.apache.tuscany.core.invocation.spi.ProxyCreationException;
 import org.apache.tuscany.core.invocation.spi.ProxyFactory;
 import org.osoa.sca.ServiceRuntimeException;
 
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 public class JavaScriptComponentContext extends AbstractContext implements SimpleComponentContext
{
 
     private Map<String, Class> services;
@@ -103,9 +97,8 @@
 
     private void notifyListeners(boolean notify) {
         if (notify) {
-            for (Iterator iter = contextListener.iterator(); iter.hasNext();) {
-                LifecycleEventListener listener = (LifecycleEventListener) iter.next();
-                listener.onInstanceCreate(this);
+            for (RuntimeEventListener listener : listeners) {
+                listener.onEvent(EventContext.CONTEXT_CREATED,this);
             }
         }
     }

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/AbstractContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/AbstractContext.java?rev=392156&r1=392155&r2=392156&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/AbstractContext.java
(original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/AbstractContext.java
Thu Apr  6 19:03:13 2006
@@ -49,18 +49,17 @@
         return lifecycleState;
     }
 
-    public void setLifecycleState(int state) {
-        lifecycleState = state;
-    }
-
-    protected List<LifecycleEventListener> contextListener = new CopyOnWriteArrayList<LifecycleEventListener>();
+    // Listeners for context events
+    protected List<RuntimeEventListener> listeners = new CopyOnWriteArrayList<RuntimeEventListener>();
 
-    public void addContextListener(LifecycleEventListener listener) {
-        contextListener.add(listener);
+    public void addListener(RuntimeEventListener listener) {
+        assert (listener != null) : "Listener cannot be null";
+        listeners.add(listener);
     }
 
-    public void removeContextListener(LifecycleEventListener listener) {
-        contextListener.remove(listener);
+    public void removeListener(RuntimeEventListener listener) {
+        assert (listener != null) : "Listener cannot be null";
+        listeners.remove(listener);
     }
 
     public String toString() {

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/AggregateContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/AggregateContext.java?rev=392156&r1=392155&r2=392156&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/AggregateContext.java
(original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/AggregateContext.java
Thu Apr  6 19:03:13 2006
@@ -23,7 +23,7 @@
      * Propagates an event to registered listeners. All lifecycle events will be propagated
to children in the order
      * that they were registered. Listeners are expected to be well-behaved and if an exception
is thrown the
      * notification process will be aborted.
-     * 
+     *
      * @param pEventType the type of event. Basic types are defined in {@link EventContext}
      * @param pMessage the message associated with the event or null
      * @throws EventException if an error occurs while sending the event
@@ -32,10 +32,10 @@
 
     /**
      * Registers a listener to receive notifications for the context
-     * 
+     *
      * @throws ContextRuntimeException if an error occurs during registration
      */
-    public void registerListener(RuntimeEventListener listener) throws ContextRuntimeException;
+    public void addListener(RuntimeEventListener listener) throws ContextRuntimeException;
 
     /**
      * Adds runtime artifacts represented by the set of model objects to the aggregate context
by merging them with

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=392156&r1=392155&r2=392156&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
Thu Apr  6 19:03:13 2006
@@ -56,7 +56,7 @@
 
     /**
      * Returns the lifecycle state
-     * 
+     *
      * @see #UNINITIALIZED
      * @see #INITIALIZING
      * @see #INITIALIZED
@@ -68,27 +68,27 @@
 
     /**
      * Starts the container
-     * 
+     *
      * @throws CoreRuntimeException
      */
     public void start() throws CoreRuntimeException;
 
     /**
      * Stops the container
-     * 
+     *
      * @throws CoreRuntimeException
      */
     public void stop() throws CoreRuntimeException;
 
     /**
-     * Registers a listener for context events
+     * Registers a listener to receive notifications for the context
+     *
+     * @throws ContextRuntimeException if an error occurs during registration
      */
-    public void addContextListener(LifecycleEventListener listener);
+    public void addListener(RuntimeEventListener listener) throws ContextRuntimeException;
+
+    public void removeListener(RuntimeEventListener listener) throws ContextRuntimeException;
 
-    /**
-     * Deregisters a context event listener
-     */
-    public void removeContextListener(LifecycleEventListener listener);
 
 }
 

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/EventContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/EventContext.java?rev=392156&r1=392155&r2=392156&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/EventContext.java
(original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/EventContext.java
Thu Apr  6 19:03:13 2006
@@ -45,6 +45,8 @@
     
     public static final int SYSTEM_STOP = 8;
 
+    public static final int CONTEXT_CREATED = 9;
+
     /* An identifier type associated with an HTTP session */
     public static final Object HTTP_SESSION = new Object();
 

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractAggregateContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractAggregateContext.java?rev=392156&r1=392155&r2=392156&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractAggregateContext.java
(original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractAggregateContext.java
Thu Apr  6 19:03:13 2006
@@ -19,7 +19,6 @@
 import javax.wsdl.Part;
 import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
@@ -65,9 +64,6 @@
     // A component context name to scope context index
     protected Map<String, ScopeContext> scopeIndex;
 
-    // Listeners for context events
-    protected List<RuntimeEventListener> listeners = new CopyOnWriteArrayList<RuntimeEventListener>();
-
     // Blocking latch to ensure the module is initialized exactly once prior to servicing
requests
     protected CountDownLatch initializeLatch = new CountDownLatch(1);
 
@@ -137,7 +133,7 @@
                 initializeProxies();
                 for (ScopeContext scope : scopeContexts.values()) {
                     // register scope contexts as a listeners for events in the aggregate
context
-                    registerListener(scope);
+                    addListener(scope);
                     scope.start();
                 }
                 lifecycleState = RUNNING;
@@ -413,11 +409,6 @@
             configurations.put(configuration.getName(), configuration);
         }
 
-    }
-
-    public void registerListener(RuntimeEventListener listener) {
-        assert (listener != null) : "Listener cannot be null";
-        listeners.add(listener);
     }
 
     public void fireEvent(int eventType, Object message) throws EventException {

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/HttpSessionScopeContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/HttpSessionScopeContext.java?rev=392156&r1=392155&r2=392156&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/HttpSessionScopeContext.java
(original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/HttpSessionScopeContext.java
Thu Apr  6 19:03:13 2006
@@ -29,7 +29,7 @@
  * 
  * @version $Rev$ $Date$
  */
-public class HttpSessionScopeContext extends AbstractScopeContext implements RuntimeEventListener,
LifecycleEventListener {
+public class HttpSessionScopeContext extends AbstractScopeContext implements RuntimeEventListener
{
 
     // The collection of service component contexts keyed by session
     private Map<Object, Map<String, InstanceContext>> contexts;
@@ -37,10 +37,6 @@
     // Stores ordered lists of contexts to shutdown keyed by session
     private Map<Object, Queue<SimpleComponentContext>> destroyableContexts;
 
-    // ----------------------------------
-    // Constructors
-    // ----------------------------------
-
     public HttpSessionScopeContext(EventContext eventContext) {
         super(eventContext);
         setName("Http Session Scope");
@@ -68,13 +64,32 @@
     }
 
     public void onEvent(int type, Object key) {
-        checkInit();
         if (key == null) {
             return;
         }
-        if (type == EventContext.SESSION_END) {
-            notifyInstanceShutdown(key);
-            destroyComponentContext(key);
+        switch(type){
+            case EventContext.SESSION_END:
+                checkInit();
+                notifyInstanceShutdown(key);
+                destroyComponentContext(key);
+                break;
+            case EventContext.CONTEXT_CREATED:
+                checkInit();
+                if (key instanceof SimpleComponentContext) {
+                     SimpleComponentContext simpleCtx = (SimpleComponentContext)key;
+                     // if destroyable, queue the context to have its component implementation
instance released
+                     if (simpleCtx.isDestroyable()) {
+                         Object sessionKey = getEventContext().getIdentifier(EventContext.HTTP_SESSION);
+                         Queue<SimpleComponentContext> comps = destroyableContexts.get(sessionKey);
+                         if (comps == null) {
+                             ScopeRuntimeException e = new ScopeRuntimeException("Shutdown
queue not found for key");
+                             e.setIdentifier(sessionKey.toString());
+                             throw e;
+                         }
+                         comps.add(simpleCtx);
+                     }
+                }
+                break;
         }
     }
 
@@ -102,7 +117,7 @@
             ContextFactory<InstanceContext> configuration = contextFactorys.get(ctxName);
             if (configuration != null) {
                 ctx = configuration.createContext();
-                ctx.addContextListener(this);
+                ctx.addListener(this);
                 ctx.start();
                 ctxs.put(ctx.getName(), ctx);
             }
@@ -146,23 +161,6 @@
         definitions.remove(ctxName);
     }
 
-    public void onInstanceCreate(Context context) throws ScopeRuntimeException {
-        checkInit();
-        if (context instanceof SimpleComponentContext) {
-            SimpleComponentContext simpleCtx = (SimpleComponentContext)context;
-            // if destroyable, queue the context to have its component implementation instance
released
-            if (simpleCtx.isDestroyable()) {
-                Object key = getEventContext().getIdentifier(EventContext.HTTP_SESSION);
-                Queue<SimpleComponentContext> comps = destroyableContexts.get(key);
-                if (comps == null) {
-                    ScopeRuntimeException e = new ScopeRuntimeException("Shutdown queue not
found for key");
-                    e.setIdentifier(key.toString());
-                    throw e;
-                }
-                comps.add(simpleCtx);
-            }
-        }
-    }
 
     /**
      * Returns an array of {@link SimpleComponentContext}s representing components that need
to be notified of scope shutdown or
@@ -201,7 +199,7 @@
         Map<String, InstanceContext> sessionContext = new ConcurrentHashMap<String,
InstanceContext>(contextFactorys.size());
         for (ContextFactory<InstanceContext> config : contextFactorys.values()) {
             InstanceContext context = config.createContext();
-            context.addContextListener(this);
+            context.addListener(this);
             context.start();
             sessionContext.put(context.getName(), context);
         }

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=392156&r1=392155&r2=392156&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
Thu Apr  6 19:03:13 2006
@@ -29,7 +29,7 @@
  * 
  * @version $Rev$ $Date$
  */
-public class ModuleScopeContext extends AbstractScopeContext implements RuntimeEventListener,
LifecycleEventListener {
+public class ModuleScopeContext extends AbstractScopeContext implements RuntimeEventListener
{
 
     // Component contexts in this scope keyed by name
     private Map<String, InstanceContext> componentContexts;
@@ -42,11 +42,24 @@
     }
 
      public void onEvent(int type, Object key) {
-        if (type == EventContext.MODULE_START) {
-            lifecycleState = RUNNING;
-            initComponentContexts();
-        } else if (type == EventContext.MODULE_STOP) {
-            notifyInstanceShutdown(key);
+         switch(type){
+             case EventContext.MODULE_START:
+                lifecycleState = RUNNING;
+                initComponentContexts();
+                break;
+            case EventContext.MODULE_STOP:
+                notifyInstanceShutdown(key);
+                break;
+            case EventContext.CONTEXT_CREATED:
+                checkInit();
+                if (key instanceof SimpleComponentContext) {
+                    SimpleComponentContext serviceContext = (SimpleComponentContext) key;
+                    // Queue the context to have its implementation instance released if
destroyable
+                    if (serviceContext.isDestroyable()) {
+                        destroyableContexts.add(serviceContext);
+                    }
+                }
+                break;
         }
     }
 
@@ -100,17 +113,6 @@
         removeContext(ctxName);
     }
 
-    public void onInstanceCreate(Context context) {
-        checkInit();
-        if (context instanceof SimpleComponentContext) {
-            SimpleComponentContext serviceContext = (SimpleComponentContext) context;
-            // Queue the context to have its implementation instance released if destroyable
-            if (serviceContext.isDestroyable()) {
-                destroyableContexts.add(serviceContext);
-            }
-        }
-    }
-
     /**
      * Returns an array of {@link SimpleComponentContext}s representing components that need
to be notified of scope shutdown.
      */
@@ -129,7 +131,7 @@
             destroyableContexts = new ConcurrentLinkedQueue<SimpleComponentContext>();
             for (ContextFactory<InstanceContext> config : contextFactorys.values())
{
                 InstanceContext context = config.createContext();
-                context.addContextListener(this);
+                context.addListener(this);
                 context.start();
                 componentContexts.put(context.getName(), context);
             }

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=392156&r1=392155&r2=392156&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
Thu Apr  6 19:03:13 2006
@@ -29,7 +29,7 @@
  * 
  * @version $Rev$ $Date$
  */
-public class RequestScopeContext extends AbstractScopeContext implements RuntimeEventListener,
LifecycleEventListener {
+public class RequestScopeContext extends AbstractScopeContext implements RuntimeEventListener
{
 
     // A collection of service component contexts keyed by thread. Note this could have been
implemented with a ThreadLocal but
     // using a Map allows finer-grained concurrency.
@@ -44,12 +44,27 @@
     }
 
     public void onEvent(int type, Object key) {
-        checkInit();
         /* clean up current context for pooled threads */
-        if (type == EventContext.REQUEST_END) {
-            getEventContext().clearIdentifier(EventContext.HTTP_SESSION);
-            notifyInstanceShutdown(Thread.currentThread());
-            destroyContext();
+        switch(type){
+            case EventContext.REQUEST_END:
+                checkInit();
+                getEventContext().clearIdentifier(EventContext.HTTP_SESSION);
+                notifyInstanceShutdown(Thread.currentThread());
+                destroyContext();
+                break;
+            case EventContext.CONTEXT_CREATED:
+                checkInit();
+                assert(key instanceof Context): "Context must be passed on created event";
+                Context context = (Context)key;
+                if (context instanceof SimpleComponentContext) {
+                    SimpleComponentContext simpleCtx = (SimpleComponentContext)context;
+                    // Queue the context to have its implementation instance released if
destroyable
+                    if (simpleCtx.isDestroyable()) {
+                        Queue<SimpleComponentContext> collection = destroyComponents.get(Thread.currentThread());
+                        collection.add(simpleCtx);
+                    }
+                }
+                break;
         }
     }
 
@@ -95,7 +110,7 @@
             ContextFactory<InstanceContext> configuration = contextFactorys.get(ctxName);
             if (configuration != null) {
                 ctx = configuration.createContext();
-                ctx.addContextListener(this);
+                ctx.addListener(this);
                 ctx.start();
                 contexts.put(ctx.getName(), ctx);
             }
@@ -137,17 +152,6 @@
         destroyComponents.get(key).remove(context);
     }
 
-    public void onInstanceCreate(Context context) {
-        checkInit();
-        if (context instanceof SimpleComponentContext) {
-            SimpleComponentContext simpleCtx = (SimpleComponentContext)context;
-            // Queue the context to have its implementation instance released if destroyable
-            if (simpleCtx.isDestroyable()) {
-                Queue<SimpleComponentContext> collection = destroyComponents.get(Thread.currentThread());
-                collection.add(simpleCtx);
-            }
-        }
-    }
 
     /**
      * Returns an array of {@link SimpleComponentContext}s representing components that need
to be notified of scope shutdown.
@@ -185,7 +189,7 @@
             Queue<SimpleComponentContext> shutdownQueue = new ConcurrentLinkedQueue<SimpleComponentContext>();
             for (ContextFactory<InstanceContext> config : contextFactorys.values())
{
                 InstanceContext context = config.createContext();
-                context.addContextListener(this);
+                context.addListener(this);
                 context.start();
                 contexts.put(context.getName(), context);
             }

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=392156&r1=392155&r2=392156&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
Thu Apr  6 19:03:13 2006
@@ -27,7 +27,7 @@
  * 
  * @version $Rev$ $Date$
  */
-public class StatelessScopeContext extends AbstractScopeContext implements RuntimeEventListener,
LifecycleEventListener {
+public class StatelessScopeContext extends AbstractScopeContext implements RuntimeEventListener
{
 
    // Component contexts keyed by name
     private Map<String, InstanceContext> contextMap;
@@ -94,10 +94,6 @@
         return null;
     }
 
-    public void onInstanceCreate(Context component) {
-        // do nothing
-    }
-
     private void prepare() throws CoreRuntimeException {
         if (lifecycleState != RUNNING) {
             throw new IllegalStateException("Scope not in INITIALIZED state [" + lifecycleState
+ "]");
@@ -107,7 +103,7 @@
             for (ContextFactory<InstanceContext> config : contextFactorys.values())
{
                 for (int i = 0; i < contextFactorys.size(); i++) {
                     InstanceContext context = config.createContext();
-                    context.addContextListener(this);
+                    context.addListener(this);
                     context.start();
                     contextMap.put(context.getName(), context);
                 }

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeContextImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeContextImpl.java?rev=392156&r1=392155&r2=392156&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeContextImpl.java
(original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeContextImpl.java
Thu Apr  6 19:03:13 2006
@@ -169,7 +169,7 @@
         }
     }
 
-    public void registerListener(RuntimeEventListener listener) {
+    public void addListener(RuntimeEventListener listener) {
         assert (listener != null) : "Listener cannot be null";
         listeners.add(listener);
     }

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemAggregateContextImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemAggregateContextImpl.java?rev=392156&r1=392155&r2=392156&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemAggregateContextImpl.java
(original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemAggregateContextImpl.java
Thu Apr  6 19:03:13 2006
@@ -191,7 +191,7 @@
                 }
                 for (ScopeContext scope : scopeContexts.values()) {
                     // register scope contexts as a listeners for events in the aggregate
context
-                    registerListener(scope);
+                    addListener(scope);
                     scope.start();
                 }
                 lifecycleState = RUNNING;
@@ -238,10 +238,6 @@
         this.module = module;
     }
 
-    public void addContextListener(LifecycleEventListener listener) {
-        super.addContextListener(listener);
-    }
-
     public void setEventContext(EventContext eventContext) {
         this.eventContext = eventContext;
     }
@@ -398,7 +394,7 @@
 
     }
 
-    public void registerListener(RuntimeEventListener listener) {
+    public void addListener(RuntimeEventListener listener) {
         assert (listener != null) : "Listener cannot be null";
         listeners.add(listener);
     }

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemComponentContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemComponentContext.java?rev=392156&r1=392155&r2=392156&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemComponentContext.java
(original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemComponentContext.java
Thu Apr  6 19:03:13 2006
@@ -101,11 +101,11 @@
                 Object instance = objectFactory.getInstance();
                 startInstance(instance);
                 if (notify) {
-                    for (LifecycleEventListener aContextListener : contextListener) {
-                        aContextListener.onInstanceCreate(this);
+                    for (RuntimeEventListener listener : listeners) {
+                        listener.onEvent(EventContext.CONTEXT_CREATED,this);
                     }
                 }
-                setLifecycleState(RUNNING);
+                lifecycleState = RUNNING;
                 if (stateless) {
                     return instance;
                 } else {
@@ -114,7 +114,7 @@
                     return cachedTargetInstance;
                 }
             } catch (ObjectCreationException e) {
-                setLifecycleState(Context.ERROR);
+                lifecycleState = Context.ERROR;
                 TargetException te = new TargetException("Error creating instance for component",
e);
                 te.setIdentifier(getName());
                 throw te;
@@ -144,12 +144,12 @@
             throw new IllegalStateException("Component must be in UNINITIALIZED state ["
+ getLifecycleState() + "]");
         }
         if (objectFactory == null) {
-            setLifecycleState(ERROR);
+            lifecycleState = ERROR;
             ContextInitException e = new ContextInitException("Object factory not found ");
             e.setIdentifier(getName());
             throw e;
         }
-        setLifecycleState(INITIALIZED);
+        lifecycleState = INITIALIZED;
     }
 
     public void stop() {
@@ -162,7 +162,7 @@
                 }
             }
         }
-        setLifecycleState(STOPPED);
+        lifecycleState = STOPPED;
     }
 
     // ----------------------------------

Modified: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/MockScopeContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/MockScopeContext.java?rev=392156&r1=392155&r2=392156&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/MockScopeContext.java
(original)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/MockScopeContext.java
Thu Apr  6 19:03:13 2006
@@ -45,6 +45,12 @@
     public void stop() {
     }
 
+    public void addListener(RuntimeEventListener listener) throws ContextRuntimeException
{
+    }
+
+    public void removeListener(RuntimeEventListener listener) throws ContextRuntimeException
{
+    }
+
     public String getName() {
         return "Mock Scope Container";
     }
@@ -104,13 +110,6 @@
     public void setName(String name) {
     }
 
-
-    public void addContextListener(LifecycleEventListener listener) {
-    }
-
-
-    public void removeContextListener(LifecycleEventListener listener) {
-    }
 
 
 }



Mime
View raw message