--- /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:
+ * Matthew Khouzam - Initial API and implementation
+ * Simon Delisle - Added a method to remove the iterator
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core;
+
+import java.util.HashMap;
+
+/**
+ * Ctf Iterator Manager, allows mapping of iterators (a limited resource) to
+ * contexts (many many resources).
+ *
+ * @author Matthew Khouzam
+ * @version 1.0
+ * @since 1.1
+ */
+public abstract class CtfIteratorCEO {
+ /*
+ * A side note synchronized works on the whole object, Therefore add and
+ * remove will be thread safe.
+ */
+
+ /*
+ * The map of traces to trace managers.
+ */
+ private static HashMap<CtfTmfTrace, CtfIteratorManager> map = new HashMap<>();
+
+ /**
+ * Registers a trace to the iterator manager, the trace can now get
+ * iterators.
+ *
+ * @param trace
+ * the trace to register.
+ */
+ public static synchronized void addTrace(final CtfTmfTrace trace) {
+ map.put(trace, new CtfIteratorManager(trace));
+ }
+
+ /**
+ * Removes a trace to the iterator manager.
+ *
+ * @param trace
+ * the trace to register.
+ */
+ public static synchronized void removeTrace(final CtfTmfTrace trace) {
+ CtfIteratorManager mgr = map.remove(trace);
+ if (mgr != null) {
+ mgr.clear();
+ }
+ }
+
+ /**
+ * Get an iterator for a given trace and context.
+ *
+ * @param trace
+ * the trace
+ * @param ctx
+ * the context
+ * @return the iterator
+ * @since 2.0
+ */
+ public static synchronized CtfIterator getIterator(final CtfTmfTrace trace,
+ final CtfTmfContext ctx) {
+ return map.get(trace).getIterator(ctx);
+ }
+
+ /**
+ * Remove an iterator for a given trace and context
+ *
+ * @param trace
+ * the trace
+ * @param ctx
+ * the context
+ * @since 2.1
+ */
+ public static synchronized void removeIterator(final CtfTmfTrace trace, final CtfTmfContext ctx) {
+ CtfIteratorManager traceManager = map.get(trace);
+ if (traceManager != null) {
+ traceManager.removeIterator(ctx);
+ }
+ }
+}
/*******************************************************************************
- * Copyright (c) 2012, 2013 Ericsson
+ * Copyright (c) 2014 Ericsson
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v1.0 which
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Matthew Khouzam - Initial API and implementation
- * Simon Delisle - Added a method to remove the iterator
+ * Alexandre Montplaisir - Renamed/extracted from CtfTraceManager
*******************************************************************************/
+
package org.eclipse.tracecompass.tmf.ctf.core;
import java.util.ArrayList;
import java.util.Random;
/**
- * Ctf Iterator Manager, allows mapping of iterators (a limited resource) to
- * contexts (many many resources).
- *
- * @author Matthew Khouzam
- * @version 1.0
- * @since 1.1
- */
-public abstract class CtfIteratorManager {
- /*
- * A side note synchronized works on the whole object, Therefore add and
- * remove will be thread safe.
- */
-
- /*
- * The map of traces to trace managers.
- */
- private static HashMap<CtfTmfTrace, CtfTraceManager> map = new HashMap<>();
-
- /**
- * Registers a trace to the iterator manager, the trace can now get
- * iterators.
- *
- * @param trace
- * the trace to register.
- */
- public static synchronized void addTrace(final CtfTmfTrace trace) {
- map.put(trace, new CtfTraceManager(trace));
- }
-
- /**
- * Removes a trace to the iterator manager.
- *
- * @param trace
- * the trace to register.
- */
- public static synchronized void removeTrace(final CtfTmfTrace trace) {
- CtfTraceManager mgr = map.remove(trace);
- if (mgr != null) {
- mgr.clear();
- }
- }
-
- /**
- * Get an iterator for a given trace and context.
- *
- * @param trace
- * the trace
- * @param ctx
- * the context
- * @return the iterator
- * @since 2.0
- */
- public static synchronized CtfIterator getIterator(final CtfTmfTrace trace,
- final CtfTmfContext ctx) {
- return map.get(trace).getIterator(ctx);
- }
-
- /**
- * Remove an iterator for a given trace and context
- *
- * @param trace
- * the trace
- * @param ctx
- * the context
- * @since 2.1
- */
- public static synchronized void removeIterator(final CtfTmfTrace trace, final CtfTmfContext ctx) {
- CtfTraceManager traceManager = map.get(trace);
- if (traceManager != null) {
- traceManager.removeIterator(ctx);
- }
- }
-}
-
-/**
- * A trace manager
+ * A trace iterator manager
*
* @author Matthew Khouzam
*/
-class CtfTraceManager {
+class CtfIteratorManager {
/*
* Cache size. Under 1023 on linux32 systems. Number of file handles
* created.
*/
private final Random fRnd;
- public CtfTraceManager(CtfTmfTrace trace) {
+ public CtfIteratorManager(CtfTmfTrace trace) {
fMap = new HashMap<>();
fRandomAccess = new ArrayList<>();
fRnd = new Random(System.nanoTime());
fMap.clear();
fRandomAccess.clear();
}
-}
+}
\ No newline at end of file
@Override
public void dispose() {
- CtfIteratorManager.removeIterator(fTrace, this);
+ CtfIteratorCEO.removeIterator(fTrace, this);
}
/**
* @return an iterator
*/
private CtfIterator getIterator() {
- return CtfIteratorManager.getIterator(fTrace, this);
+ return CtfIteratorCEO.getIterator(fTrace, this);
}
}
try {
this.fTrace = new CTFTrace(path);
- CtfIteratorManager.addTrace(this);
+ CtfIteratorCEO.addTrace(this);
CtfTmfContext ctx;
/* Set the start and (current) end times for this trace */
ctx = (CtfTmfContext) seekEvent(0L);
* Register every event type. When you call getType, it will
* register a trace to that type in the TmfEventTypeManager
*/
- try (CtfIterator iter = CtfIteratorManager.getIterator(this, ctx)) {
+ try (CtfIterator iter = CtfIteratorCEO.getIterator(this, ctx)) {
for (IEventDeclaration ied : iter.getEventDeclarations()) {
CtfTmfEventType ctfTmfEventType = fContainedEventTypes.get(ied.getName());
if (ctfTmfEventType == null) {
@Override
public synchronized void dispose() {
- CtfIteratorManager.removeTrace(this);
+ CtfIteratorCEO.removeTrace(this);
if (fTrace != null) {
fTrace.close();
fTrace = null;
// -------------------------------------------
private static CtfIterator getIterator(CtfTmfTrace trace, CtfTmfContext context) {
- return CtfIteratorManager.getIterator(trace, context);
+ return CtfIteratorCEO.getIterator(trace, context);
}
/**