• 设计模式之美学习-结构型-门面模式(二十三)


    说明

    要求一个子系统的外部与其内部的通信必须通过一个统一的对象进行。门面模式提供一个高层次的接口,使得子系统更易于使用。最核心的目的:简化子系统,简化客户使用,屏蔽多个子系统

    源码中的应用

    flowable 

    ProcessEngineImpl

    /**
     * 门面
     */
    public class ProcessEngineImpl implements ProcessEngine {
        private static final Logger LOGGER = 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 AsyncExecutor asyncExecutor;
        protected AsyncExecutor asyncHistoryExecutor;
        protected CommandExecutor commandExecutor;
        protected Map<Class<?>, SessionFactory> sessionFactories;
        protected TransactionContextFactory transactionContextFactory;
        protected ProcessEngineConfigurationImpl processEngineConfiguration;
    
        public ProcessEngineImpl(ProcessEngineConfigurationImpl processEngineConfiguration) {
            this.processEngineConfiguration = processEngineConfiguration;
            this.name = processEngineConfiguration.getEngineName();
            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.asyncHistoryExecutor = processEngineConfiguration.getAsyncHistoryExecutor();
            this.commandExecutor = processEngineConfiguration.getCommandExecutor();
            this.sessionFactories = processEngineConfiguration.getSessionFactories();
            this.transactionContextFactory = processEngineConfiguration.getTransactionContextFactory();
            if (processEngineConfiguration.isUsingRelationalDatabase() && processEngineConfiguration.getDatabaseSchemaUpdate() != null) {
                this.commandExecutor.execute(processEngineConfiguration.getSchemaCommandConfig(), new SchemaOperationsProcessEngineBuild());
            }
    
            if (this.name == null) {
                LOGGER.info("default ProcessEngine created");
            } else {
                LOGGER.info("ProcessEngine {} created", this.name);
            }
    
            ProcessEngines.registerProcessEngine(this);
            if (processEngineConfiguration.getProcessEngineLifecycleListener() != null) {
                processEngineConfiguration.getProcessEngineLifecycleListener().onProcessEngineBuilt(this);
            }
    
            processEngineConfiguration.getEventDispatcher().dispatchEvent(FlowableEventBuilder.createGlobalEvent(FlowableEngineEventType.ENGINE_CREATED));
            if (this.asyncExecutor != null && this.asyncExecutor.isAutoActivate()) {
                this.asyncExecutor.start();
            }
    
            if (this.asyncHistoryExecutor != null && this.asyncHistoryExecutor.isAutoActivate()) {
                this.asyncHistoryExecutor.start();
            }
    
        }
    
        public void close() {
            ProcessEngines.unregister(this);
            if (this.asyncExecutor != null && this.asyncExecutor.isActive()) {
                this.asyncExecutor.shutdown();
            }
    
            if (this.asyncHistoryExecutor != null && this.asyncHistoryExecutor.isActive()) {
                this.asyncHistoryExecutor.shutdown();
            }
    
            Runnable closeRunnable = this.processEngineConfiguration.getProcessEngineCloseRunnable();
            if (closeRunnable != null) {
                closeRunnable.run();
            }
    
            if (this.processEngineConfiguration.getProcessEngineLifecycleListener() != null) {
                this.processEngineConfiguration.getProcessEngineLifecycleListener().onProcessEngineClosed(this);
            }
    
            this.processEngineConfiguration.getEventDispatcher().dispatchEvent(FlowableEventBuilder.createGlobalEvent(FlowableEngineEventType.ENGINE_CLOSED));
        }
    
        public String getName() {
            return this.name;
        }
    
        public IdentityService getIdentityService() {
            return this.identityService;
        }
    
        public ManagementService getManagementService() {
            return this.managementService;
        }
    
        public TaskService getTaskService() {
            return this.taskService;
        }
    
        public HistoryService getHistoryService() {
            return this.historicDataService;
        }
    
        public RuntimeService getRuntimeService() {
            return this.runtimeService;
        }
    
        public RepositoryService getRepositoryService() {
            return this.repositoryService;
        }
    
        public FormService getFormService() {
            return this.formService;
        }
    
        public DynamicBpmnService getDynamicBpmnService() {
            return this.dynamicBpmnService;
        }
    
        public ProcessEngineConfigurationImpl getProcessEngineConfiguration() {
            return this.processEngineConfiguration;
        }
    }

    例子

    public class ModuleA {
        //示意方法
        public void testA(){
            System.out.println("调用ModuleA中的testA方法");
        }
    }
    public class ModuleB {
        //示意方法
        public void testB(){
            System.out.println("调用ModuleB中的testB方法");
        }
    }
    public class ModuleC {
        //示意方法
        public void testC(){
            System.out.println("调用ModuleC中的testC方法");
        }
    }
    public class Facade {
        //示意方法,满足客户端需要的功能
        public void test(){
            ModuleA a = new ModuleA();
            a.testA();
            ModuleB b = new ModuleB();
            b.testB();
            ModuleC c = new ModuleC();
            c.testC();
        }
    }
    public class Facade {
        //示意方法,满足客户端需要的功能
        public void test(){
            ModuleA a = new ModuleA();
            a.testA();
            ModuleB b = new ModuleB();
            b.testB();
            ModuleC c = new ModuleC();
            c.testC();
        }
    }
    public class Facade {
        //示意方法,满足客户端需要的功能
        public void test(){
            ModuleA a = new ModuleA();
            a.testA();
            ModuleB b = new ModuleB();
            b.testB();
            ModuleC c = new ModuleC();
            c.testC();
        }
    }
  • 相关阅读:
    适配器模式(PHP实现)
    php基础设计模式 注册树模式、工厂模式、单列模式
    mongodb数据库操作--备份 还原 导出 导入
    mongodb 非 admin 库 认证登陆失败 原因(百度好多都 是渣)db.addUser() 请走开。
    css3 标题超过长度自动省略号
    html5新增及废除属性
    HTML5 改良的 input 元素的种类
    SQLite学习笔记(十一)&&虚拟机原理
    SQLite使用(三)&&核心API使用
    SQLite使用(二)&&数据类型
  • 原文地址:https://www.cnblogs.com/LQBlog/p/12572681.html
Copyright © 2020-2023  润新知