Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  * Copyright 2013 JBoss Inc
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.
import  javax.enterprise.context.ApplicationScoped;
import  javax.enterprise.inject.Any;
import  javax.enterprise.inject.Instance;
import  javax.enterprise.inject.Produces;
import  javax.enterprise.util.AnnotationLiteral;
import  javax.inject.Inject;
import  org.kie.api.runtime.manager.RuntimeEnvironment;
import  org.kie.api.runtime.manager.RuntimeManager;
import  org.kie.api.runtime.manager.RuntimeManagerFactory;
import  org.kie.internal.runtime.manager.cdi.qualifier.PerProcessInstance;
import  org.kie.internal.runtime.manager.cdi.qualifier.PerRequest;
import  org.kie.internal.runtime.manager.cdi.qualifier.Singleton;

Producer method used to build instances of RuntimeManager automatically by CDI container. It contains dedicated producer methods for all supported manager types:
  • singleton
  • per request
  • per process instance
It requires two bean injected that are required for successful instantiation of RuntimeManager:
  • RuntimeEnvironment
  • RuntimeManagerFactory
Injections are controlled with qualifiers so same should be used at injection points that should receive them

See also:
public class RuntimeManagerProducer {
    private Instance<RuntimeEnvironment> environmentInstance;
    private RuntimeManagerFactory runtimeManagerFactory;
    public RuntimeManager newSingletonRuntimeManager() {
        RuntimeEnvironment environment = .select(new AnnotationLiteral<Singleton>(){}).get();
        return .newSingletonRuntimeManager(environment);
    public RuntimeManager newPerRequestRuntimeManager() {
        RuntimeEnvironment environment = .select(new AnnotationLiteral<PerRequest>(){}).get();
        return .newPerRequestRuntimeManager(environment);
    public RuntimeManager newPerProcessInstanceRuntimeManager() {
        RuntimeEnvironment environment = .select(new AnnotationLiteral<PerProcessInstance>(){}).get();
        return .newPerProcessInstanceRuntimeManager(environment);
New to GrepCode? Check out our FAQ X