org.javagroup.process
Class StandardJProcess

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

public class StandardJProcess
extends java.lang.Object
implements java.lang.Runnable, JProcess, ResourceDisposalListener

An implementation of the JProcess interface. Should only be used by a ProcessManager.

Version:
$Id: StandardJProcess.java,v 1.3 1998/11/02 22:21:22 luke Exp $

Field Summary
protected  URLClassLoader _classLoader
          Classloader used to load target class
protected  java.util.Vector _lockedResources
          Resources locked by this process.
protected  java.lang.String _name
          Process name
protected  long _pid
          Unique process-id
protected  java.lang.ThreadGroup _processThreadGroup
          Threadgroup for threads in this process
protected  java.util.Vector _resourcesLockedTo
          Resources this process is locked to
protected  int _state
          state of process
 
Constructor Summary
StandardJProcess(java.lang.String className, long pid, java.lang.String[] args, java.lang.ThreadGroup parent, java.net.URL[] classpath)
          Creates a process.
 
Method Summary
 void addClassPath(java.net.URL[] classpath)
           
 void bindToResource(Resource resource)
           
protected  URLClassLoader createClassLoader()
          Factory method for creating a classloader.
protected  java.lang.ThreadGroup createThreadGroup(java.lang.ThreadGroup parent)
          Factory method for creating a process ThreadGroup.
 java.lang.ClassLoader getClassLoader()
          Return the classloader used to load the target class
 java.lang.String getName()
          Get the name of this process.
 long getPid()
          Return the process-id.
 int getState()
           
 java.lang.ThreadGroup getThreadGroup()
          Return the ThreadGroup for threads in this process.
 void kill()
           
 void launch()
          Start the process running.
 void registerAndBindToResource(Resource resource)
          Register and bind to a resource.
 void registerResource(Resource resource)
          Register a resource.
protected  void releaseResource(Resource resource)
           
 void releaseResources()
          Release all resource locks.
 void resourceDisposed(Resource resource)
           
 void run()
          Should not be called directly.
 java.lang.String toString()
           
 void tryGarbageCollect()
          Checks if the process is finished running, and if so kills it off to clean up the process table and allow the ClassLoader etc to be garbage collected.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_pid

protected long _pid
Unique process-id

_name

protected java.lang.String _name
Process name

_classLoader

protected URLClassLoader _classLoader
Classloader used to load target class

_processThreadGroup

protected java.lang.ThreadGroup _processThreadGroup
Threadgroup for threads in this process

_lockedResources

protected java.util.Vector _lockedResources
Resources locked by this process.

_resourcesLockedTo

protected java.util.Vector _resourcesLockedTo
Resources this process is locked to

_state

protected int _state
state of process
Constructor Detail

StandardJProcess

public StandardJProcess(java.lang.String className,
                        long pid,
                        java.lang.String[] args,
                        java.lang.ThreadGroup parent,
                        java.net.URL[] classpath)
                 throws ProcessCreationException
Creates a process. This should invoked by a ProcessManager.
Parameters:
className - The fully-qualified name of the target class.
args - The arguments to pass to the target's main(String[]) method.
pid - The process-id number.
classpath - A list of URLs to check for classes.
Method Detail

launch

public void launch()
Start the process running.
Specified by:
launch in interface JProcess

addClassPath

public void addClassPath(java.net.URL[] classpath)

run

public void run()
Should not be called directly.
Specified by:
run in interface java.lang.Runnable

createClassLoader

protected URLClassLoader createClassLoader()
Factory method for creating a classloader.
Returns:
A URLClassLoader for loading the target class.

createThreadGroup

protected java.lang.ThreadGroup createThreadGroup(java.lang.ThreadGroup parent)
Factory method for creating a process ThreadGroup.
Returns:
A ThreadGroup for threads in the process.

getClassLoader

public java.lang.ClassLoader getClassLoader()
Return the classloader used to load the target class
Specified by:
getClassLoader in interface JProcess
Returns:
The ClassLoader for this process.

getThreadGroup

public java.lang.ThreadGroup getThreadGroup()
Return the ThreadGroup for threads in this process.
Specified by:
getThreadGroup in interface JProcess
Returns:
The ThreadGroup for this process.

registerResource

public void registerResource(Resource resource)
Register a resource.
Specified by:
registerResource in interface JProcess
Parameters:
resource - The resource to be registered/locked.

registerAndBindToResource

public void registerAndBindToResource(Resource resource)
Register and bind to a resource.
Specified by:
registerAndBindToResource in interface JProcess
Parameters:
resource - The resource to lock and bind to.

bindToResource

public void bindToResource(Resource resource)

releaseResources

public void releaseResources()
Release all resource locks.

releaseResource

protected void releaseResource(Resource resource)

resourceDisposed

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

kill

public void kill()
Specified by:
kill in interface JProcess

tryGarbageCollect

public void tryGarbageCollect()
Checks if the process is finished running, and if so kills it off to clean up the process table and allow the ClassLoader etc to be garbage collected.

getPid

public long getPid()
Return the process-id.
Specified by:
getPid in interface JProcess
Returns:
Process-id for this process.

getName

public java.lang.String getName()
Get the name of this process.
Specified by:
getName in interface JProcess
Returns:
A reasonably meaningful name.

getState

public int getState()
Specified by:
getState in interface JProcess

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object