Defining a component

A component is a JAR file that contains a property file named ast.properties. The properties supported in the ast.properties file are summarized in Table 11.1, “Component properties”.

Table 11.1. Component properties

PropertyDescription
Component-NameA unique indentifier for this component. This property is used both for identifying the component in log messages and to prevent the same component from being loaded multiple times. This property is required.
Component-NotifiersA comma separated list of fully qualified class names which extend com.kabira.platform.component.Notifier. This property is optional.
Configuration-FilesA comma separated list of configuration files which include path information relative to the top of the JAR. It is recommended that configuration files are stored with enough path to prevent collisions with files of the same name in other components. This property is optional.


Property values must be specified in a single line unless the "\" line continuation character is used to span lines. See Example 11.1, “Component property file” for an example property file.

White-space is allowed in the value for the Component-Name property.

All other white-space in property files is ignored.

Example 11.1. Component property file

#     $Revision: 1.1.2.1 $ 

#
#   The name of this component
#
Component-Name Snippet Component Sample

#
#   Notifiers associated with this component
#
Component-Notifiers com.kabira.snippets.components.NotifierOne, \
                        com.kabira.snippets.components.NotifierTwo

#
#   Configuration files associated with this component
#
Configuration-Files default.kcs

Locating the ast.properties file

The ast.properties file is searched for in these locations:

  • top of the JAR file

  • any element in the classpath

If the ast.properties file is located in the top of the JAR file it is always found and loaded if the JAR file is in the current class path. This is the simplest and most transparent mechanism to locate the ast.properties file.

It is also possible to locate the ast.properties file in a nested directory in a JAR file if this directory is specified in the class path.

If there are multiple ast.properties file located in a JAR file, the first one located is used. All others are ignored.

This is an example of a JAR file that contains the ast.properties file at the top of the JAR file.

Example 11.2. Location of ast.properties in JAR file

jar tf snippets.jar

META-INF/
META-INF/MANIFEST.MF
com/
com/kabira/
com/kabira/snippets/
com/kabira/snippets/components/
com/kabira/snippets/development/
com/kabira/snippets/distributedcomputing/
com/kabira/snippets/highavailability/
com/kabira/snippets/managedobjects/
com/kabira/snippets/management/
com/kabira/snippets/reference/
com/kabira/snippets/transactions/
com/kabira/snippets/vmlifecycle/

...

ast.properties

Notifiers

Component notifiers provide a mechanism to transparently perform component initialization and termination. The user of the component does not need to explicitly initialize or terminate a component.

A notifier is implemented by extending com.kabira.platform.Notifier and overriding the methods are that are needed to perform component initialization and termination. See Example 11.3, “Component notifier” for an example notifier.

Example 11.3. Component notifier

//     $Revision: 1.1.2.1 $
package com.kabira.snippets.components;

import com.kabira.platform.component.Notifier;
import com.kabira.platform.component.ComponentException;

/**
 * Component notifier one
 */
public class NotifierOne extends Notifier
{
    @Override
    protected void preConfigurationInitialize()
        throws ComponentException
    {
        try
        {
            //
            //  Resolve configuration class
            //
            Class.forName("com.kabira.snippets.components.Defaults");
        }
        catch (ClassNotFoundException ex)
        {
            new ComponentException("Class resolution failed", ex);
        }

        m_notifierName = getClass().getSimpleName();
        
        System.out.println(m_notifierName + ": - preConfigurationInitialize");
    }

    @Override
    protected void postConfigurationInitialize()
    {
        System.out.println(m_notifierName + ": - postConfigurationInitialize");

    }

    @Override
    protected void preConfigurationTerminate()
    {
        System.out.println(m_notifierName + ": - preConfigurationTerminate");

    }

    @Override
    protected void postConfigurationTerminate()
    {
        System.out.println(m_notifierName + ": - postConfigurationTerminate");
    }

    private String  m_notifierName;
}


Notifiers are created and executed in the order they are specified in the Component-Notifiers property during component initialization. They are executed and released for garbage collection in the reverse order during component termination. Since the same notifier instance is used for initialization and termination, state information can be stored in the notifier during the lifetime of the component for implementation specific reasons.

Component activation fails if:

  • a notifier class specified in the Component-Notifiers property cannot be found.

  • a notifier class does not extend from com.kabira.platform.component.Notifier.

  • a com.kabira.platform.component.ComponentException is thrown by a notifier initialization method.

Configuration

Components may contain configuration files. The configuration files contained in a component are automatically loaded and activated when a component is initialized. They are loaded and activated in the order they are specified in the Configuration-Files property. The configuration files are deactivated and removed when the component is terminated. They are deactivated and removed in the reverse order from which they were activated during initialization.

Component activation fails if:

  • a configuration file specified in the Configuration-Files property cannot be found.

  • a configuration file load fails.

  • a configuration file activation fails.

Any failures deactivating and removing configuration files during component termination are ignored.