How to Create a Process Instance with the Drools Knowledge API

import java.util.Map;

import org.drools.KnowledgeBase;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.runtime.process.ProcessInstance;
import org.drools.runtime.StatefulKnowledgeSession;

public final class DroolsSample {

  public static void main(final String[] args) {
    final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

    kbuilder.add(ResourceFactory.newClassPathResource("SampleProcess.bpmn"), ResourceType.BPMN2); // or newByteArrayResource, newDescrResource, newFileResource, newInputStreamResource, newReaderResource, newUrlResource

    final KnowledgeBase kbase = kbuilder.newKnowledgeBase();

    final StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

    final Map<String, Object> params = ...

    final ProcessInstance kinstance = ksession.createProcessInstance("SampleProcess", params);

    ksession.startProcessInstance(kinstance.getId());
  }

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s