Commit | Line | Data |
---|---|---|
5d10d135 | 1 | /******************************************************************************* |
8827c197 | 2 | * Copyright (c) 2009, 2010 Ericsson |
0c32e4c5 | 3 | * |
5d10d135 ASL |
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 | |
0c32e4c5 | 8 | * |
5d10d135 ASL |
9 | * Contributors: |
10 | * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
5945cec9 | 13 | package org.eclipse.linuxtools.internal.lttng.core.state.experiment; |
5d10d135 | 14 | |
9fa32496 | 15 | import org.eclipse.linuxtools.internal.lttng.core.Activator; |
5945cec9 FC |
16 | import org.eclipse.linuxtools.internal.lttng.core.TraceDebug; |
17 | import org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNode; | |
18 | import org.eclipse.linuxtools.internal.lttng.core.state.LttngStateException; | |
19 | import org.eclipse.linuxtools.internal.lttng.core.state.trace.IStateTraceManager; | |
20 | import org.eclipse.linuxtools.internal.lttng.core.state.trace.StateTraceManager; | |
6c13869b | 21 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
9e0640dc | 22 | import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment; |
5d10d135 ASL |
23 | |
24 | /** | |
25 | * @author alvaro | |
0c32e4c5 | 26 | * |
5d10d135 ASL |
27 | */ |
28 | public class StateManagerFactory { | |
12c155f5 FC |
29 | // ======================================================================== |
30 | // Data | |
31 | // ======================================================================= | |
32 | ||
33 | private static IStateExperimentManager experimentManager = null; | |
34 | /** | |
35 | * Allows to modify the check point interval for every new instance of trace manager | |
36 | */ | |
37 | private static Long ftraceCheckPointInterval = null; | |
38 | ||
39 | static { | |
40 | initCheck(); | |
41 | } | |
42 | ||
43 | // ======================================================================== | |
44 | // Methods | |
45 | // ======================================================================= | |
46 | ||
47 | /** | |
48 | * @param traceUniqueId | |
49 | * @param experiment | |
50 | * @return | |
51 | */ | |
0c32e4c5 | 52 | public static LTTngTreeNode getManager(ITmfTrace rtrace, LTTngTreeNode experiment) { |
12c155f5 FC |
53 | |
54 | // Validate | |
55 | if (rtrace == null) { | |
56 | return null; | |
57 | } | |
58 | ||
59 | String traceUniqueId = rtrace.getName(); | |
60 | if (traceUniqueId == null) { | |
61 | return null; | |
62 | } | |
63 | ||
64 | LTTngTreeNode managerNode = null; | |
65 | managerNode = experiment.getChildByName(traceUniqueId); | |
66 | ||
67 | if (managerNode != null && managerNode instanceof IStateTraceManager) { | |
68 | return managerNode; | |
69 | } | |
5d10d135 | 70 | |
0c32e4c5 | 71 | // LttngTraceState traceModel = |
550d787e | 72 | // StateModelFactory.getStateEntryInstance(); |
12c155f5 FC |
73 | StateTraceManager manager = null; |
74 | ||
75 | // catch potential construction problems | |
76 | try { | |
77 | manager = new StateTraceManager(experiment.getNextUniqueId(), experiment, traceUniqueId, rtrace); | |
78 | ||
79 | // Allow the possibility to configure the trace state check point | |
80 | // interval at creation time | |
81 | if (ftraceCheckPointInterval != null) { | |
82 | manager.setCheckPointInterval(ftraceCheckPointInterval); | |
83 | } | |
84 | ||
85 | } catch (LttngStateException e) { | |
9fa32496 | 86 | Activator.getDefault().logError("Unexpected Error", e); //$NON-NLS-1$ |
12c155f5 FC |
87 | } |
88 | ||
89 | experiment.addChild(manager); | |
90 | return manager; | |
91 | } | |
92 | ||
93 | /** | |
94 | * Provide the State trace set manager | |
0c32e4c5 | 95 | * |
12c155f5 FC |
96 | * @return |
97 | */ | |
98 | public static IStateExperimentManager getExperimentManager() { | |
99 | return experimentManager; | |
100 | } | |
101 | ||
102 | /** | |
103 | * Remove previously registered managers | |
0c32e4c5 | 104 | * |
12c155f5 FC |
105 | * @param traceUniqueId |
106 | */ | |
0c32e4c5 AM |
107 | public static void removeManager(ITmfTrace rtrace, LTTngTreeNode rexperiment) { |
108 | if (rtrace == null || rexperiment == null) { | |
f9a8715c | 109 | return; |
0c32e4c5 AM |
110 | } |
111 | if (rexperiment.getValue() instanceof TmfExperiment) { | |
12c155f5 FC |
112 | LTTngTreeNode childToremove = rexperiment.getChildByName(rtrace.getName()); |
113 | if (childToremove != null) { | |
114 | rexperiment.removeChild(childToremove); | |
115 | } | |
116 | } else { | |
117 | TraceDebug.debug("Invalid arguments to remove manager for trace: " //$NON-NLS-1$ | |
118 | + rtrace.getName()); | |
119 | } | |
120 | } | |
121 | ||
122 | /** | |
123 | * initialization of factory | |
124 | */ | |
125 | private static void initCheck() { | |
126 | if (experimentManager == null) { | |
127 | Long id = 0L; // unique id | |
128 | String name = "StateExperimentManager"; // name //$NON-NLS-1$ | |
129 | experimentManager = new StateExperimentManager(id, name); | |
130 | } | |
131 | } | |
132 | ||
133 | /** | |
134 | * Clea up resources | |
135 | */ | |
136 | public static void dispose() { | |
137 | if (experimentManager != null) { | |
138 | experimentManager = null; | |
139 | } | |
140 | } | |
141 | ||
142 | /** | |
143 | * @return the traceCheckPointInterval | |
144 | */ | |
145 | public static Long getTraceCheckPointInterval() { | |
146 | return ftraceCheckPointInterval; | |
147 | } | |
148 | ||
149 | /** | |
150 | * @param traceCheckPointInterval | |
151 | * the traceCheckPointInterval to set | |
152 | */ | |
153 | public static void setTraceCheckPointInterval(Long traceCheckPointInterval) { | |
154 | StateManagerFactory.ftraceCheckPointInterval = traceCheckPointInterval; | |
155 | } | |
140ad82d | 156 | } |