tmf: Add command to manually refresh traces
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / parsers / custom / CustomXmlTrace.java
index bf3aa668220985c041fd830aa8e8778376f2c8ca..8df4b1b105953db9d4d81fbbb62732403dbfc931 100644 (file)
@@ -34,6 +34,8 @@ import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
 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.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.TmfContext;
@@ -119,6 +121,11 @@ public class CustomXmlTrace extends TmfTrace implements ITmfPersistentlyIndexabl
     @Override
     public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> eventType) throws TmfTraceException {
         super.initTrace(resource, path, eventType);
+        initFile();
+    }
+
+    private void initFile() throws TmfTraceException {
+        closeFile();
         try {
             fFile = new BufferedRandomAccessFile(getPath(), "r"); //$NON-NLS-1$
         } catch (IOException e) {
@@ -129,6 +136,10 @@ public class CustomXmlTrace extends TmfTrace implements ITmfPersistentlyIndexabl
     @Override
     public synchronized void dispose() {
         super.dispose();
+        closeFile();
+    }
+
+    private void closeFile() {
         if (fFile != null) {
             try {
                 fFile.close();
@@ -669,4 +680,22 @@ public class CustomXmlTrace extends TmfTrace implements ITmfPersistentlyIndexabl
         }
         return traceTypeId;
     }
+
+    @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.027051 seconds and 5 git commands to generate.