Repository: polygene-java Updated Branches: refs/heads/develop 8e8ac22cb -> 0816506ac
POLYGENE-224 - I think this is fixed. Please note the long comment about what could happen within the same thread, i.e. activation -> anotherService -> calls this unactivated service. Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/0816506a Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/0816506a Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/0816506a Branch: refs/heads/develop Commit: 0816506ac990bc2091f4677e202dafcefbf4f501 Parents: 8e8ac22 Author: niclas <[email protected]> Authored: Sat Feb 18 11:57:10 2017 +0800 Committer: niclas <[email protected]> Committed: Sat Feb 18 11:57:10 2017 +0800 ---------------------------------------------------------------------- .../runtime/service/ServiceReferenceInstance.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/polygene-java/blob/0816506a/core/runtime/src/main/java/org/apache/polygene/runtime/service/ServiceReferenceInstance.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/service/ServiceReferenceInstance.java b/core/runtime/src/main/java/org/apache/polygene/runtime/service/ServiceReferenceInstance.java index 8cf7a1c..dafc742 100644 --- a/core/runtime/src/main/java/org/apache/polygene/runtime/service/ServiceReferenceInstance.java +++ b/core/runtime/src/main/java/org/apache/polygene/runtime/service/ServiceReferenceInstance.java @@ -58,6 +58,7 @@ public final class ServiceReferenceInstance<T> private final ServiceModel serviceModel; private final ActivationDelegate activation = new ActivationDelegate( this ); private boolean active = false; + private ServiceInstance instanceBeingActivated; ServiceReferenceInstance( ServiceModel serviceModel, ModuleDescriptor module ) { @@ -149,19 +150,29 @@ public final class ServiceReferenceInstance<T> { if( instance == null ) { - ServiceInstance newInstance = serviceModel.newInstance( module ); + if( instanceBeingActivated != 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 instanceBeingActivated; + } + instanceBeingActivated = serviceModel.newInstance( module ); try { activation.activate( serviceModel.newActivatorsInstance( module ), - newInstance, + instanceBeingActivated, () -> active = true ); } catch( Exception e ) { throw new ServiceUnavailableException( "Could not activate service " + serviceModel.identity(), e ); } - instance = newInstance; + instance = instanceBeingActivated; + instanceBeingActivated = null; } } }
