tmf: Add command to manually refresh traces
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / trace / text / TextTrace.java
index 1e41e06688bdd2046a61725b852d39a2468db6a4..bfd4a812d0cbef657d72ea32151d1a8f257de322 100644 (file)
@@ -30,6 +30,8 @@ import org.eclipse.tracecompass.internal.tmf.core.Activator;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.tracecompass.tmf.core.io.BufferedRandomAccessFile;
+import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
+import org.eclipse.tracecompass.tmf.core.signal.TmfTraceRangeUpdatedSignal;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
@@ -125,6 +127,11 @@ public abstract class TextTrace<T extends TextTraceEvent> extends TmfTrace imple
     @Override
     public void initTrace(IResource resource, String path, Class<? extends ITmfEvent> type) throws TmfTraceException {
         super.initTrace(resource, path, type);
+        initFile();
+    }
+
+    private void initFile() throws TmfTraceException {
+        closeFile();
         try {
             fFile = new BufferedRandomAccessFile(getPath(), "r"); //$NON-NLS-1$
         } catch (IOException e) {
@@ -135,6 +142,10 @@ public abstract class TextTrace<T extends TextTraceEvent> extends TmfTrace imple
     @Override
     public synchronized void dispose() {
         super.dispose();
+        closeFile();
+    }
+
+    private void closeFile() {
         if (fFile != null) {
             try {
                 fFile.close();
@@ -401,4 +412,22 @@ public abstract class TextTrace<T extends TextTraceEvent> extends TmfTrace imple
     public ITmfLocation restoreLocation(ByteBuffer bufferIn) {
         return new TmfLongLocation(bufferIn);
     }
+
+    @TmfSignalHandler
+    @Override
+    public void traceRangeUpdated(TmfTraceRangeUpdatedSignal signal) {
+        if (signal.getTrace() == this) {
+            try {
+                synchronized (this) {
+                    // Reset the file handle in case it has reached the end of the
+                    // file already. Otherwise, it will not be able to read new data
+                    // pass the previous end.
+                    initFile();
+                }
+            } catch (TmfTraceException e) {
+                Activator.logError(e.getLocalizedMessage(), e);
+            }
+        }
+        super.traceRangeUpdated(signal);
+    }
 }
This page took 0.027107 seconds and 5 git commands to generate.