use of io.micronaut.core.naming.Described in project micronaut-core by micronaut-projects.
the class DefaultInterceptorRegistry method resolveInterceptors.
@Override
@NonNull
public <T> Interceptor<T, ?>[] resolveInterceptors(@NonNull Executable<T, ?> method, @NonNull Collection<BeanRegistration<Interceptor<T, ?>>> interceptors, @NonNull InterceptorKind interceptorKind) {
final AnnotationMetadata annotationMetadata = method.getAnnotationMetadata();
if (interceptors.isEmpty()) {
return resolveToNone((ExecutableMethod<?, ?>) method, interceptorKind, annotationMetadata);
} else {
instrumentAnnotationMetadata(beanContext, method);
final Collection<AnnotationValue<?>> applicableBindings = AbstractInterceptorChain.resolveInterceptorValues(annotationMetadata, interceptorKind);
if (applicableBindings.isEmpty()) {
return resolveToNone((ExecutableMethod<?, ?>) method, interceptorKind, annotationMetadata);
} else {
@SuppressWarnings({ "unchecked", "rawtypes" }) final Interceptor[] resolvedInterceptors = (Interceptor[]) interceptorStream(method.getDeclaringType(), (Collection) interceptors, interceptorKind, applicableBindings).filter(bean -> (bean instanceof MethodInterceptor) || !(bean instanceof ConstructorInterceptor)).toArray(Interceptor[]::new);
if (LOG.isTraceEnabled()) {
LOG.trace("Resolved {} {} interceptors out of a possible {} for method: {} - {}", resolvedInterceptors.length, interceptorKind, interceptors.size(), method.getDeclaringType(), method instanceof Described ? ((Described) method).getDescription(true) : method.toString());
for (int i = 0; i < resolvedInterceptors.length; i++) {
Interceptor<?, ?> resolvedInterceptor = resolvedInterceptors[i];
LOG.trace("Interceptor {} - {}", i, resolvedInterceptor);
}
}
// noinspection unchecked
return resolvedInterceptors;
}
}
}
use of io.micronaut.core.naming.Described in project micronaut-core by micronaut-projects.
the class Micronaut method start.
/**
* @return Run this {@link Micronaut}
*/
@Override
@NonNull
public ApplicationContext start() {
long start = System.nanoTime();
printBanner();
ApplicationContext applicationContext = super.build();
try {
applicationContext.start();
Optional<EmbeddedApplication> embeddedContainerBean = applicationContext.findBean(EmbeddedApplication.class);
embeddedContainerBean.ifPresent((embeddedApplication -> {
try {
embeddedApplication.start();
boolean keepAlive = false;
if (embeddedApplication instanceof Described) {
if (LOG.isInfoEnabled()) {
long took = elapsedMillis(start);
String desc = ((Described) embeddedApplication).getDescription();
LOG.info("Startup completed in {}ms. Server Running: {}", took, desc);
}
keepAlive = embeddedApplication.isServer();
} else {
if (embeddedApplication instanceof EmbeddedServer) {
final EmbeddedServer embeddedServer = (EmbeddedServer) embeddedApplication;
if (LOG.isInfoEnabled()) {
long took = elapsedMillis(start);
URL url = embeddedServer.getURL();
LOG.info("Startup completed in {}ms. Server Running: {}", took, url);
}
keepAlive = embeddedServer.isKeepAlive();
} else {
if (LOG.isInfoEnabled()) {
long took = elapsedMillis(start);
LOG.info("Startup completed in {}ms.", took);
}
keepAlive = embeddedApplication.isServer();
}
}
Thread mainThread = Thread.currentThread();
boolean finalKeepAlive = keepAlive;
CountDownLatch countDownLatch = new CountDownLatch(1);
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
if (LOG.isInfoEnabled()) {
LOG.info("Embedded Application shutting down");
}
if (embeddedApplication.isRunning()) {
embeddedApplication.stop();
countDownLatch.countDown();
if (finalKeepAlive) {
mainThread.interrupt();
}
}
}));
if (keepAlive) {
new Thread(() -> {
try {
if (!embeddedApplication.isRunning()) {
countDownLatch.countDown();
Thread.sleep(1000);
}
} catch (InterruptedException e) {
// ignore
}
}, SHUTDOWN_MONITOR_THREAD).start();
boolean interrupted = false;
while (true) {
try {
countDownLatch.await();
break;
} catch (InterruptedException e) {
interrupted = true;
}
}
if (interrupted) {
Thread.currentThread().interrupt();
}
if (LOG.isInfoEnabled()) {
LOG.info("Embedded Application shutting down");
}
}
if (embeddedApplication.isForceExit()) {
System.exit(0);
}
} catch (Throwable e) {
handleStartupException(applicationContext.getEnvironment(), e);
}
}));
if (LOG.isInfoEnabled() && !embeddedContainerBean.isPresent()) {
LOG.info("No embedded container found. Running as CLI application");
}
return applicationContext;
} catch (Throwable e) {
handleStartupException(applicationContext.getEnvironment(), e);
return null;
}
}
Aggregations