Skip to content

Commit

Permalink
Write PID to pid file
Browse files Browse the repository at this point in the history
  • Loading branch information
jsyrjala committed Dec 1, 2014
1 parent 7e99dc3 commit 53287ed
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.management.ManagementFactory;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.nitorcreations.nflow.jetty.StartNflow;
import com.nitorcreations.nflow.metrics.NflowMetricsContext;

public class NflowPerfTestServer {
private static final Logger logger = LoggerFactory.getLogger(NflowPerfTestServer.class);
private final int port;
private final Map<String, Object> props;

Expand All @@ -26,9 +31,12 @@ public void start(File pidFile) throws Exception {
writePidFile(pidFile);
}

private void writePidFile(File pidFile) {
// TODO Auto-generated method stub
String name = ManagementFactory.getRuntimeMXBean().getName();
private void writePidFile(File pidFile) throws IOException {
String pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0];
try (PrintWriter writer = new PrintWriter(pidFile)) {
logger.info("PID is {}. Writing it to file {}", pid, pidFile.getAbsolutePath());
writer.print(pid);
}
}

public static void main(String[] args) throws Exception {
Expand Down

0 comments on commit 53287ed

Please sign in to comment.