前面关于eventType的属性值的配置简单的说了一下,activiti支持的值如下表所示:这是我摘抄的activiti官网的

Event 的名字 描述 Event的类名

ENGINE_CREATED

The process-engine this listener is attached to, has been created and is ready for API-calls.

org.activiti…​ActivitiEvent

ENGINE_CLOSED

The process-engine this listener is attached to, has been closed. API-calls to the engine are no longer possible.

org.activiti…​ActivitiEvent

ENTITY_CREATED

A new entity is created. The new entity is contained in the event.

org.activiti…​ActivitiEntityEvent

ENTITY_INITIALIZED

A new entity has been created and is fully initialized. If any children are created as part of the creation of an entity, this event will be fired AFTER the create/initialisation of the child entities as opposed to the ENTITY_CREATE event.

org.activiti…​ActivitiEntityEvent

ENTITY_UPDATED

An existing is updated. The updated entity is contained in the event.

org.activiti…​ActivitiEntityEvent

ENTITY_DELETED

An existing entity is deleted. The deleted entity is contained in the event.

org.activiti…​ActivitiEntityEvent

ENTITY_SUSPENDED

An existing entity is suspended. The suspended entity is contained in the event. Will be dispatched for ProcessDefinitions, ProcessInstances and Tasks.

org.activiti…​ActivitiEntityEvent

ENTITY_ACTIVATED

An existing entity is activated. The activated entity is contained in the event. Will be dispatched for ProcessDefinitions, ProcessInstances and Tasks.

org.activiti…​ActivitiEntityEvent

JOB_EXECUTION_SUCCESS

A job has been executed successfully. The event contains the job that was executed.

org.activiti…​ActivitiEntityEvent

JOB_EXECUTION_FAILURE

The execution of a job has failed. The event contains the job that was executed and the exception.

org.activiti…​ActivitiEntityEvent and org.activiti…​ActivitiExceptionEvent

JOB_RETRIES_DECREMENTED

The number of job retries have been decremented due to a failed job. The event contains the job that was updated.

org.activiti…​ActivitiEntityEvent

TIMER_FIRED

A timer has been fired. The event contains the job that was executed?

org.activiti…​ActivitiEntityEvent

JOB_CANCELED

A job has been canceled. The event contains the job that was canceled. Job can be canceled by API call, task was completed and associated boundary timer was canceled, on the new process definition deployment.

org.activiti…​ActivitiEntityEvent

ACTIVITY_STARTED

An activity is starting to execute

org.activiti…​ActivitiActivityEvent

ACTIVITY_COMPLETED

An activity is completed successfully

org.activiti…​ActivitiActivityEvent

ACTIVITY_CANCELLED

An activity is going to be cancelled. There can be three reasons for activity cancellation (MessageEventSubscriptionEntity, SignalEventSubscriptionEntity, TimerEntity).

org.activiti…​ActivitiActivityCancelledEvent

ACTIVITY_SIGNALED

An activity received a signal

org.activiti…​ActivitiSignalEvent

ACTIVITY_MESSAGE_RECEIVED

An activity received a message. Dispatched before the activity receives the message. When received, a ACTIVITY_SIGNAL or ACTIVITY_STARTED will be dispatched for this activity, depending on the type (boundary-event or event-subprocess start-event)

org.activiti…​ActivitiMessageEvent

ACTIVITY_ERROR_RECEIVED

An activity has received an error event. Dispatched before the actual error has been handled by the activity. The event’s activityId contains a reference to the error-handling activity. This event will be either followed by a ACTIVITY_SIGNALLED event or ACTIVITY_COMPLETE for the involved activity, if the error was delivered successfully.

org.activiti…​ActivitiErrorEvent

UNCAUGHT_BPMN_ERROR

An uncaught BPMN error has been thrown. The process did not have any handlers for that specific error. The event’s activityId will be empty.

org.activiti…​ActivitiErrorEvent

ACTIVITY_COMPENSATE

An activity is about to be compensated. The event contains the id of the activity that is will be executed for compensation.

org.activiti…​ActivitiActivityEvent

VARIABLE_CREATED

A variable has been created. The event contains the variable name, value and related execution and task (if any).

org.activiti…​ActivitiVariableEvent

VARIABLE_UPDATED

An existing variable has been updated. The event contains the variable name, updated value and related execution and task (if any).

org.activiti…​ActivitiVariableEvent

VARIABLE_DELETED

An existing variable has been deleted. The event contains the variable name, last known value and related execution and task (if any).

org.activiti…​ActivitiVariableEvent

TASK_ASSIGNED

A task has been assigned to a user. The event contains the task

org.activiti…​ActivitiEntityEvent

TASK_CREATED

