Skip to content

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

* 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

/**
* 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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

/**
* @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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have not understood what you propose here. Could you please try to rephrase or provide some code snippets? Thanks!

Copy link
Contributor

@bhufmann bhufmann Apr 7, 2025

Choose a reason for hiding this comment

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

So, the IDataProviderFactory provides a getAdapter(class) method (

) that the trace server is using to get the configurator instance. The factory implementation can decide to implement itself the ITmfDataProviderConfigurator interface or overrides the getAdapter(...) method as below and return a different class that implements the ITmfDataProviderConfigurator interface. So, the getConfigurationTable() method needs to be public instead of protected to allow that the factory class to call that method.

public class MyDataProviderFactory implements IDataProviderFactory {
// ....
   private MyConfigurator fConfigurator = new MyConfigurator();

   @Override
    public <T> @Nullable T getAdapter(@Nullable Class<T> adapter) {
        if (adapter != null && adapter.equals(ITmfDataProviderConfigurator.class)) {
            return (T) fConfigurator;
        }
        return null;
    }

// ...
}

where:

public class MyConfigurator implements ITmfDataProviderConfigurator {
// ...
}

So, if MyConfigurator would extend your new AbstractTmfDataProviderConfigurator the factory class might call fConfigurator.getConfigurationTable() to get configurations per trace. Here is the change that I had to do for the getDescriptor(trace) method of InAndOutDataProviderFactory of your example :

  @Override
    public Collection<IDataProviderDescriptor> getDescriptors(ITmfTrace trace) {
        List<IDataProviderDescriptor> list = new ArrayList<>();
        list.add(DESCRIPTOR);
        for (ITmfConfiguration config : configurator.getConfigurationTable().column(trace).values()) {
            list.add(fConfigurator.getDescriptorFromConfig(config));
        }
        return list;
    }

Having said all the above, you might be just able to change the method configurator.getDescriptorFromConfig(...) and pass the trace as parameter. Then you don't need to make the getConfigurationTable() public.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made the method public as you requested

@@ -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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

* 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@frallax frallax force-pushed the frallax-config-refactor branch from 057a18e to 70d5719 Compare April 3, 2025 12:38
@frallax frallax changed the base branch from 2021-06 to master April 3, 2025 12:39
@frallax frallax requested a review from bhufmann April 10, 2025 08:08
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