17
17
*/
18
18
package me .brandonli .mcav .media .player .vm ;
19
19
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 ;
26
20
import me .brandonli .mcav .media .player .PlayerException ;
27
21
import me .brandonli .mcav .media .player .metadata .VideoMetadata ;
28
22
import me .brandonli .mcav .media .player .pipeline .step .VideoPipelineStep ;
31
25
import me .brandonli .mcav .utils .UncheckedIOException ;
32
26
import org .checkerframework .checker .nullness .qual .Nullable ;
33
27
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
+
34
35
/**
35
36
* Provides an implementation of the {@link VMPlayer} interface to manage
36
37
* virtual machine operations using QEMU and VNC.
@@ -60,11 +61,11 @@ public class VMPlayerImpl implements VMPlayer {
60
61
*/
61
62
@ Override
62
63
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
68
69
) {
69
70
this .architecture = architecture ;
70
71
this .qemuArgs = arguments ;
@@ -86,32 +87,37 @@ private void startQemuProcess() {
86
87
final String [] arguments = command .toArray (new String [0 ]);
87
88
final ProcessBuilder processBuilder = new ProcessBuilder (arguments );
88
89
this .qemuProcess = processBuilder .start ();
89
- waitForConnection ();
90
+ this . waitForConnection ();
90
91
} catch (final IOException e ) {
91
92
throw new UncheckedIOException (e .getMessage (), e );
92
93
}
93
94
}
94
95
95
96
private void waitForConnection () {
96
- long timeout = System .currentTimeMillis () + 30000 ;
97
+ final long timeout = System .currentTimeMillis () + 30000 ;
97
98
boolean connected = false ;
98
99
while (System .currentTimeMillis () < timeout && !connected ) {
99
100
try {
100
- Socket socket = new Socket ("localhost" , this .vncPort );
101
+ final Socket socket = new Socket ("localhost" , this .vncPort );
101
102
socket .close ();
102
103
connected = true ;
104
+ this .sleep ();
103
105
} 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 ();
111
107
}
112
108
}
113
109
}
114
110
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
+
115
121
private List <String > formatQemuArguments () {
116
122
final List <String > command = new ArrayList <>();
117
123
command .add (this .architecture .getCommand ());
0 commit comments