Package org.apache.sling.launchpad.app

# Class Main

java.lang.Object
org.apache.sling.launchpad.app.Main

public class Main extends Object
The `Main` is the externally visible Standalone Java Application launcher for Sling. Please refer to the full description The Sling Launchpad on the Sling Web Site for a full description of this class.

Logging goes to standard output for informational messages and to standard error for error messages.

This class goes into the secondary artifact with the classifier app to be used as the main class when starting the Java Application.

See Also:
  - The Sling Launchpad

## Field Summary

Fields
Modifier and Type
Field
Description
`protected static final String`
`PROP_CONTROL_ACTION`
The name of the configuration property indicating the `ControlAction` to be taken in the `doControlAction()` method.
`protected static final String`
`PROP_CONTROL_SOCKET`
The name of the configuration property indicating the socket to use for the control connection.

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`Main(Map<String,String> args)`
Creates an instance of this main loader class.

## Method Summary

Modifier and Type
Method
Description
`protected int`
`doControlAction()`
After instantiating this class, this method may be called to help with the communication with a running Sling instance.
`protected boolean`
`doStart()`
Starts the application with the configuration supplied with the configuration properties when this instance has been created.
`protected boolean`
`doStart(URL launcherJar)`
`protected void`
`doStop()`
Maybe called by the application to cause the Sling Application to properly terminate by stopping the OSGi Framework.
`protected static void`
`error(String message, Throwable t)`
`String`
`getSlingHome()`
Return the absolute path to sling home
`protected static void`
`info(String message, Throwable t)`
`static void`
`main(String[] args)`
The main entry point to the Sling Launcher Standalone Java Application.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### PROP_CONTROL_ACTION

protected static final String PROP_CONTROL_ACTION
The name of the configuration property indicating the `ControlAction` to be taken in the `doControlAction()` method.

See Also:
  - Constant Field Values

### PROP_CONTROL_SOCKET

protected static final String PROP_CONTROL_SOCKET
The name of the configuration property indicating the socket to use for the control connection. The value of this property is either just a port number (in which case the host is assumed to be `localhost`) or a host name (or IP address) and port number separated by a colon.

See Also:
  - Constant Field Values

## Constructor Details

### Main

protected Main(Map<String,String> args)
Creates an instance of this main loader class. The provided arguments are used to configure the OSGi framework being launched with the `doStart(URL)` method.

Parameters:
  `args` - The map of configuration properties to be supplied to the OSGi framework. The keys in this map are assumed to be usefull without translation to the launcher and the OSGi Framework. If this parameter is `null` and empty map without configuration is assumed.

## Method Details

### main

public static void main(String[] args)
The main entry point to the Sling Launcher Standalone Java Application. This method is generally only called by the Java VM to launch Sling.

Parameters:
  `args` - The command line arguments supplied when starting the Sling Launcher through the Java VM.

### doControlAction

protected int doControlAction()
After instantiating this class, this method may be called to help with the communication with a running Sling instance. To setup this communication the configuration properties supplied to the constructor are evaluated as follows:

Control Properties

`"sling.control.socket"`

Specifies the socket to use for the control connection. This specification is of the form host:port where the host can be a host name or IP Address and may be omitted (along with the separating colon) and port is just the numeric port number at which to listen. The default is localhost:63000. It is suggested to not use an externally accessible interface for security reasons because there is no added security on this control channel for now.

`"sling.control.action"`

The actual action to execute:

- start -- Start the listener on the configured socket and expect commands there. This action is useful only when launching the Sling application since this action helps manage a running system.
- stop -- Connects to the listener running on the configured socket and send the command to terminate the Sling Application. If this command is used, it is expected the Sling Application will not start.
- status -- Connects to the listener running on the configured socket and query about its status. If this command is used, it is expected the Sling Application will not start.

After this method has executed the `j` and `PROP_CONTROL_ACTION` properties have been removed from the configuration properties.

While the `doStart()` and `doStop()` methods may be called multiple times this method should only be called once after creating this class's instance.

Returns:
  An code indicating whether the Java VM is expected to be terminated or not. If `-1` is returned, the VM should continue as intended, maybe starting the Sling Application. This code is returned if the start action (or no action at all) is supplied. Otherwise the VM should terminate with the returned code as its exit code. For the stop action, this will be zero. For the status action, this will be a LSB compliant code for daemon status check: 0 (application running), 1 (Program Dead), 3 (Program Not Running), 4 (Unknown Problem).
See Also:
  - Init Script Actions for a definition of the LSB status codes

### doStart

protected boolean doStart()
Starts the application with the configuration supplied with the configuration properties when this instance has been created.

Calling this method multiple times before calling `doStop()` will cause a message to be printed and `true` being returned.

Returns:
  `true` if startup was successful or the application is considered to be started already. Otherwise an error message has been logged and `false` is returned.

### doStart

protected boolean doStart(URL launcherJar)

### doStop

protected void doStop()
Maybe called by the application to cause the Sling Application to properly terminate by stopping the OSGi Framework.

After calling this method the Sling Application can be started again by calling the `doStart()` method.

Calling this method multiple times without calling the `doStart()` method in between has no effect after the Sling Application has been terminated.

### getSlingHome

public String getSlingHome()
Return the absolute path to sling home

Returns:
  The path to sling home

### info

protected static void info(String message, Throwable t)

### error

protected static void error(String message, Throwable t)