• 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;
      }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    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;
      }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27

    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;
      }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    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;
      }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38

    拓展实现

    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);
      }
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25

    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));
            }
    
        }
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    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
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

    参考资料和推荐阅读

    1. 暂无

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

  • 相关阅读:
    ABP应用开发(Step by Step)-下篇
    Nginz静态资源缓存
    前端笔试练习题——JS5 创建数组、JS6 判断版本
    蓝桥杯备赛第三篇(图论)
    StoneDB for MySQL 5.7 版本发布
    亚朵在美上市:募资规模缩水八成,高瓴资本退出,王海军等套现
    【Linux】权限理解
    Ps:消除锯齿与修边
    [BuckeyesCTF 2022] 部分WP
    dpdk tap设备不能转发大于1500报文问题分析
  • 原文地址:https://blog.csdn.net/xiamaocheng/article/details/127796391