jbpmAPI-5

mac2022-06-30  67

Part II. jBPM Core

5.1。概述本章介绍了API需要加载过程和执行它们。更多的细节如何定义过程本身,看看在BPMN 2.0章。与流程引擎交互(例如,开始一个过程),你需要建立一个会话。此会话将被用来与流程引擎进行通信。会话需要引用一个知识库,其中包含所有相关的过程定义的引用。这个知识库用于查找过程定义时必要的。要创建一个会话,您首先需要创建一个知识库,加载所有必要的流程定义(这可以从各种来源,从类路径中,文件系统或流程库),然后实例化一个会话。一旦你建立了一个会话,你可以使用它来开始执行流程。每当开始一个过程,创建一个新的流程实例(这一过程定义),维护流程的特定实例的状态。

 

例如,假设您正在编写一个应用程序来处理销售订单。然后您可以定义一个或多个过程定义,定义应该如何处理订单。在启动应用程序时,您首先需要创建一个包含这些过程定义的知识库。然后,您可以创建一个会话基于此知识库,这样,每当一个新的销售订单时,将启动一个新的流程实例的销售订单。这一过程实例包含的状态过程,具体的销售要求。

知识库可以跨会话和共享通常只创建一次,开始的时候应用程序(如创建知识库可以而重量级它包括解析和编译过程定义)。知识库可以动态地改变(所以你可以添加或删除进程在运行时)。

 

会话可以创建基于知识库和用于执行流程和与引擎交互。您可以创建尽可能多的独立会话需要和创建一个会话被认为是相对较轻。有多少会话创建是取决于你。一般来说,最简单的情况下开始创建一个会话,然后在应用程序中从不同的地方。你可以决定创建多个会话如果例如你想拥有多个独立处理单元(例如,如果你想要所有流程从一个客户是完全独立于流程为另一个客户,您可以创建一个独立的会话为每个客户)或如果你需要多个会话原因可伸缩性。如果你不知道该做什么,只是开始通过一个知识库包含所有您的流程定义和创建一个会话,然后使用它来执行所有的流程。

jBPM项目有一个清晰的分离API用户应该之间的相互作用和实际实现类。公共API公开了大部分的功能我们认为“正常”的用户可以安全地使用和应该保持相当稳定版本。专家用户仍然可以访问内部类但应该意识到,他们应该知道他们在做什么,内部API在未来仍可能会改变。

 

如上所述,因此jBPM API应该被用来(1)创建一个知识库,其中包含您的流程定义,和(2)创建一个会话开始新流程实例,现有的信号,注册侦听器等。

5.2. KieBase

jBPM API允许您首先创建一个知识库。这个知识库应该包括所有您的流程定义,可能需要执行该会话。创建一个知识库,用KieHelper从各种资源加载过程(例如从类路径或文件系统),然后创建一个新的知识库的帮手。下面的代码片段显示了如何创建一个知识库组成的只有一个流程定义(使用在这种情况下,资源从类路径)。

  KieHelper kieHelper = new KieHelper();   KieBase kieBase = kieHelper                     .addResource(ResourceFactory.newClassPathResource("MyProcess.bpmn"))                     .build();ResourceFactory也有类似的方法来从文件系统加载文件,从URL,InputStream、读者,等等。这被认为是手动创建知识库,虽然它很简单,不建议真正的应用程序开发但更多的尝试。后你会发现推荐和更强大的方式构建知识库,会话和更多——RuntimeManager知识。

5.3. KieSession

一旦你加载的知识库,您应该创建一个会话与引擎交互。这个会话可以用于启动新的流程,信号事件,等。下面的代码片段显示了是多么容易创建一个会话基于之前创建的知识库,并开始一个过程(通过id)。

KieSession ksession = kbase.newKieSession(); ProcessInstance processInstance = ksession.startProcess("com.sample.MyProcess");

5.3.1. ProcessRuntime

