org.javagroup.process
Class StandardProcessManager

java.lang.Object
  |
  +--org.javagroup.process.StandardProcessManager

public class StandardProcessManager
extends java.lang.Object
implements ProcessManager, ResourceDisposalListener

An implementation of the ProcessManager interface. Further documentation to come, please refer to ProcessManager for usage information.

Version:
$Id: StandardProcessManager.java,v 1.3 1998/10/29 07:00:54 luke Exp $

Field Summary
protected  java.net.URL[] _classpath
          default classpath.
protected  ProcessGarbageCollector _garbageCollector
          Garbage collector
protected  java.util.Vector _garbageQueue
          Queue of garbage processes for the gc to remove.
protected  ProcessNamespace _namespace
          Per-process namespace manager
protected  java.util.Hashtable _processes
          Hashtable of all processes.
protected  java.util.Vector _processEventListeners
          Vector of registered ProcessEventListeners
protected  java.lang.ThreadGroup _rootProcessGroup
           
protected  ProcessSecurityManager _securityManager
          SecurityManager
 
Constructor Summary
StandardProcessManager()
          Constructs a ProcessManager with no default classpath.
StandardProcessManager(java.net.URL[] classpath)
          Constructs a ProcessManager with a given default classpath.
 
Method Summary
 void addProcessEventListener(ProcessEventListener listener)
           
 JProcess createProcess(java.lang.String className)
          Create a process.
 JProcess createProcess(java.lang.String className, java.lang.String[] args)
          Create a process with given arguments.
 JProcess createProcess(java.lang.String className, java.lang.String[] args, java.net.URL[] classpath)
          Create a process with given args, and additional classpath(s).
 JProcess createProcessFromString(java.lang.String string)
          Creates a process from the information in a given String of the format: "<classname> <arg>*".
 JProcess createProcessFromString(java.lang.String string, java.net.URL[] classpath)
          Creates a process from the information in a given String of the format: "[-eclasspath url[,url]*] *".
 void doGarbageCollect()
          Perform garbage collection.
protected  void fireProcessCreationEvent(JProcess process)
           
protected  void fireProcessDestructionEvent(JProcess process)
           
 JProcess getCurrentProcess()
          Return the current process.
 Namespace getNamespaceForProcess(JProcess process)
          Get the Namespace object for the given process.
protected  long getNextPid()
          Return the next pid-number and increment the pid counter.
 JProcess getProcess(long pid)
          Get a process by process-id.
 java.util.Enumeration getProcesses()
          Get an enumeration of all processes.
 JProcess getProcessFor(java.lang.ClassLoader loader)
          Get the process whose target class was loaded by a given ClassLoader.
 JProcess getProcessFor(java.lang.ThreadGroup group)
          Get the process that a threadgroup belongs to.
 StandardIO getStandardIOForProcess(JProcess process)
          Get the streams a process uses for standard io
 void kill(long pid)
          Kill a process by pid.
protected  java.net.URL[] mergeWithDefaultClasspath(java.net.URL[] classpath)
           
 void removeProcessEventListener(ProcessEventListener listener)
           
 void resourceDisposed(Resource resource)
          For ResourceDisposalListener interface.
 void setStandardIOForProcess(JProcess process, StandardIO stdio)
          Set the streams to be used when the Process asks for standard io.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_classpath

protected java.net.URL[] _classpath
default classpath.

_processes

protected java.util.Hashtable _processes
Hashtable of all processes.

_securityManager

protected ProcessSecurityManager _securityManager
SecurityManager

_processEventListeners

protected java.util.Vector _processEventListeners
Vector of registered ProcessEventListeners

_garbageCollector

protected ProcessGarbageCollector _garbageCollector
Garbage collector

_namespace

protected ProcessNamespace _namespace
Per-process namespace manager

_garbageQueue

protected java.util.Vector _garbageQueue
Queue of garbage processes for the gc to remove.

_rootProcessGroup

protected java.lang.ThreadGroup _rootProcessGroup
Constructor Detail

StandardProcessManager

public StandardProcessManager()
Constructs a ProcessManager with no default classpath. This should not be invoked directly, instances are obtained via getInstance().

StandardProcessManager

public StandardProcessManager(java.net.URL[] classpath)
Constructs a ProcessManager with a given default classpath. This should not be invoked directly, instances are obtained via getInstance().
Method Detail

getNextPid

protected long getNextPid()
Return the next pid-number and increment the pid counter.
Returns:
A unique process-id.

createProcess

public JProcess createProcess(java.lang.String className)
                       throws ProcessCreationException
