Knopflerfish OSGi 5.2.0

org.knopflerfish.util.framework
Class ExecutableBundleActivator

java.lang.Object
  extended by org.knopflerfish.util.framework.ExecutableBundleActivator
All Implemented Interfaces:
BundleActivator

public class ExecutableBundleActivator
extends java.lang.Object
implements BundleActivator


Field Summary
protected  java.lang.String baseDirName
           
protected  BundleContext bc
           
protected  boolean bProcessExitMeansStopBundle
           
static java.lang.String BUNDLE_EXTRACT_FILES
          Manifest header (named "Bundle-Extract-Files") identifying a set of resources that should be copied to the OS file system before executing the start or stop executable is run.
static java.lang.String BUNDLE_START_EXECUTABLE
          Manifest header (named "Bundle-Start-Executable") identifying a number of hardware environments and the native language code executables that the bundle is carrying for each of these environments.
static java.lang.String BUNDLE_START_EXECUTABLE_ARGS
          Manifest header (named "Bundle-Start-Executable-Args") specifying the (space-separated) process arguments to the executable specified by BUNDLE_START_EXECUTABLE.
static java.lang.String BUNDLE_START_EXECUTABLE_EXIT_MEANS_BUNDLESTOP
          Manifest header (named "Bundle-Start-Executable-Exit-Means-Bundle-Stop"") specifying of the the process exit of the start executable should stop the bundle too.
static java.lang.String BUNDLE_STOP_EXECUTABLE
          Manifest header (named "Bundle-Stop-Executable") identifying a number of hardware environments and the native language code executables that the bundle is carrying for each of these environments.
static java.lang.String BUNDLE_STOP_EXECUTABLE_ARGS
          Manifest header (named "Bundle-Start-Executable-Args") specifying the (space-separated) process arguments to the executable specified by BUNDLE_START_EXECUTABLE.
protected  java.lang.Process runProcess
           
protected  java.io.File startFile
           
protected  java.lang.String startName
           
protected  java.io.File stopFile
           
protected  java.lang.String stopName
           
 
Constructor Summary
ExecutableBundleActivator()
           
 
Method Summary
 void debug(java.lang.String s)
          Method used for debug logging.
 void debug(java.lang.String s, java.lang.Exception e)
          Method used for debug logging.
 java.io.File getBaseDir()
          Get the base directory for extract files to be executed.
 java.lang.String getBaseDirName()
           
protected  void initFiles(java.lang.String startChoices, java.lang.String stopChoices, java.lang.String extractNames)
           
 void initFiles2(java.lang.String startName, java.lang.String stopName, java.lang.String extractNames)
           
 boolean isDebug()
          Flag which controls if logging should be done.
 boolean isProcessExitMeansStopBundle()
          Return true if exit of start process should stop bundle too.
protected  java.lang.Process runFile(java.io.File f, java.lang.String args, boolean bWaitForExit, boolean bStopBundle)
          Start a new process from a file.
 void setBaseDirName(java.lang.String s)
           
 void setProcessExitMeansStopBundle(boolean b)
          Set if exit of start process should stop bundle too.
 void start(BundleContext bc)
          Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start this bundle.
 void stop(BundleContext bc)
          Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop the bundle.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bc

protected BundleContext bc

startName

protected java.lang.String startName

stopName

protected java.lang.String stopName

startFile

protected java.io.File startFile

stopFile

protected java.io.File stopFile

runProcess

protected java.lang.Process runProcess

bProcessExitMeansStopBundle

protected boolean bProcessExitMeansStopBundle

baseDirName

protected java.lang.String baseDirName

BUNDLE_START_EXECUTABLE

public static final java.lang.String BUNDLE_START_EXECUTABLE
Manifest header (named "Bundle-Start-Executable") identifying a number of hardware environments and the native language code executables that the bundle is carrying for each of these environments.

If a matching executable is found, the executable file will be copied to the OS file system and started in the start() method

See Also:
Constant Field Values

BUNDLE_START_EXECUTABLE_ARGS

public static final java.lang.String BUNDLE_START_EXECUTABLE_ARGS
Manifest header (named "Bundle-Start-Executable-Args") specifying the (space-separated) process arguments to the executable specified by BUNDLE_START_EXECUTABLE.

See Also:
Constant Field Values

BUNDLE_STOP_EXECUTABLE_ARGS

public static final java.lang.String BUNDLE_STOP_EXECUTABLE_ARGS
Manifest header (named "Bundle-Start-Executable-Args") specifying the (space-separated) process arguments to the executable specified by BUNDLE_START_EXECUTABLE.

See Also:
Constant Field Values

BUNDLE_STOP_EXECUTABLE

public static final java.lang.String BUNDLE_STOP_EXECUTABLE
Manifest header (named "Bundle-Stop-Executable") identifying a number of hardware environments and the native language code executables that the bundle is carrying for each of these environments.

If a matching executable is found, the executable file will be copied to the OS file system and started in the stop() method.

See Also:
Constant Field Values

BUNDLE_EXTRACT_FILES

public static final java.lang.String BUNDLE_EXTRACT_FILES
Manifest header (named "Bundle-Extract-Files") identifying a set of resources that should be copied to the OS file system before executing the start or stop executable is run.

See Also:
Constant Field Values

BUNDLE_START_EXECUTABLE_EXIT_MEANS_BUNDLESTOP

public static final java.lang.String BUNDLE_START_EXECUTABLE_EXIT_MEANS_BUNDLESTOP
Manifest header (named "Bundle-Start-Executable-Exit-Means-Bundle-Stop"") specifying of the the process exit of the start executable should stop the bundle too. Set to "true" if the bundle should be stopped. Default is "true"

See Also:
Constant Field Values
Constructor Detail

ExecutableBundleActivator

public ExecutableBundleActivator()
Method Detail

start

public void start(BundleContext bc)
           throws BundleException
Description copied from interface: BundleActivator
Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start this bundle. This method can be used to register services or to allocate any resources that this bundle needs.

This method must complete and return to its caller in a timely manner.

Specified by:
start in interface BundleActivator
Parameters:
bc - The execution context of the bundle being started.
Throws:
BundleException

stop

public void stop(BundleContext bc)
          throws BundleException
Description copied from interface: BundleActivator
Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop the bundle. In general, this method should undo the work that the BundleActivator.start method started. There should be no active threads that were started by this bundle when this bundle returns. A stopped bundle must not call any Framework objects.

This method must complete and return to its caller in a timely manner.

Specified by:
stop in interface BundleActivator
Parameters:
bc - The execution context of the bundle being stopped.
Throws:
BundleException

getBaseDirName

public java.lang.String getBaseDirName()

setBaseDirName

public void setBaseDirName(java.lang.String s)

getBaseDir

public java.io.File getBaseDir()
Get the base directory for extract files to be executed.

Override to change. Default is BundleContext.getDataFile(getBaseDirName())


isProcessExitMeansStopBundle

public boolean isProcessExitMeansStopBundle()
Return true if exit of start process should stop bundle too. The initial value of this is set by reading the BUNDLE_START_EXECUTABLE_EXIT_MEANS_BUNDLESTOP manifest header.


setProcessExitMeansStopBundle

public void setProcessExitMeansStopBundle(boolean b)
Set if exit of start process should stop bundle too.


isDebug

public boolean isDebug()
Flag which controls if logging should be done. The default implementation returns true. Override if necessary.


debug

public void debug(java.lang.String s)
Method used for debug logging. Calls debug(s, null)


debug

public void debug(java.lang.String s,
                  java.lang.Exception e)
Method used for debug logging. The default implementation writes to stdout. Override if necessary.

Parameters:
s - message string to log
e - exception to log

runFile

protected java.lang.Process runFile(java.io.File f,
                                    java.lang.String args,
                                    boolean bWaitForExit,
                                    boolean bStopBundle)
Start a new process from a file.

Parameters:
f - file to run
args - space-separated process arguments
bWaitForExit - if true, wait for exit before returning
bStopBundle - if true, stop bundle after process has exited.
Returns:
the created process instance

initFiles

protected void initFiles(java.lang.String startChoices,
                         java.lang.String stopChoices,
                         java.lang.String extractNames)
                  throws java.io.IOException
Throws:
java.io.IOException

initFiles2

public void initFiles2(java.lang.String startName,
                       java.lang.String stopName,
                       java.lang.String extractNames)
                throws java.io.IOException
Throws:
java.io.IOException

Knopflerfish OSGi 5.2.0