这节我们学习下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. I NEED A OFFER!---hdu1203(01背包)

     http://acm.hdu.edu.cn/showproblem.php?pid=1203   Problem Description Speakless很早就想出国,现在他已经考完了所有需要的考 ...

  2. P1420 最长连号

    洛谷——P1420 最长连号 题目描述 输入n个正整数,(1<=n<=10000),要求输出最长的连号的长度.(连号指从小到大连续自然数) 输入输出格式 输入格式: 第一行,一个数n; 第 ...

  3. SeaGlass:手工搭建伪基站监控系统

    “伪基站”即假基站,设备一般由主机和笔记本电脑或手机组成,通过短信群发器.短信发信机等相关设备能够搜取以其为中心.一定半径范围内的手机卡信息,利用2G移动通信的缺陷,通过伪装成运营商的基站,冒用他人手 ...

  4. 从JVM的角度看JAVA代码--代码优化

    从JVM的角度看JAVA代码–代码优化 从JVM的角度看JAVA代码代码优化 片段一反复计算 片段二反复比較 在JVM载入优化为class文件,运行class文件时,会有JIT(Just-In-Tim ...

  5. 再谈用java实现Smtp发送邮件之Socket编程

    很多其它内容欢迎訪问个人站点   http://icodeyou.com 前几天利用Socket实现了用java语言搭建webserver,全程下来应该会对Socket这个东西已经使用的很熟悉了.尽管 ...

  6. sqlzoo练习答案--SELECT within SELECT Tutorial

    This tutorial looks at how we can use SELECT statements within SELECT statements to perform more com ...

  7. 如何将Python的py程序打包成跨平台的exe文件

    在编写了自己的第一个可以爬写网页源代码的程序之后,发现如果在没有安装了pythonLDLE程序的计算机上根本就跑不出来.所以开始寻找可以将程序打包成跨平台运行的exe文件. 经过自己费力的谷歌没有一个 ...

  8. 打造极致性能数据库中间件丨LVS+Keepalive+华为云DDM之理论篇

    背景说明 华为云分布式数据库中间件(Distributed Database Middleware,简称DDM),专注于解决数据库分布式扩展问题,突破了传统数据库的容量和性能瓶颈,实现海量数据高并发访 ...

  9. 深度学习笔记之关于总结、展望、参考文献和Deep Learning学习资源(五)

    不多说,直接上干货! 十.总结与展望 1)Deep learning总结 深度学习是关于自动学习要建模的数据的潜在(隐含)分布的多层(复杂)表达的算法.换句话来说,深度学习算法自动的提取分类需要的低层 ...

  10. A Simple Example About Privileged Methods in JavaScript

    Douglas Crockford classified the "class methods" in JavaScript into three types: private, ...