1 22 23 package org.aspectj.debugger.request; 24 25 import org.aspectj.debugger.base.*; 26 27 import com.sun.jdi.*; 28 import java.util.*; 29 30 38 39 public class ThreadsRequest extends Request { 40 41 private String threadGroupName; 42 43 public ThreadsRequest(Debugger debugger, String threadGroupName) { 44 super(debugger); 45 this.threadGroupName = threadGroupName.trim(); 46 } 47 48 public Object go() throws NoVMException, DebuggerException { 49 List list = new ArrayList(); 50 if (threadGroupName == null || threadGroupName.length() == 0) { 51 list = getAllThreads(); 52 } else { 53 list = getThreads(); 54 } 55 return list; 56 } 57 58 private List getAllThreads() throws NoVMException, DebuggerException { 59 return vm().allThreads(); 60 } 61 62 private List getThreads() throws NoVMException, DebuggerException { 63 List result = getThreads(null); 64 if (result == null) { 65 throw new ThreadGroupNotFoundException(); 66 } 67 return result; 68 } 69 70 private List getThreads(ThreadGroupReference ref) throws NoVMException, DebuggerException { 71 if (ref != null) { 72 if (ref.name().equals(threadGroupName)) { 73 return ref.threads(); 74 } 75 76 try { 77 long ourID = Long.parseLong(threadGroupName); 78 long refID = ref.uniqueID(); 79 if (ourID == refID) { 80 return ref.threads(); 81 } 82 } catch (NumberFormatException e) { 83 } 84 } 85 86 List threadGroups = null; 87 if (ref == null) { 88 threadGroups = vm().topLevelThreadGroups(); 89 } else { 90 threadGroups = ref.threadGroups(); 91 } 92 Iterator iter = threadGroups.iterator(); 93 while (iter.hasNext()) { 94 List threads = getThreads((ThreadGroupReference) iter.next()); 95 if (threads != null) { 96 return threads; 97 } 98 } 99 return null; 100 } 101 102 class ThreadGroupNotFoundException extends DebuggerException { 103 public ThreadGroupNotFoundException() { 104 super(ThreadsRequest.this.threadGroupName + 105 " is not a valid thread group."); 106 } 107 } 108 } 109 | Popular Tags |