Skip to content

Commit ff1e395

Browse files
committed
Delay Tweaks
1 parent 79d2e24 commit ff1e395

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

mcav-common/src/main/java/me/brandonli/mcav/media/player/vm/VMPlayerImpl.java

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@
1717
*/
1818
package me.brandonli.mcav.media.player.vm;
1919

20-
import static java.util.Objects.requireNonNull;
21-
22-
import java.io.IOException;
23-
import java.net.Socket;
24-
import java.util.ArrayList;
25-
import java.util.List;
2620
import me.brandonli.mcav.media.player.PlayerException;
2721
import me.brandonli.mcav.media.player.metadata.VideoMetadata;
2822
import me.brandonli.mcav.media.player.pipeline.step.VideoPipelineStep;
@@ -31,6 +25,13 @@
3125
import me.brandonli.mcav.utils.UncheckedIOException;
3226
import org.checkerframework.checker.nullness.qual.Nullable;
3327

28+
import java.io.IOException;
29+
import java.net.Socket;
30+
import java.util.ArrayList;
31+
import java.util.List;
32+
33+
import static java.util.Objects.requireNonNull;
34+
3435
/**
3536
* Provides an implementation of the {@link VMPlayer} interface to manage
3637
* virtual machine operations using QEMU and VNC.
@@ -60,11 +61,11 @@ public class VMPlayerImpl implements VMPlayer {
6061
*/
6162
@Override
6263
public boolean start(
63-
final VideoPipelineStep step,
64-
final int port,
65-
final Architecture architecture,
66-
final VMConfiguration arguments,
67-
final VideoMetadata metadata
64+
final VideoPipelineStep step,
65+
final int port,
66+
final Architecture architecture,
67+
final VMConfiguration arguments,
68+
final VideoMetadata metadata
6869
) {
6970
this.architecture = architecture;
7071
this.qemuArgs = arguments;
@@ -86,32 +87,37 @@ private void startQemuProcess() {
8687
final String[] arguments = command.toArray(new String[0]);
8788
final ProcessBuilder processBuilder = new ProcessBuilder(arguments);
8889
this.qemuProcess = processBuilder.start();
89-
waitForConnection();
90+
this.waitForConnection();
9091
} catch (final IOException e) {
9192
throw new UncheckedIOException(e.getMessage(), e);
9293
}
9394
}
9495

9596
private void waitForConnection() {
96-
long timeout = System.currentTimeMillis() + 30000;
97+
final long timeout = System.currentTimeMillis() + 30000;
9798
boolean connected = false;
9899
while (System.currentTimeMillis() < timeout && !connected) {
99100
try {
100-
Socket socket = new Socket("localhost", this.vncPort);
101+
final Socket socket = new Socket("localhost", this.vncPort);
101102
socket.close();
102103
connected = true;
104+
this.sleep();
103105
} catch (final IOException e) {
104-
try {
105-
Thread.sleep(500);
106-
} catch (final InterruptedException ex) {
107-
Thread thread = Thread.currentThread();
108-
thread.interrupt();
109-
throw new PlayerException(ex.getMessage(), ex);
110-
}
106+
this.sleep();
111107
}
112108
}
113109
}
114110

111+
private void sleep() {
112+
try {
113+
Thread.sleep(500);
114+
} catch (final InterruptedException ex) {
115+
final Thread thread = Thread.currentThread();
116+
thread.interrupt();
117+
throw new PlayerException(ex.getMessage(), ex);
118+
}
119+
}
120+
115121
private List<String> formatQemuArguments() {
116122
final List<String> command = new ArrayList<>();
117123
command.add(this.architecture.getCommand());

0 commit comments

Comments
 (0)