- if(failureMessage != null) {
- throw new ComponentDefinitionException(failureMessage);
- }
-
- // The following code is a bit odd so requires some explanation. A little background... If a bean
- // is a prototype then the corresponding Recipe create method does not register the bean as created
- // with the BlueprintRepository and thus the destroy method isn't called on container destroy. We
- // rely on destroy being called to close our DTCL registration. Unfortunately the default setting
- // for the prototype flag in AbstractRecipe is true and the DependentComponentFactoryRecipe, which
- // is created for DependentComponentFactoryMetadata types of which we are one, doesn't have a way for
- // us to indicate the prototype state via our metadata.
- //
- // The ExecutionContext is actually backed by the BlueprintRepository so we access it here to call
- // the removePartialObject method which removes any partially created instance, which does not apply
- // in our case, and also has the side effect of registering our bean as created as if it wasn't a
- // prototype. We also obtain our corresponding Recipe instance and clear the prototype flag. This
- // doesn't look to be necessary but is done so for completeness. Better late than never. Note we have
- // to do this here rather than in startTracking b/c the ExecutionContext is not available yet at that
- // point.
- //
- // Now the stopTracking method is called on container destroy but startTracking/stopTracking can also
- // be called multiple times during the container creation process for Satisfiable recipes as bean
- // processors may modify the metadata which could affect how dependencies are satisfied. An example of
- // this is with service references where the OSGi filter metadata can be modified by bean processors
- // after the initial service dependency is satisfied. However we don't have any metadata that could
- // be modified by a bean processor and we don't want to register/unregister our DTCL multiple times
- // so we only process startTracking once and close the DTCL registration once on container destroy.
- ExecutionContext executionContext = ExecutionContext.Holder.getContext();
- executionContext.removePartialObject(id);
-
- Recipe myRecipe = executionContext.getRecipe(id);
- if(myRecipe instanceof AbstractRecipe) {
- LOG.debug("{}: setPrototype to false", id);
- ((AbstractRecipe)myRecipe).setPrototype(false);
- } else {
- LOG.warn("{}: Recipe is null or not an AbstractRecipe", id);
- }