1 11 package org.eclipse.jdt.internal.debug.ui.monitors; 12 13 14 import java.util.ArrayList ; 15 import java.util.HashMap ; 16 import java.util.List ; 17 import java.util.Map ; 18 19 import org.eclipse.jdt.debug.core.IJavaObject; 20 import org.eclipse.jdt.debug.core.IJavaThread; 21 import org.eclipse.jface.viewers.ITreeContentProvider; 22 import org.eclipse.jface.viewers.Viewer; 23 24 27 public class DeadLocksViewContentProvider implements ITreeContentProvider { 28 29 Object [] fRoots= null; 30 31 38 public class ContentThreadWrapper { 39 public IJavaThread fThread; 40 public Object fParent= null; 41 public boolean caughtInADeadLock; 42 public Object fChild= null; 43 44 protected ContentThreadWrapper(IJavaThread thread, Object parent) { 45 fThread= thread; 46 fParent= parent; 47 } 48 49 52 public boolean equals(Object obj) { 53 if (!(obj instanceof ContentThreadWrapper)) { 54 return false; 55 } 56 ContentThreadWrapper other= (ContentThreadWrapper)obj; 57 58 return other.fThread.equals(fThread); 59 } 60 61 64 public int hashCode() { 65 return fThread.hashCode(); 66 } 67 68 } 69 70 73 public class ContentMonitorWrapper { 74 public IJavaObject fMonitor; 75 public Object fParent= null; 76 public Object fChild= null; 77 78 protected ContentMonitorWrapper(IJavaObject monitor, Object parent) { 79 fMonitor= monitor; 80 fParent= parent; 81 } 82 83 86 public boolean equals(Object obj) { 87 if (!(obj instanceof ContentMonitorWrapper)) { 88 return false; 89 } 90 ContentMonitorWrapper other= (ContentMonitorWrapper)obj; 91 92 return other.fMonitor.equals(fMonitor); 93 } 94 95 98 public int hashCode() { 99 return fMonitor.hashCode(); 100 } 101 } 102 103 106 public Object [] getChildren(Object parentElement) { 107 Object object= null; 108 if (parentElement instanceof ContentThreadWrapper) { 109 object= ((ContentThreadWrapper)parentElement).fChild; 110 } else if (parentElement instanceof ContentMonitorWrapper) { 111 object= ((ContentMonitorWrapper)parentElement).fChild; 112 } 113 if (object != null) { 114 return new Object []{object}; 115 } 116 return null; 117 } 118 119 122 public Object getParent(Object element) { 123 if (element instanceof ContentThreadWrapper) { 124 return ((ContentThreadWrapper)element).fParent; 125 } else if (element instanceof ContentMonitorWrapper) { 126 return ((ContentMonitorWrapper)element).fParent; 127 } 128 129 return null; 130 } 131 132 135 public boolean hasChildren(Object element) { 136 137 if (element instanceof ContentThreadWrapper) { 138 return ((ContentThreadWrapper)element).fChild != null; 139 } else if (element instanceof ContentMonitorWrapper) { 140 return ((ContentMonitorWrapper)element).fChild != null; 141 } 142 143 return false; 144 } 145 146 149 public Object [] getElements(Object inputElement) { 150 if (fRoots == null) { 151 MonitorManager manager= (MonitorManager) inputElement; 152 int numDeadLocks= manager.getNumberOfDeadlocks(); 153 fRoots= new Object [numDeadLocks]; 155 156 for (int i = 0; i < numDeadLocks; i++) { 157 ContentThreadWrapper rootWrapper = new ContentThreadWrapper(manager.getStartThread(i), null); 159 List deadlockList = manager.getDeadlockList(i); 160 Map tree= new HashMap (deadlockList.size()); 161 tree.put(rootWrapper, rootWrapper); 162 buildDeadlockTree(rootWrapper, tree, rootWrapper, deadlockList); 163 fRoots[i] = rootWrapper; 164 } 165 } 166 return fRoots; 167 } 168 169 protected void buildDeadlockTree(ContentThreadWrapper ctw, Map tree, Object parent, List deadlockList) { 170 Object next; 171 Object object; 172 Object inTree; 173 List childFinder= new ArrayList (deadlockList.size()); 174 for (int j= 1; j < deadlockList.size(); j++) { 175 next= deadlockList.get(j); 176 177 if (next instanceof IJavaObject) { 178 object= new ContentMonitorWrapper((IJavaObject)next, parent); 179 } else { 180 object= new ContentThreadWrapper((IJavaThread)next, parent); 181 } 182 if (j == 1) { 183 ctw.fChild= object; 184 } 185 inTree= tree.get(object); 186 if (inTree instanceof ContentThreadWrapper) { 187 ((ContentThreadWrapper)inTree).caughtInADeadLock= true; 188 ((ContentThreadWrapper)object).caughtInADeadLock= true; 189 } else if (inTree == null){ 190 tree.put(object, object); 191 } 192 parent= object; 193 childFinder.add(object); 194 } 195 196 for (int j = 0; j < childFinder.size() - 1; j++) { 197 Object element = childFinder.get(j); 198 if (element instanceof ContentMonitorWrapper) { 199 ((ContentMonitorWrapper)element).fChild= childFinder.get(j+1); 200 } else { 201 ((ContentThreadWrapper)element).fChild= childFinder.get(j+1); 202 } 203 } 204 } 205 206 209 public void dispose() { 210 MonitorManager.getDefault().removeDeadlockUpdateListener(); 211 } 212 213 216 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 217 MonitorManager.getDefault().addDeadlockUpdateListener(this); 218 } 219 220 protected void clearDeadlockInformation() { 221 fRoots= null; 222 } 223 } 224 | Popular Tags |