Search in sources :

Example 1 with ArcContainerImpl

use of io.quarkus.arc.impl.ArcContainerImpl in project quarkus by quarkusio.

the class Arc method initialize.

/**
 * @param currentContextFactory
 * @return the initialized container
 */
public static ArcContainer initialize(CurrentContextFactory currentContextFactory) {
    ArcContainerImpl container = INSTANCE.get();
    if (container == null) {
        synchronized (INSTANCE) {
            container = INSTANCE.get();
            if (container == null) {
                // Set the container instance first because Arc.container() can be used within ArcContainerImpl.init()
                container = new ArcContainerImpl(currentContextFactory);
                INSTANCE.set(container);
                container.init();
            }
        }
    }
    return container;
}
Also used : ArcContainerImpl(io.quarkus.arc.impl.ArcContainerImpl)

Example 2 with ArcContainerImpl

use of io.quarkus.arc.impl.ArcContainerImpl in project quarkus by quarkusio.

the class Arc method shutdown.

public static void shutdown() {
    ArcContainerImpl container = INSTANCE.get();
    if (container != null) {
        synchronized (INSTANCE) {
            container = INSTANCE.get();
            if (container != null) {
                container.shutdown();
                INSTANCE.set(null);
            }
        }
    }
}
Also used : ArcContainerImpl(io.quarkus.arc.impl.ArcContainerImpl)

Example 3 with ArcContainerImpl

use of io.quarkus.arc.impl.ArcContainerImpl in project quarkus by quarkusio.

the class ArcDevRecorder method createBeansHandler.

public Handler<RoutingContext> createBeansHandler() {
    return new Handler<RoutingContext>() {

        @Override
        public void handle(RoutingContext ctx) {
            ctx.response().putHeader("Content-Type", "application/json");
            ArcContainerImpl container = ArcContainerImpl.instance();
            List<InjectableBean<?>> beans = new ArrayList<>();
            beans.addAll(container.getBeans());
            beans.addAll(container.getInterceptors());
            beans.addAll(container.getDecorators());
            String kindParam = ctx.request().getParam("kind");
            InjectableBean.Kind kind = kindParam != null ? InjectableBean.Kind.from(kindParam.toUpperCase()) : null;
            String scopeEndsWith = ctx.request().getParam("scope");
            String beanClassStartsWith = ctx.request().getParam("beanClass");
            for (Iterator<InjectableBean<?>> it = beans.iterator(); it.hasNext(); ) {
                InjectableBean<?> injectableBean = it.next();
                if (kind != null && !kind.equals(injectableBean.getKind())) {
                    it.remove();
                }
                if (scopeEndsWith != null && !injectableBean.getScope().getName().endsWith(scopeEndsWith)) {
                    it.remove();
                }
                if (beanClassStartsWith != null && !injectableBean.getBeanClass().getName().startsWith(beanClassStartsWith)) {
                    it.remove();
                }
            }
            JsonArrayBuilder array = Json.array();
            for (InjectableBean<?> injectableBean : beans) {
                JsonObjectBuilder bean = Json.object();
                bean.put("id", injectableBean.getIdentifier());
                bean.put("kind", injectableBean.getKind().toString());
                bean.put("generatedClass", injectableBean.getClass().getName());
                bean.put("beanClass", injectableBean.getBeanClass().getName());
                JsonArrayBuilder types = Json.array();
                for (Type beanType : injectableBean.getTypes()) {
                    types.add(beanType.getTypeName());
                }
                bean.put("types", types);
                JsonArrayBuilder qualifiers = Json.array();
                for (Annotation qualifier : injectableBean.getQualifiers()) {
                    if (qualifier.annotationType().equals(Any.class) || qualifier.annotationType().equals(Default.class)) {
                        qualifiers.add("@" + qualifier.annotationType().getSimpleName());
                    } else {
                        qualifiers.add(qualifier.toString());
                    }
                }
                bean.put("qualifiers", qualifiers);
                bean.put("scope", injectableBean.getScope().getName());
                if (injectableBean.getDeclaringBean() != null) {
                    bean.put("declaringBean", injectableBean.getDeclaringBean().getIdentifier());
                }
                if (injectableBean.getName() != null) {
                    bean.put("name", injectableBean.getName());
                }
                if (injectableBean.isAlternative()) {
                    bean.put("alternativePriority", injectableBean.getAlternativePriority());
                }
                if (injectableBean.isDefaultBean()) {
                    bean.put("isDefault", true);
                }
                array.add(bean);
            }
            ctx.response().end(array.build());
        }
    };
}
Also used : ArrayList(java.util.ArrayList) DevConsolePostHandler(io.quarkus.devconsole.runtime.spi.DevConsolePostHandler) Handler(io.vertx.core.Handler) Any(javax.enterprise.inject.Any) Default(javax.enterprise.inject.Default) Annotation(java.lang.annotation.Annotation) RoutingContext(io.vertx.ext.web.RoutingContext) Type(java.lang.reflect.Type) ArcContainerImpl(io.quarkus.arc.impl.ArcContainerImpl) InjectableBean(io.quarkus.arc.InjectableBean) JsonArrayBuilder(io.quarkus.vertx.http.runtime.devmode.Json.JsonArrayBuilder) JsonObjectBuilder(io.quarkus.vertx.http.runtime.devmode.Json.JsonObjectBuilder)

Example 4 with ArcContainerImpl

use of io.quarkus.arc.impl.ArcContainerImpl in project quarkus by quarkusio.

the class ArcDevRecorder method createObserversHandler.

public Handler<RoutingContext> createObserversHandler() {
    return new Handler<RoutingContext>() {

        @Override
        public void handle(RoutingContext ctx) {
            ctx.response().putHeader("Content-Type", "application/json");
            ArcContainerImpl container = ArcContainerImpl.instance();
            List<InjectableObserverMethod<?>> observers = container.getObservers();
            JsonArrayBuilder array = Json.array();
            for (InjectableObserverMethod<?> injectableObserver : observers) {
                JsonObjectBuilder observer = Json.object();
                observer.put("generatedClass", injectableObserver.getClass().getName());
                observer.put("observedType", injectableObserver.getObservedType().getTypeName());
                if (!injectableObserver.getObservedQualifiers().isEmpty()) {
                    JsonArrayBuilder qualifiers = Json.array();
                    for (Annotation qualifier : injectableObserver.getObservedQualifiers()) {
                        qualifiers.add(qualifier.toString());
                    }
                    observer.put("qualifiers", qualifiers);
                }
                observer.put("priority", injectableObserver.getPriority());
                observer.put("reception", injectableObserver.getReception().toString());
                observer.put("transactionPhase", injectableObserver.getTransactionPhase().toString());
                observer.put("async", injectableObserver.isAsync());
                if (injectableObserver.getDeclaringBeanIdentifier() != null) {
                    observer.put("declaringBean", injectableObserver.getDeclaringBeanIdentifier());
                }
                array.add(observer);
            }
            ctx.response().end(array.build());
        }
    };
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) ArcContainerImpl(io.quarkus.arc.impl.ArcContainerImpl) InjectableObserverMethod(io.quarkus.arc.InjectableObserverMethod) DevConsolePostHandler(io.quarkus.devconsole.runtime.spi.DevConsolePostHandler) Handler(io.vertx.core.Handler) JsonArrayBuilder(io.quarkus.vertx.http.runtime.devmode.Json.JsonArrayBuilder) JsonObjectBuilder(io.quarkus.vertx.http.runtime.devmode.Json.JsonObjectBuilder) Annotation(java.lang.annotation.Annotation)

Example 5 with ArcContainerImpl

use of io.quarkus.arc.impl.ArcContainerImpl in project quarkus by quarkusio.

the class ArcRecorder method handleLifecycleEvents.

public void handleLifecycleEvents(ShutdownContext context, LaunchMode launchMode, boolean disableApplicationLifecycleObservers) {
    ArcContainerImpl container = ArcContainerImpl.instance();
    List<Class<?>> mockBeanClasses;
    // If needed then mock all app observers in the test mode
    if (launchMode == LaunchMode.TEST && disableApplicationLifecycleObservers) {
        Predicate<String> predicate = container.select(TestApplicationClassPredicate.class).get();
        mockBeanClasses = new ArrayList<>();
        for (InjectableBean<?> bean : container.getBeans()) {
            // Mock observers for all application class beans
            if (bean.getKind() == Kind.CLASS && predicate.test(bean.getBeanClass().getName())) {
                mockBeanClasses.add(bean.getBeanClass());
            }
        }
    } else {
        mockBeanClasses = Collections.emptyList();
    }
    fireLifecycleEvent(container, new StartupEvent(), mockBeanClasses);
    context.addShutdownTask(new Runnable() {

        @Override
        public void run() {
            fireLifecycleEvent(container, new ShutdownEvent(), mockBeanClasses);
        }
    });
}
Also used : ArcContainerImpl(io.quarkus.arc.impl.ArcContainerImpl) StartupEvent(io.quarkus.runtime.StartupEvent) PreloadedTestApplicationClassPredicate(io.quarkus.arc.runtime.test.PreloadedTestApplicationClassPredicate) TestApplicationClassPredicate(io.quarkus.runtime.test.TestApplicationClassPredicate) ShutdownEvent(io.quarkus.runtime.ShutdownEvent)

Aggregations

ArcContainerImpl (io.quarkus.arc.impl.ArcContainerImpl)7 DevConsolePostHandler (io.quarkus.devconsole.runtime.spi.DevConsolePostHandler)4 JsonArrayBuilder (io.quarkus.vertx.http.runtime.devmode.Json.JsonArrayBuilder)4 JsonObjectBuilder (io.quarkus.vertx.http.runtime.devmode.Json.JsonObjectBuilder)4 Handler (io.vertx.core.Handler)4 RoutingContext (io.vertx.ext.web.RoutingContext)4 Annotation (java.lang.annotation.Annotation)3 Type (java.lang.reflect.Type)2 Any (javax.enterprise.inject.Any)2 Default (javax.enterprise.inject.Default)2 InjectableBean (io.quarkus.arc.InjectableBean)1 InjectableObserverMethod (io.quarkus.arc.InjectableObserverMethod)1 RemovedBean (io.quarkus.arc.RemovedBean)1 PreloadedTestApplicationClassPredicate (io.quarkus.arc.runtime.test.PreloadedTestApplicationClassPredicate)1 ShutdownEvent (io.quarkus.runtime.ShutdownEvent)1 StartupEvent (io.quarkus.runtime.StartupEvent)1 TestApplicationClassPredicate (io.quarkus.runtime.test.TestApplicationClassPredicate)1 ArrayList (java.util.ArrayList)1