1:工作流引擎?
ProcessEngine對象,這是Activiti工作的核心。負責生成流程運行時的各種實例及數(shù)據(jù)、監(jiān)控和管理流程的運行。?
2:BPMN?
業(yè)務(wù)流程建模與標注(Business Process Model and Notation,BPMN) ,描述流程的基本符號,包括這些圖元如何組合成一個業(yè)務(wù)流程圖(Business Process Diagram),如下所示:

圖示說明:
(空)開始事件?是我們流程的入口。
用戶任務(wù)是流程中與操作者相關(guān)的任務(wù)聲明。 注意第一個任務(wù)分配給accountancy組, 第二個任務(wù)分配給management組。 參考用戶任務(wù)分配章節(jié)了解更多關(guān)于用戶任務(wù)分配人員和群組的問題。
當流程達到空結(jié)束事件就會結(jié)束。
這些元素都使用連線連接。 這些連線擁有source?和?target屬性, 定義了連線的方向。
3:數(shù)據(jù)庫
Activiti的后臺是有數(shù)據(jù)庫的支持,所有的表都以ACT_開頭。 第二部分是表示表的用途的兩個字母標識。 用途也和服務(wù)的API對應(yīng)。?
ACT_RE_*: ‘RE’表示repository。 這個前綴的表包含了流程定義和流程靜態(tài)資源 (圖片,規(guī)則,等等)。?
ACT_RU_*: ‘RU’表示runtime。 這些運行時的表,包含流程實例,任務(wù),變量,異步任務(wù),等運行中的數(shù)據(jù)。 Activiti只在流程實例執(zhí)行過程中保存這些數(shù)據(jù), 在流程結(jié)束時就會刪除這些記錄。 這樣運行時表可以一直很小速度很快。?
ACT_ID_*: ‘ID’表示identity。 這些表包含身份信息,比如用戶,組等等。?
ACT_HI_*: ‘HI’表示history。 這些表包含歷史數(shù)據(jù),比如歷史流程實例, 變量,任務(wù)等等。?
ACT_GE_*: 通用數(shù)據(jù), 用于不同場景下,如存放資源文件。
engine:?引擎執(zhí)行的表。必須。
identity:?包含用戶,群組,用戶與組之間的關(guān)系的表。????????? 這些表是可選的,只有使用引擎自帶的默認身份管理時才需要。
history:?包含歷史和審計信息的表??蛇x的:歷史級別設(shè)為none時不會使用。????????? 注意這也會引用一些需要把數(shù)據(jù)保存到歷史表中的功能(比如任務(wù)的評論)。
4.數(shù)據(jù)源
databaseSchemaUpdate:???????????? 設(shè)置流程引擎啟動和關(guān)閉時如何處理數(shù)據(jù)庫表。
false(默認):檢查數(shù)據(jù)庫表的版本和依賴庫的版本,????????????????? 如果版本不匹配就拋出異常。
true: 構(gòu)建流程引擎時,執(zhí)行檢查,如果需要就執(zhí)行更新。????????????????? 如果表不存在,就創(chuàng)建。
create-drop: 構(gòu)建流程引擎時創(chuàng)建數(shù)據(jù)庫表,????????????????? 關(guān)閉流程引擎時刪除這些表。
5.代碼示例
// Create Activiti process engine
ProcessEngine processEngine = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration().buildProcessEngine();
// Get Activiti services
RepositoryService repositoryService = processEngine.getRepositoryService();
RuntimeService runtimeService = processEngine.getRuntimeService();
// Deploy the process definition
repositoryService
.createDeployment().addClasspathResource("FinancialReportProcess.bpmn20.xml").deploy();
// Start a process instance
String procId = runtimeService.startProcessInstanceByKey("financialReport").getId();
// Get the first task
TaskService taskService = processEngine.getTaskService();
List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup("accountancy").list();
for (Task task : tasks) {
System.out.println("Following task is available for accountancy group: " + task.getName());
// claim it
taskService.claim(task.getId(), "fozzie");
}
// Verify Fozzie can now retrieve the task
tasks= taskService.createTaskQuery().taskAssignee("fozzie").list();
for (Task task : tasks) {
System.out.println("Task for fozzie: " + task.getName());
// Complete the task
taskService.complete(task.getId());
}
System.out.println("Number of tasks for fozzie: "+ taskService.createTaskQuery().taskAssignee("fozzie").count());
// Retrieve and claim the second task
tasks= taskService.createTaskQuery().taskCandidateGroup("management").list();
for (Task task : tasks) {
System.out.println("Following task is available for accountancy group: " + task.getName());
taskService.claim(task.getId(), "kermit");
}
// Completing the second task ends the process
for (Task task : tasks) {
taskService.complete(task.getId());
}
// verify that the process is actually finished
HistoryService historyService = processEngine.getHistoryService();
HistoricProcessInstance historicProcessInstance =historyService.createHistoricProcessInstanceQuery().processInstanceId(procId).singleResult();
System.out.println("Process instance end time: " + historicProcessInstance.getEndTime());