Everyware™ Software Framework

<<Previous     Quickstart     Next>>

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:

           

Prerequisites

 

Bootstrap Service

Start by opening the HelloWorld.java class you created in the Hello World Using the ESF Log Service exercise.  We 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.  We then append the LABEL to every log message that we display.  You can see the complete code below.

 

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;

      }

}

 

We 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.

 

Now we can 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.  We need to add a new <bundle> definition in the file between the <service> tags.  This is what we would use to have the bundle start at LOG_LEVEL_DEBUG

 

  <bundle>

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

    <log_level>LOG_LEVEL_DEBUG</log_level>

  </bundle>

 

Note 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 we are telling the Bootstrap Service to load only the newest version of this bundle in the bundlefiles directory.

 

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

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

 

Bootstrap Debugging

Using 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 using 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.  However, 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 this:

 

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.

 

<<Previous     Quickstart     Next>>

 

Copyright © 2010 Eurotech Inc.  All rights reserved.