com.bigdata.jini.start.config
Class JiniServiceConfiguration.JiniServiceStarter<V extends JiniServiceProcessHelper>

java.lang.Object
  extended by com.bigdata.jini.start.config.ServiceConfiguration.AbstractServiceStarter<V>
      extended by com.bigdata.jini.start.config.JavaServiceConfiguration.JavaServiceStarter<V>
          extended by com.bigdata.jini.start.config.ManagedServiceConfiguration.ManagedServiceStarter<V>
              extended by com.bigdata.jini.start.config.JiniServiceConfiguration.JiniServiceStarter<V>
Type Parameters:
V -
All Implemented Interfaces:
Callable<V>
Direct Known Subclasses:
BigdataServiceConfiguration.BigdataServiceStarter
Enclosing class:
JiniServiceConfiguration

public class JiniServiceConfiguration.JiniServiceStarter<V extends JiniServiceProcessHelper>
extends ManagedServiceConfiguration.ManagedServiceStarter<V>

Version:
$Id$
Author:
Bryan Thompson

Field Summary
 
Fields inherited from class com.bigdata.jini.start.config.ManagedServiceConfiguration.ManagedServiceStarter
fed, logicalServiceZNode, logicalServiceZPath, restart, serviceDir, serviceName, serviceUUID
 
Fields inherited from class com.bigdata.jini.start.config.JavaServiceConfiguration.JavaServiceStarter
cls
 
Fields inherited from class com.bigdata.jini.start.config.ServiceConfiguration.AbstractServiceStarter
listener
 
Constructor Summary
protected JiniServiceConfiguration.JiniServiceStarter(JiniFederation fed, IServiceListener listener, String logicalServiceZPath, net.jini.core.entry.Entry[] attributes)
           
 
Method Summary
protected  void addServiceOptions(List<String> cmds)
          Extended to specify the configuration file (in the service directory) as an argument to the java class whose main routine will be invoked and to add the JiniServiceConfiguration.Options.JINI_OPTIONS.
protected  net.jini.core.lookup.ServiceItem awaitServiceDiscoveryOrDeath(ProcessHelper processHelper, long timeout, TimeUnit unit)
          Waits up to timeout units for the service to either by discovered by jini or to die.
protected  void awaitServiceStart(V processHelper, long timeout, TimeUnit unit)
          Overridden to monitor for the jini join of the service and the creation of the znode corresponding to the physical service instance.
 void awaitZNodeCreatedOrDeath(net.jini.core.lookup.ServiceItem serviceItem, ProcessHelper processHelper, long timeout, TimeUnit unit)
          Waits up to timeout units for the znode for the physical service to be created or the process to die.
protected  net.jini.core.entry.Entry[] getEntries(net.jini.core.entry.Entry[] entries)
          Returns the Entry[] used to describe the service (allows the override or addition of entries at service creation time).
 String[] getImports()
          Imports that will be written into the generated ConfigurationFile.
protected  Properties getProperties(Properties properties)
          Extension hook for adding or overriding properties.
protected  V newProcessHelper(String className, ProcessBuilder processBuilder, IServiceListener listener)
          Return the ProcessHelper that will be used to manage the process.
protected  void setUp()
          Extended to write the Configuration file in the service directory.
protected  void writeComments(Writer out)
          Write comments at the top of the configuration file.
protected  void writeConfigFile()
          Generates the contents of the configuration file and writes it on the configFile.
protected  void writeConfigFile(Writer out)
          Generates the contents of the configuration file.
protected  void writeEntries(Writer out)
           
protected  void writeEntry(Writer out, net.jini.core.entry.Entry e)
          Write out the ctor for an Entry.
protected  void writeExporterEntry(Writer out)
          Writes the AbstractServer.ConfigurationOptions#SERVICE_ID_FILE entry.
protected  void writeGroups(Writer out)
           
protected  void writeLocators(Writer out)
           
protected  void writeLogicalServiceZPathEntry(Writer out)
          Writes the AbstractServer.ConfigurationOptions#LOGICAL_SERVICE_ZPATH entry.
protected  void writeProperties(Writer out)
          Writes the properties for the specificed class namespace into the generated service configuration file.
protected  void writeServiceDescription(Writer out)
          Writes the ServiceDescription.
protected  void writeServiceDirEntry(Writer out)
          Writes the AbstractServer.ConfigurationOptions#SERVICE_DIR entry.
