tmf: Add command to manually refresh traces
[deliverable/tracecompass.git] / btf / org.eclipse.tracecompass.btf.core / src / org / eclipse / tracecompass / btf / core / trace / BtfTrace.java
index 1dc22f6f4e24bec4f8d620ef0364170c9f13f4c4..ef796b9320429e4ea240fa142595bdd3eba6387f 100644 (file)
@@ -38,6 +38,8 @@ import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.tracecompass.tmf.core.io.BufferedRandomAccessFile;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceContext;
+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.ITmfTraceProperties;
@@ -218,6 +220,26 @@ public class BtfTrace extends TmfTrace implements ITmfPersistentlyIndexable, ITm
 
     }
 
+    private void initFile() throws TmfTraceException {
+        closeFile();
+        try {
+            fFileInput = new BufferedRandomAccessFile(getPath(), "r"); //$NON-NLS-1$
+        } catch (IOException e) {
+            throw new TmfTraceException(e.getMessage(), e);
+        }
+    }
+
+    private void closeFile() {
+        if (fFileInput != null) {
+            try {
+                fFileInput.close();
+            } catch (IOException e) {
+            } finally {
+                fFileInput = null;
+            }
+        }
+    }
+
     @Override
     public IStatus validate(IProject project, String path) {
         File file = new File(path);
@@ -470,4 +492,21 @@ public class BtfTrace extends TmfTrace implements ITmfPersistentlyIndexable, ITm
         super.dispose();
     }
 
+    @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.024532 seconds and 5 git commands to generate.