ProcessRuntime接口定义的所有会话交互的方法与流程,如下所示。

 

  /**      * 启动一个新的流程实例的过程(定义)      * 使用引用给定的进程id。      *       * @param processId  进程的id,应该开始了      * @return ProcessInstance表示实例的过程就开始了      */     ProcessInstance startProcess(String processId);     /**      * 启动一个新的流程实例的过程(定义)      * 被给定的进程id引用使用。可以传递参数      * 同行审判(as),这些将考试和测验科as of the process变量。     *       *       * @param processId  the id of the process that should be started      * @param parameters  the process variables that should be set when starting the process instance       * @return the ProcessInstance that represents the instance of the process that was started      */     ProcessInstance startProcess(String processId,                                  Map<String, Object> parameters);     /**      * 信号的引擎类型参数定义一个事件发生      * 哪种类型的事件和事件参数可以包含额外的信息吗     * 相关事件。听这种类型的所有流程实例     * (外部)事件将通知。由于性能的原因,这种类型的事件      *信号时才应该使用一个流程实例应该能够通知      *其他流程实例。内部事件一个流程实例,使用      * processInstanceId signalEvent方法,还包括的流程实例      * in question.       *       * @param type the type of event      * @param event the data associated with this event      */     void signalEvent(String type,                      Object event);     /**      * Signals the process instance that an event has occurred. The type parameter defines      * which type of event and the event parameter can contain additional information      * related to the event.  All node instances inside the given process instance that      * are listening to this type of (internal) event will be notified.  Note that the event      * will only be processed inside the given process instance.  All other process instances      * waiting for this type of event will not be notified.      *       * @param type the type of event      * @param event the data associated with this event      * @param processInstanceId the id of the process instance that should be signaled      */     void signalEvent(String type,                      Object event,                      long processInstanceId);     /**      * Returns a collection of currently active process instances.  Note that only process      * instances that are currently loaded and active inside the engine will be returned.      * When using persistence, it is likely not all running process instances will be loaded      * as their state will be stored persistently.  It is recommended not to use this      * method to collect information about the state of your process instances but to use      * a history log for that purpose.      *       * @return a collection of process instances currently active in the session      */     Collection<ProcessInstance> getProcessInstances();     /**      * Returns the process instance with the given id.  Note that only active process instances      * will be returned.  If a process instance has been completed already, this method will return      * null.      *       * @param id the id of the process instance      * @return the process instance with the given id or null if it cannot be found      */     ProcessInstance getProcessInstance(long processInstanceId);     /**      * Aborts the process instance with the given id.  If the process instance has been completed      * (or aborted), or the process instance cannot be found, this method will throw an      * IllegalArgumentException.      *       * @param id the id of the process instance      */     void abortProcessInstance(long processInstanceId);     /**      * Returns the WorkItemManager related to this session.  This can be used to      * register new WorkItemHandlers or to complete (or abort) WorkItems.      *       * @return the WorkItemManager related to this session      */     WorkItemManager getWorkItemManager();

5.3.2. Event Listeners

会话提供了注册和删除侦听器方法。可以使用ProcessEventListener听流程相关事件,如开始或完成一个过程,进入和离开一个节点,等等。下面,ProcessEventListener类显示的不同的方法。一个事件对象提供相关信息,如流程实例和节点实例与事件有关。你可以使用这个API来登记自己的事件监听器。

