/Users/lyon/j4p/src/javagroup/process/ProcessManager.java

1    /* 
2     * Copyright (C) 1997 Luke Gorrie 
3     * 
4     * This library is free software; you can redistribute it and/or 
5     * modify it under the terms of the GNU Library General Public 
6     * License as published by the Free Software Foundation; either 
7     * version 2 of the License, or (at your option) any later version. 
8     * 
9     * This library is distributed in the hope that it will be useful, 
10    * but WITHOUT ANY WARRANTY; without even the implied warranty of 
11    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12    * Library General Public License for more details. 
13    * 
14    * You should have received a copy of the GNU Library General Public 
15    * License along with this library; if not, write to the 
16    * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
17    * MA 02139, USA. 
18    */ 
19    
20   package javagroup.process; 
21    
22   import javagroup.util.StandardIO; 
23    
24   import java.net.URL; 
25   import java.util.Enumeration; 
26    
27   public interface ProcessManager { 
28    
29       /** 
30        * Create a process with given args, and additional classpath(s). 
31        * 
32        * @param className The name of the target class. 
33        */ 
34       public JProcess createProcess(String className) 
35               throws ProcessCreationException; 
36    
37       /** 
38        * Create a process with given args, and additional classpath(s). 
39        * 
40        * @param className The name of the target class. 
41        * @param args      The arguments to pass to the main(String[]) 
42        *                  method. 
43        */ 
44       public JProcess createProcess(String className, String[] args) 
45               throws ProcessCreationException; 
46    
47       /** 
48        * Create a process with given args, and additional classpath(s). 
49        * 
50        * @param className The name of the target class. 
51        * @param args      The arguments to pass to the main(String[]) 
52        *                  method. 
53        * @param classPath An array of URLs to search for classes in. 
54        */ 
55       public JProcess createProcess(String className, String[] args, 
56                                     URL[] classPath) 
57               throws ProcessCreationException; 
58    
59       /** 
60        * Creates a process from the information in a given String of the 
61        * format: "<classname> <arg>*". 
62        * 
63        * @param line The string to decode process info from. 
64        * @return The created JProcess. 
65        */ 
66       public JProcess createProcessFromString(String line) 
67               throws ProcessCreationException; 
68    
69       /** 
70        * Creates a process from the information in a given String of the 
71        * format: "<classname> <arg>*". 
72        * 
73        * @param line    The string to decode process info from. 
74        * @param classPath Classpaths to search in addition to defaults. 
75        * @return The created JProcess. 
76        */ 
77       public JProcess createProcessFromString(String line, URL[] classPath) 
78               throws ProcessCreationException; 
79    
80    
81       /** 
82        * Get the process that a threadgroup belongs to. 
83        * 
84        * @param group The ThreadGroup to attribute a process to. 
85        * @return The process owning the group, or null if none found. 
86        */ 
87       public JProcess getProcessFor(ThreadGroup group); 
88    
89       /** 
90        * Get the process that a classloader belongs to. 
91        * 
92        * @return The process owning the group, or null if none found. 
93        */ 
94       public JProcess getProcessFor(ClassLoader loader); 
95    
96       /** 
97        * Return the current process. 
98        * 
99        * @return The process making the invocation, or null if none can be 
100       *         determined. 
101       */ 
102      public JProcess getCurrentProcess(); 
103   
104      /** 
105       * Get a process by process-id. 
106       * 
107       * @param pid The id-number of the process. 
108       * @return The process, or null if no match. 
109       */ 
110      public JProcess getProcess(long pid); 
111   
112   
113      /** 
114       * Get an enumeration of all processes. 
115       * 
116       * @return Enumeration of all processes. 
117       */ 
118      public Enumeration getProcesses(); 
119   
120      /** 
121       * Kill a process by pid. 
122       * 
123       * @param pid The process-id to kill. 
124       */ 
125      public void kill(long pid); 
126   
127      public void addProcessEventListener(ProcessEventListener listener); 
128   
129      public void removeProcessEventListener(ProcessEventListener listener); 
130   
131      /** 
132       * Perform garbage collection.  Usually invoked by the garbage 
133       * collector. 
134       */ 
135      public void doGarbageCollect(); 
136   
137      /** 
138       * Set the streams to be used when the Process asks for standard io. 
139       * 
140       * @param process The process to set for. 
141       */ 
142      public StandardIO getStandardIOForProcess(JProcess process); 
143   
144      /** 
145       * Get the streams a process uses for standard io 
146       * 
147       * @param process The process to get streams for. 
148       * @param stdio   The set of IO streams to use as standard io. 
149       */ 
150      public void setStandardIOForProcess(JProcess process, 
151                                          StandardIO stdio); 
152   
153  } 
154