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() {
77 // This allow us to return an Array of the correct type of the exact correct dimension, without looping
78 return allProcesses
.values().toArray(new TimeRangeEventProcess
[allProcesses
.size()]);
82 * Clear the children information for processes related to a specific trace
83 * e.g. just before refreshing data with a new time range
85 * @param traceId The trace unique id (trace name?) on which we need to eliminate children.
87 public void clearChildren(String traceId
) {
88 TimeRangeEventProcess process
= null;
89 Iterator
<ProcessKey
> iterator
= allProcesses
.keySet().iterator();
91 while (iterator
.hasNext()) {
92 process
= allProcesses
.get(iterator
.next());
94 if (process
.getTraceID().equals(traceId
)) {
95 // Reset clear childEventComposites() and traceEvents()
96 // Also restore the nextGoodTime to the insertionTime for the drawing
103 * Clear all process items
105 public void clearProcesses() {
106 allProcesses
.clear();
110 * Remove the process related to a specific trace e.g. during trace
113 * @param traceId The trace unique id (trace name?) on which we want to remove process
115 public void removeProcesses(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
.getCpuId().equals(valueRef
.getCpu()) ) &&
183 (procKey
.getCreationtime().equals(valueRef
.getCreationTime()) ) )
189 if ( (procKey
.getPid().equals(this.pid
) ) &&
190 (procKey
.getTraceId().equals(this.traceId
) ) &&
191 (procKey
.getCpuId().equals(this.cpuId
) ) &&
192 (procKey
.getCreationtime().equals(this.creationtime
) ) )
199 TraceDebug
.debug("ERROR : The given key is not of the type ProcessKey!" + obj
.getClass().toString());
205 // *** WARNING : Everything in there work because the check "valueRef != null" is the same for ALL getter
206 // Do NOT change this check without checking.
207 public Long
getPid() {
208 if ( valueRef
!= null ) {
209 return valueRef
.getPid();
216 public Long
getCpuId() {
217 if ( valueRef
!= null ) {
218 return valueRef
.getCpu();
225 public String
getTraceId() {
226 if ( valueRef
!= null ) {
227 return valueRef
.getTraceID();
234 public Long
getCreationtime() {
235 if ( valueRef
!= null ) {
236 return valueRef
.getCreationTime();
244 public int hashCode() {
245 return this.toString().hashCode();
250 public String
toString() {
251 if ( valueRef
!= null ) {
252 return (valueRef
.getPid().toString() + ":" + valueRef
.getCpu().toString() + ":" + valueRef
.getTraceID().toString() + ":" + valueRef
.getCreationTime().toString());
255 return (pid
.toString() + ":" + cpuId
.toString() + ":" + traceId
.toString() + ":" + creationtime
.toString());