public interface ProcessEventListener {   void beforeProcessStarted( ProcessStartedEvent event );   void afterProcessStarted( ProcessStartedEvent event );   void beforeProcessCompleted( ProcessCompletedEvent event );   void afterProcessCompleted( ProcessCompletedEvent event );   void beforeNodeTriggered( ProcessNodeTriggeredEvent event );   void afterNodeTriggered( ProcessNodeTriggeredEvent event );   void beforeNodeLeft( ProcessNodeLeftEvent event );   void afterNodeLeft( ProcessNodeLeftEvent event );   void beforeVariableChanged(ProcessVariableChangedEvent event);   void afterVariableChanged(ProcessVariableChangedEvent event); }一个关于事件前后的注意事项:这些事件通常像一堆,这意味着任何事件发生之前事件的直接结果,之间会发生之前和之后的事件。例如,如果一个后续节点触发的结果离开一个节点,该节点触发事件将发生afterNodeLeftEvent beforeNodeLeftEvent和中间的节点的左(第二个节点的触发是离开第一个节点)的直接结果。这样做可以让我们获得更容易导致事件之间的关系。同样,所有节点和节点离开事件触发启动过程的直接结果之间会发生beforeProcessStarted和afterProcessStarted事件。一般来说,如果你只是希望得到通知当一个特定事件发生时,你应该看着事件前只(发生时立即在事件实际发生之前)。时只查看事件之后,一个会觉得被解雇事件错误的订单,但由于事件触发后一堆(事件只会火当所有事件后,由于这个事件触发已经解雇了)。事件后只能使用如果你想确保所有与此有关的处理已经结束(例如,当您希望得到通知在开始的一个特定的流程实例已经结束。 还请注意,并不是所有的节点总是生成节点和/或节点离开事件触发。根据节点的类型,某些节点可能只剩下生成节点事件,别人可能只产生节点触发事件。抓住中间事件例如不产生触发事件(它们只剩下生成事件,因为它们不是真的引发了另一个节点,而激活以外)。同样,把中间事件不是生成左事件(他们只产生触发事件,因为它们不是真的离开,因为他们没有传出连接)。jBPM开箱即用的提供了一个侦听器,可以用来创建一个审计日志(输出到控制台或文件系统)上的一个文件。该审核日志包含所有在运行时发生的不同事件所以很容易找出发生了什么事。注意,这些伐木工只能用于调试目的。以下日志实现默认支持:控制台记录器:这到控制台记录器写出所有的事件。文件日志:这个日志程序写出所有的事件到一个文件使用XML表示。此日志文件可能会被用在IDE生成树可视化执行期间发生的事件。螺纹文件日志:因为一个文件日志记录器将事件写入磁盘只有当关闭日志记录器或当事件记录器的数量达到一个预定义的水平,它不能在运行时调试过程时使用。螺纹文件记录器将事件写入一个文件指定的时间间隔后,使它可以使用日志记录器来可视化实时进展,而调试过程。KieServices让你KieRuntimeLogger添加到会话,如下所示。当创建一个控制台记录器,知识需要创建日志记录器的会话必须作为参数传递。文件日志还需要创建日志文件的名称,和螺纹文件日志需要间隔(以毫秒为单位),在此之后的事件应该被保存。你应该关闭日志记录器在您的应用程序。   import org.kie.api.KieServices;   import org.kie.api.logger.KieRuntimeLogger;   ...   KieRuntimeLogger logger = KieServices.Factory.get().getLoggers().newFileLogger(ksession, "test");   // add invocations to the process engine here,   // e.g. ksession.startProcess(processId);   ...   logger.close();创建的日志文件的文件的伐木工包含一个基于xml的概述在运行时发生的所有事件。它可以打开在Eclipse中,在Drools Eclipse插件使用审计视图,事件被可视化为树的地方。事件发生前后之间的事件显示为孩子的事件。下面的屏幕截图显示了一个简单的例子,开始一个过程的激活导致开始节点,一个动作节点和结束节点,之后完成的过程。5.3.3。相关的钥匙常见的一种需求在处理过程能力分配给流程实例的业务标识符,可以稍后引用不知道实际的流程实例的id(生成)。jBPM提供这些功能,允许使用CorrelationKey CorrelationProperties组成的。CorrelationKey可以有单独的属性描述它(在大多数情况下),但它可以作为多值属性集。相关功能提供接口的一部CorrelationAwareProcessRuntime这暴露了以下方法:       /**       * Start a new process instance.  The process (definition) that should       * be used is referenced by the given process id.  Parameters can be passed       * to the process instance (as name-value pairs), and these will be set       * as variables of the process instance.       *       * @param processId  the id of the process that should be started       * @param correlationKey custom correlation key that can be used to identify process instance       * @param parameters  the process variables that should be set when starting the process instance       * @return the ProcessInstance that represents the instance of the process that was started       */       ProcessInstance startProcess(String processId, CorrelationKey correlationKey, Map<String, Object> parameters);       /**       * Creates a new process instance (but does not yet start it).  The process       * (definition) that should be used is referenced by the given process id.       * Parameters can be passed to the process instance (as name-value pairs),       * and these will be set as variables of the process instance.  You should only       * use this method if you need a reference to the process instance before actually       * starting it.  Otherwise, use startProcess.       *       * @param processId  the id of the process that should be started       * @param correlationKey custom correlation key that can be used to identify process instance       * @param parameters  the process variables that should be set when creating the process instance       * @return the ProcessInstance that represents the instance of the process that was created (but not yet started)       */       ProcessInstance createProcessInstance(String processId, CorrelationKey correlationKey, Map<String, Object> parameters);       /**       * Returns the process instance with the given correlationKey.  Note that only active process instances       * will be returned.  If a process instance has been completed already, this method will return       * null.       *       * @param correlationKey the custom correlation key assigned when process instance was created       * @return the process instance with the given id or null if it cannot be found       */       ProcessInstance getProcessInstance(CorrelationKey correlationKey);

 

相关性通常使用长时间运行的流程,因此需要启用能够永久持久性存储相关信息。5.3.4线程。在以下文本,我们会参考两种类型的“多线程”:逻辑与技术。多线程技术是当多个线程或进程开始在电脑上,例如Java或C程序。逻辑多线程是我们所看到在BPM流程过程达到并行网关为例。从功能的角度来看,最初的过程将分为两个过程,以并行方式执行。当然,jBPM引擎支持逻辑多线程:例如,流程,包括并行网关。我们选择使用一个线程来实现逻辑多线程:jBPM流程,包括逻辑多线程将只在一个技术线程执行。这样做的主要原因是,多个(技术)线程需要能够彼此交流状态信息,如果他们正在相同的过程。这个需求带来了一系列的并发症。虽然看起来似乎多线程将带来性能优势,确保所需的额外的逻辑不同的线程一起工作也意味着这是没有保证的。也有额外的开销,因为我们需要避免竞态条件和死锁。一般来说,jBPM引擎在串行执行行动。例如,当发动机任务过程中遇到一个脚本,它将同步执行的脚本,等待它完成在继续之前执行。类似地,如果一个过程遇到一个并行网关,它将依次触发每个即将离任的分支,一个接一个。这是可能的因为几乎总是即时执行,这意味着它非常快,生产几乎没有开销。因此,用户通常会不会注意到这一点。同样,动作脚本过程中也同步执行,和引擎将等待他们在继续之前完成这一过程。例如,做一个thread . sleep(…)作为脚本的一部分,不会让引擎继续执行其他地方但会阻塞引擎线程在此期间。同样的原则也适用于服务任务。当一个服务任务是达到在一个过程中,发动机也将同步调用此服务的处理程序。引擎将等待completeWorkItem(…)方法返回之前继续执行。重要的是,你的服务处理程序执行如果没有即时执行异步服务。一个例子,这将是一个服务调用外部服务的任务。因为远程调用此服务的延迟和等待太久,结果将会如何可能是一个好主意异步调用这个服务。这意味着处理程序只会调用服务并将通知引擎后,结果是可用的。同时,流程引擎然后继续执行过程。人工任务服务的一个典型的例子,需要异步调用,因为我们不想让引擎等到人类演员来回应请求。人工任务处理程序只会创建一个新的任务(任务列表的分配演员)人工任务节点时触发。引擎将能够继续执行过程的其余部分(如果有必要)和异步处理程序将通知引擎当用户已经完成了任务。5.4 . RuntimeManager.RuntimeManager引入了简化和授权使用API的知识特别是在上下文的过程。它提供了可配置的策略,控制实际运行时执行(KieSessions如何提供),默认情况下提供了以下:单——运行时经理维护单一KieSession无论可用的进程数量每个请求运行时经理提供新的KieSession为每个请求每个流程实例,运行时经理之间保持映射流程实例和KieSession总是提供相同KieSession每当处理流程实例运行时经理主要负责管理和交付RuntimeEngine给调用者的实例。反过来,RuntimeEngine jBPM引擎封装了两个最重要的元素:KieSessionTaskService这两个组件已经配置为彼此工作顺利从最终用户没有额外的配置。不再需要注册处理程序或人工任务跟踪是否连接到服务。 public interface RuntimeManager {     /**      * Returns <code>RuntimeEngine</code> instance that is fully initialized:      * <ul>      *  <li>KiseSession is created or loaded depending on the strategy</li>      *  <li>TaskService is initialized and attached to ksession (via listener)</li>      *  <li>WorkItemHandlers are initialized and registered on ksession</li>      *  <li>EventListeners (process, agenda, working memory) are initialized and added to ksession</li>      * </ul>      * @param context the concrete implementation of the context that is supported by given <code>RuntimeManager</code>      * @return instance of the <code>RuntimeEngine</code>      */     RuntimeEngine getRuntimeEngine(Context<?> context);          /**      * Unique identifier of the <code>RuntimeManager</code>      * @return      */     String getIdentifier();         /**      * Disposes <code>RuntimeEngine</code> and notifies all listeners about that fact.      * This method should always be used to dispose <code>RuntimeEngine</code> that is not needed      * anymore. <br/>      * ksession.dispose() shall never be used with RuntimeManager as it will break the internal      * mechanisms of the manager responsible for clear and efficient disposal.<br/>      * Dispose is not needed if <code>RuntimeEngine</code> was obtained within active JTA transaction,       * this means that when getRuntimeEngine method was invoked during active JTA transaction then dispose of      * the runtime engine will happen automatically on transaction completion.      * @param runtime      */     void disposeRuntimeEngine(RuntimeEngine runtime);          /**      * Closes <code>RuntimeManager</code> and releases its resources. Shall always be called when      * runtime manager is not needed any more. Otherwise it will still be active and operational.      */     void close();      }RuntimeEngine接口提供了最重要的方法来获得引擎组件: public interface RuntimeEngine {     /**      * Returns <code>KieSession</code> configured for this <code>RuntimeEngine</code>      * @return      */     KieSession getKieSession();          /**      * Returns <code>TaskService</code> configured for this <code>RuntimeEngine</code>      * @return      */     TaskService getTaskService();    }RuntimeManager将确保无论战略,它将提供相同功能的时候RuntimeEngine的初始化和配置。这意味着:KieSession将含有相同的工厂(在内存或基于JPA)WorkItemHandlers将注册在每个KieSession(从数据库加载或新创建的)事件监听器(流程、议程WorkingMemory)将注册在每个KieSession(从数据库加载或新创建的)TaskService将配置:JTA事务管理器至于KieSession相同的实体管理器工厂UserGroupCallback从环境另一方面,RuntimeManager维护引擎处理以及通过提供专用的方法处理RuntimeEngine不再需要的时候它会释放任何资源。5.4.2. Strategies单策略——指示RuntimeManager保持单一实例RuntimeEngine(以及反过来单一实例KieSession TaskService)。访问RuntimeEngine同步,线程安全虽然它带有一个性能损失由于同步。这种策略类似于默认可用在jBPM版本5。x,它被认为是最简单的策略和建议。它有以下特征重要的评估,同时考虑了给定的场景:小内存占用,单一实例的运行时引擎和任务服务简单和紧凑的设计和使用适合低到中等负载流程引擎由于同步访问由于单一KieSession实例所有状态对象(如事实)是直接可见的所有流程实例,反之亦然没有上下文,这意味着当检索实例的RuntimeEngine singleton RuntimeManager上下文实例并不重要,通常EmptyContext.get()虽然使用null参数是可以接受的跟踪KieSession RuntimeManager重启之间使用id,以确保它将使用相同的会话——这个id作为序列化文件磁盘上的临时存储位置,取决于环境可以以下之一:jbpm.data价值。dir系统属性jboss.server.data价值。dir系统属性. io .给出的值tmpdir系统属性每个请求策略——指示RuntimeManager为每个请求提供RuntimeEngine的新实例。当请求RuntimeManager将考虑在单一事务中一个或多个调用。它必须返回相同的实例RuntimeEngine在单一事务以确保正确性国家另有操作在一个调用不可见。这是一种“无状态”策略,只提供了请求范围状态,一旦请求完成RuntimeEngine将永久破坏——KieSession信息从数据库中删除,以防使用持久性。它有以下特点:完全隔离流程引擎和任务为每个请求服务操作完全无状态,存储事实只有请求的持续时间是有意义的适合高负载、无状态流程(不涉及事实或计时器之间应当保存请求)KieSession只有生活期间的要求和最终被摧毁没有上下文,这意味着当从每个请求检索实例RuntimeEngine RuntimeManager上下文实例并不重要,通常EmptyContext.get()虽然使用null参数是可以接受的每个流程实例策略——指示RuntimeManager保持严格的KieSession和ProcessInstance之间的关系。这意味着KieSession可以只要ProcessInstance属于活跃。这个策略提供最灵活的方法,利用先进的功能引擎像规则评估的隔离(仅给流程实例),最大的性能和减少潜在的瓶颈intriduced同步,同时减少数量的KieSessions流程实例,而不是实际数量的请求数(与每个请求策略)。它有以下特点:最先进的战略提供隔离只给流程实例严格KieSession和ProcessInstance之间的关系以确保它总是带来同样KieSession ProcessInstance合并生命周期的KieSession ProcessInstance使两个处理流程实例完成(完成或中止)允许维护数据(如事实,计时器)在流程实例的范围,只有流程实例将可以访问这些数据介绍了一些开销由于需要查找和加载KieSession流程实例验证使用KieSession所以不能用于其他流程实例(ab),在这种情况下抛出异常上下文——接受以下上下文实例:EmptyContext或null -启动流程实例时没有可用的流程实例idProcessInstanceIdContext——在流程实例被创建后使用CorrelationKeyContext——作为替代ProcessInstanceIdContext使用自定义(业务)的关键,而不是流程实例id第5.4.3使用。定期使用场景RuntimeManager是:在应用程序启动时构建RuntimeManager并保持应用程序的整个生命时间,它是线程安全的,可以(或者应该)并发访问在请求使用适当的上下文实例得到RuntimeEngine RuntimeManager致力于RuntimeManager的策略从RuntimeEngine得到KieSession和/或TaskService上执行操作KieSession和/或TaskService如startProcess completeTask等等一旦完成处理处置使用RuntimeManager RuntimeEngine。disposeRuntimeEngine方法在应用程序关闭关闭RuntimeManager5.4.3.1。例如这里是如何构建RuntimeManager并获得RuntimeEngine(封装KieSession和TaskService):     // first configure environment that will be used by RuntimeManager     RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get()     .newDefaultInMemoryBuilder()     .addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2)     .get();     // next create RuntimeManager - in this case singleton strategy is chosen     RuntimeManager manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);     // then get RuntimeEngine out of manager - using empty context as singleton does not keep track     // of runtime engine as there is only one     RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());     // get KieSession from runtime runtimeEngine - already initialized with all handlers, listeners, etc that were configured     // on the environment     KieSession ksession = runtimeEngine.getKieSession();     // add invocations to the process engine here,     // e.g. ksession.startProcess(processId);     // and last dispose the runtime engine     manager.disposeRuntimeEngine(runtimeEngine);

 这个示例提供了简单的(最小)的方式使用RuntimeManager RuntimeEngine虽然它提供了一些很有价值的信息:KieSession将通过使用newDefaultInMemoryBuilder仅在内存中会有单一可执行过程——通过增加它作为一种资产TaskService配置,并通过LocalHTWorkItemHandler KieSession支持过程中用户任务能力

5.4.4配置。知道什么时候创建的复杂性,处理,注册处理程序等的终端用户和移动到运行时经理知道何时/如何执行这些操作但仍然允许细粒度控制这个过程通过提供全面RuntimeEnvironment的配置。   public interface RuntimeEnvironment {     /**      * Returns <code>KieBase</code> that shall be used by the manager      * @return      */     KieBase getKieBase();          /**      * KieSession environment that shall be used to create instances of <code>KieSession</code>      * @return      */     Environment getEnvironment();          /**      * KieSession configuration that shall be used to create instances of <code>KieSession</code>      * @return      */     KieSessionConfiguration getConfiguration();          /**      * Indicates if persistence shall be used for the KieSession instances      * @return      */     boolean usePersistence();          /**      * Delivers concrete implementation of <code>RegisterableItemsFactory</code> to obtain handlers and listeners      * that shall be registered on instances of <code>KieSession</code>      * @return      */     RegisterableItemsFactory getRegisterableItemsFactory();          /**      * Delivers concrete implementation of <code>UserGroupCallback</code> that shall be registered on instances       * of <code>TaskService</code> for managing users and groups.      * @return      */     UserGroupCallback getUserGroupCallback();          /**      * Delivers custom class loader that shall be used by the process engine and task service instances      * @return      */     ClassLoader getClassLoader();          /**      * Closes the environment allowing to close all depending components such as ksession factories, etc       */     void close();5.4.4.1。建筑RuntimeEnvironment尽管大多数RuntimeEnvironment接口提供了对数据的访问作为环境的一部分,将使用RuntimeManager,用户应该利用建筑样式类提供API来配置RuntimeEnvironment流利使用预定义的设置。 public interface RuntimeEnvironmentBuilder {     public RuntimeEnvironmentBuilder persistence(boolean persistenceEnabled);     public RuntimeEnvironmentBuilder entityManagerFactory(Object emf);     public RuntimeEnvironmentBuilder addAsset(Resource asset, ResourceType type);     public RuntimeEnvironmentBuilder addEnvironmentEntry(String name, Object value);     public RuntimeEnvironmentBuilder addConfiguration(String name, String value);     public RuntimeEnvironmentBuilder knowledgeBase(KieBase kbase);     public RuntimeEnvironmentBuilder userGroupCallback(UserGroupCallback callback);     public RuntimeEnvironmentBuilder registerableItemsFactory(RegisterableItemsFactory factory);     public RuntimeEnvironment get();     public RuntimeEnvironmentBuilder classLoader(ClassLoader cl);          public RuntimeEnvironmentBuilder schedulerService(Object globalScheduler);         RuntimeEnvironmentBuilder的实例可以通过RuntimeEnvironmentBuilderFactory提供预配置的构建器简化和RuntimeManager帮助用户构建环境。 public interface RuntimeEnvironmentBuilderFactory {     /**      * Provides completely empty <code>RuntimeEnvironmentBuilder</code> instance that allows to manually      * set all required components instead of relying on any defaults.      * @return new instance of <code>RuntimeEnvironmentBuilder</code>      */     public RuntimeEnvironmentBuilder newEmptyBuilder();          /**      * Provides default configuration of <code>RuntimeEnvironmentBuilder</code> that is based on:      * <ul>      *  <li>DefaultRuntimeEnvironment</li>      * </ul>      * @return new instance of <code>RuntimeEnvironmentBuilder</code> that is already preconfigured with defaults      *       * @see DefaultRuntimeEnvironment      */     public RuntimeEnvironmentBuilder newDefaultBuilder();          /**      * Provides default configuration of <code>RuntimeEnvironmentBuilder</code> that is based on:      * <ul>      *  <li>DefaultRuntimeEnvironment</li>      * </ul>      * but it does not have persistence for process engine configured so it will only store process instances in memory      * @return new instance of <code>RuntimeEnvironmentBuilder</code> that is already preconfigured with defaults      *       * @see DefaultRuntimeEnvironment      */     public RuntimeEnvironmentBuilder newDefaultInMemoryBuilder();          /**      * Provides default configuration of <code>RuntimeEnvironmentBuilder</code> that is based on:      * <ul>      *  <li>DefaultRuntimeEnvironment</li>      * </ul>      * This one is tailored to works smoothly with kjars as the notion of kbase and ksessions      * @param groupId group id of kjar      * @param artifactId artifact id of kjar      * @param version version number of kjar      * @return new instance of <code>RuntimeEnvironmentBuilder</code> that is already preconfigured with defaults      *       * @see DefaultRuntimeEnvironment      */     public RuntimeEnvironmentBuilder newDefaultBuilder(String groupId, String artifactId, String version);          /**      * Provides default configuration of <code>RuntimeEnvironmentBuilder</code> that is based on:      * <ul>      *  <li>DefaultRuntimeEnvironment</li>      * </ul>      * This one is tailored to works smoothly with kjars as the notion of kbase and ksessions      * @param groupId group id of kjar      * @param artifactId artifact id of kjar      * @param version version number of kjar      * @param kbaseName name of the kbase defined in kmodule.xml stored in kjar      * @param ksessionName name of the ksession define in kmodule.xml stored in kjar      * @return new instance of <code>RuntimeEnvironmentBuilder</code> that is already preconfigured with defaults      *       * @see DefaultRuntimeEnvironment      */     public RuntimeEnvironmentBuilder newDefaultBuilder(String groupId, String artifactId, String version, String kbaseName, String ksessionName);          /**      * Provides default configuration of <code>RuntimeEnvironmentBuilder</code> that is based on:      * <ul>      *  <li>DefaultRuntimeEnvironment</li>      * </ul>      * This one is tailored to works smoothly with kjars as the notion of kbase and ksessions      * @param releaseId <code>ReleaseId</code> that described the kjar      * @return new instance of <code>RuntimeEnvironmentBuilder</code> that is already preconfigured with defaults      *       * @see DefaultRuntimeEnvironment      */     public RuntimeEnvironmentBuilder newDefaultBuilder(ReleaseId releaseId);          /**      * Provides default configuration of <code>RuntimeEnvironmentBuilder</code> that is based on:      * <ul>      *  <li>DefaultRuntimeEnvironment</li>      * </ul>      * This one is tailored to works smoothly with kjars as the notion of kbase and ksessions      * @param releaseId <code>ReleaseId</code> that described the kjar      * @param kbaseName name of the kbase defined in kmodule.xml stored in kjar      * @param ksessionName name of the ksession define in kmodule.xml stored in kjar      * @return new instance of <code>RuntimeEnvironmentBuilder</code> that is already preconfigured with defaults      *       * @see DefaultRuntimeEnvironment      */     public RuntimeEnvironmentBuilder newDefaultBuilder(ReleaseId releaseId, String kbaseName, String ksessionName);          /**      * Provides default configuration of <code>RuntimeEnvironmentBuilder</code> that is based on:      * <ul>      *  <li>DefaultRuntimeEnvironment</li>      * </ul>      * It relies on KieClasspathContainer that requires to have kmodule.xml present in META-INF folder which       * defines the kjar itself.      * Expects to use default kbase and ksession from kmodule.      * @return new instance of <code>RuntimeEnvironmentBuilder</code> that is already preconfigured with defaults      *       * @see DefaultRuntimeEnvironment      */

转载于:https://www.cnblogs.com/luocheng/p/4494619.html

相关资源:垃圾分类数据集及代码
最新回复(0)