org.apache.sling.kickstart.control

## Class ControlListener

- java.lang.Object
- - org.apache.sling.kickstart.control.ControlListener

All Implemented Interfaces:
  Runnable

    public class ControlListener
    extends Object
    implements Runnable

The `ControlListener` class is a helper class for the `ControlTarget` class to support in Sling standalone application process communication. This class implements the client and server sides of a TCP/IP based communication channel to control a running Sling application.

The server side listens for commands on a configurable host and port `localhost:63000` by default supporting the following commands:

Command | Description
--- | ---
`status` | Request status information. Currently only OK is sent back. If no connection can be created to the server the client assumes Sling is not running.
`stop` | Requests Sling to shutdown.

### Constructor Summary

Constructors
Constructor and Description
`ControlListener(ControlTarget controlTarget, String listenSpec)` Creates an instance of this control support class.

### Method Summary

All Methods Instance Methods Concrete Methods
`int` `dumpThreads()` Implements the client side of the control connection sending the command to retrieve a thread dump.
`boolean` `listen()` Implements the server side of the control connection starting a thread listening on the host and port configured on setup of this instance.
`void` `run()` Implements the server thread receiving commands from clients and acting upon them.
`int` `shutdownServer()` Implements the client side of the control connection sending the command to shutdown Sling.
`int` `statusServer()` Implements the client side of the control connection sending the command to check whether Sling is active.

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

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

### Constructor Detail

#### ControlListener

    public ControlListener(ControlTarget controlTarget,
                           String listenSpec)

Creates an instance of this control support class.

The host (name or address) and port number of the socket is defined by the `listenSpec` parameter. This parameter is defined as `[ host ":" ] port`. If the parameter is empty or `null` it defaults to localhost:0. If the host name is missing it defaults to localhost.

Parameters:
  `controlTarget` - The Main class reference. This is only required if this instance is used for the server side to listen for remote stop commands. Otherwise this argument may be `null`.
  `listenSpec` - The specification for the host and port for the socket connection. See above for the format of this parameter.

### Method Detail

#### listen

    public boolean listen()

Implements the server side of the control connection starting a thread listening on the host and port configured on setup of this instance.

Returns:
  True if launched successfully

#### shutdownServer

    public int shutdownServer()

Implements the client side of the control connection sending the command to shutdown Sling.

Returns:
  Command Execution Return Code for Stop

#### statusServer

    public int statusServer()

Implements the client side of the control connection sending the command to check whether Sling is active.

Returns:
  Command Execution Return Code for Status

#### dumpThreads

    public int dumpThreads()

Implements the client side of the control connection sending the command to retrieve a thread dump.

Returns:
  Command Execution Return Code for Threads

#### run

    public void run()

Implements the server thread receiving commands from clients and acting upon them.

Specified by:
  `run` in interface `Runnable`