Initial Commit
[packages] / xemacs-packages / jde / java / src / jde / debugger / command / Suspend.java
1 package jde.debugger.command;
2 import java.util.Iterator;
3
4 import com.sun.jdi.ObjectReference;
5 import com.sun.jdi.ThreadGroupReference;
6 import com.sun.jdi.ThreadReference;
7 import jde.debugger.Etc;
8 import jde.debugger.JDEException;
9
10
11 /**
12  * 'suspend' command.
13  * <p>
14  *
15  * <b>Syntax:</b>
16  * <pre>
17  * suspend [threadID]*
18  *
19  * </pre>
20  *
21  * <b>Comments:</b>
22  * <ul>
23  * <li> threadIDs can be retrieved using the get_threads command
24  * <li> if the list is omitted, the entire VM is suspended
25  * <li> threadIDs can refer to either threads or threadgroups.
26  * </ul>
27  *
28  * @author Paul Kinnucan
29  * @version $Revision: 1.2 $
30  *
31  * Copyright (c) 2000, 2001, 2003    Paul Kinnucan
32  *
33  */
34 public class Suspend extends DebugProcessCommand {
35   
36   /**
37    *
38    * @exception jde.debugger.JDEException <description>
39    */
40   public void doCommand() throws JDEException {
41     // see if there are arguments (should be the thread id). if so, we
42     // suspend the thread ids passed. else, suspend the whole vm.
43     if (m_args.size() > 0) {
44       Iterator it = m_args.iterator();
45       while (it.hasNext()) {
46                 
47         Long uniqueID = Etc.safeGetLong(it.next(), "thread(group)");
48                 
49         ObjectReference oRef = (ObjectReference) m_debugger.getStore().get(uniqueID);
50         if (oRef == null) {
51           throw new JDEException("Invalid ThreadID, or the thread/threadgroup is dead");
52         } else if (oRef instanceof ThreadReference) {
53           ((ThreadReference) oRef).suspend();
54         } else if (oRef instanceof ThreadGroupReference) {
55           ((ThreadGroupReference) oRef).suspend();
56         } else {
57           throw new JDEException("The object is not a thread or a threadgroup");
58         }
59       }
60       m_debugger.signalCommandResult(m_cmdID, null, CMD_OK);
61     } else {
62       try {
63         m_debugger.getVM().suspend();
64         m_debugger.signalCommandResult(m_cmdID, null, CMD_OK);
65       } catch (Exception ex) {
66         throw new JDEException("Unable to suspend the application");
67       }
68     }
69   }
70     
71   public Object clone() {return new Suspend();}
72     
73 } // Suspend
74
75 /*
76  * $Log: Suspend.java,v $
77  * Revision 1.2  2003/01/15 05:56:26  paulk
78  * Add Petter Mahlen's changes.
79  *
80  * Revision 1.1  2001/03/24 13:35:25  paulk
81  * Initial revision.
82  *
83  *
84  */
85
86 // End of Suspend.java