IBM BPM, V8.0.1, All platforms > Programming IBM BPM > Developing client applications for BPEL processes and tasks > Developing EJB client applications > Developing applications for BPEL processes > Manage the lifecycle of a BPEL process > Starting BPEL processes
Starting a long-running process that contains a non-unique starting service
A long-running process can be started through multiple initiating receive or pick activities. You can use the initiate method to start the process. If the starting service is not unique, for example, the process starts with multiple receive or pick activities, or a pick activity that has multiple onMessage definitions, then you must identify the service to be called.
Procedure
- Optional: List the process templates to find the name of the process you want to start.
This step is optional if you already know the name of the process.
FilterOptions fo = new FilterOptions(); fo.setSelectedAttributes("PTID"); fo.setQueryCondition("EXECUTION_MODE=EXECUTION_MODE_LONG_RUNNING"); EntityResultSet result = process.queryEntities("PROCESS_TEMPLATE", fo, null, null);The results are sorted by name. The query returns an array containing the first 50 sorted templates that can be started as long-running processes.
- Determine the starting service to be called.
Entity entity = (Entity) result.getEntities().get(0); PTID ptid = (PTID) entity.getAttributeValue("PTID"); ActivityServiceTemplateData[] startActivities = process.getStartActivities(ptid);- Start the process with an input message of the appropriate type.
When you create the message, you must specify its message type name so that the message definition is contained.
If you specify a process-instance name, it must not start with an underscore. If a process-instance name is not specified, the process instance ID (PIID) in String format is used as the name.
ActivityServiceTemplateData activity = startActivities[0]; //create a message for the service to be called ClientObjectWrapper input = process.createMessage (activity.getServiceTemplateID(), activity.getActivityTemplateID(), activity.getInputMessageTypeName()); DataObject myMessage = null; if ( input.getObject()!= null && input.getObject() instanceof DataObject ) { myMessage = (DataObject)input.getObject(); //set the strings in the message, for example, a customer name myMessage.setString("CustomerName", "Smith");} //start the process PIID piid = process.sendMessage(activity.getServiceTemplateID(), activity.getActivityTemplateID(), input);This action creates an instance and passes some customer data. When the process starts, the operation returns the object ID of the new process instance to the caller.
The starter of the process instance is set to the caller of the request and receives a work item for the process instance. The process administrators, readers, and editors of the process instance are determined and receive work items for the process instance. The follow-on activity instances are determined. These are started automatically or, if they are human task, receive, or pick activities, work items are created for the potential owners.
Related concepts:
Authorization for creating and starting BPEL processes