A task has been created. This is dispatched after the ENTITY_CREATE event. In case the task is part of a process, this event will be fired before the task listeners are executed.

org.activiti…​ActivitiEntityEvent

TASK_COMPLETED

A task has been completed. This is dispatched before the ENTITY_DELETE event. In case the task is part of a process, this event will be fired before the process has moved on and will be followed by a ACTIVITY_COMPLETE event, targeting the activity that represents the completed task.

org.activiti…​ActivitiEntityEvent

PROCESS_COMPLETED

A process has been completed. Dispatched after the last activity ACTIVITY_COMPLETED event. Process is completed when it reaches state in which process instance does not have any transition to take.

org.activiti…​ActivitiEntityEvent

PROCESS_CANCELLED

A process has been cancelled. Dispatched before the process instance is deleted from runtime. Process instance is cancelled by API call RuntimeService.deleteProcessInstance

org.activiti…​ActivitiCancelledEvent

MEMBERSHIP_CREATED

A user has been added to a group. The event contains the ids of the user and group involved.

org.activiti…​ActivitiMembershipEvent

MEMBERSHIP_DELETED

A user has been removed from a group. The event contains the ids of the user and group involved.

org.activiti…​ActivitiMembershipEvent

MEMBERSHIPS_DELETED

All members will be removed from a group. The event is thrown before the members are removed, so they are still accessible. No individual MEMBERSHIP_DELETED events will be thrown if all members are deleted at once, for performance reasons.

org.activiti…​ActivitiMembershipEvent

简单的说明:

所有的ENTITY_\*事件关联流程引擎的entity-event事件,具体的entity-event监听的范围有这些:

  • ENTITY_CREATED, ENTITY_INITIALIZED, ENTITY_DELETED: Attachment, Comment, Deployment, Execution, Group, IdentityLink, Job, Model, ProcessDefinition, ProcessInstance, Task, User.

  • ENTITY_UPDATED: Attachment, Deployment, Execution, Group, IdentityLink, Job, Model, ProcessDefinition, ProcessInstance, Task, User.

  • ENTITY_SUSPENDED, ENTITY_ACTIVATED: ProcessDefinition, ProcessInstance/Execution, Task.

补充说明:

事件监听器仅仅会监听流程引擎里面的事件发生,所以如果你有其他的引擎在运行同一个数据库里面,仅仅是在同一个流程引擎中注册的事件监听器会被调用,在其他流程引擎中注册的,即使在同一个JVM运行也不会生效。即使是这样,你需要谨慎和更新/操作实体参与派遣的事件。

三、工作流核心--流程引擎

Activiti的流程引擎穿插在整个工作流中,从ProcessEngine中你可以获取不同的service, ProcessEngine和Service对象都是线程安全的,所以在整个服务器中你只需要存在这些单例对象就可以了。

ProcessEngine和Service对象的创建方式如下:

ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RuntimeService runtimeService = processEngine.getRuntimeService();
RepositoryService repositoryService = processEngine.getRepositoryService();
TaskService taskService = processEngine.getTaskService();
ManagementService managementService = processEngine.getManagementService();
IdentityService identityService = processEngine.getIdentityService();
HistoryService historyService = processEngine.getHistoryService();
FormService formService = processEngine.getFormService();

ProcessEngines.getDefaultProcessEngine(),合理的关闭和初始化所有的ProcessEngine的方法是:ProcessEngines.destroy()和ProcessEngines.init() 。ProcessEngines对象将会扫描所有不同目录的activiti.cfg.xmlactiviti-context.xml文件,对于所有的activiti.cfg.xml文件,内部都会调用Activiti底层的方法,ProcessEngineConfiguration.createProcessEngineConfigurationFromInputStream(inputStream).buildProcessEngine(),对于所有的activiti-context.xml,ProcessEngine将会被以Spring的方式创建,在Spring的上下文创建后,ProcessEngine将会被加进Spring的上下文中。

所有的Service是无状态的,这意味这你可以在具有多个节点的集群上面,每个相同的数据库上面进行调用这些Service,而不用关心是那一台机器调用的,任何服务的调用都是幂等的,无论它何处运行。

注:幂等:是一个数学与计算机学概念,常见于抽象代数中。 在编程中.一个幂等操作的特点是其任意多次执行所产生的影响均与一次执行的影响相同。

一般的,在Activiti的开发中都会先去获取RepositoryService,RepositoryService提供了管理和操作deployments和process definitions,这里就不用细说更多细节的东西了,一个流程定义的java对象其实就是BPMN 2.0文件的副本,流程定义对象也表现了每一步流程步骤的结构和行为。deployment是在工作流引擎里面打包的单位,也就是说它囊括了单个的bpmn文件到流程的文件夹和相关资源,在一个deployment中应该包含多少配置文件取决于开发者。RepositoryService允许发布文件夹,发布一个deployment意味着将会上传到引擎中,在存进数据库之前需要检查和解析,从那时起,deployment中所有的流程就可以启动了.

