@Override
public <T extends ComponentDefinition> Component doCreate(Class<T> definition, Optional<Init<T>> initEvent, Optional<ConfigUpdate> update) {
ComponentDefinition component;
childrenLock.writeLock().lock();
try {
parentThreadLocal.set(this);
childUpdate.set(update);
component = createInstance(definition, initEvent);
ComponentCore child = component.getComponentCore();
child.setScheduler(scheduler);
children.add(child);
return child;
} catch (InstantiationException e) {
throw new RuntimeException("Cannot create component "
+ definition.getCanonicalName(), e);
} catch (IllegalAccessException e) {
throw new RuntimeException("Cannot create component "
+ definition.getCanonicalName(), e);
} catch (NoSuchMethodException e) {
throw new RuntimeException("Cannot create component "
+ definition.getCanonicalName(), e);
} catch (InvocationTargetException e) {
throw new RuntimeException("Cannot create component "
+ definition.getCanonicalName(), e);
} finally {
childrenLock.writeLock().unlock();
}
}