raccoon.core.manager
Class ServiceManager

java.lang.Object
  extended by raccoon.core.types.AbsComponent
      extended by raccoon.core.types.AbsLoadable
          extended by raccoon.core.types.AbsConfigurableLoadable
              extended by raccoon.core.manager.ServiceManager
All Implemented Interfaces:
IBaseComponent, IConfigurable, ILoadable, ILogable, IServiceManager

public class ServiceManager
extends AbsConfigurableLoadable
implements IServiceManager

The main component that handles the life cycle of any component that complies to the contract IBaseComponent.

Since:
Raccoon v0.1, refactored in Raccoon v0.5
Version:
$Id: ServiceManager.java,v 1.1 2004/08/08 20:19:18 crouvrais Exp $
Author:
Cedric ROUVRAIS

Field Summary
static java.lang.String MAPPING_PROPERTY_NAME
          The property used by the service manager to locate the mapping file that it should use.
static java.lang.String SERVICES_XML_FILE
          The property used by the service manager to locate the services xml file that it should use.
 
Fields inherited from class raccoon.core.types.AbsConfigurableLoadable
mConfigurableManager
 
Fields inherited from class raccoon.core.types.AbsLoadable
mIsLoaded
 
Fields inherited from class raccoon.core.types.AbsComponent
mIsInError
 
Constructor Summary
ServiceManager()
           
 
Method Summary
 void bootstrap()
          Force the ServiceManager to auto load using the specified ResourceBundle in the appropriate java property.
 void clear()
          Clears all the current errors attached to this component.
 void configureParameters()
          Configures the various parameters for this component.
 java.lang.String getConfigurationName()
          Convenience method to check in debug mode if this service manager is using the right configuration file.
static void invokeBeanProperty(java.lang.Object pBeanInstance, java.lang.String pPropertyName, java.lang.String pPropertyType, java.lang.String pPropertyValue, java.lang.String pCollectionType)
          Invokes the given property setter.
static boolean isConfigurable()
          Does this component require a property file to be correctly configured.
static boolean isInitialisable()
          Does this component need to be started and stopped?.
 boolean isLoaded(java.lang.String pComponentName)
          Checks if a given service is already loaded, convenience method for faster access.
 boolean isLoaded(java.lang.String pComponentName, java.lang.String pComponentKey)
          Checks if a given service is already loaded, convenience method for faster access.
 boolean isLogable()
          Does this component require a logging component in order to function correctly?.
 void load()
          Invoked by the service helper to start this component once it has been configured.
 IBaseComponent lookup(java.lang.String pComponentName)
          Retrieves a component that has been loaded and initialised based upon it's logical name.
 IBaseComponent lookup(java.lang.String pComponentName, java.lang.String pComponentKey)
          Retrieves a component that has been loaded and initialised based upon it's logical key name.
 IBaseComponent lookup(java.lang.String pComponentName, java.lang.String pComponentKey, java.util.Hashtable pBeanProperties)
          Retrieves a component that has been loaded and initialised based upon it's logical key name.
 void setConfig(IConfig pConfig)
          Defines the configuration service used by this component.
 void shutdown(boolean pThrowOnError)
          Shuts down all the loaded components.
 void unload()
          Invoked by the service manager to stop this component.
 
Methods inherited from class raccoon.core.types.AbsConfigurableLoadable
isStable, setConfigurableManager, setLogger
 
Methods inherited from class raccoon.core.types.AbsLoadable
getLog, isInError, isInitialised, isRunning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface raccoon.api.types.IServiceManager
isStable
 

Field Detail

MAPPING_PROPERTY_NAME

public static final java.lang.String MAPPING_PROPERTY_NAME
The property used by the service manager to locate the mapping file that it should use.

See Also:
Constant Field Values

SERVICES_XML_FILE

public static final java.lang.String SERVICES_XML_FILE
The property used by the service manager to locate the services xml file that it should use.

See Also:
Constant Field Values
Constructor Detail

ServiceManager

public ServiceManager()
Method Detail

isConfigurable

public static boolean isConfigurable()
Does this component require a property file to be correctly configured.

Returns:
true if this component needs property file.

isLogable

public boolean isLogable()
Does this component require a logging component in order to function correctly?.

Returns:
true if this component needs a logging component.

isInitialisable

public static boolean isInitialisable()
Does this component need to be started and stopped?.

Returns:
true if this component needs to be started and stopped.

setConfig

public void setConfig(IConfig pConfig)
Defines the configuration service used by this component.

Parameters:
pConfig - the configuration service.

clear

public void clear()
Clears all the current errors attached to this component.


getConfigurationName

public java.lang.String getConfigurationName()
Convenience method to check in debug mode if this service manager is using the right configuration file.

