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
55 public void addItem(TimeRangeEventProcess newItem
) {
56 if (newItem
!= null) {
57 allProcesses
.put(new ProcessKey(newItem
), newItem
);
66 public Integer
getUniqueId() {
71 * This method is intended for read only purposes in order to keep the
72 * internal data structure in synch
74 * @return TimeRangeEventProcess[]
76 public TimeRangeEventProcess
[] readItems() {
78 // This allow us to return an Array of the correct type of the exact correct dimension, without looping
79 return allProcesses
.values().toArray(new TimeRangeEventProcess
[allProcesses
.size()]);
83 * Clear the children information for processes e.g. just before refreshing
84 * data with a new time range
86 public void clearChildren() {
87 TimeRangeEventProcess process
= null;
88 Iterator
<ProcessKey
> iterator
= allProcesses
.keySet().iterator();
90 while (iterator
.hasNext()) {
91 process
= allProcesses
.get(iterator
.next());
97 * Clear all process items
99 public void clearItems() {
100 allProcesses
.clear();
104 * Remove the process related to a specific trace e.g. during trace
107 * @param traceId The trace unique id (trace name?) on which we want to remove process
109 public void removeItems(String traceId
) {
110 ProcessKey iterKey
= null;
112 Iterator
<ProcessKey
> iterator
= allProcesses
.keySet().iterator();
113 while (iterator
.hasNext()) {
114 iterKey
= iterator
.next();
116 if (allProcesses
.get(iterKey
).getTraceID().equals(traceId
)) {
117 allProcesses
.remove(iterKey
);
123 * Search by keys (pid, cpuId, traceId and creationTime)<p>
125 * A match is returned if the four arguments received match an entry
126 * Otherwise null is returned
128 * @param searchedPid The processId (Pid) we are looking for
129 * @param searchedCpuId The cpu Id we are looking for
130 * @param searchedTraceID The traceId (trace name?) we are looking for
131 * @param searchedCreationtime The creation time we are looking for
133 * @return TimeRangeEventProcess
135 public TimeRangeEventProcess
findProcess(Long searchedPid
, Long searchedCpuId
, String searchedTraceID
, Long searchedCreationtime
) {
136 // Get the TimeRangeEventProcess associated to a key we create here
137 TimeRangeEventProcess foundProcess
= allProcesses
.get( new ProcessKey(searchedPid
, searchedCpuId
, searchedTraceID
, searchedCreationtime
) );
145 private TimeRangeEventProcess valueRef
= null;
147 private Long pid
= null;
148 private Long cpuId
= null;
149 private String traceId
= null;
150 private Long creationtime
= null;
152 @SuppressWarnings("unused")
153 private ProcessKey() { }
155 public ProcessKey(TimeRangeEventProcess newRef
) {
159 public ProcessKey(Long newPid
, Long newCpuId
, String newTraceId
, Long newCreationTime
) {
162 traceId
= newTraceId
;
163 creationtime
= newCreationTime
;
167 public boolean equals(Object obj
) {
168 boolean isSame
= false;
170 if ( obj
instanceof ProcessKey
) {
171 ProcessKey procKey
= (ProcessKey
) obj
;
173 if ( valueRef
!= null ) {
174 if ( (procKey
.getPid().equals(valueRef
.getPid()) ) &&
175 (procKey
.getTraceId().equals(valueRef
.getTraceID()) ) &&
176 (procKey
.getCpuId().equals(valueRef
.getCpu()) ) &&
177 (procKey
.getCreationtime().equals(valueRef
.getCreationTime()) ) )
183 if ( (procKey
.getPid().equals(this.pid
) ) &&
184 (procKey
.getTraceId().equals(this.traceId
) ) &&
185 (procKey
.getCpuId().equals(this.cpuId
) ) &&
186 (procKey
.getCreationtime().equals(this.creationtime
) ) )
193 TraceDebug
.debug("ERROR : The given key is not of the type ProcessKey!" + obj
.getClass().toString());
199 // *** WARNING : Everything in there work because the check "valueRef != null" is the same for ALL getter
200 // Do NOT change this check without checking.
201 public Long
getPid() {
202 if ( valueRef
!= null ) {
203 return valueRef
.getPid();
210 public Long
getCpuId() {
211 if ( valueRef
!= null ) {
212 return valueRef
.getCpu();
219 public String
getTraceId() {
220 if ( valueRef
!= null ) {
221 return valueRef
.getTraceID();
228 public Long
getCreationtime() {
229 if ( valueRef
!= null ) {
230 return valueRef
.getCreationTime();
238 public int hashCode() {
239 return this.toString().hashCode();
244 public String
toString() {
245 if ( valueRef
!= null ) {
246 return (valueRef
.getPid().toString() + ":" + valueRef
.getCpu().toString() + ":" + valueRef
.getTraceID().toString() + ":" + valueRef
.getCreationTime().toString());
249 return (pid
.toString() + ":" + cpuId
.toString() + ":" + traceId
.toString() + ":" + creationtime
.toString());