[290250] Applied patch with minor annotation updates
[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.getTraceEvents().clear();
78 process.getChildEventComposites().clear();
79 }
80 }
81 }
82
83 /**
84 * remove the processes related to a specific trace e.g. during trace
85 * removal
86 *
87 * @param traceId
88 */
89 public void removeProcesses(String traceId) {
90 String procTraceId;
91 for (TimeRangeEventProcess process : processes) {
92 procTraceId = process.getTraceID();
93 if (procTraceId.equals(traceId)) {
94 // Children and traceEvent will get claimed by the garbage collector when process is unreferenced
95 // Therefore, we don't need to removed them
96 processes.remove(process);
97 }
98 }
99 }
100
101 /**
102 * A match is returned if the three arguments received match an entry in the
103 * Map, otherwise null is returned
104 *
105 * @param pid
106 * @param creationtime
107 * @param traceID
108 * @return
109 */
110 public TimeRangeEventProcess findProcess(Long pid, Long creationtime,
111 String traceID) {
112 TimeRangeEventProcess rprocess = null;
113
114 for (TimeRangeEventProcess process : processes) {
115 if (process.getPid().equals(pid)) {
116 if (process.getCreationTime().equals(creationtime)) {
117 if (process.getTraceID().equals(traceID)) {
118 return process;
119 }
120 }
121 }
122 }
123
124 return rprocess;
125 }
126
127 /**
128 * Generate a unique process id while building the process list
129 *
130 * @return
131 */
132 public int bookProcId() {
133 return idgen++;
134 }
135
136 }
This page took 0.045812 seconds and 6 git commands to generate.