com.bigdata.jini.start.config
Class ServiceConfiguration.AbstractServiceStarter<V extends ProcessHelper>

java.lang.Object
  extended by com.bigdata.jini.start.config.ServiceConfiguration.AbstractServiceStarter<V>
Type Parameters:
V -
All Implemented Interfaces:
Callable<V>
Direct Known Subclasses:
JavaServiceConfiguration.JavaServiceStarter, JiniCoreServicesConfiguration.JiniCoreServicesStarter
Enclosing class:
ServiceConfiguration

public abstract class ServiceConfiguration.AbstractServiceStarter<V extends ProcessHelper>
extends Object
implements Callable<V>

A task that will (re-)start an instance of a service described by its ServiceConfiguration.

Version:
$Id$
Author:
Bryan Thompson

Field Summary
protected  IServiceListener listener
           
 
Constructor Summary
protected ServiceConfiguration.AbstractServiceStarter(IServiceListener listener)
           
 
Method Summary
protected abstract  void addCommand(List<String> cmds)
          Add the command to be executed (eg, "java", etc).
protected  void addCommandArgs(List<String> cmds)
          Adds command arguments immediately following the executable name.
protected  void addServiceOptions(List<String> cmds)
          Add options at the end of the command line.
protected  void awaitServiceStart(V processHelper, long timeout, TimeUnit unit)
          Waits a bit to see if the process returns an exit code.
 V call()
          Start a new instance of the service.
protected  List<String> getCommandLine()
          Generate the command line that will be used to start the service.
protected  File getServiceDir()
          Hook for overriding the service directory.
 ProcessBuilder newProcessBuilder()
          Return the fully prepared ProcessBuilder that will be used to execute the command.
protected  ProcessBuilder newProcessBuilder(List<String> cmds)
          Create (and possibly configure) a ProcessBuilder that will be used to start the service.
protected  V newProcessHelper(String className, ProcessBuilder processBuilder, IServiceListener listener)
          Return the ProcessHelper that will be used to manage the process.
protected  void setUp()
          Hook for extending the pre-start setup for the service.
protected  void setUpEnvironment(Map<String,String> env)
          Hook for modification of the child environment.
protected  void writeStartFile(ProcessBuilder processBuilder)
          Write a file named start in the serviceDir whose contents are the command line which may be used to start the service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listener

protected final IServiceListener listener
Constructor Detail

ServiceConfiguration.AbstractServiceStarter

protected ServiceConfiguration.AbstractServiceStarter(IServiceListener listener)
Parameters:
listener -
Method Detail

call

public V call()
                             throws Exception
Start a new instance of the service.

Note: Output of the child process will be copied onto the output of the parent process. That is where to look for any output that is written onto stdout or stderr. Normally you will want the services to write their logs on a file, syslogd, or an async appender.

Specified by:
call in interface Callable<V extends ProcessHelper>
Throws:
Exception - if the service detectably did not start.

setUp

protected void setUp()
              throws Exception
Hook for extending the pre-start setup for the service.

Throws:
Exception

getServiceDir

protected File getServiceDir()
Hook for overriding the service directory. The default returns the ServiceConfiguration.serviceDir. It SHOULD be overriden to return the actual directory in which the specific service instance will be started.

See Also:
ServiceConfiguration.serviceDir, ServiceConfiguration.getServiceDir(String, Configuration)

newProcessHelper

protected V newProcessHelper(String className,
                             ProcessBuilder processBuilder,
                             IServiceListener listener)
                                            throws IOException
Return the ProcessHelper that will be used to manage the process.

Parameters:
className -
processBuilder -
listener -
Returns:
Throws:
IOException

newProcessBuilder

public ProcessBuilder newProcessBuilder()
Return the fully prepared ProcessBuilder that will be used to execute the command. You may obtain the environment and command line to be used from this object.


setUpEnvironment

protected void setUpEnvironment(Map<String,String> env)
Hook for modification of the child environment.

Parameters:
env - A map. Modifications to the map will be written into the child environment.
See Also:
ProcessBuilder.environment()

getCommandLine

protected List<String> getCommandLine()
Generate the command line that will be used to start the service.


newProcessBuilder

protected ProcessBuilder newProcessBuilder(List<String> cmds)
Create (and possibly configure) a ProcessBuilder that will be used to start the service.

Parameters:
cmds -
Returns:

addCommand

protected abstract void addCommand(List<String> cmds)
Add the command to be executed (eg, "java", etc).

Parameters:
cmds -

addCommandArgs

protected void addCommandArgs(List<String> cmds)
Adds command arguments immediately following the executable name.

Parameters:
cmds -

addServiceOptions

protected void addServiceOptions(List<String> cmds)
Add options at the end of the command line.

Parameters:
cmds -

awaitServiceStart

protected void awaitServiceStart(V processHelper,
                                 long timeout,
                                 TimeUnit unit)
                          throws Exception
Waits a bit to see if the process returns an exit code. If an exit is NOT available after a timeout, then assumes that the process started successfully.

Note: This DOES NOT provide direct confirmation that the service is running in a non-error and available for answering requests. You SHOULD override this method if you have a service specific means of obtaining such confirmation.

Throws:
Exception - If a service start failure could be detected (the caller will kill the process and log an error if any exception is thrown).

writeStartFile

protected void writeStartFile(ProcessBuilder processBuilder)
                       throws IOException
Write a file named start in the serviceDir whose contents are the command line which may be used to start the service. This file is not normally used to start the service, but it may be used as a debugging aid permitting service start from the command line.

Parameters:
processBuilder - The configured process builder.
Throws:
IOException


Copyright © 2006-2011 SYSTAP, LLC. All Rights Reserved.