Skip to content

Commit 4628217

Browse files
author
Rob Austin
committed
cleanup tests and added LockCheck and test cases
1 parent eb6b895 commit 4628217

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

affinity/src/main/java/net/openhft/affinity/LockCheck.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55
import java.io.*;
66
import java.text.SimpleDateFormat;
77
import java.util.Date;
8-
import java.util.function.Supplier;
98

109

1110
/**
1211
* @author Rob Austin.
1312
*/
14-
public class LockCheck {
13+
class LockCheck {
1514

1615
static final String TMP = System.getProperty("java.io.tmpdir");
17-
public static final String TARGET = System.getProperty("project.build.directory", findTarget());
1816
private static final String OS = System.getProperty("os.name").toLowerCase();
1917
static final boolean IS_LINUX = OS.startsWith("linux");
20-
private ThreadLocal<SimpleDateFormat> df = ThreadLocal.withInitial(new Supplier() {
18+
19+
private ThreadLocal<SimpleDateFormat> df = new ThreadLocal() {
20+
2121
@Override
22-
public Object get() {
22+
protected Object initialValue() {
2323
return new SimpleDateFormat("yyyy.MM" + ".dd 'at' HH:mm:ss z");
2424
}
25-
});
25+
};
2626

2727
private static String findTarget() {
2828
for (File dir = new File(System.getProperty("user.dir")); dir != null; dir = dir.getParentFile()) {
@@ -41,10 +41,10 @@ private static String findTarget() {
4141
* @return
4242
* @throws IOException
4343
*/
44-
public boolean isCoreAlreadyAssigned(int core, long processID) throws IOException {
44+
boolean isCoreAlreadyAssigned(int core, long processID) throws IOException {
4545

46-
File file = new File(tmpDir(), "core-" + core);
47-
boolean exists = file.exists();
46+
final File file = new File(tmpDir(), "core-" + core + ".lock");
47+
final boolean exists = file.exists();
4848

4949
if (!exists) {
5050
// create a lock file
@@ -58,7 +58,6 @@ public boolean isCoreAlreadyAssigned(int core, long processID) throws IOExceptio
5858
}
5959
return false;
6060
}
61-
6261
}
6362

6463
private void replacePid(long processID, File file) throws IOException {
@@ -90,7 +89,7 @@ private void storePid(long processID, File coreFile) throws IOException {
9089
}
9190

9291
int getPid(int core) throws IOException {
93-
return getPid(new File(tmpDir(), "core-" + core));
92+
return getPid(new File(tmpDir(), "core-" + core + ".lock"));
9493
}
9594

9695
private int getPid(@NotNull File coreFile) throws IOException {
@@ -112,5 +111,4 @@ private File tmpDir() {
112111
return tempDir;
113112
}
114113

115-
116114
}

0 commit comments

Comments
 (0)