Commit | Line | Data |
---|---|---|
03c71d1e ASL |
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 | ||
8827c197 FC |
18 | import org.eclipse.linuxtools.lttng.model.LTTngTreeNode; |
19 | import org.eclipse.linuxtools.lttng.state.LttngStateException; | |
8827c197 FC |
20 | import org.eclipse.linuxtools.lttng.state.trace.IStateTraceManager; |
21 | import org.eclipse.linuxtools.lttng.state.trace.StateTraceManager; | |
8827c197 | 22 | import org.eclipse.linuxtools.tmf.trace.ITmfTrace; |
03c71d1e ASL |
23 | |
24 | /** | |
25 | * @author alvaro | |
26 | * | |
27 | */ | |
28 | public class StateManagerFactoryTestSupport { | |
29 | // ======================================================================== | |
30 | // Data | |
31 | // ======================================================================= | |
32 | ||
8827c197 | 33 | private static final Map<String, IStateTraceManager> instanceBook = new HashMap<String, IStateTraceManager>(); |
550d787e | 34 | |
03c71d1e ASL |
35 | // ======================================================================== |
36 | // Methods | |
37 | // ======================================================================= | |
38 | ||
39 | /** | |
40 | * Provide a stateManager instance per trace | |
41 | * | |
42 | * @return | |
43 | */ | |
8827c197 FC |
44 | public static IStateTraceManager getManager(ITmfTrace trace) { |
45 | String traceUniqueId = trace.getName(); | |
46 | ||
03c71d1e ASL |
47 | if (traceUniqueId == null) { |
48 | return null; | |
49 | } | |
50 | ||
51 | if (instanceBook.containsKey(traceUniqueId)) { | |
52 | return instanceBook.get(traceUniqueId); | |
53 | } | |
54 | ||
550d787e FC |
55 | // LttngTraceState traceModel = |
56 | // StateModelFactory.getStateEntryInstance(); | |
8827c197 FC |
57 | IStateTraceManager manager = null; |
58 | ||
8827c197 FC |
59 | // catch construction problems |
60 | Long id = 0L; | |
61 | LTTngTreeNode parent = null; | |
62 | ||
63 | try { | |
550d787e | 64 | manager = new StateTraceManager(id, parent, traceUniqueId, trace); |
8827c197 FC |
65 | } catch (LttngStateException e) { |
66 | e.printStackTrace(); | |
67 | } | |
03c71d1e ASL |
68 | |
69 | instanceBook.put(traceUniqueId, manager); | |
70 | return manager; | |
71 | } | |
72 | ||
73 | /** | |
74 | * Remove previously registered managers | |
75 | * @param traceUniqueId | |
76 | */ | |
77 | public static void removeManager(String traceUniqueId) { | |
78 | if (traceUniqueId != null && instanceBook.containsKey(traceUniqueId)) { | |
79 | instanceBook.remove(traceUniqueId); | |
80 | } | |
81 | } | |
82 | ||
83 | } |