Search in sources :

Example 6 with IgniteState

use of org.apache.ignite.IgniteState in project ignite by apache.

the class CommandLineStartup method main.

/**
 * Main entry point.
 *
 * @param args Command line arguments.
 */
public static void main(String[] args) {
    if (!QUITE) {
        X.println("Ignite Command Line Startup, ver. " + ACK_VER_STR);
        X.println(COPYRIGHT);
        X.println();
    }
    if (args.length > 1)
        exit("Too many arguments.", true, -1);
    if (args.length > 0 && isHelp(args[0]))
        exit(null, true, 0);
    if (args.length > 0 && args[0].isEmpty())
        exit("Empty argument.", true, 1);
    if (args.length > 0 && args[0].charAt(0) == '-')
        exit("Invalid arguments: " + args[0], true, -1);
    String cfg = null;
    if (args.length > 0)
        cfg = args[0];
    else {
        try {
            cfg = askConfigFile();
            if (cfg == null)
                exit(null, false, 0);
        } catch (IOException e) {
            exit("Failed to run interactive mode: " + e.getMessage(), false, -1);
        }
    }
    // Name of the grid loaded from the command line (unique in JVM).
    final String igniteInstanceName;
    try {
        igniteInstanceName = G.start(cfg).name();
    } catch (Throwable e) {
        e.printStackTrace();
        String note = "";
        if (X.hasCause(e, ClassNotFoundException.class))
            note = "\nNote! You may use 'USER_LIBS' environment variable to specify your classpath.";
        exit("Failed to start grid: " + e.getMessage() + note, false, -1);
        if (e instanceof Error)
            throw e;
        return;
    }
    // Exit latch for the grid loaded from the command line.
    final CountDownLatch latch = new CountDownLatch(1);
    G.addListener(new IgnitionListener() {

        @Override
        public void onStateChange(String name, IgniteState state) {
            // Skip all grids except loaded from the command line.
            if (!F.eq(igniteInstanceName, name))
                return;
            if (state == STOPPED || state == STOPPED_ON_SEGMENTATION)
                latch.countDown();
        }
    });
    try {
        latch.await();
    } catch (InterruptedException e) {
        X.error("Start was interrupted (exiting): " + e.getMessage());
    }
    String code = System.getProperty(IGNITE_RESTART_CODE);
    if (code != null)
        try {
            System.exit(Integer.parseInt(code));
        } catch (NumberFormatException ignore) {
            System.exit(0);
        }
    else
        System.exit(0);
}
Also used : IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) IgnitionListener(org.apache.ignite.IgnitionListener) IgniteState(org.apache.ignite.IgniteState)

Example 7 with IgniteState

use of org.apache.ignite.IgniteState in project ignite by apache.

the class GridCommandLineLoaderTest method testLoader.

/**
 * @throws Exception If failed.
 */
public void testLoader() throws Exception {
    String path = U.getIgniteHome() + GRID_CFG_PATH;
    info("Loading Grid from configuration file: " + path);
    G.addListener(new IgnitionListener() {

        @Override
        public void onStateChange(String name, IgniteState state) {
            if (state == STARTED) {
                info("Received started notification from grid: " + name);
                latch.countDown();
                G.stop(name, true);
            }
        }
    });
    CommandLineStartup.main(new String[] { path });
}
Also used : IgnitionListener(org.apache.ignite.IgnitionListener) IgniteState(org.apache.ignite.IgniteState)

Aggregations

IgniteState (org.apache.ignite.IgniteState)7 IgnitionListener (org.apache.ignite.IgnitionListener)7 CountDownLatch (java.util.concurrent.CountDownLatch)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)2 Nullable (org.jetbrains.annotations.Nullable)2 File (java.io.File)1 IOException (java.io.IOException)1 Random (java.util.Random)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CommandLine (org.apache.commons.cli.CommandLine)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1 Options (org.apache.commons.cli.Options)1 ParseException (org.apache.commons.cli.ParseException)1 PosixParser (org.apache.commons.cli.PosixParser)1 IgniteException (org.apache.ignite.IgniteException)1 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)1 BeansException (org.springframework.beans.BeansException)1