Skip to content

Commit

Permalink
Better eager context
Browse files Browse the repository at this point in the history
  • Loading branch information
ogesaku committed Apr 27, 2024
1 parent e1ad5e8 commit 812a176
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/main/java/com/coditory/quark/context/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,23 @@ static Context createEager(String name, Set<BeanHolder<?>> beanHolders, Set<Bean
Map<BeanDescriptor<?>, List<BeanHolder<?>>> holders = ContextResolver.resolve(beanHolders, properties);
Context context = new Context(name, holders, properties, eventBus);
context.init(initBeanHolders);
holders.forEach((descriptor, creator) -> {
if (descriptor.name() != null) {
context.get(descriptor.type(), descriptor.name());
} else {
context.getAll(descriptor.type());
try {
holders.forEach((descriptor, creator) -> {
if (descriptor.name() != null) {
context.get(descriptor.type(), descriptor.name());
} else if (descriptor.type() != Object.class) {
// Object is too generic, can be skipped for more readable exceptions
context.getAll(descriptor.type());
}
});
} catch (Throwable exception) {
try {
context.close();
} catch (Throwable closeException) {
log.warn("Could not close context", closeException);
}
});
throw exception;
}
log.info("Created eager context in {}", totalTimer.measureAndFormat());
eventBus.emit(new ContextEvent.ContextPostCreateEvent());
return context;
Expand Down

0 comments on commit 812a176

Please sign in to comment.