tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmar...@apache.org
Subject svn commit: r400265 - in /incubator/tuscany/sandbox/jboynes/sca: core2/src/main/java/org/apache/tuscany/core/context/ core2/src/main/java/org/apache/tuscany/core/context/scope/ core2/src/main/java/org/apache/tuscany/core/system/context/ core2/src/test/...
Date Sat, 06 May 2006 08:37:59 GMT
Author: jmarino
Date: Sat May  6 01:37:57 2006
New Revision: 400265

URL: http://svn.apache.org/viewcvs?rev=400265&view=rev
Log:
scope context optimizations to remove instance created notification

Added:
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/context/scope/DependencyLifecycleTestCase.java
Modified:
    incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/PojoAtomicContext.java
    incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/scope/HttpSessionScopeContext.java
    incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/scope/ModuleScopeContext.java
    incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/scope/RequestScopeContext.java
    incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/system/context/SystemAtomicContext.java
    incubator/tuscany/sandbox/jboynes/sca/model/src/main/java/org/apache/tuscany/model/Implementation.java

Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/PojoAtomicContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/PojoAtomicContext.java?rev=400265&r1=400264&r2=400265&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/PojoAtomicContext.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/PojoAtomicContext.java
Sat May  6 01:37:57 2006
@@ -2,7 +2,6 @@
 
 import org.apache.tuscany.common.ObjectCreationException;
 import org.apache.tuscany.common.ObjectFactory;
-import org.apache.tuscany.core.context.event.InstanceCreated;
 import org.apache.tuscany.core.injection.EventInvoker;
 import org.apache.tuscany.model.Scope;
 import org.apache.tuscany.spi.context.AtomicContext;
@@ -77,7 +76,6 @@
     public InstanceContext createInstance() throws ObjectCreationException {
         InstanceContext ctx = new PojoInstanceContext(this, objectFactory.getInstance());
         ctx.start();
-        publish(new InstanceCreated(this, ctx));
         return ctx;
     }
 

Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/scope/HttpSessionScopeContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/scope/HttpSessionScopeContext.java?rev=400265&r1=400264&r2=400265&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/scope/HttpSessionScopeContext.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/scope/HttpSessionScopeContext.java
Sat May  6 01:37:57 2006
@@ -6,7 +6,6 @@
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.tuscany.core.context.event.HttpSessionEnd;
-import org.apache.tuscany.core.context.event.InstanceCreated;
 import org.apache.tuscany.model.Scope;
 import org.apache.tuscany.spi.context.AtomicContext;
 import org.apache.tuscany.spi.context.InstanceContext;
@@ -40,19 +39,7 @@
         checkInit();
         if (event instanceof HttpSessionEnd) {
             checkInit();
-            shutdownInstances(((HttpSessionEnd)event).getId());
-        } else if (event instanceof InstanceCreated) {
-            checkInit();
-            InstanceContext context = ((InstanceCreated) event).getContext();
-            Object key = workContext.getIdentifier(HTTP_IDENTIFIER);
-            List<InstanceContext> destroyQueue = destroyQueues.get(key);
-            if (destroyQueue == null) {
-                destroyQueue = new ArrayList<InstanceContext>();
-                destroyQueues.put(key, destroyQueue);
-            }
-            synchronized (destroyQueue) {
-                destroyQueue.add(context);
-            }
+            shutdownInstances(((HttpSessionEnd) event).getId());
         }
     }
 
@@ -81,6 +68,14 @@
         if (ctx == null) {
             ctx = context.createInstance();
             contextMap.put(key, ctx);
+            List<InstanceContext> destroyQueue = destroyQueues.get(key);
+            if (destroyQueue == null) {
+                destroyQueue = new ArrayList<InstanceContext>();
+                destroyQueues.put(key, destroyQueue);
+            }
+            synchronized (destroyQueue) {
+                destroyQueue.add(ctx);
+            }
         }
         return ctx;
     }

Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/scope/ModuleScopeContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/scope/ModuleScopeContext.java?rev=400265&r1=400264&r2=400265&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/scope/ModuleScopeContext.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/scope/ModuleScopeContext.java
Sat May  6 01:37:57 2006
@@ -7,7 +7,6 @@
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.tuscany.core.AbstractLifecycle;
-import org.apache.tuscany.core.context.event.InstanceCreated;
 import org.apache.tuscany.core.context.event.ModuleStart;
 import org.apache.tuscany.core.context.event.ModuleStop;
 import org.apache.tuscany.model.Scope;
