Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.commons.daemon
Interface Daemon

All Known Implementing Classes:
  DaemonWrapper

    public interface Daemon

This interface provides support for native daemon invocation. Using a platform dependant helper program, classes that implement the `Daemon` interface can be initialized, started and stopped according to the conventions of the underlying operating system.

Implementors of this interface must also provide a public constructor with no arguments so that instances can be created in an automated fashion.

Version:
  1.0 (CVS $Revision: 1023303 $)
Author:
  Pier Fumagalli

Method Summary
`void` | `destroy()` Free any resources allocated by this daemon such as file descriptors or sockets.
`void` | `init(DaemonContext context)` Initialize this `Daemon` instance.
`void` | `start()` Start the operation of this `Daemon` instance.
`void` | `stop()` Stop the operation of this `Daemon` instance.

Method Detail

### init

    void init(DaemonContext context)
              throws DaemonInitException,
                     java.lang.Exception

  Initialize this `Daemon` instance.

  This method gets called once the JVM process is created and the `Daemon` instance is created thru its empty public constructor.

  Under certain operating systems (typically Unix based operating systems) and if the native invocation framework is configured to do so, this method might be called with super-user privileges.

  For example, it might be wise to create `ServerSocket` instances within the scope of this method, and perform all operations requiring super-user privileges in the underlying operating system.

  Apart from set up and allocation of native resources, this method must not start the actual operation of the `Daemon` (such as starting threads calling the `ServerSocket.accept()` method) as this would impose some serious security hazards. The start of operation must be performed in the `start()` method.

  Parameters:
    `context` - A `DaemonContext` object used to communicate with the container.
  Throws:
    `DaemonInitException` - An exception that prevented initialization where you want to display a nice message to the user, rather than a stack trace.
    `java.lang.Exception` - Any exception preventing a successful initialization.

### start

    void start()
               throws java.lang.Exception

  Start the operation of this `Daemon` instance. This method is to be invoked by the environment after the init() method has been successfully invoked and possibly the security level of the JVM has been dropped. Implementors of this method are free to start any number of threads, but need to return control after having done that to enable invocation of the stop()-method.

  Throws:
    `java.lang.Exception`

### stop

    void stop()
              throws java.lang.Exception

  Stop the operation of this `Daemon` instance. Note that the proper place to free any allocated resources such as sockets or file descriptors is in the destroy method, as the container may restart the Daemon by calling start() after stop().

  Throws:
    `java.lang.Exception`

### destroy

    void destroy()

  Free any resources allocated by this daemon such as file descriptors or sockets. This method gets called by the container after stop() has been called, before the JVM exits. The Daemon can not be restarted after this method has been called without a new call to the init() method.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright (c) 2002-2011 - Apache Software Foundation