Skip to content

Commit

Permalink
Merge pull request #352 from Nycander/main-stop
Browse files Browse the repository at this point in the history
Adds Main.stop() and cleans up a few log-strings.
  • Loading branch information
Olof Nilsson committed Dec 1, 2014
2 parents 3a7932a + 110bd30 commit a2db472
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions core/src/main/java/com/findwise/hydra/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public Main(CoreConfiguration coreConfiguration) {
private RESTServer server = null;

private volatile boolean shuttingDown = false;


private static Main main;

public static void main(String[] args) {
if (args.length > 1) {
logger.error("Some parameters on command line were ignored.");
Expand All @@ -43,7 +45,17 @@ public static void main(String[] args) {
conf = getConfiguration(null);
}

new Main(conf).startup();
main = new Main(conf);
main.startup();
}

/**
* This method should be used by service wrappers to properly shutdown Hydra.
*/
public static void stop(@SuppressWarnings("unused") String[] args) {
if (main != null) { // No need to shut things down if main never was
main.shutdown();
}
}

public void startup() {
Expand Down Expand Up @@ -103,7 +115,7 @@ public void startup() {
try {
nm.blockingStart();
} catch (IOException e) {
logger.error("Unable to start nodemaster... Shutting down.");
logger.error("Unable to start "+nm.getClass().getSimpleName()+"... Shutting down.");
shutdown();
}
}
Expand All @@ -117,10 +129,10 @@ public void shutdown() {
try {
simpleSocketServer.close();
} catch (Exception e) {
logger.debug("Caught exception while shutting down simpleSocketServer. Was it not started?", e);
logger.debug("Caught exception while shutting down "+simpleSocketServer.getClass().getSimpleName()+". Was it not started?", e);
}
} else {
logger.trace("simpleSocketServer was null");
logger.trace(simpleSocketServer.getClass().getSimpleName()+" was null");
}

if (server != null) {
Expand Down Expand Up @@ -194,6 +206,8 @@ public HydraKiller(long killDelay) {

@Override
public void run() {
currentThread().setName(getClass().getSimpleName());

try {
logger.debug("Hydra will be killed in " + killDelay + "ms unless it is shut down gracefully before then");
Thread.sleep(killDelay);
Expand Down

0 comments on commit a2db472

Please sign in to comment.