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
.TimeRangeEventProcess
;
21 * Contains the processes in use by the Control flow view
26 public class FlowProcessContainer
{
27 // ========================================================================
29 // ========================================================================
30 private final HashMap
<ProcessKey
, TimeRangeEventProcess
> allProcesses
= new HashMap
<ProcessKey
, TimeRangeEventProcess
>();
31 private static Integer uniqueId
= 0;
33 // ========================================================================
35 // ========================================================================
38 * Package level constructor
40 FlowProcessContainer() {
44 // ========================================================================
46 // ========================================================================
48 * Interface to add a new process.<p>
50 * Note : Process with the same key will be overwritten, it's calling function job to make sure the new process is unique.
52 * @param newProcess The process to add
54 public void addProcess(TimeRangeEventProcess newProcess
) {
55 if (newProcess
!= null) {
56 allProcesses
.put(new ProcessKey(newProcess
), newProcess
);
65 public Integer
getUniqueId() {
70 * This method is intended for read only purposes in order to keep the
71 * internal data structure in synch
73 * @return TimeRangeEventProcess[]
75 public TimeRangeEventProcess
[] readProcesses() {
76 // This allow us to return an Array of the correct type of the exact correct dimension, without looping
77 return allProcesses
.values().toArray(new TimeRangeEventProcess
[allProcesses
.size()]);
81 * Clear the children information for processes related to a specific trace
82 * e.g. just before refreshing data with a new time range
84 * @param traceId The trace unique id (trace name?) on which we need to eliminate children.
86 public void clearChildren(String traceId
) {
87 TimeRangeEventProcess process
= null;
88 Iterator
<ProcessKey
> iterator
= allProcesses
.keySet().iterator();
90 while (iterator
.hasNext()) {
91 process
= allProcesses
.get(iterator
.next());
93 if (process
.getTraceID().equals(traceId
)) {
94 // Reset clear childEventComposites() and traceEvents()
95 // Also restore the nextGoodTime to the insertionTime for the drawing
102 * Clear all process items
104 public void clearProcesses() {
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
114 public void removeProcesses(String traceId
) {
115 ProcessKey iterKey
= null;
117 Iterator
<ProcessKey
> iterator
= allProcesses
.keySet().iterator();
118 while (iterator
.hasNext()) {
119 iterKey
= iterator
.next();
121 if (allProcesses
.get(iterKey
).getTraceID().equals(traceId
)) {
122 allProcesses
.remove(iterKey
);
128 * Search by keys (pid, cpuId, traceId and creationTime)<p>
130 * A match is returned if the four arguments received match an entry
131 * Otherwise null is returned
133 * @param searchedPid The processId (Pid) we are looking for
134 * @param searchedCpuId The cpu Id we are looking for
135 * @param searchedTraceID The traceId (trace name?) we are looking for
136 * @param searchedCreationtime The creation time we are looking for
138 * @return TimeRangeEventProcess
140 public TimeRangeEventProcess
findProcess(Long searchedPid
, Long searchedCpuId
, String searchedTraceID
, Long searchedCreationtime
) {
141 // Get the TimeRangeEventProcess associated to a key we create here
142 TimeRangeEventProcess foundProcess
= allProcesses
.get( new ProcessKey(searchedPid
, searchedCpuId
, searchedTraceID
, searchedCreationtime
) );
150 private TimeRangeEventProcess valueRef
= null;
152 private Long pid
= null;
153 private Long cpuId
= null;
154 private String traceId
= null;
155 private Long creationtime
= null;
157 @SuppressWarnings("unused")
158 private ProcessKey() { }
160 public ProcessKey(TimeRangeEventProcess newRef
) {
164 public ProcessKey(Long newPid
, Long newCpuId
, String newTraceId
, Long newCreationTime
) {
167 traceId
= newTraceId
;
168 creationtime
= newCreationTime
;
172 public boolean equals(Object obj
) {
173 boolean isSame
= false;
175 if ( obj
instanceof ProcessKey
) {
176 ProcessKey procKey
= (ProcessKey
) obj
;
178 if ( valueRef
!= null ) {
179 if ( (procKey
.getPid().equals(valueRef
.getPid()) ) &&
180 (procKey
.getTraceId().equals(valueRef
.getTraceID()) ) &&
181 (procKey
.getCpuId().equals(valueRef
.getCpu()) ) &&
182 (procKey
.getCreationtime().equals(valueRef
.getCreationTime()) ) )
188 if ( (procKey
.getPid().equals(this.pid
) ) &&
189 (procKey
.getTraceId().equals(this.traceId
) ) &&
190 (procKey
.getCpuId().equals(this.cpuId
) ) &&
191 (procKey
.getCreationtime().equals(this.creationtime
) ) )
198 TraceDebug
.debug("ERROR : The given key is not of the type ProcessKey!" + obj
.getClass().toString());
204 // *** WARNING : Everything in there work because the check "valueRef != null" is the same for ALL getter
205 // Do NOT change this check without checking.
206 public Long
getPid() {
207 if ( valueRef
!= null ) {
208 return valueRef
.getPid();
215 public Long
getCpuId() {
216 if ( valueRef
!= null ) {
217 return valueRef
.getCpu();
224 public String
getTraceId() {
225 if ( valueRef
!= null ) {
226 return valueRef
.getTraceID();
233 public Long
getCreationtime() {
234 if ( valueRef
!= null ) {
235 return valueRef
.getCreationTime();
243 public int hashCode() {
244 return this.toString().hashCode();
249 public String
toString() {
250 if ( valueRef
!= null ) {
251 return (valueRef
.getPid().toString() + ":" + valueRef
.getCpu().toString() + ":" + valueRef
.getTraceID().toString() + ":" + valueRef
.getCreationTime().toString());
254 return (pid
+ ":" + cpuId
+ ":" + traceId
+ ":" + creationtime
);