这节我们学习下Activiti的7大对象,首先我们从ProcessEngine接口开始看。

/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine; import org.activiti.form.api.FormRepositoryService; /**
* Provides access to all the services that expose the BPM and workflow operations.
*
* <ul>
* <li>
* <b>{@link org.activiti.engine.RuntimeService}: </b> Allows the creation of {@link org.activiti.engine.repository.Deployment}s and the starting of and searching on
* {@link org.activiti.engine.runtime.ProcessInstance}s.</li>
* <li>
* <b>{@link org.activiti.engine.TaskService}: </b> Exposes operations to manage human (standalone) {@link org.activiti.engine.task.Task}s, such as claiming, completing and assigning tasks</li>
* <li>
* <b>{@link org.activiti.engine.IdentityService}: </b> Used for managing {@link org.activiti.engine.identity.User}s, {@link org.activiti.engine.identity.Group}s and the relations between them<</li>
* <li>
* <b>{@link org.activiti.engine.ManagementService}: </b> Exposes engine admin and maintenance operations</li>
* <li>
* <b>{@link org.activiti.engine.HistoryService}: </b> Service exposing information about ongoing and past process instances.</li>
* </ul>
*
* Typically, there will be only one central ProcessEngine instance needed in a end-user application. Building a ProcessEngine is done through a {@link ProcessEngineConfiguration} instance and is a
* costly operation which should be avoided. For that purpose, it is advised to store it in a static field or JNDI location (or something similar). This is a thread-safe object, so no special
* precautions need to be taken.
*
* @author Tom Baeyens
* @author Joram Barrez
*/
public interface ProcessEngine { /** the version of the activiti library */
public static String VERSION = "6.0.0.4"; // Note the extra .x at the end. To cater for snapshot releases with different database changes /**
* The name as specified in 'process-engine-name' in the activiti.cfg.xml configuration file. The default name for a process engine is 'default
*/
String getName(); void close(); RepositoryService getRepositoryService(); RuntimeService getRuntimeService(); FormService getFormService(); TaskService getTaskService(); HistoryService getHistoryService(); IdentityService getIdentityService(); ManagementService getManagementService(); DynamicBpmnService getDynamicBpmnService(); ProcessEngineConfiguration getProcessEngineConfiguration(); FormRepositoryService getFormEngineRepositoryService(); org.activiti.form.api.FormService getFormEngineFormService();
}

可以看出来ProcessEngine顶级接口定义了一些Service,后面我们会详细说各个Service的作用。

