jbpm4.4部署过程详情

根据ProcessEngine取得RepositoryService加载资源文件;

String deployId = processEngine.getRepositoryService().createDeployment()
	.addResourceFromClasspath("resources/jbpm/Appropriation.jpdl.xml").deploy();



部署成功回返回流程id;

该方法的执行流程如下:

1、调用DeploymentImpl类的deploy方法;

public String deploy() {
    return commandService.execute(new DeployCmd(this));
  }



执行部署命令DeployCmd的execute方法;
public String execute(Environment environment) throws Exception {
    RepositorySession repositorySession = environment.get(RepositorySession.class);
    return repositorySession.deploy(deployment);
  }



2、调用RepositorySeession的deploy();参数deployment为DeployCmd的一个属性,在构造函数中初始化;

由于new DeployCmd(this)可知,deployment为DeploymentImpl的对象;

public String deploy(NewDeployment deployment) {
    DeploymentImpl deploymentImpl = (DeploymentImpl) deployment;
    
    long dbid = DbidGenerator.getDbidGenerator().getNextId();
    deploymentImpl.setDbid(dbid);
    deploymentImpl.initResourceLobDbids();
    
    session.save(deploymentImpl); // will also save the attached resources
    deployerManager.deploy(deploymentImpl);

    return deploymentImpl.getId();
  }



源码save注释有当保存deploymentImpl时同时保持相关的资源;那么再回头看DeploymentImpl类的属性有哪些;
public class DeploymentImpl extends ProblemList implements NewDeployment {

  private static final long serialVersionUID = 1L;

  public static final String KEY_PROCESS_LANGUAGE_ID = "langid";
  public static final String KEY_PROCESS_DEFINITION_ID = "pdid";
  public static final String KEY_PROCESS_DEFINITION_KEY = "pdkey";
  public static final String KEY_PROCESS_DEFINITION_VERSION = "pdversion";

  protected long dbid;
  protected String name;
  protected long timestamp;
  protected String state = Deployment.STATE_ACTIVE;
  protected Map<String, Lob> resources;

  protected CommandService commandService;
  protected Map<String, Object> objects;
  protected Set<DeploymentProperty> objectProperties;



发现一个resources的Map,Value为Lob类型;再看流程部署调用的加载部署文件方法,这个方法就在DeploymentImple类里面;
public NewDeployment addResourceFromClasspath(String resourceName) {
    addResourceFromStreamInput(resourceName, new ResourceStreamInput(resourceName));
    return this;
  }



public NewDeployment addResourceFromStreamInput(String name, StreamInput streamInput) {
    if (resources == null) {
      resources = new HashMap<String, Lob>();
    }
    InputStream inputStream = streamInput.openStream();
    try {
      byte[] bytes = IoUtil.readBytes(inputStream);

      // Since this method is probably called outside an environment block, we
      // need to generate the dbid of the Lob later (during the actual deployment).
      Lob lob = new Lob(bytes, false);
      resources.put(name, lob);
    }
    catch (IOException e) {
      throw new JbpmException("couldn't read from " + name, e);
    }
    finally {
      IoUtil.close(inputStream);
    }
    return this;
  }



不难看出资源文件类路径为key;

主要再看 protected Set<DeploymentProperty> objectProperties;这个属性;

这个类很简单;

public class DeploymentProperty implements Serializable {
  
  private static final long serialVersionUID = 1L;

  long dbid;
  protected DeploymentImpl deployment;
  protected String objectName;
  protected String key;
  protected String stringValue;
  protected Long longValue;
  ...



持久化到数据库,其中的几条记录为

资源文件xml的开头内容为

<process name="appcardJbpmFlow2" xmlns="http://jbpm.org/4.4/jpdl">



DeploymentProperty对应的数据记录为;



你可能感兴趣的:(jbpm4.4部署过程详情)