org.objectweb.dsrg.sofa.deployment.launcher
Class Launcher

java.lang.Object
  extended by org.objectweb.dsrg.sofa.deployment.launcher.Launcher
All Implemented Interfaces:
LauncherMBean

public class Launcher
extends java.lang.Object
implements LauncherMBean

Launcher is used to launch separate programs on local machine.

Launcher is a small program which exposes its interface to remote management (using JMX; see LauncherMBean). It enables the user to start applications on local machine remotely.

You can set it to launch one default program and then this program is launched every time the launch() method is invoked, or you can use launch(...) methods with parameters to launch a different program on each call.

There is a couple of ways how to specify the default program to launch:

  1. through command line arguments. For help on command line syntax, run the program with the -h option;
  2. get the settings from the configuration server. See setDefaultsFromServer(int, int, int, boolean);
  3. get the settings from a Configuration instance. See setDefaultsFromConfiguration(Configuration, boolean);
  4. through the setDefault???() methods.


Field Summary
protected  Configuration configuration
           
 
Fields inherited from interface org.objectweb.dsrg.sofa.deployment.launcher.LauncherMBean
OUTPUT_LIMIT
 
Constructor Summary
Launcher()
          Creates a launcher instance.
Launcher(int zeroconfPort)
           
 
Method Summary
 java.lang.String[] getAllDeploymentDocks()
          Returns the list of deployment docks running on the Launcher.
 java.lang.String getConfiguration()
          Returns the configuration received from the server.
 void killProcess(int id)
          Kills the launched process with ID id.
 int launch()
          Launches the default command and returns its id.
 int launch(java.lang.String command)
          Launches the given command.
 int launch(java.lang.String[] cmdarray)
          Launches the given command with parameters.
 int launch(java.lang.String[] cmdarray, java.lang.String dir)
          Launches the given command with parameters.
 int launchClass(java.lang.String classname)
          Launches the given java class in a separate JVM.
 int launchClass(java.lang.String[] cmdarray)
          Launches the given java class with parameters in a separate JVM.
 int launchClass(java.lang.String[] cmdarray, java.lang.String dir)
          Launches the given java class with parameters in a separate JVM.
 int launchClass(java.lang.String[] cmdarray, java.lang.String jvmpath, java.lang.String[] jvmargs)
          Launches the given java class with parameters in a given JVM with specified arguments.
 int launchClass(java.lang.String[] cmdarray, java.lang.String dir, java.lang.String jvmpath, java.lang.String[] jvmargs)
          Launches the given java class with parameters in a given JVM with specified arguments.
 void launchConfiguredSofaClass(java.lang.String className)
          Launches a class in separate JVM with sofa configuration set as java properties.
 void launchConfiguredSofaClass(java.lang.String className, java.lang.String[] parameters)
          Launches a class in separate JVM with sofa configuration set as java properties.
 void launchDeploymentDock(java.lang.String dockName)
          Launches a sofa deployment dock in a separate jvm with configuration downloaded from the zeroconf server.
 void launchSofaApp(java.lang.String className, java.lang.String[] parameters)
          Launches a sofa application (e.g.
 void launchSofaClass(java.lang.String className, java.lang.String[] parameters)
           
 java.lang.String[] listProcesses()
          Returns an array of all launched processes in format ID: command arg1 arg2 ...
static void main(java.lang.String[] args)
          Used to run launcher as a standalone program.
 java.lang.String readError(int id)
          Returns the next portion of standard error of the process with ID id.
 java.lang.String readOutput(int id)
          Returns the next portion of standard output of the process with ID id.
 void setDefaultDir(java.lang.String dir)
          Sets the default working directory of new process to dir.
 void setDefaultJvm(java.lang.String jvmpath)
          Sets the default JVM path (path to java executable) to jvmpath.
 void setDefaultJvmArgs(java.lang.String[] jvmargs)
          Sets the default JVM arguments to jvmargs.
 void setDefaultsFromConfiguration(Configuration cfg, boolean erase)
           
 boolean setDefaultsFromServer()
           
 boolean setDefaultsFromServer(int port, int timeout, int tries, boolean erase)
           
 void shutSofaApp(java.lang.String appID)
          Shuts down a launched sofa application with the given appID.
 void shutSofaAppNoConf(java.lang.String appID)
           
 void startJMX(int rmiPort, java.lang.String name)
          Starts and registers the JMX interface of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

configuration

protected Configuration configuration
Constructor Detail

Launcher

public Launcher()
Creates a launcher instance.


Launcher

public Launcher(int zeroconfPort)
Method Detail

setDefaultDir

public void setDefaultDir(java.lang.String dir)
Description copied from interface: LauncherMBean
Sets the default working directory of new process to dir.

Specified by:
setDefaultDir in interface LauncherMBean
Parameters:
dir - working directory for newly lauched processes, or null if the working directory should be inherited from the current process.

setDefaultJvm

public void setDefaultJvm(java.lang.String jvmpath)
Description copied from interface: LauncherMBean
Sets the default JVM path (path to java executable) to jvmpath.

Specified by:
setDefaultJvm in interface LauncherMBean
Parameters:
jvmpath - path to JVM which should be used to launch Java classes, or null if the JVM path of this process should be used.

setDefaultJvmArgs

public void setDefaultJvmArgs(java.lang.String[] jvmargs)
Description copied from interface: LauncherMBean
Sets the default JVM arguments to jvmargs.

Specified by:
setDefaultJvmArgs in interface LauncherMBean
Parameters:
jvmargs - array of virtual machine arguments to be used when starting Java classes, or null if no JVM arguments should be used.

setDefaultsFromServer

public boolean setDefaultsFromServer()
                              throws java.net.SocketException,
                                     java.io.IOException
Throws:
java.net.SocketException
java.io.IOException

setDefaultsFromServer

public boolean setDefaultsFromServer(int port,
                                     int timeout,
                                     int tries,
                                     boolean erase)
                              throws java.net.SocketException,
                                     java.io.IOException
Throws:
java.net.SocketException
java.io.IOException

setDefaultsFromConfiguration

public void setDefaultsFromConfiguration(Configuration cfg,
                                         boolean erase)

launch

public int launch()
           throws java.io.IOException
Launches the default command and returns its id.

Throws:
java.io.IOException

launch

public int launch(java.lang.String command)
           throws java.io.IOException
Launches the given command.

Parameters:
command - The command to be launched.
Returns:
The id of the launched process.
Throws:
java.io.IOException

launch

public int launch(java.lang.String[] cmdarray)
           throws java.io.IOException
Launches the given command with parameters.

Parameters:
cmdarray - The command and its parameters.
Returns:
The id of the launched process.
Throws:
java.io.IOException

launch

public int launch(java.lang.String[] cmdarray,
                  java.lang.String dir)
           throws java.io.IOException
Launches the given command with parameters.

Parameters:
cmdarray - The command and its parameters.
dir - The working directory of the launched process.
Returns:
The id of the launched process.
Throws:
java.io.IOException

launchClass

public int launchClass(java.lang.String classname)
                throws java.io.IOException
Launches the given java class in a separate JVM.

Parameters:
classname - The class to be launched.
Returns:
Id of the launched process.
Throws:
java.io.IOException

launchClass

public int launchClass(java.lang.String[] cmdarray)
                throws java.io.IOException
Launches the given java class with parameters in a separate JVM.

Parameters:
cmdarray - The class and its parameters to be launched.
Returns:
Id of the launched process.
Throws:
java.io.IOException

launchClass

public int launchClass(java.lang.String[] cmdarray,
                       java.lang.String dir)
                throws java.io.IOException
Launches the given java class with parameters in a separate JVM.

Parameters:
cmdarray - The class and its parameters to be launched.
dir - The workdir in which the process is to be launched.
Returns:
Id of the launched process.
Throws:
java.io.IOException

launchClass

public int launchClass(java.lang.String[] cmdarray,
                       java.lang.String jvmpath,
                       java.lang.String[] jvmargs)
                throws java.io.IOException
Launches the given java class with parameters in a given JVM with specified arguments.

Parameters:
cmdarray - The class and its parameters to be launched.
jvmpath - Path to the JVM executable.
jvmargs - Arguments of the launched JVM.
Returns:
Id of the launched process.
Throws:
java.io.IOException

launchClass

public int launchClass(java.lang.String[] cmdarray,
                       java.lang.String dir,
                       java.lang.String jvmpath,
                       java.lang.String[] jvmargs)
                throws java.io.IOException
Launches the given java class with parameters in a given JVM with specified arguments.

Parameters:
cmdarray - The class and its parameters to be launched.
dir - The workdir in which the process is to be launched.
jvmpath - Path to the JVM executable.
jvmargs - Arguments of the launched JVM.
Returns:
Id of the launched process.
Throws:
java.io.IOException

listProcesses

public java.lang.String[] listProcesses()
Description copied from interface: LauncherMBean
Returns an array of all launched processes in format ID: command arg1 arg2 ....

Specified by:
listProcesses in interface LauncherMBean

readOutput

public java.lang.String readOutput(int id)
                            throws java.io.IOException
Description copied from interface: LauncherMBean
Returns the next portion of standard output of the process with ID id. The returned string will be at most LauncherMBean.OUTPUT_LIMIT characters long. If no output is available right now, returns an empty string.

Specified by:
readOutput in interface LauncherMBean
Throws:
java.io.IOException

readError

public java.lang.String readError(int id)
                           throws java.io.IOException
Description copied from interface: LauncherMBean
Returns the next portion of standard error of the process with ID id. The returned string will be at most LauncherMBean.OUTPUT_LIMIT characters long. If no error output is available right now, returns an empty string.

Specified by:
readError in interface LauncherMBean
Throws:
java.io.IOException

killProcess

public void killProcess(int id)
Description copied from interface: LauncherMBean
Kills the launched process with ID id. After the kill, id becomes invalid.

Specified by:
killProcess in interface LauncherMBean

startJMX

public void startJMX(int rmiPort,
                     java.lang.String name)
              throws java.io.IOException,
                     javax.management.JMException
Starts and registers the JMX interface of this object. Also registers the Launcher at the Zeroconf server.

Parameters:
rmiPort - The port of the RMI registry.
name - The name of the object.
Throws:
java.io.IOException
javax.management.JMException

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException,
                        javax.management.JMException
Used to run launcher as a standalone program. To get help on command line syntax, run it wit the -h option.

Throws:
java.io.IOException
javax.management.JMException

launchConfiguredSofaClass

public void launchConfiguredSofaClass(java.lang.String className,
                                      java.lang.String[] parameters)
                               throws java.io.IOException
Description copied from interface: LauncherMBean
Launches a class in separate JVM with sofa configuration set as java properties.

Specified by:
launchConfiguredSofaClass in interface LauncherMBean
Parameters:
className - Name of the class to be launched.
parameters - The parameters to be passed to the class's main function.
Throws:
java.io.IOException

launchSofaClass

public void launchSofaClass(java.lang.String className,
                            java.lang.String[] parameters)
                     throws java.io.IOException
Throws:
java.io.IOException

launchConfiguredSofaClass

public void launchConfiguredSofaClass(java.lang.String className)
                               throws java.io.IOException
Description copied from interface: LauncherMBean
Launches a class in separate JVM with sofa configuration set as java properties.

Specified by:
launchConfiguredSofaClass in interface LauncherMBean
Parameters:
className - Name of the class to be launched.
Throws:
java.io.IOException

launchDeploymentDock

public void launchDeploymentDock(java.lang.String dockName)
                          throws java.io.IOException
Description copied from interface: LauncherMBean
Launches a sofa deployment dock in a separate jvm with configuration downloaded from the zeroconf server.

Specified by:
launchDeploymentDock in interface LauncherMBean
Parameters:
dockName - The name of the deployment dock.
Throws:
java.io.IOException

launchSofaApp

public void launchSofaApp(java.lang.String className,
                          java.lang.String[] parameters)
                   throws java.io.IOException
Description copied from interface: LauncherMBean
Launches a sofa application (e.g. LogDemo) in a separate jvm with configuration downloaded from the zeroconf server.

Specified by:
launchSofaApp in interface LauncherMBean
Parameters:
className - Full name of the deployment plan to be launched (e.g. org.objectweb.dsrg.sofa.examples.logdemo.deplplan.Local).
parameters - Parameters to pass - e.g. version of the deployment plan.
Throws:
java.io.IOException

shutSofaApp

public void shutSofaApp(java.lang.String appID)
                 throws java.io.IOException
Description copied from interface: LauncherMBean
Shuts down a launched sofa application with the given appID.

Specified by:
shutSofaApp in interface LauncherMBean
Parameters:
appID - Id of the running sofa application (usually outputed when
Throws:
java.io.IOException

shutSofaAppNoConf

public void shutSofaAppNoConf(java.lang.String appID)
                       throws java.io.IOException
Throws:
java.io.IOException

getConfiguration

public java.lang.String getConfiguration()
                                  throws java.net.SocketException,
                                         java.io.IOException
Description copied from interface: LauncherMBean
Returns the configuration received from the server.

Specified by:
getConfiguration in interface LauncherMBean
Throws:
java.net.SocketException
java.io.IOException

getAllDeploymentDocks

public java.lang.String[] getAllDeploymentDocks()
Description copied from interface: LauncherMBean
Returns the list of deployment docks running on the Launcher.

Specified by:
getAllDeploymentDocks in interface LauncherMBean