
org.rzo.yajsw.app.WrapperMainServiceWin Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wrapperApp Show documentation
Show all versions of wrapperApp Show documentation
YAJSW is a java centric implementation of the java service wrapper by tanuki (JSW).
It aims at being mostly configuration compliant with the original. It should therefore be easy to switch from JSW to YAJSW.
The newest version!
/* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
package org.rzo.yajsw.app;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import jnacontrib.win32.Win32Service;
import org.rzo.yajsw.Constants;
import org.rzo.yajsw.boot.WrapperLoader;
import org.rzo.yajsw.config.YajswConfigurationImpl;
import org.rzo.yajsw.os.OperatingSystem;
import org.rzo.yajsw.os.Process;
import org.rzo.yajsw.os.StopableService;
import org.rzo.yajsw.os.ms.win.w32.WindowsXPProcess;
import org.rzo.yajsw.wrapper.WrappedProcess;
import org.rzo.yajsw.wrapper.WrappedProcessFactory;
import org.rzo.yajsw.wrapper.WrappedProcessList;
// TODO: Auto-generated Javadoc
/**
* The Class WrapperMainService.
*/
public class WrapperMainServiceWin extends Win32Service implements StopableService
{
/** The w. */
static volatile WrappedProcessList wList = new WrappedProcessList();
static volatile WrappedProcess w;
static volatile boolean _waitOnStop = false;
/** The service. */
static WrapperMainServiceWin service;
static ExecutorService pool = Executors.newFixedThreadPool(5);
/**
* Instantiates a new wrapper main service.
*/
public WrapperMainServiceWin()
{
}
private static int getPriority(YajswConfigurationImpl config)
{
String priority = config.getString("wrapper.ntservice.process_priority", "");
if ("LOW".equals(priority))
return Process.PRIORITY_LOW;
else if ("BELOW_NORMAL".equals(priority))
return Process.PRIORITY_BELOW_NORMAL;
else if ("NORMAL".equals(priority))
return Process.PRIORITY_NORMAL;
else if ("ABOVE_NORMAL".equals(priority))
return Process.PRIORITY_ABOVE_NORMAL;
else if ("HIGH".equals(priority))
return Process.PRIORITY_HIGH;
return Process.PRIORITY_UNDEFINED;
}
// this is the wrapper for services
/**
* The main method.
*
* @param args
* the arguments
*/
public static void main(String[] args)
{
String wrapperJar = WrapperLoader.getWrapperJar();
// set home dir of the service to the wrapper jar parent, so that we may find required libs
String homeDir = new File(wrapperJar).getParent();
if (!OperatingSystem.instance().setWorkingDir(homeDir))
System.out.println("could not set working dir. pls check configuration or user rights :"+homeDir);
YajswConfigurationImpl _config = new YajswConfigurationImpl(false);
boolean debug = _config.getBoolean("wrapper.debug", false);
service = new WrapperMainServiceWin();
// set service shutdown timeout
service.setServiceName(_config.getString("wrapper.ntservice.name"));
long timeout = _config.getInt("wrapper.shutdown.timeout", Constants.DEFAULT_SHUTDOWN_TIMEOUT) * 1000;
timeout += _config.getInt("wrapper.script.STOP.timeout", 0) * 1000;
timeout += _config.getInt("wrapper.script.SHUTDOWN.timeout", 0) * 1000;
timeout += _config.getInt("wrapper.script.IDLE.timeout", 0) * 1000;
timeout += _config.getInt("wrapper.script.ABORT.timeout", 0) * 1000;
if (timeout > Integer.MAX_VALUE)
timeout = Integer.MAX_VALUE;
service.setStopTimeout((int) timeout);
timeout = _config.getInt("wrapper.startup.timeout", Constants.DEFAULT_STARTUP_TIMEOUT) * 1000;
if (timeout > Integer.MAX_VALUE)
timeout = Integer.MAX_VALUE;
service.setStartupTimeout((int) timeout);
service.setAutoReportStartup(_config.getBoolean("wrapper.ntservice.autoreport.startup", true));
if (_config.containsKey("wrapperx.config"))
{
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy