Rename xxx.lttng to xxx.lttng.core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.core / 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 {
12c155f5
FC
28 // ========================================================================
29 // Data
30 // =======================================================================
31
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;
37
38 static {
39 initCheck();
40 }
41
42 // ========================================================================
43 // Methods
44 // =======================================================================
45
46 /**
47 * @param traceUniqueId
48 * @param experiment
49 * @return
50 */
51 public static LTTngTreeNode getManager(ITmfTrace rtrace, LTTngTreeNode experiment) {
52
53 // Validate
54 if (rtrace == null) {
55 return null;
56 }
57
58 String traceUniqueId = rtrace.getName();
59 if (traceUniqueId == null) {
60 return null;
61 }
62
63 LTTngTreeNode managerNode = null;
64 managerNode = experiment.getChildByName(traceUniqueId);
65
66 if (managerNode != null && managerNode instanceof IStateTraceManager) {
67 return managerNode;
68 }
5d10d135 69
550d787e
FC
70// LttngTraceState traceModel =
71// StateModelFactory.getStateEntryInstance();
12c155f5
FC
72 StateTraceManager manager = null;
73
74 // catch potential construction problems
75 try {
76 manager = new StateTraceManager(experiment.getNextUniqueId(), experiment, traceUniqueId, rtrace);
77
78 // Allow the possibility to configure the trace state check point
79 // interval at creation time
80 if (ftraceCheckPointInterval != null) {
81 manager.setCheckPointInterval(ftraceCheckPointInterval);
82 }
83
84 } catch (LttngStateException e) {
85 e.printStackTrace();
86 }
87
88 experiment.addChild(manager);
89 return manager;
90 }
91
92 /**
93 * Provide the State trace set manager
94 *
95 * @return
96 */
97 public static IStateExperimentManager getExperimentManager() {
98 return experimentManager;
99 }
100
101 /**
102 * Remove previously registered managers
103 *
104 * @param traceUniqueId
105 */
106 public static void removeManager(ITmfTrace rtrace, LTTngTreeNode rexperiment) {
107 if (rtrace != null && rexperiment != null && rexperiment.getValue() instanceof TmfExperiment<?>) {
108 LTTngTreeNode childToremove = rexperiment.getChildByName(rtrace.getName());
109 if (childToremove != null) {
110 rexperiment.removeChild(childToremove);
111 }
112 } else {
113 TraceDebug.debug("Invalid arguments to remove manager for trace: " //$NON-NLS-1$
114 + rtrace.getName());
115 }
116 }
117
118 /**
119 * initialization of factory
120 */
121 private static void initCheck() {
122 if (experimentManager == null) {
123 Long id = 0L; // unique id
124 String name = "StateExperimentManager"; // name //$NON-NLS-1$
125 experimentManager = new StateExperimentManager(id, name);
126 }
127 }
128
129 /**
130 * Clea up resources
131 */
132 public static void dispose() {
133 if (experimentManager != null) {
134 experimentManager = null;
135 }
136 }
137
138 /**
139 * @return the traceCheckPointInterval
140 */
141 public static Long getTraceCheckPointInterval() {
142 return ftraceCheckPointInterval;
143 }
144
145 /**
146 * @param traceCheckPointInterval
147 * the traceCheckPointInterval to set
148 */
149 public static void setTraceCheckPointInterval(Long traceCheckPointInterval) {
150 StateManagerFactory.ftraceCheckPointInterval = traceCheckPointInterval;
151 }
e31e01e8 152}
This page took 0.03635 seconds and 5 git commands to generate.