@@ -48,12 +47,6 @@
             eagerInitContexts();
         } else if (event instanceof ModuleStop) {
             shutdownContexts();
-        } else if (event instanceof InstanceCreated) {
-            checkInit();
-            synchronized (destroyQueue) {
-                // Queue the context to have its implementation instance released if destroyable
-                destroyQueue.add(((InstanceCreated) event).getContext());
-            }
         }
     }
 
@@ -95,7 +88,6 @@
     public void register(AtomicContext context) {
         checkInit();
         instanceContexts.put(context, EMPTY);
-        context.addListener(this);
     }
 
 
@@ -105,6 +97,9 @@
         if (ctx == EMPTY) {
             ctx = context.createInstance();
             instanceContexts.put(context, ctx);
+            synchronized (destroyQueue) {
+                destroyQueue.add(ctx);
+            }
         }
         return ctx;
     }

Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/scope/RequestScopeContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/scope/RequestScopeContext.java?rev=400265&r1=400264&r2=400265&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/scope/RequestScopeContext.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/scope/RequestScopeContext.java
Sat May  6 01:37:57 2006
@@ -5,7 +5,6 @@
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
-import org.apache.tuscany.core.context.event.InstanceCreated;
 import org.apache.tuscany.core.context.event.RequestEnd;
 import org.apache.tuscany.model.Scope;
 import org.apache.tuscany.spi.context.AtomicContext;
@@ -40,17 +39,6 @@
         if (event instanceof RequestEnd) {
             checkInit();
             shutdownInstances(Thread.currentThread());
-        } else if (event instanceof InstanceCreated) {
-            checkInit();
-            InstanceContext context = ((InstanceCreated) event).getContext();
-            List<InstanceContext> destroyQueue = destroyQueues.get(Thread.currentThread());
-            if (destroyQueue == null) {
-                destroyQueue = new ArrayList<InstanceContext>();
-                destroyQueues.put(Thread.currentThread(), destroyQueue);
-            }
-            synchronized (destroyQueue) {
-                destroyQueue.add(context);
-            }
         }
     }
 
@@ -68,7 +56,6 @@
 
     public void register(AtomicContext context) {
         contexts.put(context, new ConcurrentHashMap<Thread, InstanceContext>());
-        context.addListener(this);
     }
 
     public InstanceContext getInstanceContext(AtomicContext context) throws TargetException
{
@@ -77,6 +64,14 @@
         if (ctx == null) {
             ctx = context.createInstance();
             instanceContextMap.put(Thread.currentThread(), ctx);
+            List<InstanceContext> destroyQueue = destroyQueues.get(Thread.currentThread());
+            if (destroyQueue == null) {
+                destroyQueue = new ArrayList<InstanceContext>();
+                destroyQueues.put(Thread.currentThread(), destroyQueue);
+            }
+            synchronized (destroyQueue) {
+                destroyQueue.add(ctx);
+            }
         }
         return ctx;
     }

Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/system/context/SystemAtomicContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/system/context/SystemAtomicContext.java?rev=400265&r1=400264&r2=400265&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/system/context/SystemAtomicContext.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/system/context/SystemAtomicContext.java
Sat May  6 01:37:57 2006
@@ -7,7 +7,6 @@
 import org.apache.tuscany.common.ObjectFactory;
 import org.apache.tuscany.core.context.PojoAtomicContext;
 import org.apache.tuscany.core.context.PojoInstanceContext;
-import org.apache.tuscany.core.context.event.InstanceCreated;
 import org.apache.tuscany.core.injection.EventInvoker;
 import org.apache.tuscany.spi.QualifiedName;
 import org.apache.tuscany.spi.context.InstanceContext;
@@ -33,7 +32,6 @@
     public InstanceContext createInstance() throws ObjectCreationException {
         InstanceContext ctx = new PojoInstanceContext(this, objectFactory.getInstance());
         ctx.start();
-        publish(new InstanceCreated(this, ctx));
         return ctx;
     }
 

