Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2015 JBoss Inc
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
 */
 
 package org.kie.remote.services.cdi;
 
 import java.util.Map;
 
 import  javax.enterprise.context.ApplicationScoped;
 import  javax.enterprise.event.Event;
 import  javax.enterprise.event.Observes;
 import  javax.inject.Inject;
 
 import  org.jbpm.runtime.manager.impl.PerProcessInstanceRuntimeManager;
 import  org.jbpm.runtime.manager.impl.RuntimeEngineImpl;
 import  org.jbpm.services.api.DeploymentEvent;
 import  org.jbpm.services.cdi.Deploy;
 import  org.jbpm.services.cdi.Undeploy;
 import  org.kie.api.runtime.manager.Context;
 import  org.kie.api.runtime.manager.RuntimeEngine;
 import  org.kie.api.runtime.manager.RuntimeManager;
 import  org.kie.internal.runtime.manager.context.EmptyContext;
 import  org.kie.internal.runtime.manager.context.ProcessInstanceIdContext;
 import  org.slf4j.Logger;
 import  org.slf4j.LoggerFactory;

  • Keeps track of the RuntimeManager instances for each deployment for use by the Remote API.
  • Keeps track of the list of classes in deployments.
    • This is necessary in order for serialization of inputs containing instances of (user) classes defined in the KJar deployments.
    • See the JaxbContextResolver for more info.
 
 @ApplicationScoped
 public class DeploymentInfoBean {
 
     private static final Logger logger = LoggerFactory.getLogger(DeploymentInfoBean.class);
     
     
     private Map<String, RuntimeManager> domainRuntimeManagers = new ConcurrentHashMap<String, RuntimeManager>();  
    
     @Inject
     @Deploy
     private Event<DeploymentProcessedEventdeployEvent;
     
     @Inject
     @Undeploy
     private Event<DeploymentProcessedEventundeployEvent;
     
     // Observer methods -----------------------------------------------------------------------------------------------------------
    
    
Called when the workbench/console/business-central deploys a new deployment.

Parameters:
event
 
     public void addOnDeploy(@Observes @Deploy DeploymentEvent event) {
         RuntimeManager runtimeManager = .put(event.getDeploymentId(), event.getDeployedUnit().getRuntimeManager());
         ifruntimeManager != null ) { 
             .warn("RuntimeManager for domain {} has been replaced"event.getDeploymentId());
         }
         .put(event.getDeploymentId(), event.getDeployedUnit().getDeployedClasses());
         if != null ) { 
             .fire(new DeploymentProcessedEvent(event.getDeploymentId()));
         }
     }
   
    
Called when the workbench/console/business-central *un*deploys (removes) a deployment.

Parameters:
event
 
     public void removeOnUnDeploy(@Observes @Undeploy DeploymentEvent event) {
         RuntimeManager runtimeManager = .remove(event.getDeploymentId());
         ifruntimeManager == null ) { 
             .warn("RuntimeManager for domain {}  does not exist and can not be undeployed."event.getDeploymentId());
         }
         .remove(event.getDeploymentId());
         if != null ) { 
             .fire(new DeploymentProcessedEvent(event.getDeploymentId()));
         }
     }
     
    // Methods for other beans/resources ------------------------------------------------------------------------------------------
   
    public RuntimeManager getRuntimeManager(String domainName) { 
       return .get(domainName);
    }
    public void disposeRuntimeEngine(RuntimeEngine runtimeEngine) {
        if (runtimeEngine != null) {
            RuntimeManager manager = ((RuntimeEngineImpl) runtimeEngine).getManager();
            manager.disposeRuntimeEngine(runtimeEngine);
        }
    }

    
Retrieve the relevant RuntimeEngine instance.

Parameters:
deploymentId The id of the deployment for the RuntimeEngine.
processInstanceId The process instance id, if available.
Returns:
The RuntimeEngine instance.
    public RuntimeEngine getRuntimeEngine(String deploymentIdLong processInstanceId) {
        RuntimeManager runtimeManager = getRuntimeManager(deploymentId);
        if (runtimeManager == null) {
            throw new DeploymentNotFoundException("No runtime manager could be found for deployment '" + deploymentId + "'.");
        }
        Context<?> runtimeContext;
        ifruntimeManager instanceof PerProcessInstanceRuntimeManager ) { 
            ifprocessInstanceId == null || processInstanceId < 0 ) { 
                ifprocessInstanceId != null ) { 
                    processInstanceId = null;
                }
                // Use the static method here instead of the constructor in order to use mock static magic in the tests
                runtimeContext = ProcessInstanceIdContext.get();
            } else { 
                runtimeContext = ProcessInstanceIdContext.get(processInstanceId);
            }
        } else { 
            runtimeContext = EmptyContext.get();
        }
        return runtimeManager.getRuntimeEngine(runtimeContext);
    }
  
    
Used by classes involved with de/serialzation in order to retrieve (user-defined) clases to be used in de/serialization.

Parameters:
deploymentId The deployment unit id
Returns:
A Collection of Classes that are in the deployment unit
    public Collection<Class<?>> getDeploymentClasses(String deploymentId) { 
        ifemptyDeploymentId(deploymentId) ) { 
            return Collections.emptySet();
        }
        Collection<Class<?>> classes = .get(deploymentId);
        ifclasses == null ) { 
            return Collections.emptySet();
        }
        return classes;
     }
     public Collection<StringgetDeploymentIds() { 
         return .keySet();
     }
     public static boolean emptyDeploymentId(String deploymentId) { 
         return deploymentId == null || deploymentId.trim().isEmpty();
     }
New to GrepCode? Check out our FAQ X