1 11 package org.eclipse.jdt.internal.debug.core.model; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 import org.eclipse.debug.core.DebugException; 18 import org.eclipse.debug.core.model.ITerminate; 19 import org.eclipse.jdt.debug.core.IJavaThread; 20 import org.eclipse.jdt.debug.core.IJavaThreadGroup; 21 22 import com.sun.jdi.ThreadGroupReference; 23 import com.sun.jdi.ThreadReference; 24 25 29 public class JDIThreadGroup extends JDIDebugElement implements IJavaThreadGroup, ITerminate { 30 31 private ThreadGroupReference fGroup = null; 32 private String fName = null; 33 34 41 public JDIThreadGroup(JDIDebugTarget target, ThreadGroupReference group) { 42 super(target); 43 fGroup = group; 44 } 45 46 49 public synchronized IJavaThread[] getThreads() throws DebugException { 50 try { 51 List threads = fGroup.threads(); 52 List modelThreads = new ArrayList (threads.size()); 53 Iterator iterator = threads.iterator(); 54 while (iterator.hasNext()) { 55 ThreadReference ref = (ThreadReference) iterator.next(); 56 JDIThread thread = getJavaDebugTarget().findThread(ref); 57 if (thread != null) { 58 modelThreads.add(thread); 59 } 60 } 61 return (IJavaThread[]) modelThreads.toArray(new IJavaThread[modelThreads.size()]); 62 } catch (RuntimeException e) { 63 targetRequestFailed(JDIDebugModelMessages.JDIThreadGroup_0, e); 64 } 65 return null; 66 } 67 68 71 public IJavaThreadGroup getThreadGroup() throws DebugException { 72 try { 73 ThreadGroupReference reference = fGroup.parent(); 74 if (reference != null) { 75 return getJavaDebugTarget().findThreadGroup(reference); 76 } 77 } catch (RuntimeException e) { 78 targetRequestFailed(JDIDebugModelMessages.JDIThreadGroup_1, e); 79 } 80 return null; 81 } 82 83 86 public IJavaThreadGroup[] getThreadGroups() throws DebugException { 87 try { 88 List groups = fGroup.threadGroups(); 89 List modelGroups = new ArrayList (groups.size()); 90 Iterator iterator = groups.iterator(); 91 while (iterator.hasNext()) { 92 ThreadGroupReference ref = (ThreadGroupReference) iterator.next(); 93 JDIThreadGroup group = getJavaDebugTarget().findThreadGroup(ref); 94 if (group != null) { 95 modelGroups.add(group); 96 } 97 } 98 return (IJavaThreadGroup[]) modelGroups.toArray(new IJavaThreadGroup[modelGroups.size()]); 99 } catch (RuntimeException e) { 100 targetRequestFailed(JDIDebugModelMessages.JDIThreadGroup_2, e); 101 } 102 return null; 103 } 104 105 108 public synchronized String getName() throws DebugException { 109 if (fName == null) { 110 try { 111 fName = fGroup.name(); 112 } catch (RuntimeException e) { 113 targetRequestFailed(JDIDebugModelMessages.JDIThreadGroup_3, e); 114 } 115 } 116 return fName; 117 } 118 119 ThreadGroupReference getUnderlyingThreadGroup() { 120 return fGroup; 121 } 122 123 126 public boolean hasThreadGroups() throws DebugException { 127 try { 128 List groups = fGroup.threadGroups(); 129 return groups.size() > 0; 130 } catch (RuntimeException e) { 131 targetRequestFailed(JDIDebugModelMessages.JDIThreadGroup_4, e); 132 } 133 return false; 134 } 135 136 139 public boolean hasThreads() throws DebugException { 140 try { 141 List threads = fGroup.threads(); 142 return threads.size() > 0; 143 } catch (RuntimeException e) { 144 targetRequestFailed(JDIDebugModelMessages.JDIThreadGroup_5, e); 145 } 146 return false; 147 } 148 149 152 public boolean canTerminate() { 153 return getDebugTarget().canTerminate(); 155 } 156 157 160 public boolean isTerminated() { 161 return getDebugTarget().isTerminated(); 162 } 163 164 167 public void terminate() throws DebugException { 168 getDebugTarget().terminate(); 169 } 170 171 } 172 | Popular Tags |