~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/state/experiment/StateManagerFactory.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2009, 2010 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.internal.lttng.core.state.experiment;
 
14
 
 
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;
 
23
 
 
24
/**
 
25
 * @author alvaro
 
26
 * 
 
27
 */
 
28
public class StateManagerFactory {
 
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
     */
 
52
    public static LTTngTreeNode getManager(ITmfTrace<?> rtrace, LTTngTreeNode experiment) {
 
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
        }
 
70
 
 
71
//              LttngTraceState traceModel = 
 
72
//              StateModelFactory.getStateEntryInstance();
 
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) {
 
86
            Activator.getDefault().logError("Unexpected Error", e);  //$NON-NLS-1$
 
87
        }
 
88
 
 
89
        experiment.addChild(manager);
 
90
        return manager;
 
91
    }
 
92
 
 
93
    /**
 
94
     * Provide the State trace set manager
 
95
     * 
 
96
     * @return
 
97
     */
 
98
    public static IStateExperimentManager getExperimentManager() {
 
99
        return experimentManager;
 
100
    }
 
101
 
 
102
    /**
 
103
     * Remove previously registered managers
 
104
     * 
 
105
     * @param traceUniqueId
 
106
     */
 
107
    public static void removeManager(ITmfTrace<?> rtrace, LTTngTreeNode rexperiment) {
 
108
        if (rtrace ==  null || rexperiment == null)
 
109
            return;
 
110
        if (rexperiment.getValue() instanceof TmfExperiment<?>) {
 
111
            LTTngTreeNode childToremove = rexperiment.getChildByName(rtrace.getName());
 
112
            if (childToremove != null) {
 
113
                rexperiment.removeChild(childToremove);
 
114
            }
 
115
        } else {
 
116
            TraceDebug.debug("Invalid arguments to remove manager for trace: " //$NON-NLS-1$
 
117
                    + rtrace.getName());
 
118
        }
 
119
    }
 
120
 
 
121
    /**
 
122
     * initialization of factory
 
123
     */
 
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);
 
129
        }
 
130
    }
 
131
 
 
132
    /**
 
133
     * Clea up resources
 
134
     */
 
135
    public static void dispose() {
 
136
        if (experimentManager != null) {
 
137
            experimentManager = null;
 
138
        }
 
139
    }
 
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
    }
 
155
}