// Avoid to create duplicate instances if it is called at the same time by several threads
if (instance_ != null)
return instance_;
else if (ctx.get() != null)
return ctx.get();
ComponentTaskContext taskCtx = container.getComponentTaskContext();
boolean isRoot = taskCtx.isRoot();
if (!isRoot)
{
container.setComponentTaskContext(taskCtx = taskCtx.setLastTaskType(ComponentTaskType.CREATE));
}
try
{
ComponentTask<T> task = createTask.get();
T result = task.call(ctx);
if (instance_ != null)
{
// Avoid instantiating twice the same component in case of a cyclic reference due
// to component plugins
return instance_;
}
else if (ctx.get() != null)
return ctx.get();
ctx.push(result);
}
catch (CyclicDependencyException e)
{
throw e;
}
catch (Exception e)
{
throw new RuntimeException("Cannot create component " + getComponentImplementation(), e);
}
if (isRoot)
{
container.setComponentTaskContext(taskCtx =
taskCtx.resetDependencies(getComponentKey(), ComponentTaskType.INIT));
}
else
{
container.setComponentTaskContext(taskCtx = taskCtx.setLastTaskType(ComponentTaskType.INIT));
}
Collection<ComponentTask<Void>> tasks = initTasks.get();
ComponentTask<Void> task = null;
try