Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propose new api for configurable data provider factories #235

Draft
wants to merge 7 commits into
base: 2021-06
Choose a base branch
from

Conversation

frallax
Copy link
Contributor

@frallax frallax commented Mar 13, 2025

What it does

Proposal to extend the public API with a new class that can (should) be extended by all data provider factories that want to provide the configuration feature.

The main goal is to provide a "pattern" for configurable data provider factories, so that they follow a similar coding style (at least for the less advanced use cases). This hopefully can help to make configurable data provider factories easier to implement and to document how to implement them.

A practical example of how to use this is provided in a separate PR for the InAndOutDataProvider in the incubator project (I will add comments below).

How to test

Tests will be added if the proposal is accepted.
For the moment, checking out this branch together with the one named similarly for the incubator project, where the InAndOutDataProvider is used, it should enable seeing how the code changes while the InAndOutDataProvider has the same functions as before.

Follow-ups

If accepted, adding tests and documentation on how to create configurable data provider factories using this common pattern.

Review checklist

  • As an author, I have thoroughly tested my changes and carefully followed the instructions in this template

@frallax
Copy link
Contributor Author

frallax commented Mar 13, 2025

NOTES:

  • as a first draft, I am pushing to 2021-06 just because I have a environment configured on that env. It will eventually be pushed to master if discussions go in the right direction
  • please ignore changes to non-java files for the draft PR
  • this incubator PR shows how I foresee the usage of the new API

description = "Data provider defined by configuration " + configuration.getName(); //$NON-NLS-1$
}

TmfConfiguration.Builder builder = new TmfConfiguration.Builder();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class currently enforces the use of TmfConfiguration, A better approach might be to introduce a createConfig() method, which child classes can implement to return an ITmfConfiguration.

    @Override
    protected ITmfConfiguration createConfig() {
        return new CustomTmfConfiguration();
    }

List<ITmfConfiguration> configs = readConfigurations(tr);
readAndApplyConfiguration(trace, configs);
}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The configuration might be stored at the experiment level, so it might be better to move the following two lines outside the else block to ensure they always execute.

List<ITmfConfiguration> configs = readConfigurations(trace);
readAndApplyConfiguration(trace, configs);

Copy link
Contributor

@bhufmann bhufmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. It's good to have code re-use. The incubator InAndOutAnalysis and other downstream plug-ins with similar configurations can use it. I added some comments this PR.

* The json file extension
* @since 9.5
*/
public static final String JSON_EXTENSION = "json"; //$NON-NLS-1$
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't remove it just yet. It's api and needs to be deprecated first. In incubator master branch there is already a new class that uses it.

* if an error occurs
* @since 9.5
*/
public static void writeConfiguration(ITmfConfiguration configuration, IPath rootPath) throws TmfConfigurationException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't remove it just yet. It's api and needs to be deprecated first. In incubator master branch there is already a new class that uses it.

/**
* This class meant to be extended by data provider factories that want to be
* able to handle configurations.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need a @since 9.6 tag

/**
* @return a table mapping configuration id and trace (exp) to its configuration
*/
protected Table<String, ITmfTrace, ITmfConfiguration> getConfigurationTable(){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you put this public, then you can have the configurator as a separate class and the parent data provider factory doesn't need to extend that class (see IDataProviderFactory.getAdapter(), which needs to be overriden by the factory to return other objects that itself). I tried it with the InAndOutAnalysis and it worked.

@@ -0,0 +1,242 @@
package org.eclipse.tracecompass.tmf.core.config;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright header

* the close signal to handle
*/
@TmfSignalHandler
public void traceClosed(TmfTraceClosedSignal signal) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This this class handles tmf signals, we need to register to the signal manager and also derigster when it's disposed. You can register in the constructor.

TmfSignalManager.register(this);

Probably this class should have a dispose method to deregister from the signal manager. The factory dispose() method would call then this method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants