Skip to content

Instantly share code, notes, and snippets.

@bbalakriz
Last active August 5, 2022 09:17
Show Gist options
  • Select an option

  • Save bbalakriz/63a26f6c6438dddc52691141116dc282 to your computer and use it in GitHub Desktop.

Select an option

Save bbalakriz/63a26f6c6438dddc52691141116dc282 to your computer and use it in GitHub Desktop.
package com.test;
import org.jbpm.services.api.service.ServiceRegistry;
import org.jbpm.services.api.ProcessService;
import org.kie.server.services.api.KieServerRegistry;
import org.kie.server.services.impl.locator.ContainerLocatorProvider;
import org.kie.server.services.impl.KieServerLocator;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.Callable;
import java.util.Date;
import java.text.SimpleDateFormat;
public class RouterUtil implements java.io.Serializable {
static final long serialVersionUID = 1 L;
public RouterUtil() {}
static public long startProcessAsync(ProcessContainer container,
Map < String, Object > params) throws Exception {
ServiceRegistry serviceRegistry = ServiceRegistry.get();
ProcessService processService = (ProcessService) serviceRegistry
.service(ServiceRegistry.PROCESS_SERVICE);
KieServerRegistry kieServerRegistry = KieServerLocator.getInstance()
.getServerRegistry();
if (container == null || container.getContainerAlias() == null) {
throw new Exception("failed to get container");
}
String containerId = kieServerRegistry.getContainerId(container
.getContainerAlias(), ContainerLocatorProvider.get()
.getLocator());
long instanceId = 0 L;
if (containerId == null) {
throw new Exception("no container id found for alias " +
container.getContainerAlias());
}
ExecutorService executorService = Executors.newSingleThreadExecutor();
Future < Long > result = executorService.submit(new Callable < Long > () {
public java.lang.Long call() throws Exception {
return processService.startProcess(containerId,
container.getProcessId(), params);
}
});
try {
instanceId = result.get().longValue();
} catch (Exception e) {
System.out.println("Error while starting the process " +
container.getProcessId());
throw e;
}
executorService.shutdown();
return instanceId;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment