com.alibaba.cola.boot.AbstractComponentExecutor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cola-core Show documentation
Show all versions of cola-core Show documentation
Cola framework core components
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);
}