All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alibaba.cola.boot.AbstractComponentExecutor Maven / Gradle / Ivy

There is a newer version: 3.1.0
Show newest version
package com.alibaba.cola.boot;

import com.alibaba.cola.extension.BizScenario;
import com.alibaba.cola.extension.ExtensionCoordinate;

import java.util.function.Consumer;
import java.util.function.Function;

/**
 * @author fulan.zjf
 * @date 2017/12/21
 */
public abstract class AbstractComponentExecutor {

    /**
     * Execute extension with Response
     *
     * @param targetClz
     * @param bizScenario
     * @param exeFunction
     * @param  Response Type
     * @param  Parameter Type
     * @return
     */
    public  R execute(Class targetClz, BizScenario bizScenario, Function exeFunction) {
        T component = locateComponent(targetClz, bizScenario);
        return exeFunction.apply(component);
    }

    public  R execute(ExtensionCoordinate extensionCoordinate, Function exeFunction){
        return execute((Class) extensionCoordinate.getExtensionPointClass(), extensionCoordinate.getBizScenario(), exeFunction);
    }

    /**
     * Execute extension without Response
     *
     * @param targetClz
     * @param context
     * @param exeFunction
     * @param  Parameter Type
     */
    public  void executeVoid(Class targetClz, BizScenario context, Consumer exeFunction) {
        T component = locateComponent(targetClz, context);
        exeFunction.accept(component);
    }

    public  void executeVoid(ExtensionCoordinate extensionCoordinate, Consumer exeFunction){
        executeVoid(extensionCoordinate.getExtensionPointClass(), extensionCoordinate.getBizScenario(), exeFunction);
    }

    protected abstract  C locateComponent(Class targetClz, BizScenario context);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy