Track the available event types in each trace object instead. K.I.S.S.
Also removed the notion of "context" from TmfEventType, which is not
needed anymore.
Change-Id: I8dc1409abb08fd930dd1f8b01027ece488551ec1
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/35354
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
import org.eclipse.tracecompass.internal.gdbtrace.core.GdbTraceCorePlugin;
import org.eclipse.tracecompass.internal.gdbtrace.core.event.GdbTraceEvent;
import org.eclipse.tracecompass.internal.gdbtrace.core.event.GdbTraceEventContent;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEventType;
import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
// breakpoint (tracepoint is a kind of breakpoint)
private Map<Integer, MIBreakpointDMData> fTpInfo = new HashMap<>();
- private TmfEventType tmfEventType = new TmfEventType(ITmfEventType.DEFAULT_CONTEXT_ID, "GDB Tracepoint", TmfEventField.makeRoot(new String[] { "Content" })); //$NON-NLS-1$ //$NON-NLS-2$
+ private TmfEventType tmfEventType = new TmfEventType("GDB Tracepoint", TmfEventField.makeRoot(new String[] { "Content" })); //$NON-NLS-1$ //$NON-NLS-2$
{
new DsfGdbPlatformEventListener();
@Suite.SuiteClasses({
TmfEventFieldTest.class,
TmfEventTest.class,
- TmfEventTypeManagerTest.class,
TmfEventTypeTest.class,
TmfNanoTimestampTest.class,
TmfSimpleTimestampTest.class,
import org.eclipse.core.runtime.Path;
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEventType;
import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
private final String fSource = "Source";
- private final String fContext = ITmfEventType.DEFAULT_CONTEXT_ID;
private final String fTypeId = "TestType";
private final String fLabel1 = "AString";
private final String fLabel2 = "AnInteger";
private final String[] fLabels = new String[] { fLabel1, fLabel2 };
- private final TmfEventType fType = new TmfEventType(fContext, fTypeId, TmfEventField.makeRoot(fLabels));
+ private final TmfEventType fType = new TmfEventType(fTypeId, TmfEventField.makeRoot(fLabels));
private final Object fValue1a = "Some string";
private final Object fValue1b = Integer.valueOf(10);
final String typeId = "OtherTestType";
final String[] labels = new String[] { fLabel2, fLabel1 };
- final TmfEventType newType = new TmfEventType(fContext, typeId, TmfEventField.makeRoot(labels));
+ final TmfEventType newType = new TmfEventType(typeId, TmfEventField.makeRoot(labels));
event2 = new TmfEvent(null, 0, fTimestamp1, fSource, newType, fContent1, fReference1);
assertFalse("equals", event1.equals(event2));
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2012, 2013 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Francois Chouinard - Initial API and implementation
- * Alexandre Montplaisir - Port to JUnit4
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.core.tests.event;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Arrays;
-import java.util.Set;
-
-import org.eclipse.tracecompass.tmf.core.event.ITmfEventType;
-import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
-import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
-import org.eclipse.tracecompass.tmf.core.event.TmfEventTypeManager;
-import org.junit.Test;
-
-/**
- * Test suite for the TmfEventTypeManager class.
- */
-@SuppressWarnings("javadoc")
-public class TmfEventTypeManagerTest {
-
- // ------------------------------------------------------------------------
- // Variables
- // ------------------------------------------------------------------------
-
- private static final TmfEventTypeManager fInstance = TmfEventTypeManager.getInstance();
-
- private final String fContext1 = "JUnit context 1";
- private final String fContext2 = "JUnit context 2";
-
- private final String fTypeId1 = "Some type";
- private final String fTypeId2 = "Some other type";
- private final String fTypeId3 = "Yet another type";
- private final String fTypeId4 = "A final type";
-
- private final String fLabel0 = "label1";
- private final String fLabel1 = "label2";
- private final String fLabel2 = "label3";
-
- private final String[] fLabels0 = new String[] { };
- private final String[] fLabels1 = new String[] { fLabel0, fLabel1 };
- private final String[] fLabels2 = new String[] { fLabel1, fLabel0, fLabel2 };
-
- private final TmfEventType fType0 = new TmfEventType(fContext1, fTypeId1, TmfEventField.makeRoot(fLabels0));
- private final TmfEventType fType1 = new TmfEventType(fContext1, fTypeId2, TmfEventField.makeRoot(fLabels1));
- private final TmfEventType fType2 = new TmfEventType(fContext2, fTypeId3, TmfEventField.makeRoot(fLabels2));
- private final TmfEventType fType3 = new TmfEventType(fContext2, fTypeId4, TmfEventField.makeRoot(fLabels1));
-
- // ------------------------------------------------------------------------
- // Getters
- // ------------------------------------------------------------------------
-
- @Test
- public void testGetContexts() {
- fInstance.clear();
- fInstance.add(fContext1, fType0);
- fInstance.add(fContext1, fType1);
- fInstance.add(fContext2, fType2);
- fInstance.add(fContext2, fType3);
-
- final String[] contexts = fInstance.getContexts();
- Arrays.sort(contexts);
- assertEquals("getContexts", 2, contexts.length);
- assertEquals("getContexts", fContext1, contexts[0]);
- assertEquals("getContexts", fContext2, contexts[1]);
- }
-
- @Test
- public void testGetTypes() {
- fInstance.clear();
- fInstance.add(fContext1, fType0);
- fInstance.add(fContext1, fType1);
- fInstance.add(fContext2, fType2);
- fInstance.add(fContext2, fType3);
-
- Set<ITmfEventType> types = fInstance.getTypes(fContext1);
- assertEquals("getTypes", 2, types.size());
- assertTrue(types.contains(fType1));
- assertTrue(types.contains(fType0));
-
- types = fInstance.getTypes(fContext2);
- assertEquals("getTypes", 2, types.size());
- assertTrue(types.contains(fType2));
- assertTrue(types.contains(fType3));
- }
-
- @Test
- public void testGetType() {
- fInstance.clear();
- fInstance.add(fContext1, fType0);
- fInstance.add(fContext1, fType1);
- fInstance.add(fContext2, fType2);
- fInstance.add(fContext2, fType3);
-
- ITmfEventType type = fInstance.getType(fContext1, fType0.getName());
- assertSame("getType", fType0, type);
- type = fInstance.getType(fContext1, fType1.getName());
- assertSame("getType", fType1, type);
- type = fInstance.getType(fContext1, fType2.getName());
- assertNull("getType", type);
- type = fInstance.getType(fContext1, fType3.getName());
- assertNull("getType", type);
-
- type = fInstance.getType(fContext2, fType2.getName());
- assertSame("getType", fType2, type);
- type = fInstance.getType(fContext2, fType3.getName());
- assertSame("getType", fType3, type);
- type = fInstance.getType(fContext2, fType0.getName());
- assertNull("getType", type);
- type = fInstance.getType(fContext2, fType1.getName());
- assertNull("getType", type);
- }
-
- // ------------------------------------------------------------------------
- // Operations
- // ------------------------------------------------------------------------
-
- @Test
- public void testClear() {
- fInstance.clear();
- assertEquals("clear", 0, fInstance.getContexts().length);
- assertEquals("clear", 0, fInstance.getTypes(null).size());
- assertNull("clear", fInstance.getType(null, null));
- assertEquals("clear", "TmfEventTypeManager [fEventTypes={}]", fInstance.toString());
- }
-
- @Test
- public void testClearContext() {
- fInstance.clear();
- fInstance.add(fContext1, fType0);
- fInstance.add(fContext1, fType1);
- fInstance.add(fContext2, fType2);
- fInstance.add(fContext2, fType3);
-
- fInstance.clear(fContext1);
-
- final String[] contexts = fInstance.getContexts();
- assertEquals("clear context", 1, contexts.length);
- assertEquals("clear context", fContext2, contexts[0]);
-
- Set<ITmfEventType> types = fInstance.getTypes(fContext1);
- assertEquals("clear context", 0, types.size());
-
- ITmfEventType type = fInstance.getType(fContext1, fType0.getName());
- assertNull("clear context", type);
- type = fInstance.getType(fContext1, fType1.getName());
- assertNull("clear context", type);
-
- types = fInstance.getTypes(fContext2);
- assertEquals("clear context", 2, types.size());
- assertTrue(types.contains(fType2));
- assertTrue(types.contains(fType3));
- }
-
- @Test
- public void testBasicAdd() {
- fInstance.clear();
- fInstance.add(fContext1, fType0);
-
- final String[] contexts = fInstance.getContexts();
- assertEquals("add", 1, contexts.length);
- assertEquals("add", fContext1, contexts[0]);
-
- final Set<ITmfEventType> types = fInstance.getTypes(contexts[0]);
- assertEquals("add", 1, types.size());
- assertTrue(types.contains(fType0));
-
- ITmfEventType type = fInstance.getType(contexts[0], fType0.getName());
- assertSame("add", fType0, type);
-
- type = fInstance.getType(contexts[0], fType1.getName());
- assertNotSame("add", fType0, type);
- }
-
- @Test
- public void testAdd() {
- fInstance.clear();
- fInstance.add(fContext1, fType0);
- fInstance.add(fContext1, fType1);
- fInstance.add(fContext2, fType2);
- fInstance.add(fContext2, fType3);
-
- final String[] contexts = fInstance.getContexts();
- Arrays.sort(contexts);
- assertEquals("add", 2, contexts.length);
- assertEquals("add", fContext1, contexts[0]);
- assertEquals("add", fContext2, contexts[1]);
-
- Set<ITmfEventType> types = fInstance.getTypes(fContext1);
- assertEquals("add", 2, types.size());
- assertTrue(types.contains(fType0));
- assertTrue(types.contains(fType1));
-
- types = fInstance.getTypes(fContext2);
- assertEquals("add", 2, types.size());
- assertTrue(types.contains(fType2));
- assertTrue(types.contains(fType3));
-
- ITmfEventType type = fInstance.getType(fContext1, fType0.getName());
- assertSame("add", fType0, type);
- type = fInstance.getType(fContext1, fType1.getName());
- assertSame("add", fType1, type);
- type = fInstance.getType(fContext2, fType2.getName());
- assertSame("add", fType2, type);
- type = fInstance.getType(fContext2, fType3.getName());
- assertSame("add", fType3, type);
-
- type = fInstance.getType(fContext1, fType2.getName());
- assertNull("add", type);
- type = fInstance.getType(fContext2, fType0.getName());
- assertNull("add", type);
- }
-
- // ------------------------------------------------------------------------
- // Object
- // ------------------------------------------------------------------------
-
- @Test
- public void testToString() {
- fInstance.clear();
- assertEquals("toString", "TmfEventTypeManager [fEventTypes={}]", fInstance.toString());
-
- fInstance.add(fContext1, fType0);
- assertEquals("toString", "TmfEventTypeManager [fEventTypes={" + fContext1 + "={" + fTypeId1 + "=" + fType0 + "}}]", fInstance.toString());
- }
-
-}
// Variables
// ------------------------------------------------------------------------
- private final String fContext1 = "JUnit context 1";
- private final String fContext2 = "JUnit context 2";
-
private final String fTypeId1 = "Some type";
private final String fTypeId2 = "Some other type";
private final String[] fLabels1 = new String[] { fLabel0, fLabel1 };
private final String[] fLabels2 = new String[] { fLabel1, fLabel0, fLabel2 };
- private final ITmfEventType fType0 = new TmfEventType(fContext1, fTypeId1, TmfEventField.makeRoot(fLabels0));
- private final ITmfEventType fType1 = new TmfEventType(fContext1, fTypeId2, TmfEventField.makeRoot(fLabels1));
- private final ITmfEventType fType2 = new TmfEventType(fContext2, fTypeId1, TmfEventField.makeRoot(fLabels2));
- private final ITmfEventType fType3 = new TmfEventType(fContext2, fTypeId2, TmfEventField.makeRoot(fLabels1));
+ private final ITmfEventType fType0 = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels0));
+ private final ITmfEventType fType1 = new TmfEventType(fTypeId2, TmfEventField.makeRoot(fLabels1));
+ private final ITmfEventType fType2 = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels2));
+ private final ITmfEventType fType3 = new TmfEventType(fTypeId2, TmfEventField.makeRoot(fLabels1));
// ------------------------------------------------------------------------
// Constructors
@Test
public void testDefaultConstructor() {
final ITmfEventType type = new TmfEventType();
- assertEquals("getContext", ITmfEventType.DEFAULT_CONTEXT_ID, type.getContext());
assertEquals("getName", ITmfEventType.DEFAULT_TYPE_ID, type.getName());
assertNull("getRootField", type.getRootField());
assertEquals("getFieldNames", 0, type.getFieldNames().size());
@Test
public void testFullConstructor() {
- final ITmfEventType type0 = new TmfEventType(fContext1, fTypeId1, TmfEventField.makeRoot(fLabels0));
- assertEquals("getContext", fContext1, type0.getContext());
+ final ITmfEventType type0 = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels0));
assertEquals("getName", fTypeId1, type0.getName());
assertEquals("getRootField", TmfEventField.makeRoot(fLabels0), type0.getRootField());
final Collection<String> labels0 = type0.getFieldNames();
assertEquals("getFieldNames length", fLabels0.length, labels0.size());
assertArrayEquals(fLabels0, labels0.toArray(new String[labels0.size()]));
- final ITmfEventType type1 = new TmfEventType(fContext1, fTypeId1, TmfEventField.makeRoot(fLabels1));
- assertEquals("getContext", fContext1, type1.getContext());
+ final ITmfEventType type1 = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels1));
assertEquals("getName", fTypeId1, type1.getName());
assertEquals("getRootField", TmfEventField.makeRoot(fLabels1), type1.getRootField());
final Collection<String> labels1 = type1.getFieldNames();
assertEquals("getFieldNames length", fLabels1.length, labels1.size());
assertArrayEquals(fLabels1, labels1.toArray(new String[labels1.size()]));
- final ITmfEventType type2 = new TmfEventType(fContext2, fTypeId2, TmfEventField.makeRoot(fLabels2));
- assertEquals("getContext", fContext2, type2.getContext());
+ final ITmfEventType type2 = new TmfEventType(fTypeId2, TmfEventField.makeRoot(fLabels2));
assertEquals("getName", fTypeId2, type2.getName());
assertEquals("getRootField", TmfEventField.makeRoot(fLabels2), type2.getRootField());
final Collection<String> labels2 = type2.getFieldNames();
assertArrayEquals(fLabels2, labels2.toArray(new String[labels2.size()]));
}
- @Test
+ @Test(expected = IllegalArgumentException.class)
public void testConstructorCornerCases() {
- try {
- new TmfEventType(null, fTypeId1, null);
- fail("TmfEventType: null context");
- } catch (final IllegalArgumentException e) {
- }
-
- try {
- new TmfEventType(fContext1, null, null);
- fail("TmfEventType: null type");
- } catch (final IllegalArgumentException e) {
- }
+ new TmfEventType(null, null);
}
@Test
public void testCopyConstructor() {
- final TmfEventType original = new TmfEventType(fContext1, fTypeId1, TmfEventField.makeRoot(fLabels1));
+ final TmfEventType original = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels1));
final TmfEventType copy = new TmfEventType(original);
- assertEquals("getContext", fContext1, copy.getContext());
assertEquals("getName", fTypeId1, copy.getName());
assertEquals("getRootField", TmfEventField.makeRoot(fLabels1), copy.getRootField());
final Collection<String> labels1 = copy.getFieldNames();
@Test
public void testToString() {
- final String expected1 = "TmfEventType [fContext=" + ITmfEventType.DEFAULT_CONTEXT_ID +
- ", fTypeId=" + ITmfEventType.DEFAULT_TYPE_ID + "]";
+ final String expected1 = "TmfEventType [fTypeId=" + ITmfEventType.DEFAULT_TYPE_ID + "]";
final TmfEventType type1 = new TmfEventType();
assertEquals("toString", expected1, type1.toString());
- final String expected2 = "TmfEventType [fContext=" + fContext1 + ", fTypeId=" + fTypeId1 + "]";
- final TmfEventType type2 = new TmfEventType(fContext1, fTypeId1, TmfEventField.makeRoot(fLabels1));
+ final String expected2 = "TmfEventType [fTypeId=" + fTypeId1 + "]";
+ final TmfEventType type2 = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels1));
assertEquals("toString", expected2, type2.toString());
}
value = TmfStateValue.nullValue();
}
ITmfTimestamp timestamp = new TmfNanoTimestamp(time);
- ITmfEventType eventType = new TmfEventType(ITmfEventType.DEFAULT_CONTEXT_ID, MIPMAP_ID, null);
+ ITmfEventType eventType = new TmfEventType(MIPMAP_ID, null);
ITmfEventField content = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, value, null);
ITmfEvent event = new TmfEvent(null, timestamp, null, eventType, content, null);
return event;
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEventType;
import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
*/
public class TmfAsyncSequenceDiagramEventTest {
- private final String fContext = ITmfEventType.DEFAULT_CONTEXT_ID;
private final String fTypeId = "Some type";
private final String fLabel0 = "label1";
private final String fLabel1 = "label2";
private final TmfTimestamp fTimestamp1 = new TmfTimestamp(12345, (byte) 2, 5);
private final TmfTimestamp fTimestamp2 = new TmfTimestamp(12350, (byte) 2, 5);
private final String fSource = "Source";
- private final TmfEventType fType = new TmfEventType(fContext, fTypeId, TmfEventField.makeRoot(fLabels));
+ private final TmfEventType fType = new TmfEventType(fTypeId, TmfEventField.makeRoot(fLabels));
private final String fReference = "Some reference";
private final ITmfEvent fEvent1;
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEventType;
import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
*/
public class TmfSyncSequenceDiagramEventTest {
- private final String fContext = ITmfEventType.DEFAULT_CONTEXT_ID;
private final String fTypeId = "Some type";
private final String fLabel0 = "label1";
private final String fLabel1 = "label2";
private final TmfTimestamp fTimestamp1 = new TmfTimestamp(12345, (byte) 2, 5);
private final String fSource = "Source";
- private final TmfEventType fType = new TmfEventType(fContext, fTypeId, TmfEventField.makeRoot(fLabels));
+ private final TmfEventType fType = new TmfEventType(fTypeId, TmfEventField.makeRoot(fLabels));
private final String fReference = "Some reference";
private final ITmfEvent fEvent1;
private static ITmfEventField ROOT = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, FIELDS);
public TmfEventTypeStub() {
- super("UnitTest", "TmfEventTypeStub", ROOT);
+ super("TmfEventTypeStub", ROOT);
}
}
}
final String[] fieldArray = new String[i];
final ITmfEventField rootField = TmfEventField.makeRoot(fields.toArray(fieldArray));
- fTypes[i] = new TmfEventType("UnitTest", "Type-" + i, rootField);
+ fTypes[i] = new TmfEventType("Type-" + i, rootField);
}
}
package org.eclipse.tracecompass.tmf.tests.stubs.trace.text;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEventType;
import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
* Default Constructor
*/
public SyslogEventType() {
- super(ITmfEventType.DEFAULT_CONTEXT_ID, TYPE_ID, TmfEventField.makeRoot(LABELS));
+ super(TYPE_ID, TmfEventField.makeRoot(LABELS));
}
}
/* Create a new event with new fields and name */
ITmfEventType customEventType = event.getType();
- TmfEventType eventType = new TmfEventType(customEventType.getContext(), getStringValue(content, EVENT_NAME_FIELD), customEventType.getRootField());
+ TmfEventType eventType = new TmfEventType(getStringValue(content, EVENT_NAME_FIELD), customEventType.getRootField());
ITmfEventField eventFields = new CustomEventContent(content.getName(), content.getValue(), fieldsArray);
TmfEvent newEvent = new TmfEvent(this, event.getTimestamp(), getStringValue(content, SOURCE_FIELD), eventType, eventFields, event.getReference());
updateAttributes(savedContext, event.getTimestamp());
// Constants
// ------------------------------------------------------------------------
- /**
- * The default event type content
- */
- public static final String DEFAULT_CONTEXT_ID = "TmfContext"; //$NON-NLS-1$
-
/**
* The default event type name
*/
// Getters
// ------------------------------------------------------------------------
- /**
- * @return the event type context
- */
- String getContext();
-
/**
* @return the event type ID
*/
// Attributes
// ------------------------------------------------------------------------
- private final String fContext;
private final String fTypeId;
private final ITmfEventField fRootField;
* Default constructor
*/
public TmfEventType() {
- this(DEFAULT_CONTEXT_ID, DEFAULT_TYPE_ID, null);
+ this(DEFAULT_TYPE_ID, null);
}
/**
* Full constructor
*
- * @param context the type context
* @param typeId the type name
* @param root the root field
*/
- public TmfEventType(final String context, final String typeId, final ITmfEventField root) {
- if (context == null || typeId == null) {
+ public TmfEventType(final String typeId, final ITmfEventField root) {
+ if (typeId == null) {
throw new IllegalArgumentException();
}
- fContext = context;
fTypeId = typeId;
fRootField = root;
-
- // Register to the event type manager
- TmfEventTypeManager.getInstance().add(context, this);
}
/**
if (type == null) {
throw new IllegalArgumentException();
}
- fContext = type.getContext();
fTypeId = type.getName();
fRootField = type.getRootField();
}
// ITmfEventType
// ------------------------------------------------------------------------
- @Override
- public String getContext() {
- return fContext;
- }
-
@Override
public String getName() {
return fTypeId;
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + fContext.hashCode();
result = prime * result + fTypeId.hashCode();
return result;
}
return false;
}
final TmfEventType other = (TmfEventType) obj;
- if (!fContext.equals(other.fContext)) {
- return false;
- }
if (!fTypeId.equals(other.fTypeId)) {
return false;
}
@Override
@SuppressWarnings("nls")
public String toString() {
- return "TmfEventType [fContext=" + fContext + ", fTypeId=" + fTypeId + "]";
+ return "TmfEventType [fTypeId=" + fTypeId + "]";
}
}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2012, 2013 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Francois Chouinard - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.core.event;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import com.google.common.collect.ImmutableSet;
-
-/**
- * A central repository for the available event types. Types are managed by
- * context space.
- *
- * @version 1.0
- * @author Francois Chouinard
- *
- * @see ITmfEventType
- */
-public final class TmfEventTypeManager {
-
- // ------------------------------------------------------------------------
- // Attributes
- // ------------------------------------------------------------------------
-
- // The event type manager singleton
- private static TmfEventTypeManager fEventTypeManager = null;
-
- // The available types, per context
- private final Map<String, HashMap<String, ITmfEventType>> fEventTypes;
-
- // ------------------------------------------------------------------------
- // Constructors
- // ------------------------------------------------------------------------
-
- /**
- * The singleton constructor
- */
- private TmfEventTypeManager() {
- fEventTypes = new HashMap<>();
- }
-
- /**
- * @return the TmfEventTypeManager singleton
- */
- public static synchronized TmfEventTypeManager getInstance() {
- if (fEventTypeManager == null) {
- fEventTypeManager = new TmfEventTypeManager();
- }
- return fEventTypeManager;
- }
-
- // ------------------------------------------------------------------------
- // Operations
- // ------------------------------------------------------------------------
-
- /**
- * Add a context:type pair to the available types
- *
- * @param context the target context
- * @param type the type to add
- */
- public synchronized void add(final String context, final ITmfEventType type) {
- HashMap<String, ITmfEventType> types = fEventTypes.get(context);
- if (types == null) {
- types = new HashMap<>();
- }
- types.put(type.getName(), type);
- fEventTypes.put(context, types);
- }
-
- /**
- * Return the list of currently defined contexts
- *
- * @return the list of contexts
- */
- public synchronized String[] getContexts() {
- return fEventTypes.keySet().toArray(new String[fEventTypes.size()]);
- }
-
- /**
- * Return the list of types defined for a given context
- *
- * @param context the context to look into
- * @return the list of types defined for that context
- * @since 3.0
- */
- public synchronized Set<ITmfEventType> getTypes(final String context) {
- final HashMap<String, ITmfEventType> types = fEventTypes.get(context);
- if (types != null) {
- return ImmutableSet.copyOf(types.values());
- }
- return ImmutableSet.of();
- }
-
- /**
- * Return an event type
- *
- * @param context the context to look into
- * @param typeId the type ID
- * @return the corresponding type
- */
- public synchronized ITmfEventType getType(final String context, final String typeId) {
- final HashMap<String, ITmfEventType> types = fEventTypes.get(context);
- if (types != null) {
- return types.get(typeId);
- }
- return null;
- }
-
- /**
- * Remove the types associated to a context
- *
- * @param context the context to remove
- */
- public synchronized void clear(final String context) {
- fEventTypes.remove(context);
- }
-
- /**
- * Remove all contexts and types
- */
- public synchronized void clear() {
- fEventTypes.clear();
- }
-
- // ------------------------------------------------------------------------
- // Object
- // ------------------------------------------------------------------------
-
- @Override
- @SuppressWarnings("nls")
- public String toString() {
- return "TmfEventTypeManager [fEventTypes=" + fEventTypes + "]";
- }
-
-}
*/
public abstract class CustomEventType extends TmfEventType {
- private static String CONTEXT_ID = "CustomEventType"; //$NON-NLS-1$
-
/**
* Constructor
*
* Trace definition
*/
public CustomEventType(CustomTraceDefinition definition) {
- super(CONTEXT_ID, definition.definitionName, getRootField(definition));
+ super(definition.definitionName, getRootField(definition));
}
private static ITmfEventField getRootField(CustomTraceDefinition definition) {
*
* @return The set of events that might be present in the trace
*/
- Set<ITmfEventType> getContainedEventTypes();
+ Set<? extends ITmfEventType> getContainedEventTypes();
}
* @return a set of the names of these events, if some names are clashing
* they will only appear once
*/
- public static Set<String> getEventNames(Iterable<ITmfEventType> eventTypes) {
+ public static Set<String> getEventNames(Iterable<? extends ITmfEventType> eventTypes) {
Set<String> retSet = new HashSet<>();
for (ITmfEventType eventType : eventTypes) {
retSet.add(eventType.getName());
import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfEventType;
-import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub;
import org.junit.Test;
/**
public void testCtfTmfEventType() {
String eventName = "";
ITmfEventField content = new TmfEventField("", null, new ITmfEventField[] {});
- CtfTmfEventType result = new CtfTmfEventType(eventName, new TmfTraceStub(), content);
+ CtfTmfEventType result = new CtfTmfEventType(eventName, content);
assertNotNull(result);
assertEquals("", result.toString());
assertEquals("", result.getName());
- assertEquals("Ctf Event/null", result.getContext());
}
/**
@Test
public void testToString() {
ITmfEventField emptyField = new TmfEventField("", null, new ITmfEventField[] {});
- CtfTmfEventType fixture = new CtfTmfEventType("", new TmfTraceStub() , emptyField);
+ CtfTmfEventType fixture = new CtfTmfEventType("" , emptyField);
String result = fixture.toString();
*/
@Test
public void testGetContainedEventTypes() {
- Set<ITmfEventType> result = fixture.getContainedEventTypes();
+ Set<? extends ITmfEventType> result = fixture.getContainedEventTypes();
assertNotNull(result);
assertFalse(result.isEmpty());
}
*/
@Test
public void testEventLookup() {
- Set<ITmfEventType> eventTypes = fixture.getContainedEventTypes();
+ Set<? extends ITmfEventType> eventTypes = fixture.getContainedEventTypes();
Set<String> eventNames = TmfEventTypeCollectionHelper.getEventNames(eventTypes);
assertTrue(eventNames.contains("sched_switch"));
assertFalse(eventNames.contains("Sched_switch"));
@Override
public ITmfEventType getType() {
- CtfTmfEventType ctfTmfEventType = CtfTmfEventType.get(getTrace(), fEventName);
- if (ctfTmfEventType == null) {
- /* Should only return null the first time */
- ctfTmfEventType = new CtfTmfEventType(fEventName, getTrace(), getContent());
+ CtfTmfEventType ctfTmfEventType = new CtfTmfEventType(fEventName, getContent());
+
+ /* Register the event type in the owning trace, but only if there is one */
+ CtfTmfTrace trace = getTrace();
+ if (trace != null) {
+ trace.registerEventType(ctfTmfEventType);
}
+
return ctfTmfEventType;
}
import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
-import org.eclipse.tracecompass.tmf.core.event.TmfEventTypeManager;
-import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
/**
* The CTF extension of the TMF event type
*
- * @version 1.0
* @author Matthew khouzam
*/
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
* The event name
- * @param trace
- * the parent trace
* @param content
* The event field
* @since 3.0
*/
- public CtfTmfEventType(String eventName, ITmfTrace trace, ITmfEventField content) {
- super(computeContextName(trace), eventName, content);
+ public CtfTmfEventType(String eventName, ITmfEventField content) {
+ super(eventName, content);
}
/**
public String toString() {
return getName();
}
-
- /**
- * 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 String computeContextName(ITmfTrace trace) {
- return CONTEXT_ID + "/" + (trace == null ? UNKNOWN_TRACE : trace.getPath()); //$NON-NLS-1$
- }
}
import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.tracecompass.internal.tmf.ctf.core.Activator;
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEventType;
import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
-import org.eclipse.tracecompass.tmf.core.event.TmfEventTypeManager;
import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
// Fields
// -------------------------------------------
+ private final Map<String, CtfTmfEventType> fContainedEventTypes =
+ Collections.synchronizedMap(new HashMap<String, CtfTmfEventType>());
+
/* Reference to the CTF Trace */
private CTFTrace fTrace;
*/
try (CtfIterator iter = CtfIteratorManager.getIterator(this, ctx)) {
for (IEventDeclaration ied : iter.getEventDeclarations()) {
- CtfTmfEventType ctfTmfEventType = CtfTmfEventType.get(this, ied.getName());
+ CtfTmfEventType ctfTmfEventType = fContainedEventTypes.get(ied.getName());
if (ctfTmfEventType == null) {
List<ITmfEventField> content = new ArrayList<>();
/* Should only return null the first time */
content.toArray(new ITmfEventField[content.size()])
);
- ctfTmfEventType = new CtfTmfEventType(ied.getName(), this, contentTree);
+ ctfTmfEventType = new CtfTmfEventType(ied.getName(), contentTree);
+ fContainedEventTypes.put(ctfTmfEventType.getName(), ctfTmfEventType);
}
}
}
* @since 3.0
*/
@Override
- public Set<ITmfEventType> getContainedEventTypes() {
- TmfEventTypeManager instance = TmfEventTypeManager.getInstance();
- Set<ITmfEventType> eventTypes = instance.getTypes(CtfTmfEventType.computeContextName(this));
- return ImmutableSet.copyOf(eventTypes);
+ public Set<CtfTmfEventType> getContainedEventTypes() {
+ return ImmutableSet.copyOf(fContainedEventTypes.values());
+ }
+
+ /**
+ * Register an event type to this trace.
+ *
+ * Package-visible so that {@link CtfTmfEvent#getType} can call it.
+ *
+ * FIXME This could probably be made cleaner?
+ */
+ void registerEventType(CtfTmfEventType eventType) {
+ fContainedEventTypes.put(eventType.getName(), eventType);
}
// -------------------------------------------
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
- /**
- * The default Context ID for a PcapEvent
- */
- @SuppressWarnings("null")
- public static final @NonNull String DEFAULT_PCAP_CONTEXT_ID = Messages.PcapEventType_DefaultContext == null ? EMPTY_STRING : Messages.PcapEventType_DefaultContext;
-
/**
* The default Pcap Type ID for a PcapEvent
*/
* the root field
*/
public PcapEventType(final String typeId, final @Nullable ITmfEventField root) {
- super(DEFAULT_PCAP_CONTEXT_ID, typeId, root);
+ super(typeId, root);
}
/**
private static final String fTestName = "ColumnDataProviderTest";
- private final String fContext = "UnitTest";
-
private final String fTypeId1 = "Some type1";
private final String fTypeId2 = "Some type2";
private final String fSource = "Source";
- private final TmfEventType fType1 = new TmfEventType(fContext, fTypeId1, TmfEventField.makeRoot(fLabels));
- private final TmfEventType fType2 = new TmfEventType(fContext, fTypeId1, TmfEventField.makeRoot(fLabels));
- private final TmfEventType fType3 = new TmfEventType(fContext, fTypeId2, TmfEventField.makeRoot(fLabels));
+ private final TmfEventType fType1 = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels));
+ private final TmfEventType fType2 = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels));
+ private final TmfEventType fType3 = new TmfEventType(fTypeId2, TmfEventField.makeRoot(fLabels));
private final String fReference = "Some reference";
private static final String fTestName = "StatisticsDataTest";
- private final String fContext = "UnitTest";
private final String fTypeId1 = "Some type1";
private final String fTypeId2 = "Some type2";
private final String fSource = "Source";
- private final TmfEventType fType1 = new TmfEventType(fContext, fTypeId1, TmfEventField.makeRoot(fLabels));
- private final TmfEventType fType2 = new TmfEventType(fContext, fTypeId1, TmfEventField.makeRoot(fLabels));
- private final TmfEventType fType3 = new TmfEventType(fContext, fTypeId2, TmfEventField.makeRoot(fLabels));
+ private final TmfEventType fType1 = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels));
+ private final TmfEventType fType2 = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels));
+ private final TmfEventType fType3 = new TmfEventType(fTypeId2, TmfEventField.makeRoot(fLabels));
private final String fReference = "Some reference";
private static final String fTestName = "TreeContentProviderTest";
- private final String fContext = "UnitTest";
private final String fTypeId1 = "Some type1";
private final String fTypeId2 = "Some type2";
private final String fSource = "Source";
- private final TmfEventType fType1 = new TmfEventType(fContext, fTypeId1, TmfEventField.makeRoot(fLabels));
- private final TmfEventType fType2 = new TmfEventType(fContext, fTypeId2, TmfEventField.makeRoot(fLabels));
+ private final TmfEventType fType1 = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels));
+ private final TmfEventType fType2 = new TmfEventType(fTypeId2, TmfEventField.makeRoot(fLabels));
private final String fReference = "Some reference";
String[] labels = {"sender", "receiver", "signal"};
- TmfEventType tmfEventType = new TmfEventType("UnitTest", type, TmfEventField.makeRoot(labels));
+ TmfEventType tmfEventType = new TmfEventType(type, TmfEventField.makeRoot(labels));
String content = "[";
content += sender;