提交 920af645 编写于 作者: J JackieTien97

Make View Portable

上级 a45248d4
...@@ -87,27 +87,42 @@ public class MNodeFactoryLoader { ...@@ -87,27 +87,42 @@ public class MNodeFactoryLoader {
new Reflections( new Reflections(
new ConfigurationBuilder().forPackages(scanPackages.toArray(new String[0]))); new ConfigurationBuilder().forPackages(scanPackages.toArray(new String[0])));
Set<Class<?>> nodeFactorySet = reflections.getTypesAnnotatedWith(MNodeFactory.class); Set<Class<?>> nodeFactorySet = reflections.getTypesAnnotatedWith(MNodeFactory.class);
IMNodeFactory res = null;
int priority = Integer.MIN_VALUE;
for (Class<?> nodeFactory : nodeFactorySet) { for (Class<?> nodeFactory : nodeFactorySet) {
if (isGenericMatch(nodeFactory, nodeType) && isEnvMatch(nodeFactory, env)) { if (isGenericMatch(nodeFactory, nodeType) && isEnvMatch(nodeFactory, env)) {
try { try {
return (IMNodeFactory) nodeFactory.getDeclaredConstructor().newInstance(); MNodeFactory annotationInfo = nodeFactory.getAnnotation(MNodeFactory.class);
if (annotationInfo.priority() > priority) {
res = (IMNodeFactory) nodeFactory.getDeclaredConstructor().newInstance();
}
} catch (Exception e) { } catch (Exception e) {
throw new SchemaExecutionException(e); throw new SchemaExecutionException(e);
} }
} }
} }
if (res != null) {
return res;
}
// if no satisfied MNodeFactory in customer env found, use default env // if no satisfied MNodeFactory in customer env found, use default env
for (Class<?> nodeFactory : nodeFactorySet) { for (Class<?> nodeFactory : nodeFactorySet) {
if (isGenericMatch(nodeFactory, nodeType) if (isGenericMatch(nodeFactory, nodeType)
&& isEnvMatch(nodeFactory, SchemaConstant.DEFAULT_MNODE_FACTORY_ENV)) { && isEnvMatch(nodeFactory, SchemaConstant.DEFAULT_MNODE_FACTORY_ENV)) {
try { try {
return (IMNodeFactory) nodeFactory.getDeclaredConstructor().newInstance(); MNodeFactory annotationInfo = nodeFactory.getAnnotation(MNodeFactory.class);
if (annotationInfo.priority() > priority) {
res = (IMNodeFactory) nodeFactory.getDeclaredConstructor().newInstance();
}
} catch (Exception e) { } catch (Exception e) {
throw new SchemaExecutionException(e); throw new SchemaExecutionException(e);
} }
} }
} }
throw new SchemaExecutionException("No satisfied MNodeFactory found"); if (res != null) {
return res;
} else {
throw new SchemaExecutionException("No satisfied MNodeFactory found");
}
} }
public boolean isGenericMatch(Class<?> factory, Class<?> targetType) { public boolean isGenericMatch(Class<?> factory, Class<?> targetType) {
......
...@@ -28,4 +28,11 @@ import java.lang.annotation.Target; ...@@ -28,4 +28,11 @@ import java.lang.annotation.Target;
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
public @interface MNodeFactory { public @interface MNodeFactory {
String env() default "IoTDB"; String env() default "IoTDB";
/**
* The higher the number, the higher the priority.
*
* @return the priority of this class.
*/
int priority() default 0;
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册