D
D
DDwrt1002021-03-09 13:00:30
Java
DDwrt100, 2021-03-09 13:00:30

How does the inheritance mechanism work in Java in large products like SPRING, KAFKA?

Good afternoon. Please help me figure it out.
I have already met this situation several times: when using large products like Spring.
To write custom logic for some modules, you need to inherit from some class (of type AbstarctSecContext), and rewrite some modules using the Override annotation, for example, to make your template engine work.
And I do not understand the mechanism of this action. For example, how does the program know that the product code has a successor and needs to use it, and not the previous implementation in its work?
Below I give an example of a training code for kafka streams, where you write your own connector.

public class TestSinkConnector  extends SinkConnector {

    public static final String FILE_CONFIG = "file";
    public static final String NAME_CONFIG = "numb";

    // config start
    private static final ConfigDef CONFIG_DEF = new ConfigDef()
            .define(FILE_CONFIG, Type.STRING, Importance.HIGH, "Destination filename");
    // config end

    private String fileName = "/tmp/monitor.txt";

    @Override
    public String version() {
        return "1.0";
    }

    @Override
    public void start(Map<String, String> props) {

        // config start
        AbstractConfig parsedConfig = new AbstractConfig(CONFIG_DEF, props);
        fileName = parsedConfig.getString(FILE_CONFIG);
        // config end
    }

    @Override
    public Class<? extends Task> taskClass() {
        return TestSinkTask.class;
    }

    @Override
    public List<Map<String, String>> taskConfigs(int maxTasks) {
        ArrayList<Map<String, String>> configs = new ArrayList<>();
        for(int i=0; i<maxTasks; i++) {
            Map<String, String> config = new HashMap<>();
            config.put(NAME_CONFIG,"NUMBER-"+(i+1));
            config.put(FILE_CONFIG,fileName);
            configs.add(config);
        }
        return configs;
    }

    @Override
    public void stop() {
    }

    @Override
    public ConfigDef config() {
        return new ConfigDef();
    }

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-03-09
@DDwrt100

If you don't explicitly register it anywhere, then using reflection .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question