可以看到他的实现类有ProcessEngineImpl,接下来我们看下ProcessEngineImpl类:

 /* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.impl; import java.util.Map; import org.activiti.engine.DynamicBpmnService;
import org.activiti.engine.FormService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.IdentityService;
import org.activiti.engine.ManagementService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.delegate.event.ActivitiEventType;
import org.activiti.engine.delegate.event.impl.ActivitiEventBuilder;
import org.activiti.engine.impl.asyncexecutor.AsyncExecutor;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.activiti.engine.impl.cfg.TransactionContextFactory;
import org.activiti.engine.impl.interceptor.CommandExecutor;
import org.activiti.engine.impl.interceptor.SessionFactory;
import org.activiti.form.api.FormRepositoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; /**
* @author Tom Baeyens
*/
public class ProcessEngineImpl implements ProcessEngine { private static Logger log = LoggerFactory.getLogger(ProcessEngineImpl.class); protected String name;
protected RepositoryService repositoryService;
protected RuntimeService runtimeService;
protected HistoryService historicDataService;
protected IdentityService identityService;
protected TaskService taskService;
protected FormService formService;
protected ManagementService managementService;
protected DynamicBpmnService dynamicBpmnService;
protected FormRepositoryService formEngineRepositoryService;
protected org.activiti.form.api.FormService formEngineFormService;
protected AsyncExecutor asyncExecutor;
protected CommandExecutor commandExecutor;
protected Map<Class<?>, SessionFactory> sessionFactories;
protected TransactionContextFactory transactionContextFactory;
protected ProcessEngineConfigurationImpl processEngineConfiguration; public ProcessEngineImpl(ProcessEngineConfigurationImpl processEngineConfiguration) {
this.processEngineConfiguration = processEngineConfiguration;
this.name = processEngineConfiguration.getProcessEngineName();
this.repositoryService = processEngineConfiguration.getRepositoryService();
this.runtimeService = processEngineConfiguration.getRuntimeService();
this.historicDataService = processEngineConfiguration.getHistoryService();
this.identityService = processEngineConfiguration.getIdentityService();
this.taskService = processEngineConfiguration.getTaskService();
this.formService = processEngineConfiguration.getFormService();
this.managementService = processEngineConfiguration.getManagementService();
this.dynamicBpmnService = processEngineConfiguration.getDynamicBpmnService();
this.asyncExecutor = processEngineConfiguration.getAsyncExecutor();
this.commandExecutor = processEngineConfiguration.getCommandExecutor();
this.sessionFactories = processEngineConfiguration.getSessionFactories();
this.transactionContextFactory = processEngineConfiguration.getTransactionContextFactory();
this.formEngineRepositoryService = processEngineConfiguration.getFormEngineRepositoryService();
this.formEngineFormService = processEngineConfiguration.getFormEngineFormService(); if (processEngineConfiguration.isUsingRelationalDatabase() && processEngineConfiguration.getDatabaseSchemaUpdate() != null) {
commandExecutor.execute(processEngineConfiguration.getSchemaCommandConfig(), new SchemaOperationsProcessEngineBuild());
} if (name == null) {
log.info("default activiti ProcessEngine created");
} else {
log.info("ProcessEngine {} created", name);
} ProcessEngines.registerProcessEngine(this); if (asyncExecutor != null && asyncExecutor.isAutoActivate()) {
asyncExecutor.start();
} if (processEngineConfiguration.getProcessEngineLifecycleListener() != null) {
processEngineConfiguration.getProcessEngineLifecycleListener().onProcessEngineBuilt(this);
} processEngineConfiguration.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createGlobalEvent(ActivitiEventType.ENGINE_CREATED));
} public void close() {
ProcessEngines.unregister(this);
if (asyncExecutor != null && asyncExecutor.isActive()) {
asyncExecutor.shutdown();
} commandExecutor.execute(processEngineConfiguration.getSchemaCommandConfig(), new SchemaOperationProcessEngineClose()); if (processEngineConfiguration.getProcessEngineLifecycleListener() != null) {
processEngineConfiguration.getProcessEngineLifecycleListener().onProcessEngineClosed(this);
} processEngineConfiguration.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createGlobalEvent(ActivitiEventType.ENGINE_CLOSED));
} // getters and setters
// ////////////////////////////////////////////////////// public String getName() {
return name;
} public IdentityService getIdentityService() {
return identityService;
} public ManagementService getManagementService() {
return managementService;
} public TaskService getTaskService() {
return taskService;
} public HistoryService getHistoryService() {
return historicDataService;
} public RuntimeService getRuntimeService() {
return runtimeService;
} public RepositoryService getRepositoryService() {
return repositoryService;
} public FormService getFormService() {
return formService;
} public DynamicBpmnService getDynamicBpmnService() {
return dynamicBpmnService;
} public ProcessEngineConfigurationImpl getProcessEngineConfiguration() {
return processEngineConfiguration;
} public FormRepositoryService getFormEngineRepositoryService() {
return formEngineRepositoryService;
} public org.activiti.form.api.FormService getFormEngineFormService() {
return formEngineFormService;
}
}

可以看到在ProcessEngine的实现类ProcessEngineImpl里边初始化了各个Service。


RepositoryService

