Project Wonder 5.0

er.extensions.foundation
Class ERXRuntimeUtilities

java.lang.Object
  extended by er.extensions.foundation.ERXRuntimeUtilities

public class ERXRuntimeUtilities
extends java.lang.Object

Collection of utilities dealing with threads and processes.

Author:
ak, david

Nested Class Summary
static class ERXRuntimeUtilities.Result
           
static class ERXRuntimeUtilities.StreamReader
           
static class ERXRuntimeUtilities.TimeoutException
           
static class ERXRuntimeUtilities.TimeoutTimerTask
           
 
Field Summary
static org.apache.log4j.Logger log
          logging support
 
Constructor Summary
ERXRuntimeUtilities()
           
 
Method Summary
static void addThreadInterrupt(java.lang.Thread thread, java.lang.String message)
          Call this to get the thread in question interrupted on the next call to checkThreadInterrupt().
static void checkThreadInterrupt()
          When you have an inner loop and you want to be able to bail out on a stop request, call this method and you will get interrupted when another thread wants you to.
static java.lang.String clearThreadInterrupt(java.lang.Thread thread)
          Clear the interrupt flag for the thread.
static com.webobjects.foundation.NSBundle createBundleIfNeeded(java.lang.String name)
          Hack to create a bundle after the app is loaded.
static ERXRuntimeUtilities.Result execute(java.lang.String[] command, java.lang.String[] envp, java.io.File dir, long timeout)
          Excecutes the specified command line commands.
static ERXRuntimeUtilities.Result[] executeCommandLineCommandsWithEnvVarsInWorkingDir(java.lang.String[][] commands, java.lang.String[] envp, java.io.File dir)
          Excecutes the specified command line commands.
static ERXRuntimeUtilities.Result executeCommandLineCommandWithArgumentsWithEnvVarsInWorkingDir(java.lang.String[] command, java.lang.String[] envp, java.io.File dir)
          Excecutes the specified command line commands.
static void freeProcessResources(java.lang.Process p)
          Frees all of a resources associated with a given process and then destroys it.
static com.webobjects.foundation.NSMutableDictionary<java.lang.String,java.lang.Object> informationForBundles()
           
static com.webobjects.foundation.NSMutableDictionary<java.lang.String,java.lang.Object> informationForContext(com.webobjects.appserver.WOContext context)
           
static com.webobjects.foundation.NSMutableDictionary<java.lang.String,java.lang.Object> informationForException(java.lang.Exception e)
          Returns a dictionary with useful stuff.
static com.webobjects.foundation.NSBundle loadBundleIfNeeded(java.io.File bundleFile)
          Load an application, framework or jar bundle if not already loaded.
static java.lang.Throwable originalThrowable(java.lang.Throwable t)
          Retrieves the actual cause of an error by unwrapping them as far as possible, i.e.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public static final org.apache.log4j.Logger log
logging support

Constructor Detail

ERXRuntimeUtilities

public ERXRuntimeUtilities()
Method Detail

createBundleIfNeeded

public static com.webobjects.foundation.NSBundle createBundleIfNeeded(java.lang.String name)
Hack to create a bundle after the app is loaded. Useful for the insistence of EOF on JavaXXXAdaptor bundles.

Parameters:
name -
Returns:
a new bundle under the system temp directory

loadBundleIfNeeded

public static com.webobjects.foundation.NSBundle loadBundleIfNeeded(java.io.File bundleFile)
Load an application, framework or jar bundle if not already loaded.

Parameters:
bundleFile - - the directory or archive (e.g., jar, war) of the bundle to load
Returns:
the bundle found at the given uri.
Throws:
com.webobjects.foundation.NSForwardException - if bundle loading fails

informationForException

public static com.webobjects.foundation.NSMutableDictionary<java.lang.String,java.lang.Object> informationForException(java.lang.Exception e)
Returns a dictionary with useful stuff.

Parameters:
e -

informationForBundles

public static com.webobjects.foundation.NSMutableDictionary<java.lang.String,java.lang.Object> informationForBundles()

informationForContext

public static com.webobjects.foundation.NSMutableDictionary<java.lang.String,java.lang.Object> informationForContext(com.webobjects.appserver.WOContext context)

originalThrowable

public static java.lang.Throwable originalThrowable(java.lang.Throwable t)
Retrieves the actual cause of an error by unwrapping them as far as possible, i.e. NSForwardException.originalThrowable(), InvocationTargetException.getTargetException() or Exception.getCause() are regarded as actual causes.


