Flowable 6.6.0 BPMN用户指南-(2)配置 - 2.18.2 配置和设置/2.18.3 运行时增加侦听器

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


《Flowable 6.6.0 BPMN用户指南》

2. 配置

有关Flowable文档的其他资料,参见:

《Flowable文档大全》

2.18.2 配置和设置(Configuration and setup)

If an event-listener is configured in the process engine configuration, it will be active when the process engine starts and will remain active after subsequent reboots of the engine.

The property eventListeners expects a list of org.flowable.engine.delegate.event.FlowableEventListener instances. As usual, you can either declare an inline bean definition or use a ref to an existing bean instead. The snippet below adds an event-listener to the configuration that is notified when any event is dispatched, regardless of its type:

如果在流程引擎配置中配置了事件侦听器,则它将在流程引擎启动时处于活动(active)状态,并在随后重新启动引擎(subsequent reboots of the engine)后保持活动状态。

属性eventListeners需要一个org.flowable.engine.delegate.event.FlowableEventListener实例的列表(list)。与往常一样,您可以声明内联bean定义,也可以使用对现有bean的引用。下面的代码段向配置中添加了一个事件侦听器,该配置在引发任何事件时都会收到通知,而不考虑其类型:

<bean id="processEngineConfiguration"
    class="org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration">
    ...
    <property name="eventListeners">
      <list>
         <bean class="org.flowable.engine.example.MyEventListener" />
      </list>
    </property>
</bean>

To get notified when certain types of events get dispatched, use the typedEventListeners property, which expects a map. The key of a map-entry is a comma-separated list of event-names (or a single event-name). The value of a map-entry is a list of org.flowable.engine.delegate.event.FlowableEventListener instances. The snippet below adds an event-listener to the configuration, that is notified when a job execution was successful or failed:

要在引发某些类型的事件时获取通知,请使用typedEventListeners属性,该属性需要一个map。map项(map-entry)的key键是以逗号分隔的事件名称列表(或单个事件名称)。map项的值是org.flowable.engine.delegate.event.FlowableEventListener实例。下面的代码段将向配置中添加一个事件侦听器,当作业执行成功或失败时,将通知该侦听器:

<bean id="processEngineConfiguration"
    class="org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration">
    ...
    <property name="typedEventListeners">
      <map>
        <entry key="JOB_EXECUTION_SUCCESS,JOB_EXECUTION_FAILURE" >
          <list>
            <bean class="org.flowable.engine.example.MyJobEventListener" />
          </list>
        </entry>
      </map>
    </property>
</bean>

The order of dispatching events is determined by the order in which the listeners were added. First, all normal event-listeners are called (eventListeners property) in the order they are defined in the list. After that, all typed event listeners (typedEventListeners properties) are called, if an event of the right type is dispatched.

事件的引发顺序由侦听器的添加顺序决定。首先,按照列表中定义的顺序调用所有常规事件侦听器(eventListeners属性)。之后,如果引发了某种类型的事件,则调用所有类型化事件侦听器(typedEventListeners属性)。

2.18.3 运行时增加侦听器

It’s possible to add and remove additional event-listeners to the engine by using the API (RuntimeService):

可以使用API(RuntimeService)向引擎添加和删除其他事件侦听器:

/**
 * Adds an event-listener which will be notified of ALL events by the dispatcher.
 * @param listenerToAdd the listener to add
 */
void addEventListener(FlowableEventListener listenerToAdd);

/**
 * Adds an event-listener which will only be notified when an event occurs,
 * which type is in the given types.
 * @param listenerToAdd the listener to add
 * @param types types of events the listener should be notified for
 */
void addEventListener(FlowableEventListener listenerToAdd, FlowableEventType... types);

/**
 * Removes the given listener from this dispatcher. The listener will no longer be notified,
 * regardless of the type(s) it was registered for in the first place.
 * @param listenerToRemove listener to remove
 */
 void removeEventListener(FlowableEventListener listenerToRemove);

Please note that the listeners added at runtime are not retained when the engine is rebooted.

请注意,重新启动引擎时不会保留运行时添加的侦听器。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

月满闲庭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值