Activiti 中每一个不同版本的业务流程的定义都需要使用一些定义文件,部署文件和支持数据 ( 例如 BPMN2.0 XML 文件,表单定义文件,流程定义图像文件等 ),这些文件都存储在 Activiti 内建的 Repository 中。Repository Service 提供了对 repository 的存取服务。

RuntimeService

Activiti 中,每当一个流程定义被启动一次之后,都会生成一个相应的流程对象实例。Runtime Service 提供了启动流程、查询流程实例、设置获取流程实例变量等功能。此外它还提供了对流程部署,流程定义和流程实例的存取服务。

TaskService

在 Activiti 中业务流程定义中的每一个执行节点被称为一个 Task,对流程中的数据存取,状态变更等操作均需要在 Task 中完成。Task Service 提供了对用户 Task 和 Form相关的操作。它提供了运行时任务查询、领取、完成、删除以及变量设置等功能。

IdentityService

Activiti 中内置了用户以及组管理的功能,必须使用这些用户和组的信息才能获取到相应的 Task。Identity Service 提供了对 Activiti 系统中的用户和组的管理功能。

ManagementService

Management Service 提供了对 Activiti 流程引擎的管理和维护功能,这些功能不在工作流驱动的应用程序中使用,主要用于 Activiti 系统的日常维护。

HistoryService

History Service 用于获取正在运行或已经完成的流程实例的信息,与 Runtime Service 中获取的流程信息不同,历史信息包含已经持久化存储的永久信息,并已经被针对查询优化。

FormService

Activiti 中的流程和状态 Task 均可以关联业务相关的数据。通过使用 Form Service 可以存取启动和完成任务所需的表单数据并且根据需要来渲染表单。

DynamicBpmnService

一个新增的服务,用于动态修改流程中的一些参数信息等,是引擎中的一个辅助的服务

FormRepositoryService

部署表单等

以上就是比较常用的一些Service,下面我们看看如何获取Service

//创建一个流程引擎
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//获取RepositoryService
RepositoryService repositoryService = processEngine.getRepositoryService();
//获取RuntimeService
RuntimeService runtimeService = processEngine.getRuntimeService();
//获取TaskService
TaskService taskService = processEngine.getTaskService();
//获取FormService
FormService formService = processEngine.getFormEngineFormService();
//获取DynamicBpmnService
DynamicBpmnService dynamicBpmnService = processEngine.getDynamicBpmnService();
//获取ManagementService
ManagementService managementService = processEngine.getManagementService();

以上的代码在创建流程引擎的时候也会把对应的表创建好,下一节我们看Activiti对应的表的含义。最后贴上一个activiti.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/db_activiti?characterEncoding=utf8" />
<property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
<property name="jdbcUsername" value="root" />
<property name="jdbcPassword" value="" />
<property name="databaseSchemaUpdate" value="true" />
</bean> </beans>

