btf: Remove AutoCloseable from BtfTrace
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 7 Jul 2015 20:00:17 +0000 (16:00 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 8 Sep 2015 18:42:11 +0000 (14:42 -0400)
Despite many great advantages, AutoCloseable does not work well
with subclasses of ITmfTrace, because it would imply that such
objects are not exposed publicly by other objects tracking them.

This is not the case in TMF, as many objects expose ITmfTrace's
through getters. Using instead TmfTrace's standard dispose()
method is more appropriate in subclasses.

Change-Id: I1d342d15dba7f8f6e75985f8aee6ed159838d424
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/51540
Reviewed-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
btf/org.eclipse.tracecompass.btf.core.tests/src/org/eclipse/tracecompass/btf/core/tests/trace/BtfTraceTest.java
btf/org.eclipse.tracecompass.btf.core.tests/src/org/eclipse/tracecompass/btf/core/tests/utils/TestBtfTrace.java
btf/org.eclipse.tracecompass.btf.core/META-INF/MANIFEST.MF
btf/org.eclipse.tracecompass.btf.core/pom.xml
btf/org.eclipse.tracecompass.btf.core/src/org/eclipse/tracecompass/btf/core/trace/BtfTrace.java

index 2ac8625b36a7aee222217ef522cfd7e4532fdbeb..b4ec8f7b47096440b1d7fcf101cd5d5c9edfec86 100644 (file)
@@ -13,7 +13,6 @@ package org.eclipse.tracecompass.btf.core.tests.trace;
 
 import static org.junit.Assert.*;
 
-import java.io.IOException;
 import java.util.Map;
 
 import org.eclipse.tracecompass.btf.core.tests.utils.BtfTestTrace;
@@ -50,9 +49,7 @@ public class BtfTraceTest {
      */
     @After
     public void cleanup() {
-        try {
-            fixture.close();
-        } catch (IOException e) {}
+        fixture.dispose();
     }
 
     /**
index 1fcf4f48a8464c76bcbed320bd922424e926eb50..47290a436b0ef0a1e75bc2129a10e664198c1bcf 100644 (file)
@@ -12,8 +12,6 @@
 
 package org.eclipse.tracecompass.btf.core.tests.utils;
 
-import java.io.IOException;
-
 import org.eclipse.tracecompass.btf.core.trace.BtfTrace;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
@@ -36,26 +34,26 @@ public class TestBtfTrace {
      *             exception
      */
     public static void main(String[] args) throws TmfTraceException {
-        try (BtfTrace trace = new BtfTrace()) {
-            trace.initTrace(null, BtfTestTrace.BTF_TEST.getFullPath(), null);
-            System.out.println(trace.toString());
-            ITmfContext ctx = trace.seekEvent(0);
-            ITmfContext ctx1 = trace.seekEvent(10);
-            ITmfEvent event = trace.getNext(ctx);
-            ITmfEvent compare = null;
-            while (event != null) {
-                if (event.getRank() == 10) {
-                    compare = event;
-                }
-                printEvent(event);
-                event = trace.getNext(ctx);
+        BtfTrace trace = new BtfTrace();
+        trace.initTrace(null, BtfTestTrace.BTF_TEST.getFullPath(), null);
+        System.out.println(trace.toString());
+
+        ITmfContext ctx = trace.seekEvent(0);
+        ITmfContext ctx1 = trace.seekEvent(10);
+        ITmfEvent event = trace.getNext(ctx);
+        ITmfEvent compare = null;
+        while (event != null) {
+            if (event.getRank() == 10) {
+                compare = event;
             }
-            ITmfEvent other = trace.getNext(ctx1);
-            printEvent(other);
-            printEvent(compare);
-        } catch (IOException e) {
-            e.printStackTrace();
+            printEvent(event);
+            event = trace.getNext(ctx);
         }
+        ITmfEvent other = trace.getNext(ctx1);
+        printEvent(other);
+        printEvent(compare);
+
+        trace.dispose();
     }
 
     private static void printEvent(ITmfEvent event) {
index 47338932ec224ba959ecbd5d1f491fc28102aa58..be67a5674bed9291218ae98abfa2c9fea1a8d994 100644 (file)
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: %Bundle-Name
 Bundle-Vendor: %Bundle-Vendor
-Bundle-Version: 1.0.0.qualifier
+Bundle-Version: 2.0.0.qualifier
 Bundle-Localization: plugin
 Bundle-SymbolicName: org.eclipse.tracecompass.btf.core;singleton:=true
 Bundle-Activator: org.eclipse.tracecompass.btf.core.Activator
index 43fbd30c7228a3f3a89879f74190c64ac9f34239..0f4d5e1e92215a28c640b3a7ad4c5653b2ba2496 100644 (file)
@@ -18,7 +18,6 @@
   </parent>
 
   <artifactId>org.eclipse.tracecompass.btf.core</artifactId>
-  <version>1.0.0-SNAPSHOT</version>
   <packaging>eclipse-plugin</packaging>
 
   <name>Best Trace Format Plug-in</name>
index 7f92f718dd69bfcc6315d7f09420481f058f671d..bffcbe1059f55c31b2acf33100915e836d5a4ebe 100644 (file)
@@ -59,7 +59,7 @@ import com.google.common.collect.ImmutableMap;
  *
  * @author Matthew Khouzam
  */
-public class BtfTrace extends TmfTrace implements ITmfPersistentlyIndexable, ITmfTraceProperties, AutoCloseable {
+public class BtfTrace extends TmfTrace implements ITmfPersistentlyIndexable, ITmfTraceProperties {
 
     private static final int MAX_FIELDS = 7;
 
@@ -450,10 +450,15 @@ public class BtfTrace extends TmfTrace implements ITmfPersistentlyIndexable, ITm
     }
 
     @Override
-    public void close() throws IOException {
-        if (fFileInput != null) {
-            fFileInput.close();
+    public synchronized void dispose() {
+        RandomAccessFile raf = fFileInput;
+        if (raf != null) {
+            try {
+                raf.close();
+            } catch (IOException e) {
+            }
         }
+        super.dispose();
     }
 
 }
This page took 0.027403 seconds and 5 git commands to generate.