Author: jmarino
Date: Thu May 4 14:37:54 2006
New Revision: 399863
URL: http://svn.apache.org/viewcvs?rev=399863&view=rev
Log:
more scope context refactors
Added:
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/context/scope/
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/context/scope/BasicModuleScopeTestCase.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/mock/context/MockCompositeContext.java
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/ScopeRegistry.java
Removed:
incubator/tuscany/sandbox/jboynes/sca/core/src/main/java/org/apache/tuscany/core/context/scope/ModuleScopeContext.java
Modified:
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/WorkContextImpl.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/context/scope/StatelessScopeContext.java
Modified:
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/WorkContextImpl.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/WorkContextImpl.java?rev=399863&r1=399862&r2=399863&view=diff
==============================================================================
---
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/WorkContextImpl.java
(original)
+++
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/WorkContextImpl.java
Thu May 4 14:37:54 2006
@@ -1,14 +1,14 @@
package org.apache.tuscany.core.context;
-import java.util.Map;
import java.util.HashMap;
+import java.util.Map;
-import org.apache.tuscany.spi.context.WorkContext;
import org.apache.tuscany.spi.context.CompositeContext;
+import org.apache.tuscany.spi.context.WorkContext;
/**
- * An implementation of an [EMAIL PROTECTED]
org.apache.tuscany.spi.context.WorkContext} that handles event-to-thread
associations using an
- * <code>InheritableThreadLocal</code>
+ * An implementation of an [EMAIL PROTECTED]
org.apache.tuscany.spi.context.WorkContext} that handles event-to-thread
+ * associations using an <code>InheritableThreadLocal</code>
*
* @version $Rev: 393567 $ $Date: 2006-04-12 11:28:58 -0700 (Wed, 12 Apr 2006)
$
*/
@@ -21,19 +21,28 @@
* a map ( associated with the current thread) of scope identifiers keyed
on the event context id type. the scope identifier
* may be a [EMAIL PROTECTED] ScopeIdentifier} or an opaque id
*/
- private ThreadLocal<Map<Object,Object>> eventContext = new
InheritableThreadLocal<Map<Object,Object>>();
+ private ThreadLocal<Map<Object, Object>> workContext = new
InheritableThreadLocal<Map<Object, Object>>();
public CompositeContext getCurrentModule() {
- return (CompositeContext)eventContext.get().get(CURRENT_MODULE);
+ Map<Object, Object> map = workContext.get();
+ if (map == null) {
+ return null;
+ }
+ return (CompositeContext) map.get(CURRENT_MODULE);
}
public void setCurrentModule(CompositeContext context) {
- eventContext.get().put(CURRENT_MODULE,context);
+ Map<Object, Object> map = workContext.get();
+ if (map == null) {
+ map = new HashMap<Object, Object>();
+ workContext.set(map);
+ }
+ map.put(CURRENT_MODULE, context);
}
public Object getIdentifier(Object type) {
- Map<Object,Object> map = eventContext.get();
+ Map<Object, Object> map = workContext.get();
if (map == null) {
return null;
}
@@ -47,10 +56,10 @@
}
public void setIdentifier(Object type, Object identifier) {
- Map<Object,Object> map = eventContext.get();
+ Map<Object, Object> map = workContext.get();
if (map == null) {
- map = new HashMap<Object,Object>();
- eventContext.set(map);
+ map = new HashMap<Object, Object>();
+ workContext.set(map);
}
map.put(type, identifier);
}
@@ -59,14 +68,14 @@
if (type == null) {
return;
}
- Map map = eventContext.get();
+ Map map = workContext.get();
if (map != null) {
map.remove(type);
}
}
public void clearIdentifiers() {
- eventContext.remove();
+ workContext.remove();
}
public WorkContextImpl() {
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=399863&r1=399862&r2=399863&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
Thu May 4 14:37:54 2006
@@ -40,12 +40,19 @@
checkInit();
if (event instanceof HttpSessionEnd) {
checkInit();
- shutdownInstances();
+ shutdownInstances(((HttpSessionEnd)event).getId());
} else if (event instanceof InstanceCreated) {
checkInit();
InstanceContext context = ((InstanceCreated) event).getContext();
- List<InstanceContext> destroyQueue =
destroyQueues.get(workContext.getIdentifier(HTTP_IDENTIFIER));
- destroyQueue.add(context);
+ 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);
+ }
}
}
@@ -62,28 +69,21 @@
public void register(AtomicContext context) {
contexts.put(context, new ConcurrentHashMap<Object,
InstanceContext>());
- Object key = workContext.getIdentifier(HTTP_IDENTIFIER);
- List<InstanceContext> destroyQueue = destroyQueues.get(key);
-
- if (destroyQueue == null) {
- destroyQueues.put(key, new ArrayList<InstanceContext>());
- }
context.addListener(this);
}
public InstanceContext getInstanceContext(AtomicContext context) throws
TargetException {
- Map<Object,InstanceContext> contextMap = contexts.get(context);
+ Map<Object, InstanceContext> contextMap = contexts.get(context);
InstanceContext ctx =
contextMap.get(workContext.getIdentifier(HTTP_IDENTIFIER));
- if(ctx == null){
+ if (ctx == null) {
ctx = context.createInstance();
- contextMap.put(context,ctx);
+ contextMap.put(context, ctx);
}
return ctx;
}
- private void shutdownInstances() {
- Object key = workContext.getIdentifier(HTTP_IDENTIFIER);
+ private void shutdownInstances(Object key) {
List<InstanceContext> destroyQueue = destroyQueues.get(key);
if (destroyQueue != null) {
for (InstanceContext ctx : destroyQueue) {
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=399863&r1=399862&r2=399863&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
Thu May 4 14:37:54 2006
@@ -6,44 +6,34 @@
import java.util.Map;
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;
import org.apache.tuscany.spi.CoreRuntimeException;
import org.apache.tuscany.spi.context.AtomicContext;
-import org.apache.tuscany.spi.context.CompositeContext;
-import org.apache.tuscany.spi.context.Context;
import org.apache.tuscany.spi.context.InstanceContext;
import org.apache.tuscany.spi.context.TargetException;
import org.apache.tuscany.spi.context.WorkContext;
import org.apache.tuscany.spi.event.Event;
/**
- * Manages instanceContexts whose implementations are module scoped. This
scope instanceContexts eagerly
- * starts instanceContexts when a [EMAIL PROTECTED]
org.apache.tuscany.core.context.event.ModuleStart} event is received.
- * If a contained context has an implementation marked to eagerly initialized,
the an instance will be created
- * at that time as well. Contained instanceContexts are shutdown when a [EMAIL
PROTECTED]
- * org.apache.tuscany.core.context.event.ModuleStop} event is received in
reverse order to which their
- * implementation instances were created.
+ * Manages instanceContexts whose implementations are module scoped
*
* @version $Rev: 399161 $ $Date: 2006-05-02 23:09:37 -0700 (Tue, 02 May 2006)
$
*/
public class ModuleScopeContext extends AbstractScopeContext<AtomicContext> {
- private Map<Context, InstanceContext> instanceContexts;
-
- // the queue of instanceContexts to destroy, in the order that their
instances were created
- private Map<CompositeContext, List<AtomicContext>> registeredContexts;
-
+ private final Map<AtomicContext, InstanceContext> instanceContexts;
// the queue of instanceContexts to destroy, in the order that their
instances were created
- private Map<CompositeContext, List<InstanceContext>> destroyQueues;
+ private final List<InstanceContext> destroyQueue;
+ private static final InstanceContext EMPTY = new EmptyContext();
public ModuleScopeContext(WorkContext workContext) {
super("Module Scope", workContext);
- instanceContexts = new ConcurrentHashMap<Context, InstanceContext>();
- registeredContexts = new ConcurrentHashMap<CompositeContext,
List<AtomicContext>>();
- destroyQueues = new ConcurrentHashMap<CompositeContext,
List<InstanceContext>>();
+ instanceContexts = new ConcurrentHashMap<AtomicContext,
InstanceContext>();
+ destroyQueue = new ArrayList<InstanceContext>();
}
public Scope getScope() {
@@ -55,14 +45,15 @@
checkInit();
if (event instanceof ModuleStart) {
lifecycleState = RUNNING;
- eagerInitContexts(((ModuleStart) event).getContext());
+ eagerInitContexts();
} else if (event instanceof ModuleStop) {
- shutdownContexts(((ModuleStop) event).getContext());
+ shutdownContexts();
} else if (event instanceof InstanceCreated) {
checkInit();
- // Queue the context to have its implementation instance released
if destroyable
- List<InstanceContext> destroyQueue =
destroyQueues.get(workContext.getCurrentModule());
- destroyQueue.add(((InstanceCreated) event).getContext());
+ synchronized (destroyQueue) {
+ // Queue the context to have its implementation instance
released if destroyable
+ destroyQueue.add(((InstanceCreated) event).getContext());
+ }
}
}
@@ -70,6 +61,7 @@
if (lifecycleState != UNINITIALIZED) {
throw new IllegalStateException("Scope must be in UNINITIALIZED
state [" + lifecycleState + "]");
}
+ lifecycleState = RUNNING;
}
public synchronized void stop() {
@@ -82,10 +74,9 @@
/**
* Notifies instanceContexts of a shutdown in reverse order to which they
were started
*/
- private void shutdownContexts(CompositeContext ctx) {
+ private void shutdownContexts() {
checkInit();
- List<InstanceContext> destroyQueue = destroyQueues.remove(ctx);
- if (destroyQueue == null || destroyQueue.size() == 0) {
+ if (destroyQueue.size() == 0) {
return;
}
synchronized (destroyQueue) {
@@ -97,38 +88,13 @@
context.stop();
}
}
- }
- }
-
- private void eagerInitContexts(CompositeContext module) throws
CoreRuntimeException {
- checkInit();
- assert(module != null): "Current module not set in work context";
- List<AtomicContext> contexts = registeredContexts.get(module);
- synchronized (contexts) {
- for (AtomicContext context : contexts) {
- if (context.isEagerInit()) {
- InstanceContext instanceCtx = context.createInstance();
- instanceContexts.put(context, instanceCtx);
- instanceCtx.start();
- }
- }
+ destroyQueue.clear();
}
}
public void register(AtomicContext context) {
checkInit();
- CompositeContext module = workContext.getCurrentModule();
- List<AtomicContext> atomicContexts = registeredContexts.get(module);
- List<InstanceContext> destroyQueue = destroyQueues.get(module);
- if (atomicContexts == null) {
- atomicContexts = registeredContexts.put(module, new
ArrayList<AtomicContext>());
- }
- if (destroyQueue == null) {
- destroyQueues.put(module, new ArrayList<InstanceContext>());
- }
- synchronized (atomicContexts) {
- atomicContexts.add(context);
- }
+ instanceContexts.put(context, EMPTY);
context.addListener(this);
}
@@ -136,12 +102,30 @@
public InstanceContext getInstanceContext(AtomicContext context) throws
TargetException {
checkInit();
InstanceContext ctx = instanceContexts.get(context);
- if (ctx == null) {
+ if (ctx == EMPTY) {
ctx = context.createInstance();
instanceContexts.put(context, ctx);
}
return ctx;
}
+ private void eagerInitContexts() throws CoreRuntimeException {
+ checkInit();
+ for (Map.Entry<AtomicContext, InstanceContext> entry :
instanceContexts.entrySet()) {
+ AtomicContext context = entry.getKey();
+ if (context.isEagerInit()) {
+ InstanceContext instanceCtx = context.createInstance();
+ instanceContexts.put(context, instanceCtx);
+ instanceCtx.start();
+ }
+ }
+
+ }
+
+ private static class EmptyContext extends AbstractLifecycle implements
InstanceContext {
+ public Object getInstance() {
+ return null;
+ }
+ }
}
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=399863&r1=399862&r2=399863&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
Thu May 4 14:37:54 2006
@@ -21,8 +21,8 @@
*/
public class RequestScopeContext extends AbstractScopeContext<AtomicContext> {
- private Map<AtomicContext, Map<Thread, InstanceContext>> contexts;
- private Map<Thread, List<InstanceContext>> destroyQueues;
+ private final Map<AtomicContext, Map<Thread, InstanceContext>> contexts;
+ private final Map<Thread,List<InstanceContext>> destroyQueues;
public RequestScopeContext(WorkContext workContext) {
super("Request Scope", workContext);
@@ -43,7 +43,13 @@
checkInit();
InstanceContext context = ((InstanceCreated) event).getContext();
List<InstanceContext> destroyQueue =
destroyQueues.get(Thread.currentThread());
- destroyQueue.add(context);
+ if (destroyQueue == null){
+ destroyQueue = new ArrayList<InstanceContext>();
+ destroyQueues.put(Thread.currentThread(),destroyQueue);
+ }
+ synchronized (destroyQueue) {
+ destroyQueue.add(context);
+ }
}
}
@@ -60,28 +66,22 @@
public void register(AtomicContext context) {
contexts.put(context, new ConcurrentHashMap<Thread,
InstanceContext>());
- List<InstanceContext> destroyQueue =
destroyQueues.get(Thread.currentThread());
-
- if (destroyQueue == null) {
- destroyQueues.put(Thread.currentThread(), new
ArrayList<InstanceContext>());
- }
context.addListener(this);
-
}
public InstanceContext getInstanceContext(AtomicContext context) throws
TargetException {
- Map<Thread,InstanceContext> instanceContextMap = contexts.get(context);
- InstanceContext ctx = instanceContextMap.get(Thread.currentThread());
- if(ctx == null){
+ Map<Thread, InstanceContext> instanceContextMap =
contexts.get(context);
+ InstanceContext ctx = instanceContextMap.get(Thread.currentThread());
+ if (ctx == null) {
ctx = context.createInstance();
- instanceContextMap.put(Thread.currentThread(),ctx);
+ instanceContextMap.put(Thread.currentThread(), ctx);
}
return ctx;
}
private void shutdownInstances() {
List<InstanceContext> destroyQueue =
destroyQueues.get(Thread.currentThread());
- if (destroyQueue != null) {
+ synchronized (destroyQueue) {
for (InstanceContext ctx : destroyQueue) {
ctx.stop();
}
Modified:
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/scope/StatelessScopeContext.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/scope/StatelessScopeContext.java?rev=399863&r1=399862&r2=399863&view=diff
==============================================================================
---
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/scope/StatelessScopeContext.java
(original)
+++
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/scope/StatelessScopeContext.java
Thu May 4 14:37:54 2006
@@ -13,32 +13,23 @@
*/
package org.apache.tuscany.core.context.scope;
-import java.util.Map;
-import java.util.List;
-import java.util.ArrayList;
-
import org.apache.tuscany.model.Scope;
import org.apache.tuscany.spi.context.AtomicContext;
import org.apache.tuscany.spi.context.InstanceContext;
import org.apache.tuscany.spi.context.TargetException;
import org.apache.tuscany.spi.context.WorkContext;
-import org.apache.tuscany.spi.context.CompositeContext;
import org.apache.tuscany.spi.event.Event;
/**
- * A container that manages stateless components.
+ * A container that manages stateless components in a non-pooled fashion so
basically it does nothing
*
* @version $Rev: 399161 $ $Date: 2006-05-02 23:09:37 -0700 (Tue, 02 May 2006)
$
*/
public class StatelessScopeContext extends AbstractScopeContext<AtomicContext>
{
- private Map<CompositeContext, List<AtomicContext>> contexts;
- private WorkContext workContext;
-
public StatelessScopeContext(WorkContext workContext) {
super("Stateless scope", workContext);
assert(workContext != null): "Work context was null";
- this.workContext = workContext;
}
public Scope getScope() {
@@ -56,31 +47,15 @@
if (lifecycleState != RUNNING) {
throw new IllegalStateException("Scope in wrong state [" +
lifecycleState + "]");
}
- contexts = null;
lifecycleState = STOPPED;
//TODO stop all contexts
}
public void onEvent(Event event) {
- List<AtomicContext> ctxs =
contexts.get(workContext.getCurrentModule());
- if(ctxs != null){
- for (AtomicContext atomicContext : ctxs) {
- atomicContext.stop();
- }
- }
}
public void register(AtomicContext context) {
checkInit();
- CompositeContext module = workContext.getCurrentModule();
- List<AtomicContext> ctxs = contexts.get(module);
- if (ctxs == null) {
- ctxs = new ArrayList<AtomicContext>();
- }
- synchronized (ctxs) {
- ctxs.add(context);
- }
- contexts.put(module, ctxs);
}
public InstanceContext getInstanceContext(AtomicContext context) throws
TargetException {
Added:
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/context/scope/BasicModuleScopeTestCase.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/context/scope/BasicModuleScopeTestCase.java?rev=399863&view=auto
==============================================================================
---
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/context/scope/BasicModuleScopeTestCase.java
(added)
+++
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/context/scope/BasicModuleScopeTestCase.java
Thu May 4 14:37:54 2006
@@ -0,0 +1,81 @@
+package org.apache.tuscany.core.context.scope;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.common.ObjectFactory;
+import org.apache.tuscany.core.context.WorkContextImpl;
+import org.apache.tuscany.core.context.event.ModuleStop;
+import org.apache.tuscany.core.injection.EventInvoker;
+import org.apache.tuscany.core.injection.MethodEventInvoker;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.mock.component.ModuleScopeInitDestroyComponent;
+import org.apache.tuscany.core.mock.context.MockCompositeContext;
+import org.apache.tuscany.core.system.context.SystemAtomicContext;
+import org.apache.tuscany.spi.context.CompositeContext;
+import org.apache.tuscany.spi.context.WorkContext;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public class BasicModuleScopeTestCase extends TestCase {
+
+ private EventInvoker<Object> initInvoker;
+ private EventInvoker<Object> destroyInvoker;
+ private ObjectFactory<?> factory;
+
+ public void testLifecycleManagement() throws Exception {
+ WorkContext workContext = new WorkContextImpl();
+ CompositeContext currentModule = new MockCompositeContext();
+ ModuleScopeContext scopeContext = new ModuleScopeContext(workContext);
+ scopeContext.start();
+ SystemAtomicContext atomicContext = createContext();
+ atomicContext.setScopeContext(scopeContext);
+ // start the request
+ workContext.setCurrentModule(currentModule);
+ ModuleScopeInitDestroyComponent o1 = (ModuleScopeInitDestroyComponent)
scopeContext.getInstance(atomicContext);
+ assertTrue(o1.isInitialized());
+ assertFalse(o1.isDestroyed());
+ ModuleScopeInitDestroyComponent o2 = (ModuleScopeInitDestroyComponent)
scopeContext.getInstance(atomicContext);
+ assertEquals(o1, o2);
+ scopeContext.onEvent(new ModuleStop(this, currentModule));
+ assertTrue(o1.isDestroyed());
+ scopeContext.stop();
+ }
+
+ public void testModuleIsolation() throws Exception {
+ WorkContext workContext = new WorkContextImpl();
+ CompositeContext currentModule = new MockCompositeContext();
+ ModuleScopeContext scopeContext = new ModuleScopeContext(workContext);
+ scopeContext.start();
+
+ SystemAtomicContext atomicContext = createContext();
+ atomicContext.setScopeContext(scopeContext);
+ SystemAtomicContext atomicContext2 = createContext();
+ atomicContext2.setScopeContext(scopeContext);
+
+ workContext.setCurrentModule(currentModule);
+ ModuleScopeInitDestroyComponent o1 = (ModuleScopeInitDestroyComponent)
scopeContext.getInstance(atomicContext);
+ assertTrue(o1.isInitialized());
+ assertFalse(o1.isDestroyed());
+
+ ModuleScopeInitDestroyComponent o2 = (ModuleScopeInitDestroyComponent)
scopeContext.getInstance(atomicContext);
+ assertSame(o1, o2);
+ scopeContext.onEvent(new ModuleStop(this, currentModule));
+ assertTrue(o1.isDestroyed());
+ scopeContext.stop();
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ factory = new
PojoObjectFactory<ModuleScopeInitDestroyComponent>(ModuleScopeInitDestroyComponent.class.getConstructor((Class[])
null), null, null);
+ initInvoker = new
MethodEventInvoker<Object>(ModuleScopeInitDestroyComponent.class.getMethod("init",
(Class[]) null));
+ destroyInvoker = new
MethodEventInvoker<Object>(ModuleScopeInitDestroyComponent.class.getMethod("destroy",
(Class[]) null));
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ private SystemAtomicContext createContext() {
+ return new SystemAtomicContext("foo", factory, false, initInvoker,
destroyInvoker);
+ }
+}
Added:
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/mock/context/MockCompositeContext.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/mock/context/MockCompositeContext.java?rev=399863&view=auto
==============================================================================
---
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/mock/context/MockCompositeContext.java
(added)
+++
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/mock/context/MockCompositeContext.java
Thu May 4 14:37:54 2006
@@ -0,0 +1,25 @@
+package org.apache.tuscany.core.mock.context;
+
+import org.apache.tuscany.core.context.AbstractContext;
+import org.apache.tuscany.spi.context.CompositeContext;
+import org.apache.tuscany.spi.context.TargetException;
+import org.apache.tuscany.spi.context.Context;
+import org.apache.tuscany.spi.QualifiedName;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public class MockCompositeContext extends AbstractContext implements
CompositeContext {
+
+ public Object getInstance(QualifiedName qName) throws TargetException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void registerContext(Context context) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Context getContext(String name) {
+ throw new UnsupportedOperationException();
+ }
+}
Added:
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/ScopeRegistry.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/ScopeRegistry.java?rev=399863&view=auto
==============================================================================
---
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/ScopeRegistry.java
(added)
+++
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/ScopeRegistry.java
Thu May 4 14:37:54 2006
@@ -0,0 +1,24 @@
+/**
+ *
+ * Copyright 2005 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.spi.context;
+
+import java.util.List;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public interface ScopeRegistry {
+
+ List<ScopeContext> getScopeContexts(CompositeContext module);
+}