请选择 进入手机版 | 继续访问电脑版

Flowable 6.6.0 BPMN用户指南-(2)配置 - 2.18.4 向流程定义增加侦听器

[复制链接]
舞鴐雲腾 发表于 2020-12-31 19:25:31 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
《Flowable 6.6.0 BPMN用户指南》

2. 设置


Flowable 6.6.0 用户指南相关文档下载

精编Flowable 6.6.0 应用步调指南中文PDF版
精编Flowable 6.6.0 表单用户指南中文PDF版
有关Flowable文档的其他资料,拜见:

《Flowable文档大全》
2.18.4 向流程界说增加侦听器

It’s possible to add listeners to a specific process-definition. The listeners will only be called for events related to the process definition and to all events related to process instances that are started with that specific process definition. The listener implementations can be defined using a fully qualified classname, an expression that resolves to a bean that implements the listener interface or can be configured to throw a message/signal/error BPMN event.
可以将侦听器添加到特定的流程界说中。仅针对与流程界说相关的事件调用侦听器,以及针对使用该特定流程界说启动的流程实例相关的所有事件调用侦听器。侦听器实现可以使用完全限定的类名来界说,该类名是一个剖析为实现侦听器接口的bean的表达式。侦听器实现也可以设置为抛出消息/信号/错误(message/signal/error)BPMN事件。
2.18.4.1 执行用户界说逻辑的侦听器

The snippet below adds 2 listeners to a process-definition. The first listener will receive events of any type, with a listener implementation based on a fully-qualified class name. The second listener is only notified when a job is successfully executed or when it failed, using a listener that has been defined in the beans property of the process engine configuration.
下面的代码片段将2个侦听器添加到流程界说中。第一个侦听器将吸收任何范例的事件,侦听器实现基于完全限定(fully-qualified)的类名。第二个侦听器仅在作业乐成执行或失败时通知,使用流程引擎设置的beans属性中界说的侦听器。
  1.               ...
复制代码
For events related to entities, it’s also possible to add listeners to a process-definition that get only notified when entity-events occur for a certain entity type. The snippet below shows how this can be achieved. It can be used along for ALL entity-events (first example) or for specific event types only (second example).
对于与实体相关的事件,也可以将侦听器添加到流程界说中,该流程界说仅在特定实体范例(certain entity type)的实体事件(entity-event)发生时收到通知。下面的代码片段展示了如何实现这一点。它可以用于针对所有实体事件(第一个示例)或仅用于针对特定事件范例(第二个示例)。
  1.               ...
复制代码
Supported values for the entityType are: attachment, comment, execution, identity-link, job, process-instance, process-definition, task.
entityType支持的值包罗:attachment, comment, execution, identity-link, job, process-instance, process-definition, task(附件、注释、执行、身份毗连、作业、流程实例、流程界说、任务)。
2.18.4.2 抛出BPMN事件的侦听器

Another way of handling events being dispatched is to throw a BPMN event. Please bear in mind that it only makes sense to throw BPMN-events with certain kinds of Flowable event types. For example, throwing a BPMN event when the process-instance is deleted will result in an error. The snippet below shows how to throw a signal inside process-instance, throw a signal to an external process (global), throw a message-event inside the process-instance and throw an error-event inside the process-instance. Instead of using the class or delegateExpression, the attribute throwEvent is used, along with an additional attribute, specific to the type of event being thrown.
另一种处理惩罚被分发事件的方法是抛出一个BPMN事件。请记取,只有抛出与特定范例的Flowable事件关联的BPMN事件才有意义。比方,当流程实例被删除时抛出BPMN事件将导致错误。下面的代码片段显示了如何在流程实例内部抛出信号(signal)、向外部流程(全局)抛出信号(globalSignal)、在流程实例内部抛出消息(message)事件,以及在流程实例内部抛堕落误(error)事件。没有使用类或delegateExpression,而是使用了与所引发事件范例相关的throwEvent属性以及一个附加属性(signalName)。
  1.                                 
复制代码
If additional logic is needed to decide whether or not to throw the BPMN-event, it’s possible to extend the listener-classes provided by Flowable. By overriding the isValidEvent(FlowableEvent event) in your subclass, the BPMN-event throwing can be prevented. The classes involved are org.flowable.engine.test.api.event.SignalThrowingEventListenerTest, org.flowable.engine.impl.bpmn.helper.MessageThrowingEventListener and org.flowable.engine.impl.bpmn.helper.ErrorThrowingEventListener.
如果需要额外的逻辑来决定是否抛出BPMN事件,那么可以扩展Flowable提供的侦听器类。通过在子类中重写isValidEvent(FlowableEvent事件),可以阻止抛出BPMN事件。涉及的类有org.flowable.engine.test.api.event.SignalThrowingEventListenerTest,org.flowable.engine.impl.bpmn.helper.MessageThrowingEventListener和org.flowable.engine.impl.bpmn.helper.ErrorthrowingVentListener。
2.18.4.3 关于流程界说侦听器的说明



  • Event-listeners can only be declared on the process element, as a child-element of the extensionElements. Listeners cannot be defined on individual activities in the process.
  • 事件侦听器只能在process元素上声明,并作为extensionElements的子元素。不能在流程中的单个运动上界说侦听器。
  • Expressions used in the delegateExpression do not have access to the execution-context, as other expressions (for example, in gateways) have. They can only reference beans defined in the beans property of the process engine configuration or when using Spring (and the beans property is absent) to any spring-bean that implements the listener interface.
  • 与其他表达式(比方,在网关中)一样,delegateExpression中使用的表达式不能访问执行上下文(execution-context)。它们只能引用在流程引擎设置的beans属性中界说的bean,或者当使用Spring(且没有beans属性)时,引用实现监听器接口的Spring-bean。
  • When using the class attribute of a listener, there will only be a single instance of that class created. Make sure the listener implementations do not rely on member-fields or ensure safe usage from multiple threads/contexts.
  • 当使用监听器的class属性时,只会创建该类的一个实例。确保侦听器实现不依赖成员字段(member-field),或确保在多线程/上下文(multiple threads/contexts)时的安全使用。
  • When an illegal event-type is used in the events attribute or illegal throwEvent value is used, an exception will be thrown when the process-definition is deployed (effectively failing the deployment). When an illegal value for class or delegateExecution is supplied (either a nonexistent class, a nonexistent bean reference or a delegate not implementing listener interface), an exception will be thrown when the process is started (or when the first valid event for that process-definition is dispatched to the listener). Make sure the referenced classes are on the classpath and that the expressions resolve to a valid instance.
  • 如果events属性中使用了非法事件范例,或使用了非法throwEvent值,在摆设流程界说时将引发异常(实际上导致摆设失败)。如果为class或delegateExecution提供了非法值(不存在的类、不存在的bean引用或未实现侦听器接口的委托(delegate)),在流程启动时(或当该流程界说的第一个有效事件被分发到侦听器时)将引发异常。确保引用的类位于类路径(classpath)上,而且表达式剖析为有效实例。

来源:https://blog.csdn.net/weixin_52265084/article/details/111769733
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则


专注素材教程免费分享
全国免费热线电话

18768367769

周一至周日9:00-23:00

反馈建议

27428564@qq.com 在线QQ咨询

扫描二维码关注我们

Powered by Discuz! X3.4© 2001-2013 Comsenz Inc.( 蜀ICP备2021001884号-1 )