Example usage for org.apache.commons.daemon DaemonContext DaemonContext

List of usage examples for org.apache.commons.daemon DaemonContext DaemonContext

Introduction

In this page you can find the example usage for org.apache.commons.daemon DaemonContext DaemonContext.

Prototype

DaemonContext

Source Link

Usage

From source file:es.upv.grycap.opengateway.examples.AppDaemon.java

/**
 * Main entry point to the application./*from www  . jav  a  2  s  . com*/
 * @param args - arguments passed to the application
 * @throws Exception - if the application fails to start the required services
 */
public static void main(final String[] args) throws Exception {
    final AppDaemon daemon = new AppDaemon();
    Runtime.getRuntime().addShutdownHook(new Thread() {
        public void run() {
            try {
                daemon.stop();
            } catch (Exception e) {
                System.err.println(
                        new StringBuffer("Failed to stop application: ").append(e.getMessage()).toString());
            }
            try {
                daemon.destroy();
            } catch (Exception e) {
                System.err.println(
                        new StringBuffer("Failed to stop application: ").append(e.getMessage()).toString());
            }
        }
    });
    daemon.init(new DaemonContext() {
        @Override
        public DaemonController getController() {
            return null;
        }

        @Override
        public String[] getArguments() {
            return args;
        }
    });
    daemon.start();
}

From source file:es.upv.grycap.opengateway.core.test.BootTest.java

@Test
public void testBoot() throws Exception {
    // create new instance
    final TestDaemon daemon = new TestDaemon(clustered);
    assertThat("Test daemon was created", daemon, notNullValue());
    daemon.init(new DaemonContext() {
        @Override//from   w  w w  . jav  a2s  .com
        public DaemonController getController() {
            return null;
        }

        @Override
        public String[] getArguments() {
            return null;
        }
    });
    daemon.start();

    // await until the services are started or fail with timeout
    daemon.awaitHealthy(30l, TimeUnit.SECONDS);

    // await until the services are stopped or fail with timeout
    daemon.awaitStopped(30l, TimeUnit.SECONDS);
}

From source file:es.upv.grycap.opengateway.examples.test.AppDaemonTest.java

@BeforeClass
public static void setUp() throws Exception {
    // install bridges to logging APIs in order to capture Hazelcast and Vert.x messages
    getLogManager().init();//from w ww . j av  a2 s  .c  o  m
    // start the daemon
    daemon = new AppDaemon();
    daemon.init(new DaemonContext() {
        @Override
        public DaemonController getController() {
            return null;
        }

        @Override
        public String[] getArguments() {
            return null;
        }
    });
    daemon.start();
    daemon.awaitHealthy(30l, TimeUnit.SECONDS);
    uri = "http://localhost:" + port;
    // test that the server started
    final Waiter waiter = new Waiter();
    http2Client().asyncGet(uri, newArrayList("text/html"), false, new Callback() {
        @Override
        public void onResponse(final Response response) throws IOException {
            waiter.assertTrue(response.isSuccessful());
            waiter.assertThat(response.body().contentLength(), greaterThan(0l));
            final String payload = response.body().source().readUtf8();
            waiter.assertThat(payload, allOf(notNullValue(), not(equalTo(""))));
            waiter.resume();
        }

        @Override
        public void onFailure(final Request request, final IOException throwable) {
            waiter.fail(throwable);
        }
    });
    waiter.await(30l, TimeUnit.SECONDS);
}

From source file:org.eclipse.scada.da.utils.daemon.DaemonStarter.java

public DaemonStarter(final Class<?> className, final String[] args) throws Exception {
    final Object o = className.newInstance();
    if (!(o instanceof Daemon)) {
        throw new RuntimeException(String.format("Class must implement '%s'", Daemon.class));
    }/*from   w w w.j a v a 2s. c o m*/

    final DaemonController controller = this;
    this.daemon = (Daemon) o;
    this.daemon.init(new DaemonContext() {

        @Override
        public String[] getArguments() {
            return args;
        }

        @Override
        public DaemonController getController() {
            return controller;
        }
    });
    this.daemon.start();

}

From source file:pl.nask.hsn2.service.CuckooService.java

public static void main(final String[] args) throws DaemonInitException, InterruptedException {
    ServiceMain cus = new CuckooService();
    cus.init(new DaemonContext() {
        public DaemonController getController() {
            return null;
        }/*  w w  w.  ja v a  2s  .  c  o m*/

        public String[] getArguments() {
            return args;
        }
    });
    cus.start();
    cus.getServiceRunner().join();
}

From source file:pl.nask.hsn2.service.DNSInfoService.java

public static void main(final String[] args) throws DaemonInitException, InterruptedException {
    ServiceMain dis = new DNSInfoService();
    dis.init(new DaemonContext() {
        public DaemonController getController() {
            return null;
        }//from  w ww  . jav a  2 s.  c  om

        public String[] getArguments() {
            return args;
        }
    });
    dis.start();
    dis.getServiceRunner().join();
}

From source file:pl.nask.hsn2.service.JsAnalyzerService.java

public static void main(final String[] args) throws DaemonInitException, InterruptedException {
    ServiceMain jss = new JsAnalyzerService();
    jss.init(new DaemonContext() {
        public DaemonController getController() {
            return null;
        }/*  w w w  . j  av  a  2s . c  om*/

        public String[] getArguments() {
            return args;
        }
    });
    jss.start();
    jss.getServiceRunner().join();
}

From source file:pl.nask.hsn2.service.Md5ToSSDeepService.java

public static void main(final String[] args) throws DaemonInitException, InterruptedException {
    ServiceMain mts = new Md5ToSSDeepService();
    mts.init(new DaemonContext() {
        public DaemonController getController() {
            return null;
        }//from   w ww .  j a v  a  2s . co  m

        public String[] getArguments() {
            return args;
        }
    });
    mts.start();
    mts.getServiceRunner().join();
}

From source file:pl.nask.hsn2.service.SwfService.java

public static void main(final String[] args) throws DaemonInitException, InterruptedException {
    SwfService swfs = new SwfService();
    swfs.init(new DaemonContext() {
        public DaemonController getController() {
            return null;
        }/*from   ww w.  j a v  a 2s .c  o m*/

        public String[] getArguments() {
            return args;
        }
    });
    swfs.start();
}