edu.rice.cs.plt.concurrent
Class JVMBuilder

java.lang.Object
  extended by edu.rice.cs.plt.concurrent.JVMBuilder
All Implemented Interfaces:
Lambda2<String,Iterable<? extends String>,Process>

public class JVMBuilder
extends Object
implements Lambda2<String,Iterable<? extends String>,Process>

Creates Java subprocesses via an interface similar to that of ProcessBuilder. Each JVMBuilder object is immutable, but can be used as a template for creating other JVMBuilder with altered parameters. (Unlike ProcessBuilder, there is no implicit mutation via mutable maps returned by getters.) The following parameters are supported:


Field Summary
static JVMBuilder DEFAULT
           
 
Constructor Summary
JVMBuilder(File dir)
           
JVMBuilder(Iterable<? extends File> classPath)
           
JVMBuilder(String javaCommand)
           
JVMBuilder(String javaCommand, Iterable<? extends String> jvmArgs)
           
JVMBuilder(String javaCommand, Iterable<? extends String> jvmArgs, Iterable<? extends File> classPath, File dir, Map<? extends String,? extends String> properties, Map<? extends String,? extends String> environment)
           
 
Method Summary
 JVMBuilder AddDefaultEnvironmentVar(String key, String value)
          If the current environment mappings do not contain key, produce a new JVMBuilder including the mapping, in addition to those currently set.
 JVMBuilder addDefaultEnvironmentVars(Map<? extends String,? extends String> env)
          Produce a JVMBuilder where, for each key in the given Map, if the environment variable is undefined in this JVMBuilder, it will map to the given value.
 JVMBuilder addDefaultProperties(Map<? extends String,? extends String> ps)
          Produce a JVMBuilder where, for each key in the given Map, if the property is undefined in this JVMBuilder, it will map to the given value.
 JVMBuilder addDefaultProperties(Properties ps)
          Produce a JVMBuilder where, for each key in the given Properties object (including those designated in the Properties object as defaults), if the property is undefined in this JVMBuilder, it will map to the given value.
 JVMBuilder addDefaultProperty(String key, String value)
          If the current JVM properties do not contain key, produce a new JVMBuilder including the mapping, in addition to those currently set.
 JVMBuilder addEnvironmentVar(String key, String value)
          Produce a JVMBuilder including the given environment mapping, in addition to those currently set.
 JVMBuilder addProperty(String key, String value)
          Produce a JVMBuilder including the given JVM property mapping, in addition to those currently set.
 SizedIterable<File> classPath()
           
 JVMBuilder classPath(File... classPath)
          Due to overloading rules, this cannot be invoked via varargs with 0 arguments (the getter matches instead).
 JVMBuilder classPath(Iterable<? extends File> classPath)
           
 JVMBuilder classPath(String classPath)
           
 File directory()
           
 JVMBuilder directory(File dir)
           
 JVMBuilder directory(String dir)
           
 Map<String,String> environment()
          Get an immutable view of the environment, or null if the current process's environment is used.
 JVMBuilder environment(Map<? extends String,? extends String> env)
          Produce a JVMBuilder setting the environment to the given mapping (may be null, meaning the current process's environment will be duplicated.
 Map<String,String> environmentCopy()
          Get a mutable copy of the environment.
 String javaCommand()
           
 JVMBuilder javaCommand(File javaCommand)
           
 JVMBuilder javaCommand(String javaCommand)
           
 SizedIterable<String> jvmArguments()
           
 JVMBuilder jvmArguments(Iterable<? extends String> jvmArgs)
           
 JVMBuilder jvmArguments(String... jvmArgs)
          Due to overloading rules, this cannot be invoked via varargs with 0 arguments (the getter matches instead).
 Map<String,String> properties()
          Get an immutable view of the properties.
 JVMBuilder properties(Map<? extends String,? extends String> ps)
          Produce a JVMBuilder setting the JVM properties to the given mapping.
 JVMBuilder properties(Properties ps)
          Produce a JVMBuilder setting the JVM properties to the given mapping (including keys that appear only as defaults in the Properties object).
 Map<String,String> propertiesCopy()
          Return a mutable copy of the properties.
 Process start(String mainClass, Iterable<? extends String> mainParams)
          Start a JVM process via Runtime.exec(String[], String[], File).
 Process start(String mainClass, String... mainParams)
          Start a JVM process via Runtime.exec(String[], String[], File).
 Process value(String mainClass, Iterable<? extends String> mainParams)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT

public static final JVMBuilder DEFAULT
Constructor Detail

JVMBuilder

public JVMBuilder(String javaCommand)

JVMBuilder

public JVMBuilder(String javaCommand,
                  Iterable<? extends String> jvmArgs)

JVMBuilder

public JVMBuilder(Iterable<? extends File> classPath)

JVMBuilder

public JVMBuilder(File dir)

JVMBuilder

public JVMBuilder(String javaCommand,
                  Iterable<? extends String> jvmArgs,
                  Iterable<? extends File> classPath,
                  File dir,
                  Map<? extends String,? extends String> properties,
                  Map<? extends String,? extends String> environment)
Method Detail

javaCommand

public String javaCommand()

javaCommand

public JVMBuilder javaCommand(String javaCommand)

javaCommand

public JVMBuilder javaCommand(File javaCommand)

jvmArguments

public SizedIterable<String> jvmArguments()

jvmArguments

public JVMBuilder jvmArguments(Iterable<? extends String> jvmArgs)

jvmArguments

public JVMBuilder jvmArguments(String... jvmArgs)
Due to overloading rules, this cannot be invoked via varargs with 0 arguments (the getter matches instead).


classPath

public SizedIterable<File> classPath()

classPath

public JVMBuilder classPath(Iterable<? extends File> classPath)

classPath

public JVMBuilder classPath(String classPath)

classPath

public JVMBuilder classPath(File... classPath)
Due to overloading rules, this cannot be invoked via varargs with 0 arguments (the getter matches instead).


directory

public File directory()

directory

public JVMBuilder directory(File dir)

directory

public JVMBuilder directory(String dir)

properties

public Map<String,String> properties()
Get an immutable view of the properties.


propertiesCopy

public Map<String,String> propertiesCopy()
Return a mutable copy of the properties. Changes to the result do not affect this JVMBuilder, but a modified map can be used to create another JVMBuilder.


properties

public JVMBuilder properties(Properties ps)
Produce a JVMBuilder setting the JVM properties to the given mapping (including keys that appear only as defaults in the Properties object).


properties

public JVMBuilder properties(Map<? extends String,? extends String> ps)
Produce a JVMBuilder setting the JVM properties to the given mapping.


addProperty

public JVMBuilder addProperty(String key,
                              String value)
Produce a JVMBuilder including the given JVM property mapping, in addition to those currently set.


addDefaultProperties

public JVMBuilder addDefaultProperties(Properties ps)
Produce a JVMBuilder where, for each key in the given Properties object (including those designated in the Properties object as defaults), if the property is undefined in this JVMBuilder, it will map to the given value. All current property mappings remain identical in the result.


addDefaultProperties

public JVMBuilder addDefaultProperties(Map<? extends String,? extends String> ps)
Produce a JVMBuilder where, for each key in the given Map, if the property is undefined in this JVMBuilder, it will map to the given value. All current property mappings remain identical in the result.


addDefaultProperty

public JVMBuilder addDefaultProperty(String key,
                                     String value)
If the current JVM properties do not contain key, produce a new JVMBuilder including the mapping, in addition to those currently set. Otherwise, return this.


environment

public Map<String,String> environment()
Get an immutable view of the environment, or null if the current process's environment is used.


environmentCopy

public Map<String,String> environmentCopy()
Get a mutable copy of the environment. If the environment is null (meaning the the current process's environment should be used), the result is a copy of System.getenv(). Changes to the result do not affect this JVMBuilder, but a modified environment map can be used to create another JVMBuilder.


environment

public JVMBuilder environment(Map<? extends String,? extends String> env)
Produce a JVMBuilder setting the environment to the given mapping (may be null, meaning the current process's environment will be duplicated.


addEnvironmentVar

public JVMBuilder addEnvironmentVar(String key,
                                    String value)
Produce a JVMBuilder including the given environment mapping, in addition to those currently set.


addDefaultEnvironmentVars

public JVMBuilder addDefaultEnvironmentVars(Map<? extends String,? extends String> env)
Produce a JVMBuilder where, for each key in the given Map, if the environment variable is undefined in this JVMBuilder, it will map to the given value. All current environment mappings remain identical in the result.


AddDefaultEnvironmentVar

public JVMBuilder AddDefaultEnvironmentVar(String key,
                                           String value)
If the current environment mappings do not contain key, produce a new JVMBuilder including the mapping, in addition to those currently set. Otherwise, return this.


start

public Process start(String mainClass,
                     String... mainParams)
              throws IOException
Start a JVM process via Runtime.exec(String[], String[], File). Varargs shortcut for start(String, Iterable).

Throws:
IOException

start

public Process start(String mainClass,
                     Iterable<? extends String> mainParams)
              throws IOException
Start a JVM process via Runtime.exec(String[], String[], File). The array of command strings contains, in order: the java command, the JVM args, "-classpath" followed by the class path, each property using "-D<key>=<value>" notation, the name of the given main class, and the main parameters.

Throws:
IOException - Per Runtime.exec(String[], String[], File).
SecurityException - Per Runtime.exec(String[], String[], File).

value

public Process value(String mainClass,
                     Iterable<? extends String> mainParams)
Specified by:
value in interface Lambda2<String,Iterable<? extends String>,Process>