RepositoryService也提供了一些功能, 比如:

  • 提供在流程引擎中流程定义和deployments的查询。
  • 阻塞或者激活deployment中全部或者部分流程定义。阻塞的意思是指以后这些流程定义将不会执行,直到被激活为止。
  • 获取各种资源文件,例如在deployment中的file,流程图等。
  • 获取流程定义对象的版本信息。

RepositoryService保存了静态信息,而RuntimeService则相反, RuntimeService处理流程定义实例。综上所述,process definition对象是描述流程的结构和具体步骤的表现,而流程实例对象是这个流程定义对象的执行对象。同一时间每一个流程定义对象对应了多个流程实例在运行,RuntimeService同样可以获取存储process variables(流程变量),在流程实例中获取流程变量,在流程中作用于各种execution(比如排他网关通常使用流程变量来判断流程路线的走向),Runtimeservice也允许查询流程实例和执行实例,Executions是取用BPMN 2.0的概念,Execution(也就是执行实例)可以说一个指针指出当前的流程实例的位置。RuntimeService让流程实例的深入执行,一个流程实例有几种wait states,并且RunTimeService提供的不同的方式发信号(外部的触发器触发)给流程实例,流程实例向下执行。

Tasks(任务)在Activiti中需要被实际的人员去完成,关于所有的Task的事情都交给了TaskService处理,例如:

  • 查询任务被分配的组或人员
  • 额外创建任务,这些任务是和流程实例没有关系的。
  • 任务的分配和相关人员的参与
  • 领取任务和完成任务,领取任务就是说当前任务被人获得,并且该任务将由他来完成。完成任务就是执行任务工作,常见的就是填写表单。

IdentityService是很简单的,它就是对users和group的增删改查,重要提示:activiti在运行的时候并不会检测用户,比如现在一个任务可以分配给任何人做,但activiti并不会去检查这个人是否存在于系统里,要知道Activiti是被用来提供LDAP,Active Directory等服务的。

FormService是一个可选用的Service,意味着activiti没有它不会受到影响,不会因此少了功能。这个Service用来提供start form和task form的概念。start form指的是流程实例开始之前展示用户的表单,而task form在用户需要完成任务是展示的表单。Activiti允许用户将这些表单插入流程定义中,但是没必要内嵌进入activiti。

HistoryService提供所有关于工作流引擎的历史数据,在流程执行的时候,一大笔数据会被引擎保存起来,例如流程实例开始的时候,记录了谁在做任务,做了多久,流程实例的走向等等,HistoryService提供查询方法支持这些数据的获取。

ManagementService也是一个在工作流中可选的service,它允许从数据库表和元数据中获取数据,他也提供了对作业(job)的查询和管理,Job被用来处理这些事情:定时器,异步延迟等。

3.1 异常的处理策略

activiti里面最常用的是org.activiti.engine.ActivitiException,他是一个运行时异常,在整个工作流API中都可以抛出,但最好还是根据api在相应的地方使用对应提供的异常类。比如:在RuntimeService中的一个方法

/**
* Called when the task is successfully executed.
* @param taskId the id of the task to complete, cannot be null.
* @throws ActivitiObjectNotFoundException when no task exists with the given id.
*/
void complete(String taskId);

明确的说明的id不能为空,否则抛出ActivitiIllegalArgumentException.

尽管我们想避免抛出很宽泛的异常,但是在activiti的运行执行当中,仍然有超出我们预料的异常出现,不符合下面异常的都会抛出ActivitiException:

ActivitiWrongDbException:在工作流引擎发现数据库中工作流版本和引擎本身的版本不一致的时候抛出。

ActivitiOptimisticLockingException:在并发读写相同数据,乐观锁发生版本不一致抛出异常。

ActivitiClassLoadingException:类加载的时候没有找到或者加载它的时候发生错误会抛出异常。

ActivitiObjectNotFoundException:请求对象或者动作不存在的时候抛出。

ActivitiIllegalArgumentException:在调用含参API的时候,参数值非法。

ActivitiTaskAlreadyClaimedException:在任务已经被认领的时候。