Specified by:
getConfigurationName in interface IServiceManager
Returns:
the logical name of the configuration file (the name attribute of <service>

load

public void load()
          throws LoadableException
Invoked by the service helper to start this component once it has been configured.

Specified by:
load in interface ILoadable
Overrides:
load in class AbsConfigurableLoadable
Throws:
LoadableException - if this component was unable to load itself or dependant components.

unload

public void unload()
            throws LoadableException
Invoked by the service manager to stop this component.

When extended bare in mind that the member variable mIsLoaded should be set to true and then set to false once all the init code has been performed.

Specified by:
unload in interface ILoadable
Overrides:
unload in class AbsLoadable
Throws:
LoadableException - if this component wasn't unable to unload itself or dependant services.

lookup

public IBaseComponent lookup(java.lang.String pComponentName)
                      throws RaccoonException
Retrieves a component that has been loaded and initialised based upon it's logical name.

Specified by:
lookup in interface IServiceManager
Parameters:
pComponentName - the name of the component that was given in the configuration file.
Returns:
the IBaseComponent instance loaded and initialised if necessary.
Throws:
RaccoonException - if the component couldn't be loaded or found.

isLoaded

public boolean isLoaded(java.lang.String pComponentName)
                 throws RaccoonException
Checks if a given service is already loaded, convenience method for faster access.

Invoking this method first will avoid instiating various objects if the service is already loaded by just calling lookup(String)

Specified by:
isLoaded in interface IServiceManager
Parameters:
pComponentName - the logical name of the component.
Returns:
true if the object already exists within this instance of the service manager.
Throws:
RaccoonException - if the service manager isn't stable.

isLoaded

public boolean isLoaded(java.lang.String pComponentName,
                        java.lang.String pComponentKey)
                 throws RaccoonException
Checks if a given service is already loaded, convenience method for faster access.

Invoking this method first will avoid instiating various objects if the service is already loaded by just calling lookup(String)

Specified by:
isLoaded in interface IServiceManager
Parameters:
pComponentName - the logical name of the component.
pComponentKey - a unique key that is used to identify this given component (for example a thread-id).
Returns:
true if the object already exists within this instance of the service manager.
Throws:
RaccoonException - if the service manager isn't stable.

lookup

public IBaseComponent lookup(java.lang.String pComponentName,
                             java.lang.String pComponentKey,
                             java.util.Hashtable pBeanProperties)
                      throws RaccoonException
Retrieves a component that has been loaded and initialised based upon it's logical key name.

Specified by:
lookup in interface IServiceManager
Parameters:
pComponentName - the name of the component that was given in the configuration file.
pComponentKey - a unique key that is used to identify this given component (for example a thread-id).
pBeanProperties - the bean properties that are to be set before invoking the load method.
Returns:
the IBaseComponent instance loaded and initialised if necessary.
Throws:
RaccoonException - if the component couldn't be loaded or found.

lookup

public IBaseComponent lookup(java.lang.String pComponentName,
                             java.lang.String pComponentKey)
                      throws RaccoonException
Retrieves a component that has been loaded and initialised based upon it's logical key name.

This method is useful when several instances of a given component need to be created. For example when a component isn't thread safe, passing the thread-id as the key will result in the creation of a component instance per existing thread.

Another useful situation is when a component is category orientated like the Log4j component: here the key would be the category.

Specified by:
lookup in interface IServiceManager
Parameters:
pComponentName - the name of the component that was given in the configuration file.
pComponentKey - the name of the key that was given to this component (for example a thread id).
Returns:
the IBaseComponent instance loaded and initialised if necessary.
Throws:
RaccoonException - if the component couldn't be loaded or found.

invokeBeanProperty

public static void invokeBeanProperty(java.lang.Object pBeanInstance,
                                      java.lang.String pPropertyName,
                                      java.lang.String pPropertyType,
                                      java.lang.String pPropertyValue,
                                      java.lang.String pCollectionType)
                               throws RaccoonException
Invokes the given property setter.

Parameters:
pBeanInstance - the java bean instance for which the property is to be set.
pPropertyName - the name of the property that is to be invoked
pPropertyType - the type of the property (string, integer, int, ...)
pPropertyValue - the value of the property.
pCollectionType - if this property is a collection, set this value to "collection" and the property "add"pPropertyName will be invoked, else set to null
Throws:
RaccoonException - if the process fails.

bootstrap

public void bootstrap()
               throws RaccoonException
Force the ServiceManager to auto load using the specified ResourceBundle in the appropriate java property.

Throws:
RaccoonException - if something goes wrong.

shutdown

public void shutdown(boolean pThrowOnError)
              throws RaccoonException
Shuts down all the loaded components.

Specified by:
shutdown in interface IServiceManager
Parameters:
pThrowOnError - if true will throw an exception containing all the errors that occured whilst halting the loaded services.
Throws:
RaccoonException - if pThrowOnError is true and errors occur.

configureParameters

public void configureParameters()
Configures the various parameters for this component. This method should configure the instance of IConfigurableManager provided during the invocation of AbsConfigurableLoadable.setConfigurableManager(IConfigurableManager).

Specified by:
configureParameters in interface IConfigurable
Overrides:
configureParameters in class AbsConfigurableLoadable


Copyright null null. All Rights Reserved.