Run Modes

14/06/2021 / BY / IN OSGI Components and Services / 1 Comments

Welcome to part 7 of the lecture on OSGI, in this part we will review pre-defined component configurations and Run Modes.

After reading this article, you should be able to

  1. Create pre-defined component configurations.
  2. Describe what run modes are.
  3. Create multiple component configurations specific to Run Modes.

Repository Based Configuration

Though the configurations from the web consoles looks convenient, it is only good for development & debug.

The proper way is to configure OSGI components using repository nodes, that lets you store & manage configurations together with the code, as files.

And you can have several configurations for different environments & run modes.

Repository Config Nodes – A Closer Look

  • An OSGI configuration node, is a node that contains component properties.
  • The node name must be the component name, by default it is equal to the class name.
  • The config node must be located under apps directory in a folder called config or config.run mode.
  • The nodes jcr:primaryType is sling:OsgiConfig & there are properties with values in that content node.

Repository Based Configuration

Let’s look closer at Run Modes.

Run mode is a property that is passed to the AEM instance. It instructs the AEM instance which configuration it must use, by this time you must already use author & publish run modes.
In real projects there are usually many environments & you usually specify the environment name as a run mode.
For eg, development, testing staging or production & the instance uses the corresponding environment specific configuration.
Eg. There can be a component that say, connect to an external web service & you can create several configurations for it, if the AEM runs on a local development machine, you might have a configuration that instructs the component to connect to a sort of service stub.

On the staging or QA instances there might be a configuration that instructs the component to connect to staging web service. & when the run mode is production, the configuration will tell the component to connect to the production web service.

How do we determine the Run Modes? That are currently set in the AEM.

There is more than one way to see the run modes for eg. One can go to the Status ->Sling Settings page in the web console.

There is run modes and in the square bracket that is the list of run modes currently set in the AEM instance.

Where does the AEM read the Run Modes from?

There are several places to specify the run modes, the order in which AEM tries to obtain them is shown below

  1. First it looks in the sling.properties file in the conf directory of the AEM installation.
  2. Then it tries to determine the values of -r parameter in the command line.
  3. Then the run mode can be set in CQ_RUNMODE variable as a value of sling.run.modes property in the start-up script.
  4. Or one can include the run mode in the name of the jar file.

Run Modes & OSGI Configs


While searching for the configurations that match the run mode the OSGI environment searches for nodes of type sling:OsgiConfig under apps & libs top level folder.

  • The config node must be located under a folder named config or config.some run modes.
  • The container also checks the file system – the directory crx-quickstart/Launchpad/config/

If there are several matching configuration nodes, the environment chooses the best matching configuration.

for eg, imagine that you run an AEM instance with three run modes shown in the above, stage, crx3mongo that is authoring mode, probably some staging instance & mongo micro kernel.

If there is a folder named config.author.stage.crx3mongo that’s an exacts match & it will be used – configuration from that folder will be used.

If it stops present the container will continue searching.

If there is a configuration under a folder were two run modes match, it will use one of them & the order is not important.

If there is no folder with two matches or there is no configuration in them it will search configurations in folders with one match & if nothing is present, there it will look for a configuration in cofig folder.

So, if you want to specify the default configuration for all instances you might want to place it in config folder in your application.

Configuration Manager


This XML is a serialized content node, the format in which it is serialized is called document view unlike another format or system view.

This format does not contain a system properties like creation date or user who created the node.

Note: The attribute called jcr:primaryType with its values sling:OsgiConfig it indicates that this content is a configuration node.

OSGI Property Types

You probably noticed that we used properties of various types

Property type supported in AEM are listed in javax.jcr.PropertType class.

Most often used are String, Long

Note: Integer is not supported in jcr at least in the pre-defined configurations in xml format.

In our eg. We declared int property & did not specified the exact type in the configuration xml file.

Aslo it supports Boolean & Date.

Properties can be multi-valued, for multi value property – you list the values in square brackets comma separated.

Summary

• Run modes is an AEM feature that allows instructing AEM instance which configuration to use.
• To Use run modes:
a. Store configurations in the source code as XML files.
b. Use folder naming to associate configurations with run modes.


Hope you enjoyed this article, I would like to suggest, Kindly watch video below for practical session, Thank you for your attention! In the next part we will review the component aspects of Sling Servlets & Filters. Click here to visit page!

Leave a Reply