1 /*******************************************************************************
2 * Copyright (c) 2009 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 - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.controlflow
.model
;
14 import java
.util
.HashMap
;
15 import java
.util
.Iterator
;
17 import org
.eclipse
.linuxtools
.lttng
.TraceDebug
;
18 import org
.eclipse
.linuxtools
.lttng
.ui
.model
.trange
.ItemContainer
;
19 import org
.eclipse
.linuxtools
.lttng
.ui
.model
.trange
.TimeRangeEventProcess
;
22 * Contains the processes in use by the Control flow view
27 public class FlowProcessContainer
implements ItemContainer
<TimeRangeEventProcess
> {
28 // ========================================================================
30 // ========================================================================
31 private final HashMap
<ProcessKey
, TimeRangeEventProcess
> allProcesses
= new HashMap
<ProcessKey
, TimeRangeEventProcess
>();
32 private static Integer uniqueId
= 0;
34 // ========================================================================
36 // ========================================================================
39 * Package level constructor
41 FlowProcessContainer() {
45 // ========================================================================
47 // ========================================================================
49 * Interface to add a new process.<p>
51 * Note : Process with the same key will be overwritten, it's calling function job to make sure the new process is unique.
53 * @param newProcess The process to add
56 public void addItem(TimeRangeEventProcess newItem
) {
57 if (newItem
!= null) {
58 allProcesses
.put(new ProcessKey(newItem
), newItem
);
68 public Integer
getUniqueId() {
73 * This method is intended for read only purposes in order to keep the
74 * internal data structure in synch
76 * @return TimeRangeEventProcess[]
79 public TimeRangeEventProcess
[] readItems() {
81 // This allow us to return an Array of the correct type of the exact correct dimension, without looping
82 return allProcesses
.values().toArray(new TimeRangeEventProcess
[allProcesses
.size()]);
86 * Clear the children information for processes e.g. just before refreshing
87 * data with a new time range
90 public void clearChildren() {
91 TimeRangeEventProcess process
= null;
92 Iterator
<ProcessKey
> iterator
= allProcesses
.keySet().iterator();
94 while (iterator
.hasNext()) {
95 process
= allProcesses
.get(iterator
.next());
101 * Clear all process items
104 public void clearItems() {
105 allProcesses
.clear();
109 * Remove the process related to a specific trace e.g. during trace
112 * @param traceId The trace unique id (trace name?) on which we want to remove process
115 public void removeItems(String traceId
) {
116 ProcessKey iterKey
= null;
118 Iterator
<ProcessKey
> iterator
= allProcesses
.keySet().iterator();
119 while (iterator
.hasNext()) {
120 iterKey
= iterator
.next();
122 if (allProcesses
.get(iterKey
).getTraceID().equals(traceId
)) {
123 allProcesses
.remove(iterKey
);
129 * Search by keys (pid, cpuId, traceId and creationTime)<p>
131 * A match is returned if the four arguments received match an entry
132 * Otherwise null is returned
134 * @param searchedPid The processId (Pid) we are looking for
135 * @param searchedCpuId The cpu Id we are looking for
136 * @param searchedTraceID The traceId (trace name?) we are looking for
137 * @param searchedCreationtime The creation time we are looking for
139 * @return TimeRangeEventProcess
141 public TimeRangeEventProcess
findProcess(Long searchedPid
, Long searchedCpuId
, String searchedTraceID
, Long searchedCreationtime
) {
142 // Get the TimeRangeEventProcess associated to a key we create here
143 TimeRangeEventProcess foundProcess
= allProcesses
.get( new ProcessKey(searchedPid
, searchedCpuId
, searchedTraceID
, searchedCreationtime
) );
151 private TimeRangeEventProcess valueRef
= null;
153 private Long pid
= null;
154 private Long cpuId
= null;
155 private String traceId
= null;
156 private Long creationtime
= null;
158 @SuppressWarnings("unused")
159 private ProcessKey() { }
161 public ProcessKey(TimeRangeEventProcess newRef
) {
165 public ProcessKey(Long newPid
, Long newCpuId
, String newTraceId
, Long newCreationTime
) {
168 traceId
= newTraceId
;
169 creationtime
= newCreationTime
;
173 public boolean equals(Object obj
) {
174 boolean isSame
= false;
176 if ( obj
instanceof ProcessKey
) {
177 ProcessKey procKey
= (ProcessKey
) obj
;
179 if (valueRef
!= null) {
180 if ((procKey
.getPid().equals(valueRef
.getPid()))
181 && (procKey
.getTraceId().equals(valueRef
.getTraceID()))
182 && (procKey
.getCreationtime().equals(valueRef
.getCreationTime()))) {
183 // use the cpu value to validate pid 0
184 if (valueRef
.getPid().longValue() == 0L && !procKey
.getCpuId().equals(valueRef
.getCpu())) {
191 if ((procKey
.getPid().equals(this.pid
)) && (procKey
.getTraceId().equals(this.traceId
))
192 && (procKey
.getCreationtime().equals(this.creationtime
))) {
193 // use the cpu value to validate pid 0
194 if (this.pid
.longValue() == 0L && !procKey
.getCpuId().equals(this.cpuId
)) {
203 TraceDebug
.debug("ERROR : The given key is not of the type ProcessKey!" + obj
.getClass().toString());
209 // *** WARNING : Everything in there work because the check "valueRef != null" is the same for ALL getter
210 // Do NOT change this check without checking.
211 public Long
getPid() {
212 if ( valueRef
!= null ) {
213 return valueRef
.getPid();
220 public Long
getCpuId() {
221 if ( valueRef
!= null ) {
222 return valueRef
.getCpu();
229 public String
getTraceId() {
230 if ( valueRef
!= null ) {
231 return valueRef
.getTraceID();
238 public Long
getCreationtime() {
239 if ( valueRef
!= null ) {
240 return valueRef
.getCreationTime();
248 public int hashCode() {
249 return this.toString().hashCode();
254 @SuppressWarnings("nls")
255 public String
toString() {
256 if ( valueRef
!= null ) {
257 // return (valueRef.getPid().toString() + ":" +
258 // valueRef.getCpu().toString() + ":"
259 // + valueRef.getTraceID().toString() + ":" +
260 // valueRef.getCreationTime().toString());
261 return (valueRef
.getPid().toString() + ":" + valueRef
.getTraceID().toString() + ":" + valueRef
262 .getCreationTime().toString());
265 // return (pid.toString() + ":" + cpuId.toString() + ":" +
266 // traceId.toString() + ":" + creationtime.toString());
268 return (pid
.toString() + ":" + traceId
.toString() + ":" + creationtime
.toString());