Monster merge from the integration branch. Still some problems left and JUnits failing.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng / src / org / eclipse / linuxtools / lttng / state / experiment / StateManagerFactory.java
CommitLineData
5d10d135 1/*******************************************************************************
8827c197 2 * Copyright (c) 2009, 2010 Ericsson
5d10d135
ASL
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
13package org.eclipse.linuxtools.lttng.state.experiment;
14
8827c197 15import org.eclipse.linuxtools.lttng.TraceDebug;
8827c197
FC
16import org.eclipse.linuxtools.lttng.model.LTTngTreeNode;
17import org.eclipse.linuxtools.lttng.state.LttngStateException;
8827c197
FC
18import org.eclipse.linuxtools.lttng.state.trace.IStateTraceManager;
19import org.eclipse.linuxtools.lttng.state.trace.StateTraceManager;
20import org.eclipse.linuxtools.tmf.experiment.TmfExperiment;
21import org.eclipse.linuxtools.tmf.trace.ITmfTrace;
5d10d135
ASL
22
23/**
24 * @author alvaro
25 *
26 */
27public class StateManagerFactory {
28 // ========================================================================
29 // Data
30 // =======================================================================
31
8827c197
FC
32 private static IStateExperimentManager experimentManager = null;
33 /**
34 * Allows to modify the check point interval for every new instance of trace manager
35 */
36 private static Long ftraceCheckPointInterval = null;
5d10d135 37
8827c197
FC
38 static {
39 initCheck();
40 }
5d10d135
ASL
41 // ========================================================================
42 // Methods
43 // =======================================================================
44
45 /**
8827c197
FC
46 * @param traceUniqueId
47 * @param experiment
5d10d135
ASL
48 * @return
49 */
8827c197
FC
50 public static LTTngTreeNode getManager(ITmfTrace rtrace,
51 LTTngTreeNode experiment) {
52
53 // Validate
54 if (rtrace == null) {
55 return null;
56 }
5d10d135 57
8827c197 58 String traceUniqueId = rtrace.getName();
5d10d135
ASL
59 if (traceUniqueId == null) {
60 return null;
61 }
62
63
8827c197
FC
64 LTTngTreeNode managerNode = null;
65 managerNode = experiment.getChildByName(traceUniqueId);
66
67 if (managerNode != null && managerNode instanceof IStateTraceManager) {
68 return managerNode;
5d10d135
ASL
69 }
70
550d787e
FC
71// LttngTraceState traceModel =
72// StateModelFactory.getStateEntryInstance();
8827c197
FC
73 StateTraceManager manager = null;
74
75 // catch potential construction problems
76 try {
550d787e 77 manager = new StateTraceManager(experiment.getNextUniqueId(), experiment, traceUniqueId, rtrace);
8827c197
FC
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) {
86 e.printStackTrace();
87 }
5d10d135 88
8827c197 89 experiment.addChild(manager);
5d10d135
ASL
90 return manager;
91 }
92
93 /**
94 * Provide the State trace set manager
95 *
96 * @return
97 */
8827c197 98 public static IStateExperimentManager getExperimentManager() {
5d10d135
ASL
99 return experimentManager;
100 }
101
102 /**
103 * Remove previously registered managers
104 *
105 * @param traceUniqueId
106 */
8827c197 107 public static void removeManager(ITmfTrace rtrace, LTTngTreeNode rexperiment) {
8827c197 108 if (rtrace != null && rexperiment != null
550d787e 109 && rexperiment.getValue() instanceof TmfExperiment<?>) {
8827c197
FC
110 LTTngTreeNode childToremove = rexperiment.getChildByName(rtrace
111 .getName());
112 if (childToremove != null) {
113 rexperiment.removeChild(childToremove);
114 }
115 } else {
116 TraceDebug.debug("Invalid arguments to remove manager for trace: "
117 + rtrace.getName());
5d10d135
ASL
118 }
119 }
120
121 /**
122 * initialization of factory
123 */
124 private static void initCheck() {
125 if (experimentManager == null) {
8827c197
FC
126 Long id = 0L; // unique id
127 String name = "StateExperimentManager"; // name
128 experimentManager = new StateExperimentManager(id, name);
5d10d135
ASL
129 }
130 }
131
132 /**
133 * Clea up resources
134 */
135 public static void dispose() {
136 if (experimentManager != null) {
137 experimentManager = null;
138 }
139 }
8827c197
FC
140
141 /**
142 * @return the traceCheckPointInterval
143 */
144 public static Long getTraceCheckPointInterval() {
145 return ftraceCheckPointInterval;
146 }
147
148 /**
149 * @param traceCheckPointInterval
150 * the traceCheckPointInterval to set
151 */
152 public static void setTraceCheckPointInterval(Long traceCheckPointInterval) {
153 StateManagerFactory.ftraceCheckPointInterval = traceCheckPointInterval;
154 }
e31e01e8 155}
This page took 0.032606 seconds and 5 git commands to generate.