ProcessEngine对象的各个服务组件

寵の児 提交于 2020-04-15 09:53:16

【推荐阅读】微服务还能火多久?>>>

一 代码

package com.syc.activiti;


import org.activiti.engine.HistoryService;
import org.activiti.engine.IdentityService;
import org.activiti.engine.ManagementService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;


/**
* 获取各个业务组件实例
*
*/
public class GetService {


   public static void main(String[] args) {
      //读取流程引擎配置
      ProcessEngineConfiguration config = ProcessEngineConfiguration.
            createProcessEngineConfigurationFromResource("my-config.xml");
      //创建流程引擎
      ProcessEngine engine = config.buildProcessEngine();
      //得到各个业务组件实例
      RepositoryService repositoryService = engine.getRepositoryService();
      RuntimeService runtimeService = engine.getRuntimeService();
      TaskService taskService = engine.getTaskService();
      IdentityService identityService = engine.getIdentityService();
      ManagementService managementService = engine.getManagementService();
      HistoryService historyService = engine.getHistoryService();
      // 输入类名
      System.out.println(repositoryService.getClass().getName());
      System.out.println(runtimeService.getClass().getName());
      System.out.println(taskService.getClass().getName());
      System.out.println(identityService.getClass().getName());
      System.out.println(managementService.getClass().getName());
      System.out.println(historyService.getClass().getName());
   }


}

二 结果

org.activiti.engine.impl.RepositoryServiceImpl
org.activiti.engine.impl.RuntimeServiceImpl
org.activiti.engine.impl.TaskServiceImpl
org.activiti.engine.impl.IdentityServiceImpl
org.activiti.engine.impl.ManagementServiceImpl
org.activiti.engine.impl.HistoryServiceImpl

三 相关源码

/* 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;
  }
}

 

发布了4130 篇原创文章 · 获赞 663 · 访问量 345万+
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!