Skip to content

Commit

Permalink
rename extension
Browse files Browse the repository at this point in the history
  • Loading branch information
yusu committed Jul 31, 2024
1 parent f454dc7 commit b1f96e9
Show file tree
Hide file tree
Showing 19 changed files with 73 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
/**
* @author yusu
*/
public interface IExtensionPoint {
public interface Extension {

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public <T> T invoke(String extensionCode, Predicate predicate, Object... args) {
return invoke(extensionCode, reduceFilter, args);
}

public <T> T invoke(String extensionCode, Class<? extends IExtensionPoint> extension, Object... args) {
public <T> T invoke(String extensionCode, Class<? extends Extension> extension, Object... args) {
List<ExtensionSpec> extensions = ExtensionManager.getInstance().getExtensions(extensionCode);
if (CollectionUtils.isEmpty(extensions)) {
return null;
Expand All @@ -60,7 +60,7 @@ public <T> T invoke(String extensionCode, Class<? extends IExtensionPoint> exten
return (T) invoke(extensionSpec, args);
}

public <T> T invoke(String extensionCode, Class<? extends IExtensionPoint> extension,
public <T> T invoke(String extensionCode, Class<? extends Extension> extension,
ReduceFilter reduceFilter, Object... args) {
List<ExtensionSpec> extensions = ExtensionManager.getInstance().getExtensions(extensionCode);
if (CollectionUtils.isEmpty(extensions)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.alibaba.compileflow.engine.common.Lifecycle;
import com.alibaba.compileflow.engine.common.MultiMap;
import com.alibaba.compileflow.engine.common.extension.annotation.Extension;
import com.alibaba.compileflow.engine.common.extension.annotation.ExtensionRealization;
import com.alibaba.compileflow.engine.common.extension.annotation.ExtensionPoint;
import com.alibaba.compileflow.engine.common.extension.spec.*;
import com.alibaba.compileflow.engine.common.util.ClassLoaderUtils;
Expand Down Expand Up @@ -36,8 +36,8 @@ public class ExtensionManager implements Lifecycle {

private static final Logger logger = LoggerFactory.getLogger(ExtensionManager.class);

private Set<Class<? extends IExtensionPoint>> extensionPointClasses = new HashSet<>();
private Set<Class<? extends IExtensionPoint>> extensionsClasses = new HashSet<>();
private Set<Class<? extends Extension>> extensionPointClasses = new HashSet<>();
private Set<Class<? extends Extension>> extensionsClasses = new HashSet<>();

private List<ExtensionPointSpec> extensionPointSpecs = new ArrayList<>();
private Map<String, ExtensionPointSpec> extensionPointSpecMap = new HashMap<>();
Expand All @@ -62,7 +62,7 @@ public List<ExtensionSpec> getExtensions(String extensionCode) {
return extensionSpecMap.get(extensionCode);
}

public <T extends IExtensionPoint> List<T> getExtensions(String extensionCode, Class<T> extensionClass) {
public <T extends Extension> List<T> getExtensions(String extensionCode, Class<T> extensionClass) {
List<ExtensionSpec> extensionSpecs = extensionSpecMap.get(extensionCode);
if (CollectionUtils.isEmpty(extensionSpecs)) {
return Collections.emptyList();
Expand All @@ -72,7 +72,7 @@ public <T extends IExtensionPoint> List<T> getExtensions(String extensionCode, C
.map(extension -> (T) extension).collect(Collectors.toList());
}

public void registerExtensionPoint(Class<? extends IExtensionPoint> extensionPointClass) {
public void registerExtensionPoint(Class<? extends Extension> extensionPointClass) {
if (extensionPointClasses.contains(extensionPointClass)) {
return;
}
Expand All @@ -95,14 +95,14 @@ public void registerExtensionPoint(Class<? extends IExtensionPoint> extensionPoi
extensionPointSpecMap.put(extensionPointSpec.getCode(), extensionPointSpec);
}
Class<?> returnType = method.getReturnType();
if (IExtensionPoint.class.isAssignableFrom(returnType)) {
registerExtensionPoint((Class<? extends IExtensionPoint>) returnType);
if (Extension.class.isAssignableFrom(returnType)) {
registerExtensionPoint((Class<? extends Extension>) returnType);
}
}
}

public void registerExtension(Class<? extends IExtensionPoint> extensionClass) {
IExtensionPoint extension = null;
public void registerExtension(Class<? extends Extension> extensionClass) {
Extension extension = null;
try {
extension = ClassUtils.newInstance(extensionClass);
} catch (Exception e) {
Expand All @@ -119,20 +119,20 @@ public void sortExtensionsByPriority() {
}
}

private void registerExtension(IExtensionPoint extension) {
Class<? extends IExtensionPoint> extensionClass = extension.getClass();
private void registerExtension(Extension extension) {
Class<? extends Extension> extensionClass = extension.getClass();
if (extensionsClasses.contains(extensionClass)) {
return;
}

Extension extensionAnnotation = extensionClass.getAnnotation(Extension.class);
if (extensionAnnotation == null) {
ExtensionRealization extensionRealizationAnnotation = extensionClass.getAnnotation(ExtensionRealization.class);
if (extensionRealizationAnnotation == null) {
return;
}

ExtensionPoint extensionPointAnnotation = AnnotationUtils.findAnnotation(extensionClass, ExtensionPoint.class);
if (extensionPointAnnotation != null) {
ExtensionSpec extensionSpec = ClassExtensionSpec.of(extensionAnnotation,
ExtensionSpec extensionSpec = ClassExtensionSpec.of(extensionRealizationAnnotation,
extensionPointAnnotation, extension);
extensionSpecs.add(extensionSpec);
extensionSpecMap.put(extensionSpec.getCode(), extensionSpec);
Expand All @@ -142,14 +142,14 @@ private void registerExtension(IExtensionPoint extension) {
for (Method method : methods) {
extensionPointAnnotation = AnnotationUtils.findAnnotation(method, ExtensionPoint.class);
if (extensionPointAnnotation != null) {
ExtensionSpec extensionSpec = MethodExtensionSpec.of(extensionAnnotation,
ExtensionSpec extensionSpec = MethodExtensionSpec.of(extensionRealizationAnnotation,
extensionPointAnnotation, extension, method);
extensionSpecs.add(extensionSpec);
extensionSpecMap.put(extensionSpec.getCode(), extensionSpec);
}
Class<?> returnType = method.getReturnType();
if (IExtensionPoint.class.isAssignableFrom(returnType)) {
IExtensionPoint subExtension = null;
if (Extension.class.isAssignableFrom(returnType)) {
Extension subExtension = null;
try {
subExtension = MethodUtils.invoke(extension, method);
} catch (Exception e) {
Expand Down Expand Up @@ -184,14 +184,14 @@ private void loadExtensions() {
return;
}
for (File file : files) {
Class<IExtensionPoint> extensionPointClass = ClassLoaderUtils.loadClass(file.getName());
Class<Extension> extensionPointClass = ClassLoaderUtils.loadClass(file.getName());
registerExtensionPoint(extensionPointClass);
BufferedReader reader = new BufferedReader(new FileReader(file));
String line;
while ((line = reader.readLine()) != null) {
String classFullName = line.trim();
if (StringUtils.isNotBlank(classFullName)) {
Class<IExtensionPoint> extensionClass = ClassLoaderUtils.loadClass(classFullName);
Class<Extension> extensionClass = ClassLoaderUtils.loadClass(classFullName);
registerExtension(extensionClass);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ public <T> boolean isEnabled(T target) {
return true;
}

public List<Class<? extends IExtensionPoint>> getExtensionPointClasses() {
public List<Class<? extends Extension>> getExtensionPointClasses() {
return Collections.emptyList();
}

public List<Class<? extends IExtensionPoint>> getExtensionClasses() {
public List<Class<? extends Extension>> getExtensionClasses() {
return Collections.emptyList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.alibaba.compileflow.engine.common.DirectedGraph;
import com.alibaba.compileflow.engine.common.Lifecycle;
import com.alibaba.compileflow.engine.common.extension.annotation.Extension;
import com.alibaba.compileflow.engine.common.extension.annotation.ExtensionRealization;
import com.alibaba.compileflow.engine.common.extension.annotation.PluginDependency;
import com.alibaba.compileflow.engine.common.extension.annotation.PluginDependsOn;
import com.alibaba.compileflow.engine.common.extension.config.PluginConfig;
Expand Down Expand Up @@ -320,15 +320,15 @@ private void registerExtensionPointsAndExtensions() {
String extensionPackage = plugin.getExtensionPackage() != null ? plugin.getExtensionPackage()
: plugin.getClass().getPackage().getName();
if (extensionPackage != null) {
List<Class<? extends IExtensionPoint>> extensionClasses = PackageUtils.getAllClassInPacakge(
List<Class<? extends Extension>> extensionClasses = PackageUtils.getAllClassInPacakge(
extensionPackage)
.stream().filter(IExtensionPoint.class::isAssignableFrom)
.map(clazz -> (Class<? extends IExtensionPoint>) clazz)
.stream().filter(Extension.class::isAssignableFrom)
.map(clazz -> (Class<? extends Extension>) clazz)
.collect(Collectors.toList());
for (Class<? extends IExtensionPoint> extensionClass : extensionClasses) {
Extension extensionAnnotation = AnnotationUtils.findAnnotation(extensionClass,
Extension.class);
if (extensionAnnotation != null) {
for (Class<? extends Extension> extensionClass : extensionClasses) {
ExtensionRealization extensionRealizationAnnotation = AnnotationUtils.findAnnotation(extensionClass,
ExtensionRealization.class);
if (extensionRealizationAnnotation != null) {
registerExtension(extensionClass);
} else if (ClassUtils.isAbstractOrInterface(extensionClass)) {
registerExtensionPoint(extensionClass);
Expand All @@ -339,11 +339,11 @@ private void registerExtensionPointsAndExtensions() {
}
}

private void registerExtensionPoint(Class<? extends IExtensionPoint> extensionPointClass) {
private void registerExtensionPoint(Class<? extends Extension> extensionPointClass) {
ExtensionManager.getInstance().registerExtensionPoint(extensionPointClass);
}

private void registerExtension(Class<? extends IExtensionPoint> extensionClass) {
private void registerExtension(Class<? extends Extension> extensionClass) {
ExtensionManager.getInstance().registerExtension(extensionClass);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
@Retention(RUNTIME)
@Target({TYPE})
public @interface Extension {
public @interface ExtensionRealization {

int priority() default 500;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.alibaba.compileflow.engine.common.extension.spec;

import com.alibaba.compileflow.engine.common.extension.IExtensionPoint;
import com.alibaba.compileflow.engine.common.extension.Extension;
import com.alibaba.compileflow.engine.common.extension.annotation.ExtensionPoint;

/**
Expand All @@ -9,7 +9,7 @@
public class ClassExtensionPointSpec extends ExtensionPointSpec {

public static ClassExtensionPointSpec of(ExtensionPoint extensionPointAnnotation,
Class<? extends IExtensionPoint> extensionPointClass) {
Class<? extends Extension> extensionPointClass) {
ClassExtensionPointSpec extensionMethod = new ClassExtensionPointSpec();
extensionMethod.setCode(extensionPointAnnotation.code());
extensionMethod.setName(extensionPointAnnotation.name());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.alibaba.compileflow.engine.common.extension.spec;

import com.alibaba.compileflow.engine.common.extension.IExtensionPoint;
import com.alibaba.compileflow.engine.common.extension.annotation.Extension;
import com.alibaba.compileflow.engine.common.extension.Extension;
import com.alibaba.compileflow.engine.common.extension.annotation.ExtensionRealization;
import com.alibaba.compileflow.engine.common.extension.annotation.ExtensionPoint;

/**
* @author yusu
*/
public class ClassExtensionSpec extends ExtensionSpec {

public static ExtensionSpec of(Extension extensionAnnotation,
public static ExtensionSpec of(ExtensionRealization extensionRealizationAnnotation,
ExtensionPoint extensionPointAnnotation,
IExtensionPoint extensions) {
Extension extensions) {
ExtensionSpec extensionSpec = new ClassExtensionSpec();
extensionSpec.setExtension(extensions);
extensionSpec.setScenario(extensionAnnotation.scenario());
extensionSpec.setPriority(extensionAnnotation.priority());
extensionSpec.setScenario(extensionRealizationAnnotation.scenario());
extensionSpec.setPriority(extensionRealizationAnnotation.priority());
extensionSpec.setCode(extensionPointAnnotation.code());
extensionSpec.setName(extensionPointAnnotation.name());
extensionSpec.setDescription(extensionPointAnnotation.description());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.alibaba.compileflow.engine.common.extension.spec;

import com.alibaba.compileflow.engine.common.extension.IExtensionPoint;
import com.alibaba.compileflow.engine.common.extension.Extension;
import com.alibaba.compileflow.engine.common.extension.constant.ReducePolicy;

/**
Expand All @@ -12,7 +12,7 @@ public abstract class ExtensionPointSpec extends BaseSpec {

private ReducePolicy reducePolicy;

private Class<? extends IExtensionPoint> extensionPointClass;
private Class<? extends Extension> extensionPointClass;

public String getGroup() {
return group;
Expand All @@ -30,11 +30,11 @@ public void setReducePolicy(ReducePolicy reducePolicy) {
this.reducePolicy = reducePolicy;
}

public Class<? extends IExtensionPoint> getExtensionPointClass() {
public Class<? extends Extension> getExtensionPointClass() {
return extensionPointClass;
}

public void setExtensionPointClass(Class<? extends IExtensionPoint> extensionPointClass) {
public void setExtensionPointClass(Class<? extends Extension> extensionPointClass) {
this.extensionPointClass = extensionPointClass;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.alibaba.compileflow.engine.common.extension.spec;

import com.alibaba.compileflow.engine.common.extension.IExtensionPoint;
import com.alibaba.compileflow.engine.common.extension.Extension;
import com.alibaba.compileflow.engine.common.extension.constant.ReducePolicy;

/**
Expand All @@ -16,7 +16,7 @@ public abstract class ExtensionSpec extends BaseSpec {

private ReducePolicy reducePolicy;

private IExtensionPoint extension;
private Extension extension;

public abstract boolean isCollectionFlat();

Expand Down Expand Up @@ -54,11 +54,11 @@ public void setReducePolicy(ReducePolicy reducePolicy) {
this.reducePolicy = reducePolicy;
}

public IExtensionPoint getExtension() {
public Extension getExtension() {
return extension;
}

public void setExtension(IExtensionPoint extension) {
public void setExtension(Extension extension) {
this.extension = extension;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.alibaba.compileflow.engine.common.extension.spec;

import com.alibaba.compileflow.engine.common.extension.IExtensionPoint;
import com.alibaba.compileflow.engine.common.extension.Extension;
import com.alibaba.compileflow.engine.common.extension.annotation.ExtensionPoint;

import java.lang.reflect.Method;
Expand All @@ -13,7 +13,7 @@ public class MethodExtensionPointSpec extends ExtensionPointSpec {
private Method method;

public static MethodExtensionPointSpec of(ExtensionPoint extensionPointAnnotation,
Class<? extends IExtensionPoint> extensionPointClass,
Class<? extends Extension> extensionPointClass,
Method method) {
MethodExtensionPointSpec extensionMethod = new MethodExtensionPointSpec();
extensionMethod.setCode(extensionPointAnnotation.code());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.alibaba.compileflow.engine.common.extension.spec;

import com.alibaba.compileflow.engine.common.extension.IExtensionPoint;
import com.alibaba.compileflow.engine.common.extension.annotation.Extension;
import com.alibaba.compileflow.engine.common.extension.Extension;
import com.alibaba.compileflow.engine.common.extension.annotation.ExtensionRealization;
import com.alibaba.compileflow.engine.common.extension.annotation.ExtensionPoint;
import com.alibaba.compileflow.engine.common.extension.constant.FlatType;
import com.alibaba.compileflow.engine.common.extension.invoker.FastMethodInvoker;
Expand All @@ -20,14 +20,14 @@ public class MethodExtensionSpec extends ExtensionSpec {

private Method method;

public static MethodExtensionSpec of(Extension extensionAnnotation,
public static MethodExtensionSpec of(ExtensionRealization extensionRealizationAnnotation,
ExtensionPoint extensionPointAnnotation,
IExtensionPoint extensions,
Extension extensions,
Method method) {
MethodExtensionSpec extensionSpec = new MethodExtensionSpec();
extensionSpec.setExtension(extensions);
extensionSpec.setScenario(extensionAnnotation.scenario());
extensionSpec.setPriority(extensionAnnotation.priority());
extensionSpec.setScenario(extensionRealizationAnnotation.scenario());
extensionSpec.setPriority(extensionRealizationAnnotation.priority());
extensionSpec.setCode(extensionPointAnnotation.code());
extensionSpec.setName(extensionPointAnnotation.name());
extensionSpec.setDescription(extensionPointAnnotation.description());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.alibaba.compileflow.engine.process.preruntime.compiler;

import com.alibaba.compileflow.engine.common.extension.IExtensionPoint;
import com.alibaba.compileflow.engine.common.extension.Extension;
import com.alibaba.compileflow.engine.common.extension.annotation.ExtensionPoint;
import com.alibaba.compileflow.engine.common.extension.constant.ReducePolicy;

/**
* @author yusu
*/
public interface FlowClassLoaderFactory extends IExtensionPoint {
public interface FlowClassLoaderFactory extends Extension {

String EXT_FLOW_CLASS_LOADER_CODE = "com.alibaba.compileflow.engine.process.preruntime.compiler.FlowClassLoaderFactory.getFlowClassLoader";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
package com.alibaba.compileflow.engine.process.preruntime.compiler;

import com.alibaba.compileflow.engine.common.extension.IExtensionPoint;
import com.alibaba.compileflow.engine.common.extension.Extension;
import com.alibaba.compileflow.engine.common.extension.annotation.ExtensionPoint;
import com.alibaba.compileflow.engine.common.extension.constant.ReducePolicy;

Expand All @@ -29,7 +29,7 @@
* @author yusu
*/
public interface JavaCompiler extends IExtensionPoint {
public interface JavaCompiler extends Extension {

String EXT_COMPILE_CODE = "com.alibaba.compileflow.engine.process.preruntime.compiler.JavaCompiler.compile";

Expand Down
Loading

0 comments on commit b1f96e9

Please sign in to comment.