io.quarkus.arc.runtime.BeanContainer Java Examples

The following examples show how to use io.quarkus.arc.runtime.BeanContainer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VertxRequestHandler.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public VertxRequestHandler(Vertx vertx,
        BeanContainer beanContainer,
        String rootPath,
        Executor executor) {
    this.vertx = vertx;
    this.beanContainer = beanContainer;
    // make sure rootPath ends with "/" for easy parsing
    if (rootPath == null) {
        this.rootPath = "/";
    } else if (!rootPath.endsWith("/")) {
        this.rootPath = rootPath + "/";
    } else {
        this.rootPath = rootPath;
    }

    this.executor = executor;
    Instance<CurrentIdentityAssociation> association = CDI.current().select(CurrentIdentityAssociation.class);
    this.association = association.isResolvable() ? association.get() : null;
    currentVertxRequest = CDI.current().select(CurrentVertxRequest.class).get();
}
 
Example #2
Source File: UndertowDeploymentRecorder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public RuntimeValue<ServletInfo> registerServlet(RuntimeValue<DeploymentInfo> deploymentInfo,
        String name,
        Class<?> servletClass,
        boolean asyncSupported,
        int loadOnStartup,
        BeanContainer beanContainer,
        InstanceFactory<? extends Servlet> instanceFactory) throws Exception {

    InstanceFactory<? extends Servlet> factory = instanceFactory != null ? instanceFactory
            : new QuarkusInstanceFactory(beanContainer.instanceFactory(servletClass));
    ServletInfo servletInfo = new ServletInfo(name, (Class<? extends Servlet>) servletClass,
            factory);
    deploymentInfo.getValue().addServlet(servletInfo);
    servletInfo.setAsyncSupported(asyncSupported);
    if (loadOnStartup > 0) {
        servletInfo.setLoadOnStartup(loadOnStartup);
    }
    return new RuntimeValue<>(servletInfo);
}
 
Example #3
Source File: CaffeineCacheBuildRecorder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public void buildCaches(boolean managedExecutorInitialized, BeanContainer beanContainer,
        Set<CaffeineCacheInfo> cacheInfos) {
    // The number of caches is known at build time so we can use fixed initialCapacity and loadFactor for the caches map.
    Map<String, CaffeineCache> caches = new HashMap<>(cacheInfos.size() + 1, 1.0F);

    ManagedExecutor managedExecutor = null;
    if (managedExecutorInitialized) {
        managedExecutor = beanContainer.instance(ManagedExecutor.class);
    }

    for (CaffeineCacheInfo cacheInfo : cacheInfos) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debugf(
                    "Building Caffeine cache [%s] with [initialCapacity=%s], [maximumSize=%s], [expireAfterWrite=%s] and [expireAfterAccess=%s]",
                    cacheInfo.name, cacheInfo.initialCapacity, cacheInfo.maximumSize, cacheInfo.expireAfterWrite,
                    cacheInfo.expireAfterAccess);
        }
        CaffeineCache cache = new CaffeineCache(cacheInfo, managedExecutor);
        caches.put(cacheInfo.name, cache);
    }

    beanContainer.instance(CacheRepository.class).setCaches(caches);
}
 
Example #4
Source File: VertxRequestHandler.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public VertxRequestHandler(Vertx vertx,
        BeanContainer beanContainer,
        ResteasyDeployment deployment,
        String rootPath,
        BufferAllocator allocator, Executor executor, long readTimeout) {
    this.vertx = vertx;
    this.beanContainer = beanContainer;
    this.dispatcher = new RequestDispatcher((SynchronousDispatcher) deployment.getDispatcher(),
            deployment.getProviderFactory(), null, Thread.currentThread().getContextClassLoader());
    this.rootPath = rootPath;
    this.allocator = allocator;
    this.executor = executor;
    this.readTimeout = readTimeout;
    Instance<CurrentIdentityAssociation> association = CDI.current().select(CurrentIdentityAssociation.class);
    this.association = association.isResolvable() ? association.get() : null;
    currentVertxRequest = CDI.current().select(CurrentVertxRequest.class).get();
}
 
