Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
Merge branch 'logout'
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Robertze committed Nov 11, 2015
2 parents 5eb0392 + 8f3a41e commit e2dfa30
Showing 1 changed file with 17 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,43 +102,24 @@ public void closeConnection() {
}

public void restart() {
closeConnection();
String[] mainCommand = System.getProperty("sun.java.command").split(" ");
File f = new File(mainCommand[0]);
try {
String java = System.getProperty("java.home") + "/bin/java";
List<String> vmArguments = ManagementFactory.getRuntimeMXBean()
.getInputArguments();
StringBuffer vmArgsOneLine = new StringBuffer();
for (String arg : vmArguments) {
if (!arg.contains("-agentlib")) {
vmArgsOneLine.append(arg);
vmArgsOneLine.append(" ");
}
}
final StringBuffer cmd = new StringBuffer(java + " " + vmArgsOneLine);
String[] mainCommand = System.getProperty("sun.java.command").split(" ");
if (mainCommand[0].endsWith(".jar")) {
cmd.append("-jar " + new File(mainCommand[0]).getPath());
} else {
cmd.append("-cp \"" + System.getProperty("java.class.path")
+ "\"" + mainCommand[0]);
}
for (int i = 1; i < mainCommand.length; i++) {
cmd.append(" ");
cmd.append(mainCommand[i]);
}
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try {
Runtime.getRuntime().exec(cmd.toString());
} catch (IOException e) {
logger.error("Unable to start application", e);
}
}
});
System.exit(0);
} catch (Exception e) {
logger.error("Unable to restart the application", e);
launch(f);
shutdown();
} catch (IOException e) {
logger.error("Unable to start application", e);
}
}

public void launch(File jar) throws IOException {
String[] run = {"java", "-jar", jar.getAbsolutePath()};
Runtime.getRuntime().exec(run);
}

private void shutdown() throws IOException {
logger.info("Closing current instance");
closeConnection();
System.exit(0);
}
}

0 comments on commit e2dfa30

Please sign in to comment.