org.sape.carbon.core.bootstrap
Class BootStrapper

java.lang.Object
  |
  +--org.sape.carbon.core.bootstrap.BootStrapper

public final class BootStrapper
extends Object

This class is Carbon's ultimate source for the config service and ComponentKeeper. If they have not been loaded already, this class knows how bootstrap the system to load them.

All public methods are synchronized such that the first thread to acquire the lock on this class will load the Carbon Core, all other concurrent threads will wait for the first to finish. The exception to this is the getState method. This method is synchronized on a different object so that threads merely interested in the system state do not need to wait for the system to load.

This class is final because Carbon is not designed to have this class be overridden so extending it makes no sense.

Copyright 2002 Sapient

Since:
carbon 1.0
Version:
$Revision: 1.39 $($Author: ghinkl $ / $Date: 2003/10/16 13:46:23 $)
Author:
Douglas Voet, January 2002

Field Summary
static String BOOT_LOADER_PROPERTY
          The bootloader key definition to override the bootloader
private  ComponentKeeper componentKeeper
          The ComponentKeeper for the Carbon Core
private  ConfigurationService configurationService
          The ConfigurationService for the Carbon Core
private static String DEFAULT_LOADER_CLASS_NAME
          The key to the class name of the default loader
private  DeploymentProperties deploymentProperties
          The deployement properties cache for this bootstrapper
private static BootStrapper INSTANCE
          The single static reference to the boot strapper of this system.
private  org.apache.commons.logging.Log log
          The handle to Apache-commons logger
private static String STARTUP_COMPONENT_NAME
          The default name of the startup component service
private  BootStrapperStateEnum state
          Attribute to hold the state of the Carbon Core (is it loaded or not).
private  Object stateLock
          Object used to synchronize upon when state is accessed.
 
Constructor Summary
private BootStrapper()
          This is a singleton so we have a private constructor to prevent impropper instantiation.
 
Method Summary
 ComponentKeeper fetchComponentKeeper()
          Gets a reference to the ComponentKeeper for the system.
 ConfigurationService fetchConfigurationService()
          Gets a reference to the root configuration provider for the system.
private  Loader fetchLoader()
           Factory method for getting a Loader to load the system.
 String getDeploymentProperty(String key)
          This method provides access to properties that are specific to this deployment of Carbon.
static BootStrapper getInstance()
           Static factory method for getting a reference to the BootStrapper.
 BootStrapperStateEnum getState()
          Gets the state of BootStrapper.
 void load()
           This method is responsible for making the calls to load of the Carbon Core.
 Object setDeploymentProperty(String key, String value)
          This method sets Deployment properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private org.apache.commons.logging.Log log
The handle to Apache-commons logger


configurationService

private ConfigurationService configurationService
The ConfigurationService for the Carbon Core


componentKeeper

private ComponentKeeper componentKeeper
The ComponentKeeper for the Carbon Core


state

private BootStrapperStateEnum state
Attribute to hold the state of the Carbon Core (is it loaded or not).


stateLock

private final Object stateLock
Object used to synchronize upon when state is accessed. This will never change, so it is final.


deploymentProperties

private final DeploymentProperties deploymentProperties
The deployement properties cache for this bootstrapper


BOOT_LOADER_PROPERTY

public static final String BOOT_LOADER_PROPERTY
The bootloader key definition to override the bootloader

See Also:
Constant Field Values

DEFAULT_LOADER_CLASS_NAME

private static final String DEFAULT_LOADER_CLASS_NAME
The key to the class name of the default loader

See Also:
Constant Field Values

STARTUP_COMPONENT_NAME

private static final String STARTUP_COMPONENT_NAME
The default name of the startup component service

See Also:
Constant Field Values

INSTANCE

private static final BootStrapper INSTANCE
The single static reference to the boot strapper of this system.

Constructor Detail

BootStrapper

private BootStrapper()

This is a singleton so we have a private constructor to prevent impropper instantiation.

Method Detail

fetchConfigurationService

public ConfigurationService fetchConfigurationService()

Gets a reference to the root configuration provider for the system.

Returns:
a reference to the configuration service

fetchComponentKeeper

public ComponentKeeper fetchComponentKeeper()

Gets a reference to the ComponentKeeper for the system.

Returns:
a reference to the component keeper

load

public void load()

This method is responsible for making the calls to load of the Carbon Core. It delegates to a Loader to get references to the configuration service and the ComponentKeeper for the system.

It is synchronized so it can only be run by a single thread. It also contains logic so that it will only run once.


getState

public BootStrapperStateEnum getState()

Gets the state of BootStrapper. This method allows you to determine whether or no the core is up an running yet.

Note that this method is synchronized (within the method, not in the method signature) in order to return a correct result always. If a stale result is acceptable in exchange for better performance, the synchronization can be removed.

Returns:
BootStrapperStateEnum.LOADED when the BootStrapper has been loaded, BootStrapperStateEnum.NOT_LOADED otherwise

getDeploymentProperty

public String getDeploymentProperty(String key)
This method provides access to properties that are specific to this deployment of Carbon. The system properties are searched for the requested property first. If it is not found, the value is returned from a properties file name by BootStrapper.DEPLOYMENT_CONFIG_FILE_NAME and located using the ClassLoader.getResource method. Deployment Properties should be properties that either change based on deployment or are required before the ConfigurationService is loaded. Cases of properties varying based on deployment should be minimal. In this case, the DeploymentService should be used.

This method has the same semantics as java.util.Properties.getProperty(String)

Parameters:
key - the name of the property
Returns:
String the value of the property or null if it does not exist
See Also:
ClassLoader.getResource(String), Properties.getProperty(String), DeploymentService

setDeploymentProperty

public Object setDeploymentProperty(String key,
                                    String value)
This method sets Deployment properties. If the property exists within the System properties, it is replaced, otherwise, it is written to the deployment properties maintained by this class. It does not write the new value to the properties file. This method affects the smallest scope possible. It will not write to the system wide properties unless the property already exists because that could affect other applications running in the same JVM.

This method has the same semantics as java.util.Properties.setProperty(String, String)

Parameters:
key - the key to store the value in
value - the value of the deployment property
Returns:
Object the old value of the deployment property
See Also:
Properties.setProperty(String, String)

fetchLoader

private Loader fetchLoader()

Factory method for getting a Loader to load the system. This method defaults to using the DefaultLoader unless the system property defined by BOOT_LOADER_PROPERTY is set on the commandline. In that case, the value of the system property must refer to a class that implements Loader.

Returns:
the proper loader to load the system

getInstance

public static BootStrapper getInstance()

Static factory method for getting a reference to the BootStrapper.

Returns:
BootStrapper


Copyright 1999-2003 Sapient Corporation. All Rights Reserved.