Overview
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.
Run Modes
Run modes are meant to define different sets of configuration parameters for various Sling instances.
In a web publishing environment, for example, one could use run modes like staging, production, dev, dmz or combinations of such values.
Configuration
Run modes can only be configured using a system property, or via the sling.properties file.
Using -Dsling.run.modes=foo,bar on the JVM command-line, for example, activates the foo and bar run modes.
This command-line parameter takes precedence over a similar definition (sling.run.modes=dev,staging) that might be present in the sling.properties file found in the Sling home directory.
Getting the Run Modes of the Sling instance
The SlingSettings service provides the Run Modes of the running Sling instance, examples:
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 }