17.3. EJB Interface

Starting with version 6.1, the BPM Suite execution engine supports an EJB interface for accessing KieSession and TaskService remotely. This allows for close transaction integration between the execution engine and remote customer applications.
The implementation of this interface is a single, framework independent and container agnostic API that can be used with framework specific code. The services are exposed using the jbpm.services.api and the org.jbpm.services.ejb package and described in the next section. There is also support for CDI via the org.jbpm.services.cdi package.
The implementation doesn't support a RuleService at this time, but the ProcessService class exposes an execute method that allows you to use various rule related commands, like InsertCommand and FireAllRulesCommand.

Deployment of EJB Client

The EJB interface is currently only supported on Red Hat JBoss EAP. An implementation client in the form of a WAR file is available and can be extracted from the Maven Repository for Red Hat JBoss BPM Suite from the customer portal. This EJB client is present in the Maven Repository in the form of a JAR file: jbpm-services-ejb-client-VERSION-redhat-MINOR.jar.
Note that the inclusion of EJB doesn't mean that CDI based services will be replaced. CDI And EJB can be used together but this is not recommended. Since EJB's are not available by default in Business Central, the package kie-services must always be present in the classpath. The EJB services are suitable for embedded use cases.

17.3.1. EJB Interface Methods

There are 5 main service interfaces that can be used by remote EJB clients. These methods are present in the following packages:
  1. org.jbpm.services.ejb.api: the extension to the Services API for EJB needs.
  2. org.jbpm.services.ejb.impl: EJB wrappers on top of the core service implementation.
  3. org.jbpm.services.ejb.client: The EJB remote client implementation that works on JBoss EAP only.
  • DefinitionService: Use this interface to gather information about processes (id, name and version), process variables (name and type), defined reusable subprocesses, domain specific service and user tasks and user task input and outputs.
  • DeploymentService: Use this interface to initiate deployments and un-deployments. Methods include deploy, undeploy, getRuntimeManager, getDeployedUnits, isDeployed, activate, deactivate and getDeployedUnit. Calling the deploy method with an instance of DeploymentUnit deploys it into the runtime engine by building RuntimeManager instance for the deployed unit. Upon successful deployment an instance of DeployedUnit instance is created and cached for further usage.
    These methods only work if the artifact/project is already installed in a Maven repository.
  • ProcessService: Use this interface to control the lifecycle of one or more Processes and Work Items.
  • RuntimeDataService: Use this interface to retrieve data about the runtime: process instances, process definitions, node instance information and variable information. It includes several convenience methods for gathering task information based on owner, status and time.
  • UserTaskService: Use this interface to control the lifecycle of a user task. Methods include all the usual ones: activate, start, stop, execute amongst others.
A synchronization service that syncs information between Business Central and the EJBs is also available. The synchronization interval can be set with the org.jbpm.deploy.sync.int system property.

Note

You must wait for the synchronization service to finish its synchronization of information before trrying to access this updated information via REST. Until this synchronization is finished the EJBs will not see changes done via REST.

17.3.2. Generating the EJB Services WAR

This example shows you how to create an EJB Services WAR using the new EJB Interface.
  • Update the persistence.xml file in Business Central. Edit the property hibernate.hbm2ddl.auto and set its value to update (instead of create).
  • Register the Human Task CallBack using a startup class:
    @Singleton
    @Startup
    public class StartupBean {
    
    @PostConstruct
    public void init()
    { System.setProperty("org.jbpm.ht.callback", "jaas"); }
    
    }
  • Generate the WAR file: mvn assembly:assembly
  • Deploy the generated war file (sample-war-ejb-app.war) in the JBoss EAP instance that JBoss BPM Suite 6.1 is running in.

    Note

    If deploying on a JBoss EAP container separate from the one where JBoss BPM Suite is running, you need to:
    1. You need to configure your application/app server to invoke a remote EJB.
    2. You need to configure your application/app server to propagate the security context.

    Warning

    When you deploy your EJB WAR on the same instance of JBoss EAP, avoid using the Singleton strategy for your runtime sessions. If you use the Singleton strategy, both applications will load the same ksession instance from the underlying file system and cause optimistic lock exceptions.
  • To test, create a simple web application and inject the EJB Services:
    @EJB(lookup = "ejb:/sample-war-ejb-app/ProcessServiceEJBImpl!org.jbpm.services.ejb.api.ProcessServiceEJBRemote")
    private ProcessServiceEJBRemote processService;
    
    @EJB(lookup = "ejb:/sample-war-ejb-app/UserTaskServiceEJBImpl!org.jbpm.services.ejb.api.UserTaskServiceEJBRemote")
    private UserTaskServiceEJBRemote userTaskService;
    
    @EJB(lookup = "ejb:/sample-war-ejb-app/RuntimeDataServiceEJBImpl!org.jbpm.services.ejb.api.RuntimeDataServiceEJBRemote")
    private RuntimeDataServiceEJBRemote runtimeDataService;