X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=tmf%2Forg.eclipse.tracecompass.tmf.core%2Fsrc%2Forg%2Feclipse%2Ftracecompass%2Ftmf%2Fcore%2Ftrace%2FTmfTraceManager.java;h=e3d61e854170bcaf28b2d26b4ba231f812816b25;hb=bcd8d4b12d6c8e7de2b48064e4bd629714047341;hp=77a43cb0436e02d4919d829a1a14d57213576f7a;hpb=df2597e06aa1e8f2a6ea84db36d7e1e51e5f410d;p=deliverable%2Ftracecompass.git diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/trace/TmfTraceManager.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/trace/TmfTraceManager.java index 77a43cb043..e3d61e8541 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/trace/TmfTraceManager.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/trace/TmfTraceManager.java @@ -17,6 +17,7 @@ package org.eclipse.tracecompass.tmf.core.trace; import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; import java.io.File; +import java.io.IOException; import java.net.URISyntaxException; import java.util.Collection; import java.util.Collections; @@ -26,6 +27,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.apache.commons.io.FileUtils; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; @@ -33,18 +35,19 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.URIUtil; import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.tracecompass.common.core.NonNullUtils; import org.eclipse.tracecompass.internal.tmf.core.Activator; import org.eclipse.tracecompass.tmf.core.TmfCommonConstants; import org.eclipse.tracecompass.tmf.core.signal.TmfEventFilterAppliedSignal; -import org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal; +import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal; import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler; import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager; -import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal; import org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal; +import org.eclipse.tracecompass.tmf.core.signal.TmfTraceModelSignal; import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal; import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal; +import org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal; import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange; import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp; @@ -63,6 +66,7 @@ import com.google.common.collect.ImmutableSet; * * @author Alexandre Montplaisir */ +@NonNullByDefault public final class TmfTraceManager { // ------------------------------------------------------------------------ @@ -72,7 +76,7 @@ public final class TmfTraceManager { private final Map fTraces; /** The currently-selected trace. Should always be part of the trace map */ - private ITmfTrace fCurrentTrace = null; + private @Nullable ITmfTrace fCurrentTrace = null; private static final String TEMP_DIR_NAME = ".temp"; //$NON-NLS-1$ @@ -86,7 +90,7 @@ public final class TmfTraceManager { } /** Singleton instance */ - private static TmfTraceManager tm = null; + private static @Nullable TmfTraceManager tm = null; /** * Get an instance of the trace manager. @@ -94,10 +98,12 @@ public final class TmfTraceManager { * @return The trace manager */ public static synchronized TmfTraceManager getInstance() { - if (tm == null) { - tm = new TmfTraceManager(); + TmfTraceManager mgr = tm; + if (mgr == null) { + mgr = new TmfTraceManager(); + tm = mgr; } - return tm; + return mgr; } // ------------------------------------------------------------------------ @@ -107,19 +113,21 @@ public final class TmfTraceManager { /** * Get the currently selected trace (normally, the focused editor). * - * @return The active trace + * @return The active trace, or null if there is no active + * trace */ - public synchronized ITmfTrace getActiveTrace() { + public synchronized @Nullable ITmfTrace getActiveTrace() { return fCurrentTrace; } /** * Get the trace set of the currently active trace. * - * @return The active trace set + * @return The active trace set. Empty (but non-null) if there is no + * currently active trace. * @see #getTraceSet(ITmfTrace) */ - public synchronized @NonNull Collection getActiveTraceSet() { + public synchronized Collection getActiveTraceSet() { final ITmfTrace trace = fCurrentTrace; return getTraceSet(trace); } @@ -140,7 +148,7 @@ public final class TmfTraceManager { * the trace * @return the editor file or null if the trace is not opened */ - public synchronized IFile getTraceEditorFile(ITmfTrace trace) { + public synchronized @Nullable IFile getTraceEditorFile(ITmfTrace trace) { TmfTraceContext ctx = fTraces.get(trace); if (ctx != null) { return ctx.getEditorFile(); @@ -174,18 +182,19 @@ public final class TmfTraceManager { * all the traces contained in this experiment. * * @param trace - * The trace or experiment + * The trace or experiment. If it is null, an empty collection + * will be returned. * @return The corresponding trace set. */ - public static @NonNull Collection<@NonNull ITmfTrace> getTraceSet(ITmfTrace trace) { + public static Collection getTraceSet(@Nullable ITmfTrace trace) { if (trace == null) { - return NonNullUtils.checkNotNull(ImmutableSet.of()); + return ImmutableSet.of(); } List<@NonNull ITmfTrace> traces = trace.getChildren(ITmfTrace.class); if (traces.size() > 0) { - return NonNullUtils.checkNotNull(ImmutableSet.copyOf(traces)); + return ImmutableSet.copyOf(traces); } - return NonNullUtils.checkNotNull(ImmutableSet.of(trace)); + return ImmutableSet.of(trace); } /** @@ -195,21 +204,22 @@ public final class TmfTraceManager { * this experiment, along with the experiment. * * @param trace - * The trace or experiment + * The trace or experiment. If it is null, an empty collection + * will be returned. * @return The corresponding trace set, including the experiment. */ - public static @NonNull Collection getTraceSetWithExperiment(ITmfTrace trace) { + public static Collection getTraceSetWithExperiment(@Nullable ITmfTrace trace) { if (trace == null) { - return checkNotNull(ImmutableSet. of()); + return ImmutableSet.of(); } if (trace instanceof TmfExperiment) { TmfExperiment exp = (TmfExperiment) trace; List traces = exp.getTraces(); Set alltraces = new LinkedHashSet<>(traces); alltraces.add(exp); - return NonNullUtils.checkNotNull(ImmutableSet.copyOf(alltraces)); + return ImmutableSet.copyOf(alltraces); } - return checkNotNull(Collections.singleton(trace)); + return Collections.singleton(trace); } /** @@ -266,6 +276,22 @@ public final class TmfTraceManager { } } + /** + * Delete the supplementary files of a given trace. + * + * @param trace + * The trace for which the supplementary files are to be deleted + * @since 2.2 + */ + public static void deleteSupplementaryFiles(ITmfTrace trace) { + try { + FileUtils.cleanDirectory(new File(TmfTraceManager.getSupplementaryFileDir(trace))); + } catch (IOException e) { + Activator.logError("Error deleting supplementary files for trace " + trace.getName(), e); //$NON-NLS-1$ + } + refreshSupplementaryFiles(trace); + } + // ------------------------------------------------------------------------ // Signal handlers // ------------------------------------------------------------------------ @@ -282,14 +308,12 @@ public final class TmfTraceManager { final IFile editorFile = signal.getEditorFile(); final ITmfTimestamp startTs = trace.getStartTime(); - /* Calculate the initial time range */ - final int SCALE = ITmfTimestamp.NANOSECOND_SCALE; - long offset = trace.getInitialRangeOffset().normalize(0, SCALE).getValue(); - long endTime = startTs.normalize(0, SCALE).getValue() + offset; + long offset = trace.getInitialRangeOffset().toNanos(); + long endTime = startTs.toNanos() + offset; final TmfTimeRange selectionRange = new TmfTimeRange(startTs, startTs); - final TmfTimeRange windowRange = new TmfTimeRange(startTs, new TmfTimestamp(endTime, SCALE)); + final TmfTimeRange windowRange = new TmfTimeRange(startTs, TmfTimestamp.fromNanos(endTime)); - final TmfTraceContext startCtx = new TmfTraceContext(selectionRange, windowRange, editorFile, null); + final TmfTraceContext startCtx = trace.createTraceContext(selectionRange, windowRange, editorFile, null); fTraces.put(trace, startCtx); @@ -297,6 +321,19 @@ public final class TmfTraceManager { fCurrentTrace = trace; } + /** + * Signal propagator + * + * @param signal + * any signal + * @since 2.0 + */ + @TmfSignalHandler + public synchronized void signalReceived(final TmfTraceModelSignal signal) { + fTraces.forEach((t, u) -> u.receive(signal)); + } + + /** * Handler for the TmfTraceSelectedSignal. * @@ -325,10 +362,12 @@ public final class TmfTraceManager { if (context == null) { throw new RuntimeException(); } - fTraces.put(newTrace, new TmfTraceContext(context.getSelectionRange(), + final TmfTraceContext newContext = newTrace.createTraceContext(context.getSelectionRange(), context.getWindowRange(), context.getEditorFile(), - signal.getEventFilter())); + signal.getEventFilter()); + newContext.setData(context.getData()); + fTraces.put(newTrace, newContext); } /** @@ -374,10 +413,11 @@ public final class TmfTraceManager { * else the same as the previous trace context. */ TmfTimeRange newSelectionRange = new TmfTimeRange(beginTs, endTs); - TmfTraceContext newCtx = new TmfTraceContext(newSelectionRange, + TmfTraceContext newCtx = trace.createTraceContext(newSelectionRange, prevCtx.getWindowRange(), prevCtx.getEditorFile(), prevCtx.getFilter()); + newCtx.setData(prevCtx.getData()); entry.setValue(newCtx); } } @@ -409,8 +449,9 @@ public final class TmfTraceManager { TmfTimeRange newWindowTr = (targetTr == null ? prevCtx.getWindowRange() : targetTr); /* Keep the values from the old context, except for the window range */ - TmfTraceContext newCtx = new TmfTraceContext(prevCtx.getSelectionRange(), + TmfTraceContext newCtx = trace.createTraceContext(prevCtx.getSelectionRange(), newWindowTr, prevCtx.getEditorFile(), prevCtx.getFilter()); + newCtx.setData(prevCtx.getData()); entry.setValue(newCtx); } }