Activiti工作流学习-----基于5.19.0版本(3)的更多相关文章

  1. Activiti工作流学习-----基于5.19.0版本(8)

    8.1.5 Start Event 继续上一篇的事件的分享笔记,Start Event指明该处是流程开始,至于开始事件的类型(消息到达开始,指定的事件循环开始等),定义如何开始是在开始事件圆圈图标里面 ...

  2. Activiti工作流学习-----基于5.19.0版本(2)

    二.activiti.cfg.xml的其他bean节点配置 2.1 新特性:Job Executor和Async Executor 从5.17.0版本的activiti开始提供作业执行者(Job Ex ...

  3. Activiti工作流学习-----基于5.19.0版本(5)

    五.与Spring集成 实际项目中一般都有Spring的身影,与Spring集成使得Activiti的实用性得到提高.activiti和Spring整合需要activiti-spring的jar在类路 ...

  4. Activiti工作流学习-----基于5.19.0版本(6)

    七. BPMN的简介 读者了解到这里,应付一般的工作流开发已经足够了.此处应该有华丽的分割线,在工作流项目中核心开发人员主要是对工作流业务设计以及实现,而初级开发人员是对业务功能的代码实现.以后将主要 ...

  5. Activiti工作流学习-----基于5.19.0版本(1)

    该版本的Activiti运行须知: 1.JDK 6+,Eclipse最好是Kepler以上版本. 2.试验功能都有EXPERIMENTAL标注,被标注的部分不应该视为稳定的. 有兴趣的同学可以去了解下 ...

  6. Activiti工作流学习-----基于5.19.0版本(4)

    四.使用工作流开发 org.activiti.engine.ProcessEngine提供的Service作用在工作流引擎上面,如果所示是模仿一个公司简单的审批流程,你可以下载这个Demo:Activ ...

  7. Activiti工作流学习-----基于5.19.0版本(7)

    八.BPMN 2.0流程图详解 BPMN 2.0的标准的出现是好事,用户不在被某个工作流开发商绑架或者在工作流中开发妥协,Activiti作为BPMN标准的一套解决方案,使得用户在选择工作流框架时可以 ...

  8. Activiti工作流学习之流程图应用详解

    Activiti工作流学习之流程图应用详解 1.目的  了解Activiti工作流是怎样应用流程图的. 2.环境准备2.1.相关软件及版本    jdk版本:Jdk1.7及以上 IDE:eclipse ...

  9. Activiti工作流学习之概述(一)

    一.工作流介绍 我第一次听到这个词,是蒙逼的,再看百度百度,更傻眼了,完全说的不像人话啊,举几个生活中的例子,就明白多了比如:请假.报销等等,如果文字太过抽象,请看图: 二.工作流引擎 Process ...

随机推荐

  1. Entity Framework with MySQL 学习笔记一(安装)

    声明 :  数据库是Mysql,本人的程度只到会写sql语句(不会储蓄过程), c# 会基本的ADO.NET数据库访问,LINQ基础. 这篇只做个人学习|温习作用. 新手可以参考,也请高手指正错误, ...

  2. PYTHON 正则表达示入门

    确实是实践出真知,自己手打代码之后,以前停在理论上的东东,慢慢可以进入实战了. 比如,MATCH和SEARCH之间的区别. #encoding: UTF-8 import re pattern = r ...

  3. locate,nl命令

    locate 命令 locate 让使用者可以很快速的搜寻档案系统内是否有指定的档案.其方法是先建立一个包括系统内所有档案名称及路径的数据库,之后当寻找时就只需查询这个数据库,而不必实际深入档案系统之 ...

  4. BZOJ3297: [USACO2011 Open]forgot

    3297: [USACO2011 Open]forgot Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 54  Solved: 38[Submit][ ...

  5. Android中的ScrollView实现 拖拽反弹效果

    public class BounceScrollView extends ScrollView { private View inner;// 孩子View private float y;// 点 ...

  6. HDU-3787(字符串模拟)

    Problem Description 给定两个整数A和B,其表示形式是:从个位开始,每三位数用逗号","隔开.现在请计算A+B的结果,并以正常形式输出.   Input 输入包含 ...

  7. Github开源Java项目(Disconf)上传到Maven Central Repository方法详细介绍

    最近我做了一个开源项目 Disconf:Distributed Configuration Management Platform(分布式配置管理平台) ,简单来说,就是为所有业务平台系统管理配置文件 ...

  8. rsyslog同步history日志(转载)

    前言 由于公司业务是由公司内部开人员及外包团队共同开发,所以需要使用rsyslog对history日志做收集.审计.虽然搭建及配置非常简单,但是在日常运维工作中很实用,所以记录下,方便日后快速搭建.如 ...

  9. ionic学习教程地址梳理

    Ionic是一个新的.可以使用HTML5构建混合移动应用的用户界面框架,它自称为是"本地与HTML5的结合".该框架提供了很多基本的移动用户界面范例,例如像列表(lists).标签 ...

  10. [React] React Router: Querystring Parameters

    Define query param in Link, accept path and query : const Links = () => <nav > <Link to= ...