Fix Android Studio warnings in EngineServer

This commit is contained in:
Peter Osterlund 2022-12-11 10:18:16 +01:00
parent c0963c567c
commit af1d725f27
3 changed files with 34 additions and 40 deletions

View File

@ -29,8 +29,8 @@ import java.util.Properties;
/** Manages starting and stopping PortListeners. */
public class EngineServer implements ErrorHandler {
private EngineConfig[] configs;
private PortListener[] portListeners;
private final EngineConfig[] configs;
private final PortListener[] portListeners;
private MainWindow window;
private EngineServer(int numEngines) {

View File

@ -48,8 +48,8 @@ public class MainWindow {
private JTextField[] filename;
private JTextField[] arguments;
private EngineServer server;
private EngineConfig[] configs;
private final EngineServer server;
private final EngineConfig[] configs;
public MainWindow(EngineServer server, EngineConfig[] configs) {
this.server = server;

View File

@ -30,11 +30,11 @@ import java.util.ArrayList;
/** Listens to a TCP port and connects an engine process to a TCP socket. */
public class PortListener {
private EngineConfig config;
private ErrorHandler errorHandler;
class PortListener {
private final EngineConfig config;
private final ErrorHandler errorHandler;
private Thread thread;
private final Thread thread;
private ServerSocket serverSocket;
private Socket clientSocket;
private Process proc;
@ -44,9 +44,7 @@ public class PortListener {
this.config = config;
this.errorHandler = errorHandler;
thread = new Thread() {
@Override
public void run() {
thread = new Thread(() -> {
try {
mainLoop();
} catch (InterruptedException ex) {
@ -56,8 +54,7 @@ public class PortListener {
if (!shutDownFlag)
reportError("IO error in background thread", ex);
}
}
};
});
thread.start();
}
@ -149,9 +146,7 @@ public class PortListener {
}
private Thread forwardIO(InputStream is, OutputStream os) {
Thread t = new Thread() {
@Override
public void run() {
Thread t = new Thread(() -> {
try {
byte[] buffer = new byte[4096];
while (true) {
@ -168,8 +163,7 @@ public class PortListener {
Process p = proc;
if (p != null)
p.destroyForcibly();
}
};
});
t.start();
return t;
}