use of org.apache.ignite.IgnitionListener 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);
}
use of org.apache.ignite.IgnitionListener 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 });
}
Aggregations