Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tighten up mill/main/client/lock files #3366

Merged
merged 3 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions main/client/src/mill/main/client/lock/FileLock.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

class FileLock extends Lock {

private RandomAccessFile raf;
private FileChannel chan;
final private RandomAccessFile raf;
final private FileChannel chan;

public FileLock(String path) throws Exception {
raf = new RandomAccessFile(path, "rw");
Expand Down
2 changes: 1 addition & 1 deletion main/client/src/mill/main/client/lock/FileLocked.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class FileLocked implements Locked {

protected java.nio.channels.FileLock lock;
final protected java.nio.channels.FileLock lock;

public FileLocked(java.nio.channels.FileLock lock) {
this.lock = lock;
Expand Down
2 changes: 1 addition & 1 deletion main/client/src/mill/main/client/lock/FileTryLocked.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package mill.main.client.lock;

public class FileTryLocked extends FileLocked implements TryLocked{
class FileTryLocked extends FileLocked implements TryLocked{
public FileTryLocked(java.nio.channels.FileLock lock) {
super(lock);
}
Expand Down
34 changes: 20 additions & 14 deletions main/client/src/mill/main/client/lock/Locks.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,32 @@

import mill.main.client.ServerFiles;

public class Locks implements AutoCloseable {
final public class Locks implements AutoCloseable {

public Lock processLock;
public Lock serverLock;
public Lock clientLock;
final public Lock processLock;
final public Lock serverLock;
final public Lock clientLock;

public Locks(Lock processLock, Lock serverLock, Lock clientLock){
this.processLock = processLock;
this.serverLock = serverLock;
this.clientLock = clientLock;
}

public static Locks files(String lockBase) throws Exception {
return new Locks(){{
processLock = new FileLock(lockBase + "/" + ServerFiles.processLock);
serverLock = new FileLock(lockBase + "/" + ServerFiles.serverLock);
clientLock = new FileLock(lockBase + "/" + ServerFiles.clientLock);
}};
return new Locks(
new FileLock(lockBase + "/" + ServerFiles.processLock),
new FileLock(lockBase + "/" + ServerFiles.serverLock),
new FileLock(lockBase + "/" + ServerFiles.clientLock)
);
}

public static Locks memory() {
return new Locks(){{
this.processLock = new MemoryLock();
this.serverLock = new MemoryLock();
this.clientLock = new MemoryLock();
}};
return new Locks(
new MemoryLock(),
new MemoryLock(),
new MemoryLock()
);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion main/client/src/mill/main/client/lock/MemoryLock.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class MemoryLock extends Lock {

private ReentrantLock innerLock = new ReentrantLock();
final private ReentrantLock innerLock = new ReentrantLock();

public boolean probe() {
return !innerLock.isLocked();
Expand Down
2 changes: 1 addition & 1 deletion main/client/src/mill/main/client/lock/MemoryLocked.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class MemoryLocked implements Locked {

protected java.util.concurrent.locks.Lock lock;
final protected java.util.concurrent.locks.Lock lock;

public MemoryLocked(java.util.concurrent.locks.Lock lock) {
this.lock = lock;
Expand Down
2 changes: 1 addition & 1 deletion main/client/src/mill/main/client/lock/MemoryTryLocked.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package mill.main.client.lock;

public class MemoryTryLocked extends MemoryLocked implements TryLocked {
class MemoryTryLocked extends MemoryLocked implements TryLocked {
public MemoryTryLocked(java.util.concurrent.locks.Lock lock) {
super(lock);
}
Expand Down
2 changes: 1 addition & 1 deletion main/client/src/mill/main/client/lock/TryLocked.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package mill.main.client.lock;

public interface TryLocked extends Locked {
public boolean isLocked();
boolean isLocked();
}