Repository: polygene-java Updated Branches: refs/heads/develop 0816506ac -> eaefd4109
POLYGENE-224 - Needed to do the same fix in ImportServiceReferenceInstance Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/eaefd410 Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/eaefd410 Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/eaefd410 Branch: refs/heads/develop Commit: eaefd410976b254a4d94a63b76c20a71357ee372 Parents: 0816506 Author: niclas <[email protected]> Authored: Sat Feb 18 12:01:23 2017 +0800 Committer: niclas <[email protected]> Committed: Sat Feb 18 12:01:23 2017 +0800 ---------------------------------------------------------------------- .../ImportedServiceReferenceInstance.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/polygene-java/blob/eaefd410/core/runtime/src/main/java/org/apache/polygene/runtime/service/ImportedServiceReferenceInstance.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/service/ImportedServiceReferenceInstance.java b/core/runtime/src/main/java/org/apache/polygene/runtime/service/ImportedServiceReferenceInstance.java index 697d12c..17ad458 100644 --- a/core/runtime/src/main/java/org/apache/polygene/runtime/service/ImportedServiceReferenceInstance.java +++ b/core/runtime/src/main/java/org/apache/polygene/runtime/service/ImportedServiceReferenceInstance.java @@ -51,6 +51,7 @@ public final class ImportedServiceReferenceInstance<T> private final ImportedServiceModel serviceModel; private final ActivationDelegate activation = new ActivationDelegate( this ); private boolean active = false; + private ImportedServiceInstance<T> serviceInstanceBeingActivated; public ImportedServiceReferenceInstance( ImportedServiceModel serviceModel, ModuleDescriptor module ) { @@ -156,12 +157,21 @@ public final class ImportedServiceReferenceInstance<T> { if( serviceInstance == null ) { - ImportedServiceInstance<T> newServiceInstance = serviceModel.importInstance( module ); + if( serviceInstanceBeingActivated != null ) + { + // needed because activation may request its own service. + // There is possible complication with this, as activation may use another service, which in turn + // uses the service under activation before it is being ready. This is a problem left to the + // developer to be aware of and avoid. It is similar to what can happen when pass 'this' inside + // constructors to objects, which may then use an uninitilized object. + return serviceInstanceBeingActivated.instance(); + } + serviceInstanceBeingActivated = serviceModel.importInstance( module ); try { activation.activate( serviceModel.newActivatorsInstance( module ), - newServiceInstance, () -> { + serviceInstanceBeingActivated, () -> { active = true; } ); @@ -170,8 +180,9 @@ public final class ImportedServiceReferenceInstance<T> { throw new ServiceUnavailableException( "Could not activate service " + serviceModel.identity(), e ); } - serviceInstance = newServiceInstance; - instance = newServiceInstance.instance(); + serviceInstance = serviceInstanceBeingActivated; + instance = serviceInstanceBeingActivated.instance(); + serviceInstanceBeingActivated = null; } } }
