Sling Settings and Run Modes (


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 instance
Set<String> getRunModes() The active Run Modes of the running Sling instance

The new Sling Settings Bundle replaces the former 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 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. The value is a String which contains a list of comma-separated run modes. If a run mode is given here which is not contained in any group of valid run modes (given in or it is always active, on the other hand run modes which are contained in any of the predefined groups may be modified/removed (see below for the details).

Using,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 and configuration properties, usually defined in the file or in the provisioning model of a Sling Launchpad instance.

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

The 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 run modes form a group. The individual groups are separated by a pipe character (|, which is not an OR operation, it's just as separator). A group defines a number of run modes which are mutually exclusive. It means once a group is defined, exactly one run mode will be active from that group.

The example from above consists out of 3 different groups

  1. red,green,blue
  2. one
  3. moon,mars

The rules for determining the active run modes from the selected run mode ( and the run mode options ( and are as follows :

  1. If none of the run modes in the options are selected, the first one from each group in the options is activated by default.
  2. If one is selected from a group in the options, this is active.
  3. If several are selected from one group in the options, the first one from the list of valid run modes is used.
  4. If the selected run mode is not mentioned in any of the option groups it is active

User defined run modes (e.g. via property Effectively active run modes
(none) 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 free 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>(){{ add("foo");add("wii"); }};
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.

Decisions based on Run Modes

Since version 1.4.0 (SLING-9031 and SLING-8548) of the Sling Settings bundle there is support for checking a run mode spec against the currently active run modes.

The run mode spec grammar is as follows

run mode spec ::= disjunctions
disjunctions ::= conjunctions { "," conjunctions }
conjunctions ::= conjunction { '.' conjunction }
conjunction ::= notrunmode | runmode
notrunmode ::= '-' runmode

It supports OR (,) and AND (.) combinations of run modes and negations with - .

Programmatically this can be used via SlingSettings.getBestRunModeMatchCountFromSpec(String runModeSpec).

- ( Sling Settings and Run Modes ( )