Example #5
Source File: VertxRequestHandler.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public VertxRequestHandler(Vertx vertx,
        BeanContainer beanContainer,
        ObjectMapper mapper,
        FunqyKnativeEventsConfig config,
        FunctionInvoker defaultInvoker,
        Map<String, FunctionInvoker> typeTriggers,
        Executor executor) {
    this.defaultInvoker = defaultInvoker;
    this.vertx = vertx;
    this.beanContainer = beanContainer;
    this.executor = executor;
    this.mapper = mapper;
    this.typeTriggers = typeTriggers;
    Instance<CurrentIdentityAssociation> association = CDI.current().select(CurrentIdentityAssociation.class);
    this.association = association.isResolvable() ? association.get() : null;
    Instance<IdentityProviderManager> identityProviderManager = CDI.current().select(IdentityProviderManager.class);
    this.currentVertxRequest = CDI.current().select(CurrentVertxRequest.class).get();

}
 
Example #6
Source File: FunqyHttpBindingRecorder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public Handler<RoutingContext> start(String contextPath,
        Supplier<Vertx> vertx,
        ShutdownContext shutdown,
        BeanContainer beanContainer,
        Executor executor) {

    shutdown.addShutdownTask(new Runnable() {
        @Override
        public void run() {
            FunctionConstructor.CONTAINER = null;
            objectMapper = null;
        }
    });
    FunctionConstructor.CONTAINER = beanContainer;

    return new VertxRequestHandler(vertx.get(), beanContainer, contextPath, executor);
}
 
Example #7
Source File: SqsRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<SqsAsyncClient> buildAsyncClient(RuntimeValue<? extends AwsClientBuilder> builder,
        BeanContainer beanContainer,
        ShutdownContext shutdown) {
    SqsClientProducer producer = beanContainer.instance(SqsClientProducer.class);
    producer.setAsyncConfiguredBuilder((SqsAsyncClientBuilder) builder.getValue());
    shutdown.addShutdownTask(producer::destroy);
    return new RuntimeValue<>(producer.asyncClient());
}
 
Example #8
Source File: KmsRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<KmsClient> buildClient(RuntimeValue<? extends AwsClientBuilder> builder,
        BeanContainer beanContainer,
        ShutdownContext shutdown) {
    KmsClientProducer producer = beanContainer.instance(KmsClientProducer.class);
    producer.setSyncConfiguredBuilder((KmsClientBuilder) builder.getValue());
    shutdown.addShutdownTask(producer::destroy);
    return new RuntimeValue<>(producer.client());
}
 
Example #9
Source File: CamelMainRecorder.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<CamelRuntime> createRuntime(BeanContainer beanContainer, RuntimeValue<CamelMain> main) {
    final CamelRuntime runtime = new CamelMainRuntime(main.getValue());

    // register to the container
    beanContainer.instance(CamelProducers.class).setRuntime(runtime);

    return new RuntimeValue<>(runtime);
}
 
Example #10
Source File: SnsRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<SnsClient> buildClient(RuntimeValue<? extends AwsClientBuilder> builder,
        BeanContainer beanContainer,
        ShutdownContext shutdown) {
    SnsClientProducer producer = beanContainer.instance(SnsClientProducer.class);
    producer.setSyncConfiguredBuilder((SnsClientBuilder) builder.getValue());
    shutdown.addShutdownTask(producer::destroy);
    return new RuntimeValue<>(producer.client());
}
 
Example #11
Source File: SesRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<SesAsyncClient> buildAsyncClient(RuntimeValue<? extends AwsClientBuilder> builder,
        BeanContainer beanContainer,
        ShutdownContext shutdown) {
    SesClientProducer producer = beanContainer.instance(SesClientProducer.class);
    producer.setAsyncConfiguredBuilder((SesAsyncClientBuilder) builder.getValue());
    shutdown.addShutdownTask(producer::destroy);
    return new RuntimeValue<>(producer.asyncClient());
}
 
Example #12
Source File: SesRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<SesClient> buildClient(RuntimeValue<? extends AwsClientBuilder> builder,
        BeanContainer beanContainer,
        ShutdownContext shutdown) {
    SesClientProducer producer = beanContainer.instance(SesClientProducer.class);
    producer.setSyncConfiguredBuilder((SesClientBuilder) builder.getValue());
    shutdown.addShutdownTask(producer::destroy);
    return new RuntimeValue<>(producer.client());
}
 
Example #13
Source File: KmsRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<KmsAsyncClient> buildAsyncClient(RuntimeValue<? extends AwsClientBuilder> builder,
        BeanContainer beanContainer,
        ShutdownContext shutdown) {
    KmsClientProducer producer = beanContainer.instance(KmsClientProducer.class);
    producer.setAsyncConfiguredBuilder((KmsAsyncClientBuilder) builder.getValue());
    shutdown.addShutdownTask(producer::destroy);
    return new RuntimeValue<>(producer.asyncClient());
}
 