executeCommandLineCommandWithArgumentsWithEnvVarsInWorkingDir

public static final ERXRuntimeUtilities.Result executeCommandLineCommandWithArgumentsWithEnvVarsInWorkingDir(java.lang.String[] command,
                                                                                                             java.lang.String[] envp,
                                                                                                             java.io.File dir)
                                                                                                      throws java.io.IOException
Excecutes the specified command line commands. If envp is not null the environment variables are set before executing the command.

Parameters:
command - the commands to execute like "ls -la" or "cp /tmp/file1 /tmp/file2" or "open /Applications/*.app" new String[]{"ls", "-la"} new String[]{"cp", "/tmp/file1", "/tmp/file2"} new String[]{"open", "/Applications/*.app"}
envp - a String array which represents the environment variables like String[] envp = new String[]{"PATH=/usr/bin:/bin", "CVS_RSH=ssh"}, can be null
dir - a File object representing the working directory, can be null
Returns:
the results from the processes that were executed
Throws:
java.io.IOException - if something went wrong

executeCommandLineCommandsWithEnvVarsInWorkingDir

public static final ERXRuntimeUtilities.Result[] executeCommandLineCommandsWithEnvVarsInWorkingDir(java.lang.String[][] commands,
                                                                                                   java.lang.String[] envp,
                                                                                                   java.io.File dir)
                                                                                            throws java.io.IOException
Excecutes the specified command line commands. If envp is not null the environment variables are set before executing the command.

Parameters:
commands - the commands to execute, this is an String array with two dimensions the following commands
"ls -la" or "cp /tmp/file1 /tmp/file2" or "open /Applications/*.app"
would be as String arrays
     new String[] { 
        new String[] { "ls", "-la" },
        new String[] { "cp", "/tmp/file1", "/tmp/file2" },
        new String[] { "open", "/Applications/*.app" } 
     }
 
envp - a String array which represents the environment variables like String[] envp = new String[]{"PATH=/usr/bin:/bin", "CVS_RSH=ssh"}, can be null
dir - a File object representing the working directory, can be null
Returns:
the results from the processes that were executed
Throws:
java.io.IOException - if something went wrong

execute

public static final ERXRuntimeUtilities.Result execute(java.lang.String[] command,
                                                       java.lang.String[] envp,
                                                       java.io.File dir,
                                                       long timeout)
                                                throws java.io.IOException,
                                                       ERXRuntimeUtilities.TimeoutException
Excecutes the specified command line commands. If envp is not null the environment variables are set before executing the command. This method supports timeout's. This is quite important because its -always- possible that a UNIX or WINDOWS process does not return, even with simple shell scripts. This is due to whatever bugs and hence every invocation of Process.waitFor() should be observed and stopped if a certain amount of time is over.

Parameters:
command - the commands to execute, this is an String array with two dimensions the following commands
"ls -la" or "cp /tmp/file1 /tmp/file2" or "open /Applications/*.app"
would be as String arrays
 new String[] { new String[] { "ls", "-la" },
      new String[] { "cp", "/tmp/file1", "/tmp/file2" },
      new String[] { "open", "/Applications/*.app" } }
 
envp - a String array which represents the environment variables like String[] envp = new String[]{"PATH=/usr/bin:/bin", "CVS_RSH=ssh"}, can be null
dir - a File object representing the working directory, can be null
timeout - a long which can be either 0 indicating this method call waits until the process exits or any long number larger than 0 which means if the process does not exit after timeout milliseconds then this method throws an ERXTimeoutException
Returns:
the results from the processes that were executed
Throws:
java.io.IOException - if something went wrong
ERXRuntimeUtilities.TimeoutException

freeProcessResources

public static void freeProcessResources(java.lang.Process p)
Frees all of a resources associated with a given process and then destroys it.

Parameters:
p - process to destroy

checkThreadInterrupt

public static void checkThreadInterrupt()
When you have an inner loop and you want to be able to bail out on a stop request, call this method and you will get interrupted when another thread wants you to.


addThreadInterrupt

public static void addThreadInterrupt(java.lang.Thread thread,
                                      java.lang.String message)
Call this to get the thread in question interrupted on the next call to checkThreadInterrupt().

Parameters:
thread -
message -

clearThreadInterrupt

public static java.lang.String clearThreadInterrupt(java.lang.Thread thread)
Clear the interrupt flag for the thread.

Parameters:
thread -

Last updated: Tue, Feb 21, 2017 • 05:45 PM CET

Copyright © 2002 – 2007 Project Wonder.