Flink1.15源码阅读——flink-annotations

flink-annotations源码分析

Flink-annotation类图关系

本文将详细介绍下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。

在这里插入图片描述
在这里插入图片描述

FlinkVersion

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
/**
     * 用于配置选项字段的注释,以将它们包含在特定部分中。部分跨选项类聚合的选项组,放置每个组放到一个专用文件中。
     * 参数{@link Section#position()}控制生成表中的位置,使用较低的值被放置在顶部。相同位置的字段按字母顺序排序的关键。
     */
    @Target(ElementType.FIELD)
    @Retention(RetentionPolicy.RUNTIME)
    @Internal
    public @interface Section {
        /**
         * 配置文档中应该包含此选项的部分。
         */
        String[] value() default {};

        /**
         * 该选项在其部分中的相对位置。
         */
        int position() default Integer.MAX_VALUE;
    }
@Documentation.TableOption
/**
     * 表配置选项中用于添加元数据标签的注释。
     * <p>
     * {@link TableOption#execMode()}参数表示配置工作的执行模式(批处理、流处理或两者兼有)。
     */
    @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
    /**
     * 配置选项字段或REST API消息头上用于排除它的注释文档
     */
    @Target({ElementType.FIELD, ElementType.TYPE})
    @Retention(RetentionPolicy.RUNTIME)
    @Internal
    public @interface ExcludeFromDocumentation {
        /**
         * 从文档中排除它的可选原因。
         */
        String value() default "";
    }

@Experimental

/**
 * 此注解是为了标记某个类仍处于实验阶段
 *
 * @author DeveloperZJQ
 * @since 2022-7-19
 */
@Documented
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR})
@Public
public @interface Experimental {
}

@Internal

/**
 * 标记用作稳定的方法 , 公共的api作为内部的开发者api
 *
 * @author DeveloperZJQ
 * @since 2022-7-19
 */
@Documented
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD})
@Public
public @interface Internal {
}

@Public

/**
 * 被标记的类,意味着是一个公共的稳定的接口
 *
 * @author DeveloperZJQ
 * @since 2022-7-19
 */
@Documented
@Target(ElementType.TYPE)
@Public
public @interface Public {
}

@PublicEvolving

/**
 * 标记类和方法供公众使用的注释,但接口在不断变化。
 *
 * @author DeveloperZJQ
 * @since 2022-7-19
 */
@Documented
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR})
@Public
public @interface PublicEvolving {
}

@VisibleForTesting

/**
 * 这个注释声明一个函数、字段、构造函数或整个类型只在测试时可见。
 *
 * @author DeveloperZJQ
 * @since 2022-7-19
 */
@Documented
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR})
@Internal
public @interface VisibleForTesting {
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

京河小蚁

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值