1
/*******************************************************************************
2
* Copyright (c) 2009, 2010 Ericsson
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
10
* Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11
*******************************************************************************/
13
package org.eclipse.linuxtools.internal.lttng.core.state.experiment;
15
import org.eclipse.linuxtools.internal.lttng.core.Activator;
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;
21
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
22
import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
28
public class StateManagerFactory {
29
// ========================================================================
31
// =======================================================================
33
private static IStateExperimentManager experimentManager = null;
35
* Allows to modify the check point interval for every new instance of trace manager
37
private static Long ftraceCheckPointInterval = null;
43
// ========================================================================
45
// =======================================================================
48
* @param traceUniqueId
52
public static LTTngTreeNode getManager(ITmfTrace<?> rtrace, LTTngTreeNode experiment) {
59
String traceUniqueId = rtrace.getName();
60
if (traceUniqueId == null) {
64
LTTngTreeNode managerNode = null;
65
managerNode = experiment.getChildByName(traceUniqueId);
67
if (managerNode != null && managerNode instanceof IStateTraceManager) {
71
// LttngTraceState traceModel =
72
// StateModelFactory.getStateEntryInstance();
73
StateTraceManager manager = null;
75
// catch potential construction problems
77
manager = new StateTraceManager(experiment.getNextUniqueId(), experiment, traceUniqueId, rtrace);
79
// Allow the possibility to configure the trace state check point
80
// interval at creation time
81
if (ftraceCheckPointInterval != null) {
82
manager.setCheckPointInterval(ftraceCheckPointInterval);
85
} catch (LttngStateException e) {
86
Activator.getDefault().logError("Unexpected Error", e); //$NON-NLS-1$
89
experiment.addChild(manager);
94
* Provide the State trace set manager
98
public static IStateExperimentManager getExperimentManager() {
99
return experimentManager;
103
* Remove previously registered managers
105
* @param traceUniqueId
107
public static void removeManager(ITmfTrace<?> rtrace, LTTngTreeNode rexperiment) {
108
if (rtrace == null || rexperiment == null)
110
if (rexperiment.getValue() instanceof TmfExperiment<?>) {
111
LTTngTreeNode childToremove = rexperiment.getChildByName(rtrace.getName());
112
if (childToremove != null) {
113
rexperiment.removeChild(childToremove);
116
TraceDebug.debug("Invalid arguments to remove manager for trace: " //$NON-NLS-1$
122
* initialization of factory
124
private static void initCheck() {
125
if (experimentManager == null) {
126
Long id = 0L; // unique id
127
String name = "StateExperimentManager"; // name //$NON-NLS-1$
128
experimentManager = new StateExperimentManager(id, name);
135
public static void dispose() {
136
if (experimentManager != null) {
137
experimentManager = null;
142
* @return the traceCheckPointInterval
144
public static Long getTraceCheckPointInterval() {
145
return ftraceCheckPointInterval;
149
* @param traceCheckPointInterval
150
* the traceCheckPointInterval to set
152
public static void setTraceCheckPointInterval(Long traceCheckPointInterval) {
153
StateManagerFactory.ftraceCheckPointInterval = traceCheckPointInterval;