org.apache.turbine.services

## Class BaseInitableBroker

- java.lang.Object
- - org.apache.turbine.services.BaseInitableBroker

- All Implemented Interfaces:
    InitableBroker

      public abstract class BaseInitableBroker
      extends Object
      implements InitableBroker

  A generic implementation of `InitableBroker`. Functionality provided by the broker includes:
  - Maintaining single instance of each `Initable` in the system.
  - Early initialization of `Initables` during system startup.
  - Late initialization of `Initables` before they are used.
  - Providing instances of `Initables` to requesting parties.
  - Maintaining dependencies between `Initables` during early initalization phases, including circular dependencies detection.
  Version:
    $Id: BaseInitableBroker.java 1706239 2015-10-01 13:18:35Z tv $
  Author:
    Kevin Burton, Rafal Krzewski, Henning P. Schmiedehausen

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Hashtable<String,Initable>` | `initables` A repository of Initable instances.
    `protected Stack<String>` | `stack` Names of classes being early-initialized are pushed onto this stack.

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `BaseInitableBroker()` Default constructor of InitableBroker.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Initable` | `getInitable(String className)` Provides an instance of Initable class ready to work.
    `protected Initable` | `getInitableInstance(String className)` Retrieves an instance of an Initable from the repository.
    `void` | `initClass(String className, Object data)` Performs early initialization of an Initable class.
    `void` | `shutdownClass(String className)` Shuts down an `Initable`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### initables

          protected Hashtable<String,Initable> initables

      A repository of Initable instances.

    - #### stack

          protected Stack<String> stack

      Names of classes being early-initialized are pushed onto this stack. A name appearing twice indicates a circular dependency chain.

  - ### Constructor Detail

    - #### BaseInitableBroker

          protected BaseInitableBroker()

      Default constructor of InitableBroker. This constructor does nothing. Your brokers should be singletons, therefore their constructors should be private. They should also have public YourBroker getInstance() methods.

  - ### Method Detail

    - #### initClass

          public void initClass(String className,
                       Object data)
                         throws InitializationException

      Performs early initialization of an Initable class.
      Specified by:
        `initClass` in interface `InitableBroker`
      Parameters:
        `className` - The name of the class to be initialized.
        `data` - An Object to be used for initialization activities.
      Throws:
        `InitializationException` - Initialization was not successful.

    - #### shutdownClass

          public void shutdownClass(String className)

      Shuts down an `Initable`. This method is used to release resources allocated by an `Initable`, and return it to its initial (uninitialized) state.
      Specified by:
        `shutdownClass` in interface `InitableBroker`
      Parameters:
        `className` - The name of the class to be uninitialized.

    - #### getInitable

          public Initable getInitable(String className)
                               throws InstantiationException

      Provides an instance of Initable class ready to work. If the requested class couldn't be instantiated or initialized, an InstantiationException will be thrown. You needn't handle this exception in your code, since it indicates fatal misconfiguration of the system.
      Specified by:
        `getInitable` in interface `InitableBroker`
      Parameters:
        `className` - The name of the Initable requested.
      Returns:
        An instance of the requested Initable.
      Throws:
        `InstantiationException` - if there was a problem during instantiation or initialization of the Initable.

    - #### getInitableInstance

          protected Initable getInitableInstance(String className)
                                          throws InstantiationException

      Retrieves an instance of an Initable from the repository. If the requested class is not present in the repository, it is instantiated and passed a reference to the broker, saved and then returned.
      Parameters:
        `className` - The name of the class to be instantiated.
      Throws:
        `InstantiationException` - if the requested class can't be instantiated.

Copyright © 2000-2015 The Apache Software Foundation. All Rights Reserved.