jBPM 6.0 最終版已與上月底發佈,與jBPM 5相比有很大變化,本文從API編程的角度去簡單說說jBPM 6,本文涉及到內容包括:
java
jBPM 6最主要的兩個接口指的是KieSession (ProcessRuntime)和TaskService。編程
KieSession 是最經常使用與引擎交互的接口,一個KieSession容許應用與引擎創建一個iterative conversation,where the state of the session is kept across invocations. The reasoning process may be triggered multiple times for the same set of data. 當應用程序完成使用session,dispose()方法必須被調運,這樣是爲了free the resources and used memory。
session
使用KieSession執行企業規則文件的例子:
ui
KieServices kieServices = KieServices.Factory.get(); KieContainer kContainer = kieServices.getKieClasspathContainer(); KieSession kSession = kContainer.newKieSession(); for( Object fact : facts ) { kSession.insert( fact ); } kSession.fireAllRules(); kSession.dispose();
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add(ResourceFactory.newClassPathResource("sample.bpmn"), ResourceType.BPMN2); KnowledgeBase kbase = kbuilder.newKnowledgeBase(); KieSession kSession = kbase.newStatefulKnowledgeSession(); kSession.startProcess("com.sample.processid"); kSession.signalEvent("SomeEvent", null); kSession.startProcess("com.sample.processid"); kSession.dispose();
TaskService能夠看做是對外提供的一個統一接入點,用來獲取全部TaskService服務。(The Task Service Entry Point serves as facade of all the other services, providing a single entry point to access to all the services)spa
jBPM 6運行狀態管理(Runtime Manager)使用本地 KieSession, 本地 TaskService,與jBPM 5相比,隱藏了複雜的設定過程。
code
Runtime Manager管理三種類型的session:
接口
以下爲一個session管理過程示例:
ip
RuntimeManager manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment); RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(id)); KieSession ksession = runtime.getKieSession(); // do something here, e.g. ksession.startProcess(「org.jbpm.hello」); manager.disposeRuntimeEngine(engine); manager.close();
jBPM 6默認安裝到JEE6兼容的JBoss 7容器,CDI是JEE6的基本組件,jBPM 6也提供了 將jBPM相關的服務能夠注入到CDI環境。
get
以下注冊RuntimeManager示例:it
@Inject @Singleton RuntimeManager singletonManager;
@Inject TaskService taskService;