Bootstrap Service Example

PART 3. ESF CODE EXAMPLES
Bootstrap Service

 

Example

·            Overview

·            Prerequisites

·            Bootstrap Service

·            Bootstrap Debugging

Example

 

Overview

This example shows how to extend the Hello World Using the ESF Log Service to utilize the Bootstrap Service in other ways.  We are going to add some code to make the Hello World Example ‘production ready’ and then add it to the services.xml file so it is not started via the dropins directory.

 

In this example, you will learn how to

Add some code to the bundle to make it ‘production ready’

Edit services.xml so the bundle starts as it would in a production system

See the code run

           

Prerequisites

·            Installing the Eclipse IDE

·            Integrating ESF Tooling and Projects into Eclipse

or

·            Installing ESF Tooling into Wind River Workbench

and

·            Using Working Sets

·            Hello World Using the ESF Log Service

 

Bootstrap Service

Start by opening the HelloWorld.java class you created in the Hello World Using the ESF Log Service exercise.  You will edit it by adding a ‘LABEL’ to all of the comments.  This is a best practice in ESF that is used to denote where log messages are coming from.  You then append the LABEL to every log message that you display.  The following is the complete code.

 

package com.esf.example.helloworld;

 

import com.esf.core.logger.service.IEsfLoggerService;

 

public class HelloWorld {

 

      private static final String LABEL = "com.esf.example.helloworld.HelloWorld: ";

     

      private IEsfLoggerService esfLoggerService;

     

      public void bind(IEsfLoggerService esfLoggerService) {

            this.esfLoggerService = esfLoggerService;

            esfLoggerService.logDebug(LABEL + "Hello World");

      }

     

      public void unbind() {

            esfLoggerService.logDebug(LABEL + "Goodbye World");

            this.esfLoggerService = null;

      }

}

 

You can now export the plug-in as a plug-in and fragment to build the bundle.  Once done, copy it to the /opt/esf/jvm/bundlefiles/ directory on the target system.  Make sure there are no other bundles left over from the Hello World Using the ESF Log Service remaining in the /opt/jvm/esf/dropins/ directory.

 

Next, edit the /opt/jvm/esf/configuration/.esf/com.esf.core.system.bootstrap/services.xml file.  This is the bootstrap control file that specifies the bundles to start and the log level to start them at.  You need to add a new <bundle> definition in the file between the <service> tags.  Use the following to have the bundle start at LOG_LEVEL_DEBUG.

 

  <bundle>

    <name>com.esf.example.helloworld</name>

    <log_level>LOG_LEVEL_DEBUG</log_level>

  </bundle>

 

Notice the name is the bundle’s symbolic name without the date/time stamp or the .jar at the end.  By specifying the bundle only be its symbolic name, you are telling the Bootstrap Service to load only the newest version of this bundle in the bundlefiles directory.

 

Again, this is what you see when you run the /opt/jvm/esf/start_equinox.sh.  However, now you also see the LABEL indicating where the message is coming from.  When there are many bundles outputting messages, this LABEL makes debugging much more manageable.

 

[DEBUG] 2010-07-22 20:31:28.964 - com.esf.example.helloworld.HelloWorld: Hello World

 

Bootstrap Debugging

The Bootstrap Service is typically simple to use.  However, it can be useful to turn up the verbosity of the logging of the Bootstrap Service on occasion.  The Bootstrap Service uses the Service Activator Toolkit (SAT) logging mechanism.  This is the LogUtility class.  It is simply a static class that bundles can use to log messages at ERROR, WARNING, INFO, or DEBUG levels.  However, within ESF the Bootstrap Service is the only component that uses it.  It has limitations in terms of the ability to turn up or turn down the logging dynamically or for individual bundles.  The ESF Logger Service is not running at the time the Bootstrap Service starts.  So, it uses the LogUtility class of SAT.  To modify the verbosity of the SAT logger, you can edit /opt/jvm/esf/start_equinox.sh.

 

In it you will find

 

j9 -Dorg.eclipse.soda.sat.core.util.logLevel=WARNING \

                -Declipse.ignoreApp=true \

                -jar org.eclipse.osgi_3.4.0.v20080605-1900.jar \

                -console –clean

 

Simply change WARNING to DEBUG to increase the messages about what the Bootstrap Service is doing.  Since the Bootstrap Service is stable, this should rarely be necessary.  However, it is important to point out that bundles that are started by the Bootstrap Service can cause the Bootstrap Service to hang.  It important to make sure that all bundles do not hang in their Activators since this will cause the Bootstrap Service to also pause execution.  Viewing the debug output of the Bootstrap Service is helpful in these cases.

 

The code for this example can be downloaded here.