Skip to content

Commit 146846a

Browse files
committed
Format code using IDEA default.
1 parent 5b3a614 commit 146846a

12 files changed

Lines changed: 32 additions & 39 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,16 @@ public static BitSet getAffinity() {
155155
return AFFINITY_IMPL.getAffinity();
156156
}
157157

158+
public static void setAffinity(final BitSet affinity) {
159+
AFFINITY_IMPL.setAffinity(affinity);
160+
}
161+
158162
public static void setAffinity(int cpu) {
159163
BitSet affinity = new BitSet(Runtime.getRuntime().availableProcessors());
160164
affinity.set(cpu);
161165
setAffinity(affinity);
162166
}
163167

164-
public static void setAffinity(final BitSet affinity) {
165-
AFFINITY_IMPL.setAffinity(affinity);
166-
}
167-
168168
public static int getCpu() {
169169
return AFFINITY_IMPL.getCpu();
170170
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
import org.slf4j.Logger;
2323
import org.slf4j.LoggerFactory;
2424

25-
import java.io.*;
25+
import java.io.File;
26+
import java.io.IOException;
2627

2728
/**
2829
* @author Rob Austin.
@@ -35,7 +36,6 @@ enum LockCheck {
3536
static final boolean IS_LINUX = OS.startsWith("linux");
3637
private static final int EMPTY_PID = Integer.MIN_VALUE;
3738

38-
3939
private static final LockChecker lockChecker = FileLockBasedLockChecker.getInstance();
4040

4141
static long getPID() {
@@ -87,7 +87,7 @@ static boolean isProcessRunning(long pid) {
8787
* below
8888
*/
8989
private synchronized static void storePid(long processID, int cpu) throws IOException {
90-
if(!lockChecker.obtainLock(cpu, Long.toString(processID))) {
90+
if (!lockChecker.obtainLock(cpu, Long.toString(processID))) {
9191
throw new IOException(String.format("Cannot obtain file lock for cpu %d", cpu));
9292
}
9393
}
@@ -99,10 +99,10 @@ private synchronized static boolean isLockFree(int id) {
9999
static int getProcessForCpu(int core) throws IOException {
100100
String meta = lockChecker.getMetaInfo(core);
101101

102-
if(meta != null && !meta.isEmpty()) {
102+
if (meta != null && !meta.isEmpty()) {
103103
try {
104104
return Integer.parseInt(meta);
105-
} catch(NumberFormatException e) {
105+
} catch (NumberFormatException e) {
106106
//nothing
107107
}
108108
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
import org.slf4j.Logger;
2222
import org.slf4j.LoggerFactory;
2323

24-
import java.io.IOException;
25-
import java.nio.file.Files;
26-
import java.nio.file.Paths;
2724
import java.util.NavigableMap;
2825
import java.util.TreeMap;
2926

affinity/src/main/java/net/openhft/affinity/lockchecker/FileBasedLockChecker.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,25 @@
1313
@SuppressWarnings("ResultOfMethodCallIgnored")
1414
public class FileBasedLockChecker implements LockChecker {
1515

16-
private static final Logger LOGGER = LoggerFactory.getLogger(FileBasedLockChecker.class);
1716
static final SimpleDateFormat df = new SimpleDateFormat("yyyy.MM" + ".dd 'at' HH:mm:ss z");
18-
17+
private static final Logger LOGGER = LoggerFactory.getLogger(FileBasedLockChecker.class);
1918
private static final LockChecker instance = new FileBasedLockChecker();
2019

20+
protected FileBasedLockChecker() {
21+
//nothing
22+
}
23+
2124
public static LockChecker getInstance() {
2225
return instance;
2326
}
2427

25-
protected FileBasedLockChecker() {
26-
//nothing
28+
private static File tmpDir() {
29+
final File tempDir = new File(System.getProperty("java.io.tmpdir"));
30+
31+
if (!tempDir.exists())
32+
tempDir.mkdirs();
33+
34+
return tempDir;
2735
}
2836

2937
@Override
@@ -72,13 +80,4 @@ public String getMetaInfo(int id) throws IOException {
7280
protected File toFile(int id) {
7381
return new File(tmpDir(), "cpu-" + id + ".lock");
7482
}
75-
76-
private static File tmpDir() {
77-
final File tempDir = new File(System.getProperty("java.io.tmpdir"));
78-
79-
if (!tempDir.exists())
80-
tempDir.mkdirs();
81-
82-
return tempDir;
83-
}
8483
}

affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,16 @@ public class FileLockBasedLockChecker extends FileBasedLockChecker {
3131
private static final LockChecker instance = new FileLockBasedLockChecker();
3232
private static final HashSet<StandardOpenOption> openOptions = new HashSet<>(Arrays.asList(CREATE_NEW, WRITE, READ, SYNC));
3333
private static final FileAttribute<Set<PosixFilePermission>> fileAttr = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rw-rw-rw-"));
34-
35-
public static LockChecker getInstance() {
36-
return instance;
37-
}
38-
3934
private final LockReference[] locks = new LockReference[MAX_CPUS_SUPPORTED];
4035

4136
protected FileLockBasedLockChecker() {
4237
//nothing
4338
}
4439

40+
public static LockChecker getInstance() {
41+
return instance;
42+
}
43+
4544
@Override
4645
public boolean isLockFree(int id) {
4746
return isLockFree(toFile(id), id);

affinity/src/main/java/net/openhft/affinity/lockchecker/LockReference.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package net.openhft.affinity.lockchecker;
22

3-
43
import java.nio.channels.FileChannel;
54
import java.nio.channels.FileLock;
65

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ public class AffinityTestMain {
1515
public static void main(String[] args) {
1616

1717
int cpus = 1;
18-
if(args.length == 0) {
18+
if (args.length == 0) {
1919
cpus = AffinityLock.cpuLayout().cpus() / 12;
2020
} else {
2121
cpus = Integer.valueOf(args[0]);
2222
}
2323

24-
for(int i=0; i<cpus; i++) {
24+
for (int i = 0; i < cpus; i++) {
2525
acquireAndDoWork();
2626
}
2727
}
@@ -35,7 +35,7 @@ public void run() {
3535
String threadName = Thread.currentThread().getName();
3636
System.out.println("Thread (" + threadName + ") locked onto cpu " + al.cpuId());
3737

38-
while(true) {
38+
while (true) {
3939
System.out.println(df.format(new Date()) + " - Thread (" + threadName + ") doing work on cpu " + al.cpuId() + ". IsAllocated = " + al.isAllocated() + ", isBound = " + al.isBound() + ". " + al.toString());
4040

4141
try {

affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public void shouldReturnLockForSpecifiedCpu() {
231231

232232
@Test
233233
public void lockFilesShouldBeRemovedOnRelease() {
234-
if(System.getProperty("os.name").toLowerCase().startsWith("win")) {
234+
if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
235235
return;//doesn't work on Windows
236236
}
237237
final AffinityLock lock = AffinityLock.acquireLock();

affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public class FileLockLockCheckTest {
3636

3737
private static final String TMP = System.getProperty("java.io.tmpdir");
3838
private static final String TARGET = System.getProperty("project.build.directory", findTarget());
39-
private int cpu = 11;
4039
private final TestFileLockBasedLockChecker lockChecker = new TestFileLockBasedLockChecker();
40+
private int cpu = 11;
4141

4242
private static String findTarget() {
4343
for (File dir = new File(System.getProperty("user.dir")); dir != null; dir = dir.getParentFile()) {

affinity/src/test/java/net/openhft/affinity/LockCheckTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public class LockCheckTest {
3737

3838
private static final String TMP = System.getProperty("java.io.tmpdir");
3939
private static final String TARGET = System.getProperty("project.build.directory", findTarget());
40-
private int cpu = 11;
4140
private final TestFileBasedLockChecker lockChecker = new TestFileBasedLockChecker();
41+
private int cpu = 11;
4242

4343
private static String findTarget() {
4444
for (File dir = new File(System.getProperty("user.dir")); dir != null; dir = dir.getParentFile()) {

0 commit comments

Comments
 (0)