Example #14
Source File: SqsRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<SqsClient> buildClient(RuntimeValue<? extends AwsClientBuilder> builder,
        BeanContainer beanContainer,
        ShutdownContext shutdown) {
    SqsClientProducer producer = beanContainer.instance(SqsClientProducer.class);
    producer.setSyncConfiguredBuilder((SqsClientBuilder) builder.getValue());
    shutdown.addShutdownTask(producer::destroy);
    return new RuntimeValue<>(producer.client());
}
 
Example #15
Source File: DynamodbRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<DynamoDbClient> buildClient(RuntimeValue<? extends AwsClientBuilder> builder,
        BeanContainer beanContainer,
        ShutdownContext shutdown) {
    DynamodbClientProducer producer = beanContainer.instance(DynamodbClientProducer.class);
    producer.setSyncConfiguredBuilder((DynamoDbClientBuilder) builder.getValue());
    shutdown.addShutdownTask(producer::destroy);
    return new RuntimeValue<>(producer.client());
}
 
Example #16
Source File: DynamodbRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<DynamoDbAsyncClient> buildAsyncClient(RuntimeValue<? extends AwsClientBuilder> builder,
        BeanContainer beanContainer,
        ShutdownContext shutdown) {
    DynamodbClientProducer producer = beanContainer.instance(DynamodbClientProducer.class);
    producer.setAsyncConfiguredBuilder((DynamoDbAsyncClientBuilder) builder.getValue());
    shutdown.addShutdownTask(producer::destroy);
    return new RuntimeValue<>(producer.asyncClient());
}
 
Example #17
Source File: S3Recorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<S3Client> buildClient(RuntimeValue<? extends AwsClientBuilder> builder,
        BeanContainer beanContainer,
        ShutdownContext shutdown) {
    S3ClientProducer producer = beanContainer.instance(S3ClientProducer.class);
    producer.setSyncConfiguredBuilder((S3ClientBuilder) builder.getValue());
    shutdown.addShutdownTask(producer::destroy);
    return new RuntimeValue<>(producer.client());
}
 
Example #18
Source File: S3Recorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<S3AsyncClient> buildAsyncClient(RuntimeValue<? extends AwsClientBuilder> builder,
        BeanContainer beanContainer,
        ShutdownContext shutdown) {
    S3ClientProducer producer = beanContainer.instance(S3ClientProducer.class);
    producer.setAsyncConfiguredBuilder((S3AsyncClientBuilder) builder.getValue());
    shutdown.addShutdownTask(producer::destroy);
    return new RuntimeValue<>(producer.asyncClient());
}
 
Example #19
Source File: AmazonLambdaRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public void setHandlerClass(Class<? extends RequestHandler<?, ?>> handler, BeanContainer container) {
    handlerClass = handler;
    beanContainer = container;
    ObjectMapper objectMapper = AmazonLambdaMapperRecorder.objectMapper;
    Method handlerMethod = discoverHandlerMethod(handlerClass);
    objectReader = objectMapper.readerFor(handlerMethod.getParameterTypes()[0]);
    objectWriter = objectMapper.writerFor(handlerMethod.getReturnType());
}
 
Example #20
Source File: KafkaStreamsRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public BeanContainerListener configure(Properties properties) {
    return new BeanContainerListener() {

        @Override
        public void created(BeanContainer container) {
            KafkaStreamsTopologyManager instance = container.instance(KafkaStreamsTopologyManager.class);
            instance.configure(properties);
        }
    };
}
 
Example #21
Source File: KeycloakRecorder.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public BeanContainerListener configureDataSource() {
    return new BeanContainerListener() {
        @Override
        public void created(BeanContainer container) {
            String driver = CONFIG.getRawValue("quarkus.datasource.driver");
            DataSourceSupport instance = container.instance(DataSourceSupport.class);
            DataSourceSupport.Entry entry = instance.entries.get(DataSourceUtil.DEFAULT_DATASOURCE_NAME);
            entry.resolvedDriverClass = driver;
        }
    };
}
 
Example #22
Source File: SnsRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<SnsAsyncClient> buildAsyncClient(RuntimeValue<? extends AwsClientBuilder> builder,
        BeanContainer beanContainer,
        ShutdownContext shutdown) {
    SnsClientProducer producer = beanContainer.instance(SnsClientProducer.class);
    producer.setAsyncConfiguredBuilder((SnsAsyncClientBuilder) builder.getValue());
    shutdown.addShutdownTask(producer::destroy);
    return new RuntimeValue<>(producer.asyncClient());
}
 
Example #23
Source File: SmallRyeContextPropagationRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public void configureRuntime(BeanContainer container, ExecutorService executorService) {
    // associate the static init manager to the runtime CL
    ContextManagerProvider contextManagerProvider = ContextManagerProvider.instance();
    // finish building our manager
    builder.withDefaultExecutorService(executorService);

    SmallRyeContextManager contextManager = builder.build();

    contextManagerProvider.registerContextManager(contextManager, Thread.currentThread().getContextClassLoader());

    // initialise injection
    SmallRyeContextPropagationProvider cpProvider = container.instance(SmallRyeContextPropagationProvider.class);
    cpProvider.initialize(executorService);
}
 
Example #24
Source File: ResteasyInjectorFactoryRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<InjectorFactory> setup(BeanContainer container, List<Function<Object, Object>> propertyUnwrappers) {
    QuarkusInjectorFactory.CONTAINER = container;
    QuarkusInjectorFactory.PROXY_UNWRAPPER = new Function<Object, Object>() {
        @Override
        public Object apply(Object o) {
            Object res = o;
            for (Function<Object, Object> i : propertyUnwrappers) {
                res = i.apply(res);
            }
            return res;
        }
    };
    return new RuntimeValue<>(new QuarkusInjectorFactory());
}
 
Example #25
Source File: RestClientRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public BeanContainerListener hackAroundExtension() {
    return new BeanContainerListener() {
        @Override
        public void created(BeanContainer container) {
            try {
                Field f = RestClientExtension.class.getDeclaredField("manager");
                f.setAccessible(true);
                f.set(null, CDI.current().getBeanManager());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
}
 
Example #26
Source File: QuarkusInstanceFactory.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public InstanceHandle<T> createInstance() throws InstantiationException {
    BeanContainer.Instance<T> instance = factory.create();
    return new InstanceHandle<T>() {
        @Override
        public T getInstance() {
            return instance.get();
        }

        @Override
        public void release() {
            instance.close();
        }
    };
}
 
Example #27
Source File: UndertowDeploymentRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<FilterInfo> registerFilter(RuntimeValue<DeploymentInfo> info,
        String name, Class<?> filterClass,
        boolean asyncSupported,
        BeanContainer beanContainer,
        InstanceFactory<? extends Filter> instanceFactory) throws Exception {

    InstanceFactory<? extends Filter> factory = instanceFactory != null ? instanceFactory
            : new QuarkusInstanceFactory(beanContainer.instanceFactory(filterClass));
    FilterInfo filterInfo = new FilterInfo(name, (Class<? extends Filter>) filterClass, factory);
    info.getValue().addFilter(filterInfo);
    filterInfo.setAsyncSupported(asyncSupported);
    return new RuntimeValue<>(filterInfo);
}
 
Example #28
Source File: HttpSecurityRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public BeanContainerListener initPermissions(HttpBuildTimeConfig permissions,
        Map<String, Supplier<HttpSecurityPolicy>> policies) {
    return new BeanContainerListener() {
        @Override
        public void created(BeanContainer container) {
            container.instance(PathMatchingHttpSecurityPolicy.class).init(permissions, policies);
        }
    };
}
 
Example #29
Source File: SmallRyeMetricsRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public void createRegistries(BeanContainer container) {
    MetricRegistries.get(MetricRegistry.Type.APPLICATION);
    MetricRegistries.get(MetricRegistry.Type.BASE);
    MetricRegistries.get(MetricRegistry.Type.VENDOR);

    //HACK: registration is done via statics, but cleanup is done via pre destroy
    //however if the bean is not used it will not be created, so no cleanup will be done
    //we force bean creation here to make sure the container can restart correctly
    container.instance(MetricRegistries.class).getApplicationRegistry();
}
 
Example #30
Source File: KeycloakPolicyEnforcerRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public void setup(OidcConfig oidcConfig, KeycloakPolicyEnforcerConfig config, BeanContainer beanContainer,
        HttpConfiguration httpConfiguration) {
    if (oidcConfig.defaultTenant.applicationType == OidcTenantConfig.ApplicationType.WEB_APP) {
        throw new OIDCException("Application type [" + oidcConfig.defaultTenant.applicationType + "] is not supported");
    }
    beanContainer.instance(KeycloakPolicyEnforcerAuthorizer.class).init(oidcConfig, config, httpConfiguration);
}