Activiti6.0教程 Service用途剖析 (二)的更多相关文章

  1. Activiti6.0教程 Eclipse安装Activiti Diagram插件(一)

    最近这段时间打算出一个Activiti6.0的详细教程,Activiti作为一个流行的开源工作流引擎,正在不断发展,其6.0版本以API形式提供服务,而之前版本基本都是要求我们的应用以JDK方式与其交 ...

  2. Activiti6.0教程 28张表解析 (三)

    使用Activit的朋友都知道Activiti对应的有28张表,今天我们就来说下Activit中28张表对应的含义是什么? 如何创建表? 在Activiti中创建表有三种方式,我们依次来看下: 一.通 ...

  3. Asp.Net MVC4.0 官方教程 入门指南之二--添加一个控制器

    Asp.Net MVC4.0 官方教程 入门指南之二--添加一个控制器 MVC概念 MVC的含义是 “模型-视图-控制器”.MVC是一个架构良好并且易于测试和易于维护的开发模式.基于MVC模式的应用程 ...

  4. NPOI 2.0 教程(二):编辑既存的EXCEL文件

    NPOI 2.0 教程(二):编辑既存的EXCEL文件 分类: C#技术 2014-03-11 15:40 993人阅读 评论(3) 收藏 举报 c#excelNPOI 转载请注明出处 http:// ...

  5. 零基础快速入门SpringBoot2.0教程 (二)

    一.SpringBoot2.x使用Dev-tool热部署 简介:介绍什么是热部署,使用springboot结合dev-tool工具,快速加载启动应用 官方地址:https://docs.spring. ...

  6. Activiti工作流框架学习笔记(二)之springboot2.0整合工作流Activiti6.0

    以前在工作当中做过不少与工作流Activiti有关的工作,当时都是spring集成activiti5.22的项目,现在回过头去看,其实版本已经稍微老了,因此,基于先前的工作经验,决定用较新版本的技术来 ...

  7. ASP.NET Identity 3.0教程

    (此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:我相信有些人和我一样,已经开始把ASP.NET 5用于产品开发了.不过现在最大的问题是 ...

  8. Linux Shell系列教程之(十二)Shell until循环

    本文是Linux Shell系列教程的第(十二)篇,更多Linux Shell教程请看:Linux Shell系列教程 在上两篇文章Linux Shell系列教程之(十)Shell for循环和Lin ...

  9. 11、四大组件之二-Service高级(二)Native Service

    一.Service的分类 1.1>Android Service 使用Java编写在JVM中运行的服务 1.2>Native Service 使用C/C++完成的服务,一般在系统开始时完成 ...

随机推荐

  1. POJ 1780 【手工递归】【欧拉回路】

    题意: 1.提供密码的位数. 2.密码的输入可以一直保持,取后n位作为密码.如果密码正确则开锁. 3.设计一种方法使得在输入最少的情况下破译.(即保证每个密码只输入一次) 4.输出输入的数字的序列. ...

  2. 高清(200万像素)多灯红外防水枪型网络摄像机 DH-IPC-HFW5200-IRA

    DH-IPC-HFW5200-IRA-0722A http://download.dahuatech.com/instruction_download.php?classOne=3907&cl ...

  3. jmeter的线程组执行顺序不以其出现的顺序发生变化

    jmeter可以同时配置多个线程组,那么他们的执行顺序是什么呢?和他们出现的顺序有什么关系呢? 先说下几个特殊的线程组:tearDown线程组和setUp线程组,tearDown线程组一定在最后执行, ...

  4. Oracle 行转列小结

    近期在工作中.对行转列进行了应用,在此做一个简单的小结. 转换步骤例如以下:     1.创建表结构 CREATE TABLE RowToCol ( ID NUMBER(10) not null, U ...

  5. Samba简单配置--匿名用户共享资料可读可写的实现

    http://e-mailwu.blog.163.com/blog/static/65104036200931893921923/ http://www.cnblogs.com/god_like_do ...

  6. 【转】 一张图看懂开源许可协议,开源许可证GPL、BSD、MIT、Mozilla、Apache和LGPL的区别

    原文:http://blog.csdn.net/testcs_dn/article/details/38496107 ----------------------------------------- ...

  7. 微信小程序 自定义组件(stepper)

    项目目录: 步骤一:创建组件 声明这一组文件为自定义组件 stepper.json { "component": true, "usingComponents" ...

  8. 【转】PLSQL_标准删除的方式Delete/Drop/Truncate区别和比较

  9. LoadRunner中存储表格参数------关联数组

    主要用到 web_reg_save_param_ex函数("Scope=All",), sprintf( CProdNo,"{CProdNo_%d}",i ); ...

  10. jquery验证后ajax提交,返回消息怎样统一显示的问题

    /* jquery验证后ajax提交.返回消息怎样跟jquery验证体系统一显示的问题,网上查了非常多资料.都没有找到明白的答案,通过数小时的尝试,最终攻克了,现举一个简单的样例,给须要的人參考參考吧 ...