Home » Documentation » Bundles

Sling Settings and Run Modes (org.apache.sling.settings)


The Sling Settings Bundle exposes the SlingSettingsService which allows access to the following information pertinent to a Sling instance:

Method Bundle Context Property Description
String getSlingId() --- A unique identifier of the running Sling instance. This value is created when Sling is first started and may be used to identify the instance, for example if multiple Sling instances are running on top of a Jackrabbit Repository Cluster
String getSlingHomePath() sling.home The absolute filesystem path to the directory where Sling stores all its content
URL getSlingHome() sling.home.url The Sling Home path as an java.net.URL instance
Set<String> getRunModes() sling.run.modes The active Run Modes of the running Sling instance

The new Sling Settings Bundle replaces the former Run Modes (org.apache.sling.runmode) Bundle and the SlingSettingsService previously provided by the Sling Engine bundle, as it also implements the run modes logic.

Selecting the active run modes

The run modes are selected based on the sling.run.modes property (the "selection property"), specified in the Sling settings file or as a command-line parameter (which takes precedence), out of the valid run modes defined by the properties described below.

Using -Dsling.run.modes=foo,bar on the JVM command-line, for example, activates the foo and bar run modes if that combination is valid.

The Absolute Truth about run modes definition and selection is found in the RunModeImplTest which should be self-explaining.

Defining valid run modes

Since SLING-2662 the valid run modes are defined by the sling.run.mode.options and sling.run.mode.install.options configuration properties, usually defined in the sling.properties file or in the provisioning model of a Sling Launchpad instance.

The sling.run.mode.install.options property is only used on the first startup on the Sling instance and the run modes that it defines cannot be changed later.

The sling.run.mode.options property on the other hand is used at each startup, so the run modes that it defines can be changed between executions of a given Sling instance.

The value of the both these properties is a string which looks like:


where comma-separated groups of run modes are separated by a pipe character (which is not an OR operation, it's just as separator).

Once a group is defined, exactly one run mode will be active from that group.

If none of the listed run modes are selected, the first one from each group is activated by default.

If one is selected, this is active.

If several are selected, the first one from the list of valid modes is used.



User Defines -> Result:

-> a,c
a -> a,c
b -> b,c
a,b -> a,c
a,d -> a,d
a,e,f -> a,e

Remember to look at the RunModeImplTest mentioned above for details, and feel freee to enhance it with useful examples.

Getting the Run Modes of the Sling instance

The SlingSettings service provides the Run Modes of the running Sling instance as in this example:

SlingSettings settings = ...get from BundleContext...
Set<String> currentRunModes = settings.getRunModes();

Set<String> expectedRunModes = new HashSet<String>();
if(expectedRunModes.removeAll(currentRunModes)) {
  // at least one of (foo,wii) run modes
  // is active

Getting run modes in this way is usually not needed, it's better to define bundles or configurations that are only valid in specific run modes, rather than making decisions in code based on run modes.

Rev. 1754116 by bdelacretaz on Tue, 26 Jul 2016 11:59:54 +0000
Apache Sling, Sling, Apache, the Apache feather logo, and the Apache Sling project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.