List of usage examples for org.apache.commons.daemon DaemonContext getArguments
public String[] getArguments();
String
arguments supplied by the environment. From source file:com.yahoo.sshd.server.Sshd.java
/** * Initialize this <code>Daemon</code> instance. * <p>//from ww w . java2 s. c om * This method gets called once the JVM process is created and the <code>Daemon</code> instance is created thru its * empty public constructor. * </p> * <p> * 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 <i>super-user</i> privileges. * </p> * <p> * For example, it might be wise to create <code>ServerSocket</code> instances within the scope of this method, and * perform all operations requiring <i>super-user</i> privileges in the underlying operating system. * </p> * <p> * Apart from set up and allocation of native resources, this method must not start the actual operation of the * <code>Daemon</code> (such as starting threads calling the <code>ServerSocket.accept()</code> method) as this * would impose some serious security hazards. The start of operation must be performed in the <code>start()</code> * method. * </p> * * @param context A <code>DaemonContext</code> 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. */ @Override public void init(DaemonContext arg0) throws DaemonInitException, Exception { // save our arguments this.args = arg0.getArguments(); }
From source file:com.seanbright.osgi.launcher.Daemon.java
@Override public void init(DaemonContext context) throws DaemonInitException, Exception { this.context = context; frameworkProps = loadFrameworkProperties( context.getArguments().length == 0 ? "framework.properties" : context.getArguments()[0]); factory = FrameworkFactories.get();/*from w w w.j ava 2 s . c o m*/ }
From source file:mecard.MetroService.java
@Override public void init(DaemonContext dc) throws DaemonInitException, Exception { System.out.println(new Date() + " initializing service..."); ARGS = dc.getArguments(); }
From source file:net.meddeb.pqmessenger.MsgDaemon.java
@Override public void init(DaemonContext daemonContext) throws DaemonInitException, Exception { String[] args = daemonContext.getArguments(); connected = false;/*from ww w . j av a 2 s. co m*/ msgEngine = new MsgEngine(args); logger = Logger.getLogger(this.getClass()); mainThread = new Thread() { @Override public synchronized void start() { MsgDaemon.this.stopped = false; super.start(); } @Override public void run() { logger.info(""); logger.info("-------------------------"); logger.info(LoggingMsg.getLog("pqMsgStart")); logger.info("-------------------------"); while (!stopped) { logger.info(LoggingMsg.getLog("pqMsgTrycnx")); msgEngine.startConnection(); if (msgEngine.isConnectionStarted()) { connected = true; } else { String msg = LoggingMsg.getLog("pqMsgCnxFail"); msg = MessageFormat.format(msg, msgEngine.getStrTimeretry()); logger.info(msg); } while ((true) && (msgEngine.isConnectionStarted())) { try { Thread.sleep(1000); } catch (InterruptedException e) { logger.error("e: " + e.getMessage()); } } if (connected) { logger.info(LoggingMsg.getLog("pqMsgdcnx")); connected = false; } try { Thread.sleep(msgEngine.getTimeRetry()); } catch (InterruptedException e) { logger.error("e: " + e.getMessage()); } //wait } } }; }
From source file:com.envirover.spl.SPLDaemon.java
@Override public void init(DaemonContext context) throws DaemonInitException, Exception { if (!config.init(context.getArguments())) throw new DaemonInitException("Invalid configuration."); ClassLoader loader = SPLDaemon.class.getClassLoader(); InputStream params = loader.getResourceAsStream(DEFAULT_PARAMS_FILE); if (params != null) { MAVLinkShadow.getInstance().loadParams(params); params.close();//w ww. j av a 2 s. c om } else { logger.warn("File 'default.params' with initial parameters values not found."); } MAVLinkMessageQueue mtMessageQueue = new MAVLinkMessageQueue(config.getQueueSize()); tcpServer = new MAVLinkTcpServer(config.getMAVLinkPort(), mtMessageQueue); MAVLinkMessageQueue moMessageQueue = new MAVLinkMessageQueue(config.getQueueSize()); MOMessageHandler moHandler = new MOMessageHandler(moMessageQueue); httpServer = HttpServer.create(new InetSocketAddress(config.getRockblockPort()), 0); httpServer.createContext(config.getHttpContext(), new RockBlockHttpHandler(moHandler, config.getRockBlockIMEI())); httpServer.setExecutor(null); // TODO: Broadcast MO messages to all the connected clients. RockBlockClient rockblock = new RockBlockClient(config.getRockBlockIMEI(), config.getRockBlockUsername(), config.getRockBlockPassword(), config.getRockBlockURL()); MTMessagePump mtMsgPump = new MTMessagePump(mtMessageQueue, rockblock); mtMsgPumpThread = new Thread(mtMsgPump, "mt-message-pump"); WSEndpoint.setMTQueue(mtMessageQueue); wsServer = new Server("localhost", config.getWSPort(), "/gcs", WSEndpoint.class); }
From source file:com.devti.JavaXMPPBot.JavaXMPPBot.java
@Override public void init(DaemonContext context) throws DaemonInitException, Exception { // Get paths//from w w w . jav a2 s . co m String[] args = context.getArguments(); Path configsDir, logsDir; if (args.length > 0) { configsDir = Paths.get(args[0]); } else { configsDir = Paths.get(System.getProperty("user.home"), "JavaXMPPBot", "conf.d"); } if (args.length > 1) { logsDir = Paths.get(args[1]); } else { logsDir = Paths.get(System.getProperty("user.home"), "JavaXMPPBot", "log.d"); } if (!logsDir.toFile().exists()) { throw new DaemonInitException("Logs directory '" + logsDir + "' doesn't exist."); } // Get bot configs List<Path> botConfigs = new ArrayList<>(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(configsDir, "*.conf")) { for (Path entry : stream) { botConfigs.add(entry); } } catch (DirectoryIteratorException e) { throw new DaemonInitException( "Can't list configs directory '" + configsDir + "': " + e.getLocalizedMessage()); } if (botConfigs.size() <= 0) { throw new DaemonInitException("There is no .conf files in '" + configsDir + "' directory."); } // Load bots for (Path config : botConfigs) { String id = config.getFileName().toString().replaceFirst(".conf$", ""); Path log = Paths.get(logsDir.toString(), id + ".log"); try { bots.add(new XMPPBot(id, config, new Log(log))); } catch (Exception e) { throw new DaemonInitException( "Can't load a bot with config file '" + config + "': " + e.getLocalizedMessage()); } } }
From source file:es.upv.grycap.opengateway.examples.AppDaemon.java
@Override public void init(final DaemonContext daemonContext) throws Exception { // parse application arguments CommandLine cmd = null;//from www . ja v a 2s . c om try { cmd = parseParameters(daemonContext.getArguments(), new Options()); } catch (Exception e) { logger.error("Parsing options failed.", e); System.exit(1); } // load configuration properties loadConfigOptions(cmd); // create load balancer (a real implementation of the load balancer should be used in production) final LoadBalancerClient loadBalancerClient = new SingleNodeLoadBalancer() .addService("opengateway-example.product.v1", "http://localhost:9080/products") .addService("opengateway-example.shipping.v1", "http://localhost:9080/shipping"); // create service options from configuration final VertxOptions vertxOptions = createVertxOptions(true); final DeploymentOptions deploymentOptions = createDeploymentOptions(); // configure and start the service manager serviceManager = new ServiceManager(newHashSet(new VertxService( newArrayList(SimpleRestServer.class, SecureRestServer.class, WebSocketsServer.class), vertxOptions, deploymentOptions, loadBalancerClient))); super.init(daemonContext); }
From source file:me.preilly.SimplePush.java
@Override public void init(DaemonContext dc) throws DaemonInitException { LOGGER.info("initializing got deamoncontext {}", dc); args = dc.getArguments(); }
From source file:com.msp.jsvc.JRubyDaemon.java
/** *///ww w.jav a 2s. c o m public void init(DaemonContext arguments) throws Exception { this.controller = arguments.getController(); init(arguments.getArguments()); }
From source file:com.amazonaws.codepipeline.jobworker.JobWorkerDaemon.java
/** * Initializes the daemon.//from w ww . j a va 2 s . c o m * @param context daemon context. * @throws DaemonInitException exception during initialization */ @Override public void init(final DaemonContext context) throws DaemonInitException { LOGGER.info("Initialize daemon."); final String[] arguments = context.getArguments(); if (arguments != null) { LOGGER.debug(String.format("JobWorker arguments '%s'", String.join(", ", arguments))); loadConfiguration(arguments); } }