example:
repositoryService
.createDeployment()
.addClasspathResource(resourceCP)
.deploy();
當調用上述代碼時activiti的內部調用流程如上述圖所示.
每個DeploymentBuilder實例對應一個DeploymentEntity實例,DeploymentEntity是發佈對應的持久化對象,其對應流程數據庫中的act_re_deployment表.
public class DeploymentEntity implements Serializable, Deployment, PersistentObject {
private
static
final
long
serialVersionUID
= 1L;
protected
String
id
;
protected
String
name
;
protected
String
category
;
protected
Map<String, ResourceEntity>
resources
;
protected
Date
deploymentTime
;
protected
boolean
isNew
;
........................
}
爲發佈中添加的每個resource都對應一個ResourceEntity實例,它對應流程數據庫中的act_ge_bytearray表.
資源文件在數據庫中存爲blob類型.
public class ResourceEntity implements Serializable, PersistentObject {
private static final long serialVersionUID = 1L;
protected String id;
protected String name;
protected byte[] bytes ;
protected String deploymentId;
protected boolean generated = false;
...............................
}
當調用DeploymentBuilder.deploy()後DeploymentBuilder.將其發佈任務委託給DeployCmd.注:命令模式是activiti整個架構的基礎.這使得activit的源碼很是清晰明瞭.
真正的發佈行爲是DeployCmd來完成的.
它主要有兩個操做
Context得到和當前執行線程的ComdmandContext棧、
ProcessEngineConfigurationImpl棧
、
ExecutionContext
y棧和
JobExecutorContext
等,他們都是
ThreadLocal變量,以保證每一個線程都有它們本身持有的不一樣副本實例,屏蔽了線程的資源共享問題.
在第一步操做中關心的是CommandContext
public class CommandContext {
private
static
Logger
log
= LoggerFactory.getLogger(CommandContext.
class
);
protected
Command< ? >
command
;
protected
TransactionContext
transactionContext
;
protected
Map<Class< ? >, SessionFactory>
sessionFactories
;
protected
Map<Class< ? >, Session>
sessions
=
new
HashMap<Class< ? >, Session>();
protected
Throwable
exception
=
null
;
protected
LinkedList<AtomicOperation>
nextOperations
=
new
LinkedList<AtomicOperation>();
protected
ProcessEngineConfigurationImpl
processEngineConfiguration
;
protected
FailedJobCommandFactory
failedJobCommandFactory
;
.......................................
}
它將一個線程和session及事務對應起來以保證一次流程邏輯中定義的原子操做的正確性.
第二步操做將流程文件(bpmn.xml)轉化爲流程對象和將規則文件(.drl等)添加到
KnowledgeBuilder中.
下節將看一看BpmnModel是什麼.