b3ec0f2e1aba524f1df268498e1511ca8cd64c24
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / controlflow / model / FlowProcessContainer.java
1 /*******************************************************************************
2 * Copyright (c) 2009 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 package org.eclipse.linuxtools.lttng.ui.views.controlflow.model;
13
14 import java.util.Vector;
15
16 import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventProcess;
17
18 /**
19 * Common location to allocate the processes in use by the Control flow view
20 *
21 * @author alvaro
22 *
23 */
24 public class FlowProcessContainer {
25 // ========================================================================
26 // Data
27 // ========================================================================
28 private final Vector<TimeRangeEventProcess> processes = new Vector<TimeRangeEventProcess>();
29 private int idgen = 0;
30
31 // ========================================================================
32 // Constructor
33 // ========================================================================
34
35 /**
36 * Package level constructor
37 */
38 FlowProcessContainer() {
39
40 }
41
42 // ========================================================================
43 // Methods
44 // ========================================================================
45 /**
46 * Interface to add processes.
47 *
48 * @param process
49 */
50 public void addProcesse(TimeRangeEventProcess process) {
51 if (process != null) {
52 processes.add(process);
53 }
54 }
55
56 /**
57 * This method is intended for ready only purposes in order to keep the
58 * internal data structure in Synch
59 *
60 * @return
61 */
62 public Vector<TimeRangeEventProcess> readProcesses() {
63 return processes;
64 }
65
66 /**
67 * Clear the children information for processes related to a specific trace
68 * e.g. just before refreshing data with a new time range
69 *
70 * @param traceId
71 */
72 public void clearChildren(String traceId) {
73 String procTraceId;
74 for (TimeRangeEventProcess process : processes) {
75 procTraceId = process.getTraceID();
76 if (procTraceId.equals(traceId)) {
77 process.reset();
78 }
79 }
80 }
81
82 /**
83 * remove the processes related to a specific trace e.g. during trace
84 * removal
85 *
86 * @param traceId
87 */
88 public void removeProcesses(String traceId) {
89 String procTraceId;
90 for (TimeRangeEventProcess process : processes) {
91 procTraceId = process.getTraceID();
92 if (procTraceId.equals(traceId)) {
93 // Children and traceEvent will get claimed by the garbage collector when process is unreferenced
94 // Therefore, we don't need to removed them
95 processes.remove(process);
96 }
97 }
98 }
99
100 /**
101 * A match is returned if the three arguments received match an entry in the
102 * Map, otherwise null is returned
103 *
104 * @param pid
105 * @param creationtime
106 * @param traceID
107 * @return
108 */
109 public TimeRangeEventProcess findProcess(Long pid, Long creationtime,
110 String traceID) {
111 TimeRangeEventProcess rprocess = null;
112
113 for (TimeRangeEventProcess process : processes) {
114 if (process.getPid().equals(pid)) {
115 if (process.getCreationTime().equals(creationtime)) {
116 if (process.getTraceID().equals(traceID)) {
117 return process;
118 }
119 }
120 }
121 }
122
123 return rprocess;
124 }
125
126 /**
127 * Generate a unique process id while building the process list
128 *
129 * @return
130 */
131 public int bookProcId() {
132 return idgen++;
133 }
134
135 }
This page took 0.03306 seconds and 4 git commands to generate.