activiti-spring 源码

Survive by day and develop by night.
talk for import biz , show your perfect code,full busy,skip hardness,make a better result,wait for change,challenge Survive.
happy for hardess to solve denpendies.

目录

在这里插入图片描述

概述

activiti-spring

需求:

设计思路

实现思路分析

1.ApplicationContextElResolver

public class ApplicationContextElResolver extends ELResolver {

  protected ApplicationContext applicationContext;

  public ApplicationContextElResolver(ApplicationContext applicationContext) {
    this.applicationContext = applicationContext;
  }

  public Object getValue(ELContext context, Object base, Object property) {
    if (base == null) {
      // according to javadoc, can only be a String
      String key = (String) property;

      if (applicationContext.containsBean(key)) {
        context.setPropertyResolved(true);
        return applicationContext.getBean(key);
      }
    }

    return null;
  }

2.ProcessEngineFactoryBean

protected ProcessEngineConfigurationImpl processEngineConfiguration;

  protected ApplicationContext applicationContext;
  protected ProcessEngine processEngine;

  public void destroy() throws Exception {
    if (processEngine != null) {
      processEngine.close();
    }
  }

  public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    this.applicationContext = applicationContext;
  }

  public ProcessEngine getObject() throws Exception {
    configureExpressionManager();
    configureExternallyManagedTransactions();

    if (processEngineConfiguration.getBeans() == null) {
      processEngineConfiguration.setBeans(new SpringBeanFactoryProxyMap(applicationContext));
    }

    this.processEngine = processEngineConfiguration.buildProcessEngine();
    return this.processEngine;
  }

3.SpringAdvancedBusinessCalendarManagerFactory

爬虫调度器就是可以利用多线程机制,进行调度似的更快的进行网页爬取。

4.网页解析器

public class SpringAdvancedBusinessCalendarManagerFactory {

  private Integer defaultScheduleVersion;

  private Clock clock;

  public Integer getDefaultScheduleVersion() {
    return defaultScheduleVersion;
  }

  public void setDefaultScheduleVersion(Integer defaultScheduleVersion) {
    this.defaultScheduleVersion = defaultScheduleVersion;
  }

5.SpringEntityManagerSessionFactory

public class SpringAsyncExecutor extends DefaultAsyncJobExecutor {

  protected TaskExecutor taskExecutor;
  protected SpringRejectedJobsHandler rejectedJobsHandler;

  public SpringAsyncExecutor() {
  }

  public SpringAsyncExecutor(TaskExecutor taskExecutor, SpringRejectedJobsHandler rejectedJobsHandler) {
    this.taskExecutor = taskExecutor;
    this.rejectedJobsHandler = rejectedJobsHandler;
  }

  public TaskExecutor getTaskExecutor() {
    return taskExecutor;
  }

  /**
   * Required spring injected {@link TaskExecutor} implementation that will be used to execute runnable jobs.
   *
   * @param taskExecutor
   */
  public void setTaskExecutor(TaskExecutor taskExecutor) {
    this.taskExecutor = taskExecutor;
  }

  public SpringRejectedJobsHandler getRejectedJobsHandler() {
    return rejectedJobsHandler;
  }

  /**
   * Required spring injected {@link SpringRejectedJobsHandler} implementation that will be used when jobs were rejected by the task executor.
   *
   * @param rejectedJobsHandler
   */
  public void setRejectedJobsHandler(SpringRejectedJobsHandler rejectedJobsHandler) {
    this.rejectedJobsHandler = rejectedJobsHandler;
  }

拓展实现

public class SpringEntityManagerSessionFactory implements SessionFactory {

  protected EntityManagerFactory entityManagerFactory;
  protected boolean handleTransactions;
  protected boolean closeEntityManager;

  public SpringEntityManagerSessionFactory(Object entityManagerFactory, boolean handleTransactions, boolean closeEntityManager) {
    this.entityManagerFactory = (EntityManagerFactory) entityManagerFactory;
    this.handleTransactions = handleTransactions;
    this.closeEntityManager = closeEntityManager;
  }

  public Class<?> getSessionType() {
    return EntityManagerFactory.class;
  }

  public Session openSession(CommandContext commandContext) {
    EntityManager entityManager = EntityManagerFactoryUtils.getTransactionalEntityManager(entityManagerFactory);
    if (entityManager == null) {
      return new EntityManagerSessionImpl(entityManagerFactory, handleTransactions, closeEntityManager);
    }
    return new EntityManagerSessionImpl(entityManagerFactory, entityManager, false, false);
  }

}

SpringExpressionManager

public class SpringExpressionManager extends ExpressionManager {

  protected ApplicationContext applicationContext;

  /**
   * @param applicationContext
   *          the applicationContext to use. Ignored when 'beans' parameter is not null.
   * @param beans
   *          a map of custom beans to expose. If null, all beans in the application-context will be exposed.
   */
  public SpringExpressionManager(ApplicationContext applicationContext, Map<Object, Object> beans) {
    super(beans);
    this.applicationContext = applicationContext;
  }

    @Override
    protected void addBeansResolver(CompositeELResolver elResolver) {
        if (beans != null) {
            // Only expose limited set of beans in expressions
            elResolver.add(new ReadOnlyMapELResolver(beans));
        } else {
            // Expose full application-context in expressions
            elResolver.add(new ApplicationContextElResolver(applicationContext));
        }

    }

}
public class SpringTransactionContext implements TransactionContext {

  protected PlatformTransactionManager transactionManager;
  protected CommandContext commandContext;
  protected Integer transactionSynchronizationAdapterOrder;

  public SpringTransactionContext(PlatformTransactionManager transactionManager, CommandContext commandContext) {
    this(transactionManager, commandContext, null);
  }

  public SpringTransactionContext(PlatformTransactionManager transactionManager, CommandContext commandContext, Integer transactionSynchronizationAdapterOrder) {
    this.transactionManager = transactionManager;
    this.commandContext = commandContext;
    if (transactionSynchronizationAdapterOrder != null) {
      this.transactionSynchronizationAdapterOrder = transactionSynchronizationAdapterOrder;
    } else {
      // Revert to default, which is a high number as the behaviour prior
      // to adding the order would
      // case the TransactionSynchronizationAdapter to be called AFTER all
      // Adapters that implement Ordered
      this.transactionSynchronizationAdapterOrder = Integer.MAX_VALUE;
    }
  }

参考资料和推荐阅读

  1. 暂无

欢迎阅读,各位老铁,如果对你有帮助,点个赞加个关注呗!~

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

执于代码

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

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

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

打赏作者

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

抵扣说明:

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

余额充值