1 package org.apidesign.deadlock.startuplock;
3 import java.io.DataOutputStream;
5 import java.io.FileOutputStream;
6 import java.io.IOException;
7 import java.net.ServerSocket;
9 public final class CLIHandler {
11 public static int start(File lockFile) throws IOException {
12 if (lockFile.exists ()) {
13 // read the port number and connect to it
14 int alive = readPortNumber(lockFile);
20 // otherwise try to create the file yourself
21 lockFile.createNewFile();
22 DataOutputStream os = new DataOutputStream(new FileOutputStream(lockFile));
23 ServerSocket server = new ServerSocket();
24 int p = server.getLocalPort();
31 private static int readPortNumber(File lockFile) throws IOException {