diff options
3 files changed, 49 insertions, 4 deletions
diff --git a/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.java b/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.java index 7e7ab7a9e4..7a1965198a 100644 --- a/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.java +++ b/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.java @@ -50,7 +50,20 @@ public class CompositeScopeContainer<KEY> extends AbstractScopeContainer<KEY> { public synchronized InstanceWrapper getWrapper(KEY contextId) throws TargetResolutionException { if (wrapper == null) { wrapper = createInstanceWrapper(); - wrapper.start(); + try { + wrapper.start(); + } catch (ThreadDeath td) { + throw td; + } catch (Throwable e) { + try { + wrapper.stop(); + } catch (ThreadDeath td) { + throw td; + } catch (Throwable e2) { + } + wrapper = null; + throw new TargetInitializationException(e); + } } return wrapper; } diff --git a/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainer.java b/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainer.java index f11a61e662..8fdfcc63c9 100644 --- a/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainer.java +++ b/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainer.java @@ -62,6 +62,14 @@ public class RequestScopeContainer extends AbstractScopeContainer<Thread> { // synchronized (destroyQueues) { // destroyQueues.clear(); // } + for (InstanceWrapper ctx : wrappers.values()) { + try { + ctx.stop(); + } catch (ThreadDeath td) { + throw td; + } catch (Throwable e2) { + } + } lifecycleState = STOPPED; } @@ -72,8 +80,20 @@ public class RequestScopeContainer extends AbstractScopeContainer<Thread> { } if (ctx == null) { ctx = super.createInstanceWrapper(); - ctx.start(); - wrappers.put(Thread.currentThread(), ctx); + try { + ctx.start(); + wrappers.put(Thread.currentThread(), ctx); + } catch (ThreadDeath td) { + throw td; + } catch (Throwable e) { + try { + ctx.stop(); + } catch (ThreadDeath td) { + throw td; + } catch (Throwable e2) { + } + throw new TargetInitializationException(e); + } } return ctx; } diff --git a/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainer.java b/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainer.java index a2c0edb9b4..24125b154c 100644 --- a/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainer.java +++ b/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainer.java @@ -36,7 +36,19 @@ public class StatelessScopeContainer<KEY> extends AbstractScopeContainer<KEY> { public InstanceWrapper getWrapper(KEY contextId) throws TargetResolutionException { InstanceWrapper ctx = createInstanceWrapper(); - ctx.start(); + try { + ctx.start(); + } catch (ThreadDeath td) { + throw td; + } catch (Throwable e) { + try { + ctx.stop(); + } catch (ThreadDeath td) { + throw td; + } catch (Throwable e2) { + } + throw new TargetInitializationException(e); + } return ctx; } |