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
.ui
.model
.trange
.TimeRangeEventProcess
;
20 * Contains the processes in use by the Control flow view
25 public class FlowProcessContainer
{
26 // ========================================================================
28 // ========================================================================
29 private final HashMap
<ProcessKey
, TimeRangeEventProcess
> allProcesses
= new HashMap
<ProcessKey
, TimeRangeEventProcess
>();
30 private static Integer uniqueId
= 0;
32 // ========================================================================
34 // ========================================================================
37 * Package level constructor
39 FlowProcessContainer() {
43 // ========================================================================
45 // ========================================================================
47 * Interface to add a new process.<p>
49 * Note : Process with the same key will be overwritten, it's calling function job to make sure the new process is unique.
51 * @param newProcess The process to add
53 public void addProcess(TimeRangeEventProcess newProcess
) {
54 if (newProcess
!= null) {
55 allProcesses
.put(new ProcessKey(newProcess
), newProcess
);
64 public Integer
getUniqueId() {
69 * This method is intended for read only purposes in order to keep the
70 * internal data structure in synch
72 * @return TimeRangeEventProcess[]
74 public TimeRangeEventProcess
[] readProcesses() {
75 // This allow us to return an Array of the correct type of the exact correct dimension, without looping
76 return allProcesses
.values().toArray(new TimeRangeEventProcess
[allProcesses
.size()]);
80 * Clear the children information for processes related to a specific trace
81 * e.g. just before refreshing data with a new time range
83 * @param traceId The trace unique id (trace name?) on which we need to eliminate children.
85 public void clearChildren(String traceId
) {
86 TimeRangeEventProcess process
= null;
87 Iterator
<ProcessKey
> iterator
= allProcesses
.keySet().iterator();
89 while (iterator
.hasNext()) {
90 process
= allProcesses
.get(iterator
.next());
92 if (process
.getTraceID().equals(traceId
)) {
93 // Reset clear childEventComposites() and traceEvents()
94 // Also restore the nextGoodTime to the insertionTime for the drawing
101 * Clear all process items
103 public void clearProcesses() {
104 allProcesses
.clear();
108 * Remove the process related to a specific trace e.g. during trace
111 * @param traceId The trace unique id (trace name?) on which we want to remove process
113 public void removeProcesses(String traceId
) {
114 ProcessKey iterKey
= null;
116 Iterator
<ProcessKey
> iterator
= allProcesses
.keySet().iterator();
117 while (iterator
.hasNext()) {
118 iterKey
= iterator
.next();
120 if (allProcesses
.get(iterKey
).getTraceID().equals(traceId
)) {
121 allProcesses
.remove(iterKey
);
127 * Search by keys (pid, cpuId, traceId and creationTime)<p>
129 * A match is returned if the four arguments received match an entry
130 * Otherwise null is returned
132 * @param searchedPid The processId (Pid) we are looking for
133 * @param searchedCpuId The cpu Id we are looking for
134 * @param searchedTraceID The traceId (trace name?) we are looking for
135 * @param searchedCreationtime The creation time we are looking for
137 * @return TimeRangeEventProcess
139 public TimeRangeEventProcess
findProcess(Long searchedPid
, Long searchedCpuId
, String searchedTraceID
, Long searchedCreationtime
) {
140 // Get the TimeRangeEventProcess associated to a key we create here
141 TimeRangeEventProcess foundProcess
= allProcesses
.get( new ProcessKey(searchedPid
, searchedCpuId
, searchedTraceID
, searchedCreationtime
) );
149 private TimeRangeEventProcess valueRef
= null;
151 private Long pid
= null;
152 private Long cpuId
= null;
153 private String traceId
= null;
154 private Long creationtime
= null;
156 @SuppressWarnings("unused")
157 private ProcessKey() { }
159 public ProcessKey(TimeRangeEventProcess newRef
) {
163 public ProcessKey(Long newPid
, Long newCpuId
, String newTraceId
, Long newCreationTime
) {
166 traceId
= newTraceId
;
167 creationtime
= newCreationTime
;
171 public boolean equals(Object obj
) {
172 boolean isSame
= false;
174 if ( obj
instanceof ProcessKey
) {
175 ProcessKey procKey
= (ProcessKey
) obj
;
176 if ( (procKey
.getPid().equals(this.getPid()) ) &&
177 (procKey
.getTraceId().equals(this.getTraceId()) ) &&
178 (procKey
.getCpuId().equals(this.getCpuId()) ) &&
179 (procKey
.getCreationtime().equals(this.getCreationtime()) ) )
188 // *** WARNING : Everything in there work because the check "valueRef != null" is the same for ALL getter
189 // Do NOT change this check without checking.
190 public Long
getPid() {
191 if ( valueRef
!= null ) {
192 return valueRef
.getPid();
199 public Long
getCpuId() {
200 if ( valueRef
!= null ) {
201 return valueRef
.getCpu();
208 public String
getTraceId() {
209 if ( valueRef
!= null ) {
210 return valueRef
.getTraceID();
217 public Long
getCreationtime() {
218 if ( valueRef
!= null ) {
219 return valueRef
.getCreationTime();
227 public int hashCode() {
228 return this.toString().hashCode();
233 public String
toString() {
234 if ( valueRef
!= null ) {
235 return (valueRef
.getPid().toString() + ":" + valueRef
.getCpu().toString() + ":" + valueRef
.getTraceID().toString() + ":" + valueRef
.getCreationTime().toString());
238 return (pid
+ ":" + cpuId
+ ":" + traceId
+ ":" + creationtime
);