- flink-annotations源码分析
- Flink-annotation类图关系
- FlinkVersion
- docs注解
- @ConfigGroup
- @ConfigGroups
- @Documentation
- @Documentation.OverrideDefault
- @Documentation.Section
- @Documentation.TableOption
- @Documentation.SuffixOption
- @Documentation.ExcludeFromDocumentation
- @Experimental
- @Internal
- @Public
- @PublicEvolving
- @VisibleForTesting
本文将详细介绍下flink中的自定义注解模块,了解flink注解的作用与使用。主要围绕flink源码中的 flink-annotations模块,与docs 相关的注解有@ConfigGroup和@ConfigGroups , 通常作用于配置类上;@Documentation.OverrideDefault、@Documentation.Section、@Documentation.TableOption、@Documentation.SuffixOption,@Documentation.ExcludeFromDocumentation 作用于配置类的 ConfigOption 字段上,对配置项做一些修改。另外,还有其他5种标记注解,@Experimental、@Internal、@Public、@PublicEvolving、@VisibleForTesting。
flink 版本枚举类,在SQL/Table API升级期间,它用于API版本控制和迁移测试。
docs注解 @ConfigGroup指定一组配置选项的类。组的名称将作为基础生成的html文件的文件名,定义在{@link ConfigOptionsDocGenerator}中。
如 @ConfigGroup(name = ExponentialDelayRestartStrategy",keyPrefix = “restart-strategy.exponential-delay”),生成的 HTML 文件名为 ExponentialDelayRestartStrategy ,其中的配置项名称都是以 restart-strategy.exponential-delay 开头的。
@Target({})
@Internal
public @interface ConfigGroup {
String name();
String keyPrefix();
}
@ConfigGroups
在包含配置选项的类上使用的注释,允许根据键前缀将选项分离到不同的表中。如果选项键匹配组前缀,则配置选项被分配给{@link ConfigGroup}。当一个键匹配多个前缀时,匹配时间最长的前缀优先。选项永远不会分配给多个组。不匹配任何组的选项将隐式添加到默认组。
允许一个配置类中的配置项可以按照配置项名称前缀分成不同的组,生成多个 HTML 文件。
如:
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Internal
public @interface ConfigGroups {
ConfigGroup[] groups() default {};
}
@Documentation
用于修改文档生成器行为的注释集合。
@Documentation.OverrideDefault
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@Internal
public @interface OverrideDefault {
String value();
}
@Documentation.Section
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@Internal
public @interface Section {
String[] value() default {};
int position() default Integer.MAX_VALUE;
}
@Documentation.TableOption
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@Internal
public @interface TableOption {
ExecMode execMode();
}
public enum ExecMode {
BATCH("Batch"),
STREAMING("Streaming"),
BATCH_STREAMING("Batch and Streaming");
private final String name;
ExecMode(String name) {
this.name = name;
}
@Override
public String toString() {
return name;
}
}
@Documentation.SuffixOption
@Target({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Internal
public @interface SuffixOption {
String value();
}
@Documentation.ExcludeFromDocumentation
@Target({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Internal
public @interface ExcludeFromDocumentation {
String value() default "";
}
@Experimental
@Documented
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR})
@Public
public @interface Experimental {
}
@Internal
@Documented
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD})
@Public
public @interface Internal {
}
@Public
@Documented
@Target(ElementType.TYPE)
@Public
public @interface Public {
}
@PublicEvolving
@Documented
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR})
@Public
public @interface PublicEvolving {
}
@VisibleForTesting
@Documented
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR})
@Internal
public @interface VisibleForTesting {
}