Added: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/context/scope/DependencyLifecycleTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/context/scope/DependencyLifecycleTestCase.java?rev=400265&view=auto
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/context/scope/DependencyLifecycleTestCase.java
(added)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/context/scope/DependencyLifecycleTestCase.java
Sat May  6 01:37:57 2006
@@ -0,0 +1,70 @@
+package org.apache.tuscany.core.context.scope;
+
+import junit.framework.TestCase;
+import junit.framework.Assert;
+import org.apache.tuscany.core.context.event.ModuleStart;
+import org.apache.tuscany.core.context.event.ModuleStop;
+import org.apache.tuscany.core.context.event.HttpSessionEvent;
+import org.apache.tuscany.core.context.event.HttpSessionEnd;
+import org.apache.tuscany.core.context.event.RequestStart;
+import org.apache.tuscany.core.context.event.RequestEnd;
+
+/**
+ * Tests that dependencies are initalized and destroyed in the proper order (i.e. LIFO)
+ *
+ * @version $Rev: 393992 $ $Date: 2006-04-13 18:01:05 -0700 (Thu, 13 Apr 2006) $
+ */
+public class DependencyLifecycleTestCase extends TestCase {
+
+
+
+    public void testInitDestroyOrderModuleScope() throws Exception {
+//        WorkContext ctx = new WorkContextImpl();
+//        ModuleScopeContext scope = new ModuleScopeContext(ctx);
+//        scope.registerFactories(MockContextFactory.createWiredContexts(Scope.MODULE,scope));
+//        scope.start();
+//        scope.onEvent(new ModuleStart(this));
+//        OrderedDependentPojo source = (OrderedDependentPojo) scope.getContext("source").getInstance(null);
+//        assertNotNull(source.getPojo());
+//        // expire module
+//        Assert.assertEquals(2,source.getNumberInstantiated());
+//        scope.onEvent(new ModuleStop(this));
+//        Assert.assertEquals(0,source.getNumberInstantiated());
+//        scope.stop();
+    }
+
+//    public void testInitDestroyOrderSessionScope() throws Exception {
+//        WorkContext ctx = new WorkContextImpl();
+//        SessionScopeContext scope = new SessionScopeContext(ctx);
+//        scope.registerFactories(MockContextFactory.createWiredContexts(Scope.SESSION,scope));
+//        scope.start();
+//        Object session =  new Object();
+//        ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER,session);
+//        scope.onEvent(new HttpSessionBound(this,session));
+//        OrderedDependentPojo source = (OrderedDependentPojo) scope.getContext("source").getInstance(null);
+//        assertNotNull(source.getPojo());
+//        // expire module
+//        Assert.assertEquals(2,source.getNumberInstantiated());
+//        scope.onEvent(new HttpSessionEnd(this,session));
+//        Assert.assertEquals(0,source.getNumberInstantiated());
+//        scope.stop();
+//    }
+//
+//
+//    public void testInitDestroyOrderRequestScope() throws Exception {
+//        WorkContext ctx = new WorkContextImpl();
+//        RequestScopeContext scope = new RequestScopeContext(ctx);
+//        scope.registerFactories(MockContextFactory.createWiredContexts(Scope.REQUEST,scope));
+//        scope.start();
+//        Object request =  new Object();
+//        scope.onEvent(new RequestStart(this,request));
+//        OrderedDependentPojo source = (OrderedDependentPojo) scope.getContext("source").getInstance(null);
+//        assertNotNull(source.getPojo());
+//        // expire module
+//        Assert.assertEquals(2,source.getNumberInstantiated());
+//        scope.onEvent(new RequestEnd(this,request));
+//        Assert.assertEquals(0,source.getNumberInstantiated());
+//        scope.stop();
+//    }
+
+}

Modified: incubator/tuscany/sandbox/jboynes/sca/model/src/main/java/org/apache/tuscany/model/Implementation.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/model/src/main/java/org/apache/tuscany/model/Implementation.java?rev=400265&r1=400264&r2=400265&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/model/src/main/java/org/apache/tuscany/model/Implementation.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/model/src/main/java/org/apache/tuscany/model/Implementation.java
Sat May  6 01:37:57 2006
@@ -16,6 +16,9 @@
  */
 package org.apache.tuscany.model;
 
+import java.lang.reflect.Type;
+import java.lang.reflect.ParameterizedType;
+
 /**
  * @version $Rev$ $Date$
  */
@@ -31,6 +34,15 @@
     }
 
     public Component<Implementation<T>> newComponent() {
-        return new Component(this);
+        return new Component<Implementation<T>>(this);
+    }
+
+    public Class<T> getComponentTypeClass(){
+        Type type = this.getClass().getGenericSuperclass();
+        if (type instanceof ParameterizedType) {
+            return (Class<T>) ((ParameterizedType) type).getActualTypeArguments()[0];
+
+        }
+        return null;
     }
 }



Mime
View raw message