ctf/tmf: allow multiple traces to be open with name clashing events
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 26 Mar 2014 17:39:43 +0000 (13:39 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Mon, 14 Apr 2014 20:33:15 +0000 (16:33 -0400)
This is a problem not yet encountered but that will be a showstopper.
If you have two traces with event definitions that have the same name
but different payloads the second one will override the first.

This means that if I have two traces with events that are named "bob"
and we have a state provider for each that looks up different fields
in "bob", one will no longer return the correct values and exceptions
will be thrown everywhere.

Change-Id: I05f9bc0fbbd67374fcf3680d75fcb769c4f32a3a
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/23285
Tested-by: Hudson CI
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventTypeTest.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventType.java

index 7c601b446053e5e134a04b06b2c83eac45a3b858..cbdf94760da618d8dd39f50c2fabb3fa530b36b8 100644 (file)
@@ -19,6 +19,7 @@ import static org.junit.Assert.assertNotNull;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEventType;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
 import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
+import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
 import org.junit.Test;
 
 /**
@@ -37,12 +38,12 @@ public class CtfTmfEventTypeTest {
     public void testCtfTmfEventType() {
         String eventName = "";
         ITmfEventField content = new TmfEventField("", null, new ITmfEventField[] {});
-        CtfTmfEventType result = new CtfTmfEventType( eventName, content);
+        CtfTmfEventType result = new CtfTmfEventType(eventName, new TmfTraceStub(), content);
 
         assertNotNull(result);
         assertEquals("", result.toString());
         assertEquals("", result.getName());
-        assertEquals("Ctf Event", result.getContext());
+        assertEquals("Ctf Event/null", result.getContext());
     }
 
     /**
@@ -51,7 +52,7 @@ public class CtfTmfEventTypeTest {
     @Test
     public void testToString() {
         ITmfEventField emptyField = new TmfEventField("", null, new ITmfEventField[] {});
-        CtfTmfEventType fixture = new CtfTmfEventType("", emptyField);
+        CtfTmfEventType fixture = new CtfTmfEventType("", new TmfTraceStub() , emptyField);
 
         String result = fixture.toString();
 
index d569217f3a14fe5f0605cada3d1becfc894d5933..8cab950ec05c60a4eb65b5453e6dd9cdad63f538 100644 (file)
@@ -139,10 +139,10 @@ public class CtfTmfEvent extends TmfEvent
 
     @Override
     public ITmfEventType getType() {
-        CtfTmfEventType ctfTmfEventType = CtfTmfEventType.get(fEventName);
+        CtfTmfEventType ctfTmfEventType = CtfTmfEventType.get(getTrace(), fEventName);
         if (ctfTmfEventType == null) {
             /* Should only return null the first time */
-            ctfTmfEventType = new CtfTmfEventType(fEventName, getContent());
+            ctfTmfEventType = new CtfTmfEventType(fEventName, getTrace(), getContent());
         }
         return ctfTmfEventType;
     }
index 9c3fcdffe65b8c6208f01561d8cc04f23cbd155e..80c97adc469b9a3864ac30350e261096a5f860c7 100644 (file)
@@ -14,6 +14,7 @@ package org.eclipse.linuxtools.tmf.core.ctfadaptor;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
 import org.eclipse.linuxtools.tmf.core.event.TmfEventType;
 import org.eclipse.linuxtools.tmf.core.event.TmfEventTypeManager;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
 
 /**
  * The CTF extension of the TMF event type
@@ -23,18 +24,26 @@ import org.eclipse.linuxtools.tmf.core.event.TmfEventTypeManager;
  */
 public class CtfTmfEventType extends TmfEventType {
 
+    /**
+     * CTFTmfEventType context for the event type manager
+     */
     private static final String CONTEXT_ID = "Ctf Event"; //$NON-NLS-1$
 
+    private static final String UNKNOWN_TRACE = "unknown"; //$NON-NLS-1$
+
     /**
      * Constructor for CtfTmfEventType.
      *
      * @param eventName
-     *            String
+     *            The event name
+     * @param trace
+     *            the parent trace
      * @param content
-     *            ITmfEventField
+     *            The event field
+     * @since 3.0
      */
-    public CtfTmfEventType(String eventName, ITmfEventField content) {
-        super(CONTEXT_ID, eventName, content);
+    public CtfTmfEventType(String eventName, ITmfTrace trace, ITmfEventField content) {
+        super(computeContextName(trace), eventName, content);
     }
 
     /**
@@ -50,11 +59,26 @@ public class CtfTmfEventType extends TmfEventType {
     /**
      * gets the event type for an event name
      *
+     * @param trace
+     *            the parent trace
      * @param eventName
      *            the event name
      * @return the event type
+     * @since 3.0
+     */
+    public static CtfTmfEventType get(CtfTmfTrace trace, String eventName) {
+        return (CtfTmfEventType) TmfEventTypeManager.getInstance().getType(computeContextName(trace), eventName);
+    }
+
+    /**
+     * Get the context name of a ctf trace
+     *
+     * @param trace
+     *            the trace
+     * @return the context name
+     * @since 3.0
      */
-    public static CtfTmfEventType get(String eventName){
-        return (CtfTmfEventType) TmfEventTypeManager.getInstance().getType(CONTEXT_ID, eventName);
+    public static String computeContextName(ITmfTrace trace) {
+        return CONTEXT_ID + "/" + (trace == null ? UNKNOWN_TRACE : trace.getPath()); //$NON-NLS-1$
     }
 }
This page took 0.027091 seconds and 5 git commands to generate.