Aspire ComponentImpl Class

From wiki.searchtechnologies.com
Jump to: navigation, search

For Information on Aspire 3.1 Click Here

The ComponentImpl class is a framework class that will serve as the base class for any java components that you create for Aspire. It is full of useful utilities which will help make your job easier.

How You Will Use ComponentImpl

Your component will either extend ComponentImpl or StageImpl (a sub-class of ComponentImple). See The Anatomy of a Component for more details.

  1. You will override the initialize() method
    Anything you need to initialize your component should be put here.
  2. You will override the close() method.
    Anything you need to clean up when your component is removed from Aspire should be put here.
  3. [If creating a pipeline stage] You will override the process() method of StageImpl.

Finally, ComponentImpl contains many useful methods for common component programming tasks. These are described below.

Fetching the Aspire Application

Most of the Aspire Application methods are wrapped in one of the Utilities classes (or other methods inside ComponentImpl), and so you should rarely need to access the Application itself.

But if you ever need to talk to it, you can get a reference to the application using this.getAspireApplication() from within your component.

Accessing Directories and Files

The ComponentImpl class contains methods for accessing files and directories within your Aspire installation.

Methods that fall into this category include the following:

  • getAppBundleHome()
  • appDataDir(dir)
  • getAspireHome()
  • getUrlFromAspireHome(inputPath)
  • getFilePathFromAppBundleHome(path)
  • getFilePathFromAspireHome(path)

In the above, "AppBundle Home" is the location of read-only files which are intended to be bundled with applications when they are deployed as app bundles to maven.

  • When executing inside of a deployed App Bundle, the directory will be:
    • $ASPIRE_HOME/cache/appbundles/<group-id>/<artifact-id>/<version-number>
  • When executing as a regular application (i.e. as an application.xml file inside of a regular Aspire installation), then App Bundle Home will be the same as $ASPIRE_HOME

See Aspire Directory Structure for details.

Names of Things

  • getName() - Returns the full path name of the component within Aspire. For example "/MyApp/docPipelineMgr/HTMLParse".
  • getAppName() - Get the top-level application name in which this component exists. For example, "MyApp"

Parsing Config

All configuration is captured in XML from the application.xml file and then passed to your component when it is initialized. ComponentImpl provides convenience methods when all you need are a simple parameters.

  • getStringFromConfig(...)
  • getBooleanFromConfig(...)
  • getDoubleFromConfig(...)
  • getIntegerFromConfig(...)
  • getLongFromConfig(...)

All of these methods read a simple parameter from the configuration, and allow for a default value of the parameter is not specified.

For example, your component could look like this:

 <component name="MyCOmponent" factoryName="aspire-my-component" subType="default>
   <myParam>This is a string</myParam>
   <myFlag>true</myFlag>
   <myFactor>4.3</myFactor>
 </component>

And the code to parse these parameters would look like this:

 String myParam = getStringFromConfig(config, "myParam", "Hello World");
 boolean myFlag = getBooleanFromConfig(config, "myFlag", false);
 float myFactor = getFloatFromConfig(config, "myFactor", 5.3);

All methods will check for correct parsing of the parameter type and throw an execution error during initialization if there is a problem.

Logging

ComponentImpl class provides the following methods for writing to the standard log files:

  • error(...) - for errors and exception errors
  • warn(...) - for warnings
  • info(...) - for informational messages

OSGi Access

Aspire is built within an OSGi framework, and so ComponentImpl contains methods for accessing OSGi and also accessing other Aspire components through OSGi. getBundleContext() provides direct access to OSGi and there are several convenient methods for creating OSGi ServiceTrackers to other components.

See Accessing Other Components for more information.

Other Topics

Other topics on this wiki associated with ComponentImpl: