All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.commons.daemon.Daemon Maven / Gradle / Ivy

Go to download

Apache Commons Daemon software provides an alternative invocation mechanism for unix-daemon-like Java code.

The newest version!
/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.apache.commons.daemon;

/**
 * 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. *

* @author Pier Fumagalli * @version $Id: Daemon.java 1204010 2011-11-19 16:15:23Z ggregory $ */ public interface Daemon { /** * Initializes 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. *

* * @param context A DaemonContext object used to * communicate with the container. * @exception DaemonInitException An exception that prevented * initialization where you want to display a nice message to the user, * rather than a stack trace. * @exception Exception Any exception preventing a successful * initialization. */ public void init(DaemonContext context) throws DaemonInitException, Exception; /** * Starts 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. */ public void start() throws Exception; /** * Stops 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(). */ public void stop() throws Exception; /** * Frees 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. */ public void destroy(); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy