-
Notifications
You must be signed in to change notification settings - Fork 0
Comments on "Frallax feedback" #1
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| package org.eclipse.tracecompass.tmf.core.config; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.eclipse.jdt.annotation.NonNull; | ||
| import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderDescriptor; | ||
| import org.eclipse.tracecompass.tmf.core.exceptions.TmfConfigurationException; | ||
| import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler; | ||
| import org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal; | ||
| import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal; | ||
| import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | ||
| import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager; | ||
| import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment; | ||
|
|
||
| import com.google.common.collect.HashBasedTable; | ||
| import com.google.common.collect.Table; | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
| public abstract class AbstractTmfDataProviderConfigurator implements ITmfDataProviderConfigurator{ | ||
|
|
||
| private static final Table<String, ITmfTrace, ITmfConfiguration> fTmfConfigurationTable = HashBasedTable.create(); | ||
|
|
||
| @Override | ||
| public @NonNull IDataProviderDescriptor createDataProviderDescriptors(ITmfTrace trace, ITmfConfiguration configuration) throws TmfConfigurationException { | ||
|
|
||
| if (configuration.getName().equals(TmfConfiguration.UNKNOWN)) { | ||
| throw new TmfConfigurationException("Missing configuration name of InAndOut analysis"); //$NON-NLS-1$ | ||
| } | ||
|
|
||
| if (configuration.getSourceTypeId().equals(TmfConfiguration.UNKNOWN)) { | ||
| throw new TmfConfigurationException("Missing configuration type for InAndOut analysis"); //$NON-NLS-1$ | ||
| } | ||
|
|
||
| String description = configuration.getDescription(); | ||
| if (configuration.getDescription().equals(TmfConfiguration.UNKNOWN)) { | ||
| description = "InAndOut Analysis defined by configuration " + configuration.getName(); //$NON-NLS-1$ | ||
| } | ||
|
|
||
| TmfConfiguration.Builder builder = new TmfConfiguration.Builder(); | ||
| builder.setId(configuration.getId()) | ||
| .setSourceTypeId(configuration.getSourceTypeId()) | ||
| .setName(configuration.getName()) | ||
| .setDescription(description) | ||
| .setParameters(configuration.getParameters()) | ||
| .build(); | ||
|
|
||
| ITmfConfiguration config = builder.build(); | ||
|
|
||
| applyConfiguration(trace, config, true); | ||
| if (fTmfConfigurationTable.contains(config.getId(), trace)) { | ||
| throw new TmfConfigurationException("Configuration already existis with label: " + config.getName()); //$NON-NLS-1$ | ||
| } | ||
| fTmfConfigurationTable.put(config.getId(), trace, config); | ||
| return getDescriptorFromConfig(config); | ||
| } | ||
|
|
||
| /** | ||
| * @param config | ||
| * @return A data provider descriptor based on the configuration parameter | ||
| */ | ||
| protected abstract IDataProviderDescriptor getDescriptorFromConfig(ITmfConfiguration config); | ||
|
|
||
| /** | ||
| * This is the method that handles what happens when a configuration is applied | ||
| * @param trace | ||
| * @param config | ||
| * @param writeConfig | ||
| */ | ||
| protected abstract void applyConfiguration(ITmfTrace trace, ITmfConfiguration config, boolean writeConfig); | ||
|
|
||
| // efrooo: the below move to open source | ||
| @Override | ||
| public void removeDataProviderDescriptor(ITmfTrace trace, IDataProviderDescriptor descriptor) throws TmfConfigurationException { | ||
| ITmfConfiguration creationConfiguration = descriptor.getConfiguration(); | ||
| if (creationConfiguration == null) { | ||
| throw new TmfConfigurationException("Data provider was not created by a configuration"); //$NON-NLS-1$ | ||
| } | ||
|
|
||
| String configId = creationConfiguration.getId(); | ||
| ITmfConfiguration config = fTmfConfigurationTable.get(configId, trace); | ||
| if (config == null) { | ||
| return; | ||
| } | ||
| config = fTmfConfigurationTable.remove(configId, trace); | ||
| removeConfiguration(trace, config); | ||
| } | ||
|
|
||
| /** | ||
| * This is the method that handles what happens when a configuration is removed (e.g. remove analysis, dp etc) | ||
| * @param trace | ||
| * @param config | ||
| */ | ||
| protected abstract void removeConfiguration(@NonNull ITmfTrace trace, @NonNull ITmfConfiguration config); | ||
|
|
||
| // efroroo: to open source | ||
| /** | ||
| * Signal handler for opened trace signal. Will populate trace | ||
| * configurations | ||
| * | ||
| * @param signal | ||
| * the signal to handle | ||
| */ | ||
| @TmfSignalHandler | ||
| public void traceOpened(TmfTraceOpenedSignal signal, String subfolder) { | ||
| ITmfTrace trace = signal.getTrace(); | ||
| if (trace == null) { | ||
| return; | ||
| } | ||
| try { | ||
| if (trace instanceof TmfExperiment) { | ||
| for (ITmfTrace tr : TmfTraceManager.getTraceSet(trace)) { | ||
| // Read configurations from sub-trace | ||
| List<ITmfConfiguration> configs = TmfConfiguration.readConfigurations(tr, subfolder); | ||
| readAndApplyConfiguration(trace, configs); | ||
| } | ||
| } else { | ||
| // Read configurations trace | ||
| List<ITmfConfiguration> configs = TmfConfiguration.readConfigurations(trace, subfolder); | ||
| readAndApplyConfiguration(trace, configs); | ||
| } | ||
| } catch (TmfConfigurationException e) { | ||
| // FIXME: use proper logging | ||
| // Activator.logError("Error applying configurations for trace " + trace.getName(), e); //$NON-NLS-1$ | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Handles trace closed signal | ||
| * | ||
| * @param signal | ||
| * the close signal to handle | ||
| */ | ||
| @TmfSignalHandler | ||
| public void traceClosed(TmfTraceClosedSignal signal) { | ||
| ITmfTrace trace = signal.getTrace(); | ||
| fTmfConfigurationTable.column(trace).clear(); | ||
| } | ||
|
|
||
| private void readAndApplyConfiguration(ITmfTrace trace, List<ITmfConfiguration> configs) throws TmfConfigurationException { | ||
| for (ITmfConfiguration config : configs) { | ||
| if (!fTmfConfigurationTable.contains(config.getId(), trace)) { | ||
| fTmfConfigurationTable.put(config.getId(), trace, config); | ||
| applyConfiguration(trace, config, false); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,15 +17,24 @@ | |
| import java.io.Reader; | ||
| import java.io.Writer; | ||
| import java.nio.charset.Charset; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.UUID; | ||
|
|
||
| import org.eclipse.core.runtime.IPath; | ||
| import org.eclipse.core.runtime.Path; | ||
| import org.eclipse.jdt.annotation.NonNull; | ||
| import org.eclipse.jdt.annotation.Nullable; | ||
| import org.eclipse.tracecompass.internal.tmf.core.Activator; | ||
| import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule; | ||
| import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException; | ||
| import org.eclipse.tracecompass.tmf.core.exceptions.TmfConfigurationException; | ||
| import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException; | ||
| import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | ||
| import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager; | ||
|
|
||
| import com.google.gson.Gson; | ||
| import com.google.gson.JsonParseException; | ||
|
|
@@ -343,4 +352,109 @@ public static void writeConfiguration(ITmfConfiguration configuration, IPath roo | |
| throw new TmfConfigurationException("Error writing configuration.", e); //$NON-NLS-1$ | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings("null") | ||
| private static @NonNull IPath getConfigurationRootFolder(@NonNull ITmfTrace trace, String subFolder) { | ||
| String supplFolder = TmfTraceManager.getSupplementaryFileDir(trace); | ||
| IPath supplPath = new Path(supplFolder); | ||
| supplPath = supplPath.addTrailingSeparator().append(subFolder); | ||
| return supplPath; | ||
| } | ||
|
|
||
| /** | ||
| * Reads the configurations for a given trace | ||
| * | ||
| * @param trace | ||
| * the trace to read configurations from | ||
| * @return list of configurations if any | ||
| * @throws TmfConfigurationException | ||
| * if an error occurs | ||
| */ | ||
| public static @NonNull List<ITmfConfiguration> readConfigurations(@NonNull ITmfTrace trace, String subfolder) throws TmfConfigurationException { | ||
| IPath rootPath = getConfigurationRootFolder(trace, subfolder); | ||
| File folder = rootPath.toFile(); | ||
| List<ITmfConfiguration> list = new ArrayList<>(); | ||
| if (folder.exists()) { | ||
| File[] listOfFiles = folder.listFiles(); | ||
| for (File file : listOfFiles) { | ||
| IPath path = new Path(file.getName()); | ||
| if (path.getFileExtension().equals(TmfConfiguration.JSON_EXTENSION)) { | ||
| ITmfConfiguration config = TmfConfiguration.fromJsonFile(file); | ||
| list.add(config); | ||
| } | ||
| } | ||
| } | ||
| return list; | ||
| } | ||
|
|
||
| /** | ||
| * Removes configuration from trace: | ||
| * - delete configuration file | ||
| * - remove analysis module from trace object | ||
| * | ||
| * @param config | ||
| * the configuration to remove | ||
| * @param trace | ||
| * the | ||
| * @throws TmfConfigurationException if an error occurs | ||
| */ | ||
| public static void remove(ITmfConfiguration config, @NonNull ITmfTrace trace, String baseAnalysisId) throws TmfConfigurationException { | ||
| IPath traceConfig = getConfigurationRootFolder(trace, config.getSourceTypeId()); | ||
| traceConfig = traceConfig.append(File.separator).append(config.getId()).addFileExtension(TmfConfiguration.JSON_EXTENSION); | ||
| File configFile = traceConfig.toFile(); | ||
| if ((!configFile.exists()) || !configFile.delete()) { | ||
| throw new TmfConfigurationException("Configuration file can't be deleted from trace: configId=" + config.getId()); //$NON-NLS-1$ | ||
| } | ||
|
|
||
| // Remove and clear persistent data | ||
| try { | ||
| IAnalysisModule module = trace.removeAnalysisModule(baseAnalysisId + config.getId()); | ||
| if (module != null) { | ||
| module.dispose(); | ||
| module.clearPersistentData(); | ||
| } | ||
| } catch (TmfTraceException e) { | ||
| throw new TmfConfigurationException("Error removing analysis module from trace: analysis ID=" + baseAnalysisId + config.getId(), e); //$NON-NLS-1$ | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Create the InAndOutAnalysisModule for a given configuration and trace | ||
| * | ||
| * @param config | ||
| * the input {@link ITmfConfiguration} | ||
| * @param trace | ||
| * the trace to apply it to | ||
| * @param writeConfig | ||
| * write the config (do only once) | ||
| * @return InAndOutAnalysisModule | ||
| * @throws TmfConfigurationException | ||
| * if an error occurs | ||
| */ | ||
| public static void create(@NonNull ITmfConfiguration config, @NonNull ITmfTrace trace, boolean writeConfig, IAnalysisModule module) throws TmfConfigurationException { | ||
| /* | ||
| * Apply configuration to each trace (no need to check trace type here) | ||
| */ | ||
| module.setConfiguration(config); | ||
| if (writeConfig) { | ||
| IPath traceConfigPath = TmfConfiguration.getConfigurationRootFolder(trace, config.getSourceTypeId()); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we can't store it per |
||
| TmfConfiguration.writeConfiguration(config, traceConfigPath); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also here we'll be writing a configuration to file whenever we create an analysis module, which is still binding one configuration file to one analysis module. So the configuration on data provider level will still needs to be a parallel implementation. Which means we'll be writing configuration to file in different places in the code. |
||
| } | ||
| try { | ||
| if (module.setTrace(trace)) { | ||
| IAnalysisModule oldModule = trace.addAnalysisModule(module); | ||
| if (oldModule != null) { | ||
| oldModule.dispose(); | ||
| oldModule.clearPersistentData(); | ||
| } | ||
| } else { | ||
| module.dispose(); | ||
| throw new TmfConfigurationException("InAndOut analysis module can't be created"); //$NON-NLS-1$ | ||
| } | ||
| } catch (TmfAnalysisException | TmfTraceException e) { | ||
| module.dispose(); | ||
| throw new TmfConfigurationException("Exception when setting trace", e); //$NON-NLS-1$ | ||
| } | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create() and remove() includes how the analysis module is initialized and how the configuration file is managed. But we're writing config files in our own specified location (per data provider id), so those are preferably in our own code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if we move create() and remove() to internal code,
AbstractTmfDataProviderConfigurator.traceOpened()andTmfConfiguration.readConfigurations()also needs to be in internal code, because we no longer have control over where we store the files.