Create a process.
Specified by:
createProcess in interface ProcessManager
Parameters:
className - The name of the target class.
Returns:
A process for the target.

createProcess

public JProcess createProcess(java.lang.String className,
                              java.lang.String[] args)
                       throws ProcessCreationException
Create a process with given arguments.
Specified by:
createProcess in interface ProcessManager
Parameters:
className - The name of the target class.
args - The arguments to pass to the main(String[]) method.
Returns:
A process for the target.

createProcess

public JProcess createProcess(java.lang.String className,
                              java.lang.String[] args,
                              java.net.URL[] classpath)
                       throws ProcessCreationException
Create a process with given args, and additional classpath(s).
Specified by:
createProcess in interface ProcessManager
Parameters:
className - The name of the target class.
args - The arguments to pass to the main(String[]) method.
classpath - An array of URLs to search for classes in.

createProcessFromString

public JProcess createProcessFromString(java.lang.String string)
                                 throws ProcessCreationException
Creates a process from the information in a given String of the format: "<classname> <arg>*".
Specified by:
createProcessFromString in interface ProcessManager
Parameters:
string - The string to decode process info from.
Returns:
The created JProcess.

createProcessFromString

public JProcess createProcessFromString(java.lang.String string,
                                        java.net.URL[] classpath)
                                 throws ProcessCreationException
Creates a process from the information in a given String of the format: "[-eclasspath url[,url]*] *".
Specified by:
createProcessFromString in interface ProcessManager
Parameters:
string - The string to decode process info from.
classpath - Classpaths to search in addition to defaults.
Returns:
The created JProcess.

getProcessFor

public JProcess getProcessFor(java.lang.ThreadGroup group)
Get the process that a threadgroup belongs to.
Specified by:
getProcessFor in interface ProcessManager
Parameters:
group - The ThreadGroup to attribute a process to.
Returns:
The process owning the group, or null if none found.

getProcessFor

public JProcess getProcessFor(java.lang.ClassLoader loader)
Get the process whose target class was loaded by a given ClassLoader.
Specified by:
getProcessFor in interface ProcessManager
Parameters:
loader - The classloader to check for.
Returns:
The process owning the loader, or null if none found.

mergeWithDefaultClasspath

protected java.net.URL[] mergeWithDefaultClasspath(java.net.URL[] classpath)

getCurrentProcess

public JProcess getCurrentProcess()
Return the current process.
Specified by:
getCurrentProcess in interface ProcessManager
Returns:
The process making the invocation, or null if none can be determined.

getProcess

public JProcess getProcess(long pid)
Get a process by process-id.
Specified by:
getProcess in interface ProcessManager
Parameters:
pid - The id-number of the process.
Returns:
The process, or null if no match.

getProcesses

public java.util.Enumeration getProcesses()
Get an enumeration of all processes.
Specified by:
getProcesses in interface ProcessManager
Returns:
Enumeration of all processes.

kill

public void kill(long pid)
Kill a process by pid.
Specified by:
kill in interface ProcessManager
Parameters:
pid - The process-id to kill.

addProcessEventListener

public void addProcessEventListener(ProcessEventListener listener)
Specified by:
addProcessEventListener in interface ProcessManager

removeProcessEventListener

public void removeProcessEventListener(ProcessEventListener listener)
Specified by:
removeProcessEventListener in interface ProcessManager

fireProcessDestructionEvent

protected void fireProcessDestructionEvent(JProcess process)

fireProcessCreationEvent

protected void fireProcessCreationEvent(JProcess process)

resourceDisposed

public void resourceDisposed(Resource resource)
For ResourceDisposalListener interface.
Specified by:
resourceDisposed in interface ResourceDisposalListener

doGarbageCollect

public void doGarbageCollect()
Perform garbage collection. Usually invoked by the garbage collector.
Specified by:
doGarbageCollect in interface ProcessManager

getNamespaceForProcess

public Namespace getNamespaceForProcess(JProcess process)
Get the Namespace object for the given process.
Parameters:
process - The process to get Namespace for.
Returns:
The appropriate namespace.

setStandardIOForProcess

public void setStandardIOForProcess(JProcess process,
                                    StandardIO stdio)
Set the streams to be used when the Process asks for standard io.
Specified by:
setStandardIOForProcess in interface ProcessManager
Parameters:
process - The process to set for.
stdio - The set of IO streams to use as standard io.

getStandardIOForProcess

public StandardIO getStandardIOForProcess(JProcess process)
Get the streams a process uses for standard io
Specified by:
getStandardIOForProcess in interface ProcessManager
Parameters:
process - The process to get streams for.
Returns:
The set of streams being used as standard io.