May 31
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.tests / src / org / eclipse / linuxtools / lttng / tests / state / StateManagerFactoryTestSupport.java
1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.lttng.tests.state;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
18 import org.eclipse.linuxtools.lttng.control.LttngCoreProviderFactory;
19 import org.eclipse.linuxtools.lttng.event.LttngSyntheticEvent;
20 import org.eclipse.linuxtools.lttng.model.LTTngTreeNode;
21 import org.eclipse.linuxtools.lttng.state.LttngStateException;
22 import org.eclipse.linuxtools.lttng.state.trace.IStateTraceManager;
23 import org.eclipse.linuxtools.lttng.state.trace.StateTraceManager;
24 import org.eclipse.linuxtools.tmf.component.TmfEventProvider;
25 import org.eclipse.linuxtools.tmf.trace.ITmfTrace;
26
27 /**
28 * @author alvaro
29 *
30 */
31 public class StateManagerFactoryTestSupport {
32 // ========================================================================
33 // Data
34 // =======================================================================
35
36 private static final Map<String, IStateTraceManager> instanceBook = new HashMap<String, IStateTraceManager>();
37 private static TmfEventProvider<LttngSyntheticEvent> feventProvider = null;
38 // ========================================================================
39 // Methods
40 // =======================================================================
41
42 /**
43 * Provide a stateManager instance per trace
44 *
45 * @return
46 */
47 public static IStateTraceManager getManager(ITmfTrace trace) {
48 String traceUniqueId = trace.getName();
49
50 if (traceUniqueId == null) {
51 return null;
52 }
53
54 if (instanceBook.containsKey(traceUniqueId)) {
55 return instanceBook.get(traceUniqueId);
56 }
57
58 // LttngTraceState traceModel =
59 // StateModelFactory.getStateEntryInstance();
60 IStateTraceManager manager = null;
61
62 if (feventProvider == null) {
63 feventProvider = LttngCoreProviderFactory.getEventProvider();
64 }
65
66 // catch construction problems
67 Long id = 0L;
68 LTTngTreeNode parent = null;
69
70 try {
71 manager = new StateTraceManager(id, parent, traceUniqueId, trace, feventProvider);
72 } catch (LttngStateException e) {
73 e.printStackTrace();
74 }
75
76 instanceBook.put(traceUniqueId, manager);
77 return manager;
78 }
79
80 /**
81 * Remove previously registered managers
82 * @param traceUniqueId
83 */
84 public static void removeManager(String traceUniqueId) {
85 if (traceUniqueId != null && instanceBook.containsKey(traceUniqueId)) {
86 instanceBook.remove(traceUniqueId);
87 }
88 }
89
90 }
This page took 0.034066 seconds and 6 git commands to generate.