protected  void writeZookeeperClientConfigEntries(Writer out)
          Writes the ZookeeperClientConfig into the configuration file.
 
Methods inherited from class com.bigdata.jini.start.config.ManagedServiceConfiguration.ManagedServiceStarter
getServiceDir
 
Methods inherited from class com.bigdata.jini.start.config.JavaServiceConfiguration.JavaServiceStarter
addCommand, addCommandArgs, setUpEnvironment
 
Methods inherited from class com.bigdata.jini.start.config.ServiceConfiguration.AbstractServiceStarter
call, getCommandLine, newProcessBuilder, newProcessBuilder, writeStartFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JiniServiceConfiguration.JiniServiceStarter

protected JiniServiceConfiguration.JiniServiceStarter(JiniFederation fed,
                                                      IServiceListener listener,
                                                      String logicalServiceZPath,
                                                      net.jini.core.entry.Entry[] attributes)
Parameters:
fed -
listener -
logicalServiceZPath - This zpath of the logicalService instance.
attributes - This provides the information required to restart a persistent service. When not given a new service instance will be started. When given, the same service instance will be restarted.
Method Detail

getImports

public String[] getImports()
Imports that will be written into the generated ConfigurationFile.

TODO:
The generated Configuration uses fully qualified imports so it may be that we don't need any of these.

addServiceOptions

protected void addServiceOptions(List<String> cmds)
Extended to specify the configuration file (in the service directory) as an argument to the java class whose main routine will be invoked and to add the JiniServiceConfiguration.Options.JINI_OPTIONS.

Overrides:
addServiceOptions in class ServiceConfiguration.AbstractServiceStarter<V extends JiniServiceProcessHelper>

setUp

protected void setUp()
              throws Exception
Extended to write the Configuration file in the service directory.

Note: If this is a service restart then Configuration is NOT overwritten. If you want to change the Configuration of a service which has already been started you need to either administer it through jini or shut it down and edit its configuration file.

Overrides:
setUp in class ManagedServiceConfiguration.ManagedServiceStarter<V extends JiniServiceProcessHelper>
Throws:
Exception

writeConfigFile

protected void writeConfigFile()
                        throws IOException
Generates the contents of the configuration file and writes it on the configFile.

Throws:
IOException

writeConfigFile

protected void writeConfigFile(Writer out)
                        throws IOException
Generates the contents of the configuration file.

Parameters:
out -
Throws:
IOException

writeComments

protected void writeComments(Writer out)
                      throws IOException
Write comments at the top of the configuration file.

Throws:
IOException

getEntries

protected net.jini.core.entry.Entry[] getEntries(net.jini.core.entry.Entry[] entries)
                                          throws IOException
Returns the Entry[] used to describe the service (allows the override or addition of entries at service creation time). The following attributes are added:
Name
A canonical Name entry. It is formed from the service type and the logical service znode.
Hostname
The canonical name of the host on which the service is running.
ServiceDir
The directory in which the service stores its persistent state.
ServiceUUID
The ServiceID assigned to the service represented as a UUID.

Throws:
IOException

writeEntries

protected void writeEntries(Writer out)
                     throws IOException
Parameters:
out -
Throws:
IOException

writeEntry

protected void writeEntry(Writer out,
                          net.jini.core.entry.Entry e)
                   throws IOException
Write out the ctor for an Entry. For example, generating new net.jini.lookup.entry.Name("foo") when given a Name.

Note: There is no general purpose mechanism for emitting Entry attributes using reflection, even when the Entry is an AbstractEntry (ctors do not declare the relationship between their arguments and the public fields). Further, jini will not let you use the zero arg public ctor and then set the fields from the public fields declared by the Entry class from within the generated configuration file. For example, _entry1.name = "foo"; is rejected by the ConfigurationProvider. This unpleasant situation means that we are hardcoding the ctor calls based on the class. However, you can use this method as a hook to extend the logic to handle Entry implementations which it does not already understand.

Throws:
UnsupportedOperationException - if it can not emit an entry of some unknown class.
IOException

writeGroups

protected void writeGroups(Writer out)
                    throws IOException
Throws:
IOException

writeLocators

protected void writeLocators(Writer out)
                      throws IOException
Throws:
IOException

writeServiceDescription

protected void writeServiceDescription(Writer out)
                                throws IOException
Writes the ServiceDescription. This section contains the exporter, serviceIdFile, and logicalServiceZPath entries.

Throws:
IOException

writeProperties

protected void writeProperties(Writer out)
                        throws IOException
Writes the properties for the specificed class namespace into the generated service configuration file.

Parameters:
writer -
Throws:
IOException

getProperties

protected Properties getProperties(Properties properties)
Extension hook for adding or overriding properties.

Parameters:
properties - The configured properties.
Returns:
The properties that will be written using writeProperties(Writer)

writeExporterEntry

protected void writeExporterEntry(Writer out)
                           throws IOException
Writes the AbstractServer.ConfigurationOptions#SERVICE_ID_FILE entry. This value is used by the AbstractServer to export the proxy for the service. The choice here effects the protocol that will be used for communications between the clients and the service. FIXME the [exporter] is hardwired. There are also hardwired exporters used by the JiniFederation. The whole issue needs to be resolved. The exported is a chunk of code, so it would have to be quoted to get passed along, which is why I am doing it this way.

Throws:
IOException

writeServiceDirEntry

protected void writeServiceDirEntry(Writer out)
                             throws IOException
Writes the AbstractServer.ConfigurationOptions#SERVICE_DIR entry.

Throws:
IOException

writeLogicalServiceZPathEntry

protected void writeLogicalServiceZPathEntry(Writer out)
                                      throws IOException
Writes the AbstractServer.ConfigurationOptions#LOGICAL_SERVICE_ZPATH entry. The service must use CreateMode.EPHEMERAL_SEQUENTIAL to create a child of this zpath to represent itself.

Throws:
IOException

writeZookeeperClientConfigEntries

protected void writeZookeeperClientConfigEntries(Writer out)
                                          throws IOException
Writes the ZookeeperClientConfig into the configuration file.

Throws:
IOException

newProcessHelper

protected V newProcessHelper(String className,
                             ProcessBuilder processBuilder,
                             IServiceListener listener)
                                                       throws IOException
Description copied from class: ServiceConfiguration.AbstractServiceStarter
Return the ProcessHelper that will be used to manage the process.

Overrides:
newProcessHelper in class ServiceConfiguration.AbstractServiceStarter<V extends JiniServiceProcessHelper>
Returns:
Throws:
IOException

awaitServiceStart

protected void awaitServiceStart(V processHelper,
                                 long timeout,
                                 TimeUnit unit)
                          throws Exception,
                                 TimeoutException,
                                 InterruptedException
Overridden to monitor for the jini join of the service and the creation of the znode corresponding to the physical service instance.

Overrides:
awaitServiceStart in class ServiceConfiguration.AbstractServiceStarter<V extends JiniServiceProcessHelper>
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).
TimeoutException
InterruptedException
TODO:
we could also verify the service using its proxy, e.g., by testing for a normal run state.

awaitServiceDiscoveryOrDeath

protected net.jini.core.lookup.ServiceItem awaitServiceDiscoveryOrDeath(ProcessHelper processHelper,
                                                                        long timeout,
                                                                        TimeUnit unit)
                                                                 throws Exception,
                                                                        TimeoutException,
                                                                        InterruptedException
Waits up to timeout units for the service to either by discovered by jini or to die.

Note: We recognize the service by the present of the assigned ServiceToken attribute. If a service with that ServiceToken can not be discovered by jini after a timeout, then we presume that the service could not start and throw an exception. The ServiceToken provides an attribute which is assigned by the service starter while the ServiceID is assigned by jini only after the service has joined with a jini registrar.

Parameters:
processHelper -
timeout -
unit -
Returns:
The ServiceItem for the discovered service.
Throws:
Exception
TimeoutException
InterruptedException

awaitZNodeCreatedOrDeath

public void awaitZNodeCreatedOrDeath(net.jini.core.lookup.ServiceItem serviceItem,
                                     ProcessHelper processHelper,
                                     long timeout,
                                     TimeUnit unit)
                              throws org.apache.zookeeper.KeeperException,
                                     InterruptedException,
                                     TimeoutException
Waits up to timeout units for the znode for the physical service to be created or the process to die.

Parameters:
processHelper -
timeout -
unit -
Throws:
TimeoutException
InterruptedException
org.apache.zookeeper.KeeperException


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