Skip to content

Commit cf7b627

Browse files
anshulgangwarchaturvedia
authored andcommitted
CLOUDSTACK-6001: Fixed hyperv vm console not working for 3 minutes after migration.
(cherry picked from commit fb87c85) Signed-off-by: Animesh Chaturvedi <animesh@apache.org>
1 parent 4961c13 commit cf7b627

1 file changed

Lines changed: 78 additions & 69 deletions

File tree

‎services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxyRdpClient.java‎

Lines changed: 78 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.awt.event.InputEvent;
2020
import java.awt.event.KeyEvent;
2121
import java.awt.event.MouseEvent;
22-
import java.io.IOException;
2322
import java.net.InetSocketAddress;
2423

2524
import org.apache.log4j.Logger;
@@ -55,7 +54,8 @@ public class ConsoleProxyRdpClient extends ConsoleProxyClientBase {
5554
private RdpBufferedImageCanvas _canvas = null;
5655

5756
private Thread _worker;
58-
private volatile boolean _workerDone = false;
57+
private volatile boolean _workerDone = true;
58+
private volatile long _threadStopTime;
5959

6060
private AwtMouseEventSource _mouseEventSource = null;
6161
private AwtKeyEventSource _keyEventSource = null;
@@ -231,77 +231,86 @@ public int mapMouseButton(int code) {
231231

232232
@Override
233233
public void initClient(final ConsoleProxyClientParam param) {
234-
_workerDone = false;
235-
236-
int canvasWidth = 1024;
237-
int canvasHeight = 768;
238-
setClientParam(param);
239-
240-
final String host = param.getHypervHost();
241-
final String password = param.getPassword();
242-
final String instanceId = param.getClientHostAddress();
243-
final int port = param.getClientHostPort();
244-
245-
_screen = new ScreenDescription();
246-
_canvas = new RdpBufferedImageCanvas(this, canvasWidth, canvasHeight);
247-
onFramebufferSizeChange(canvasWidth, canvasHeight);
248-
249-
_screen.addSizeChangeListener(new SizeChangeListener() {
250-
@Override
251-
public void sizeChanged(int width, int height) {
252-
if (_canvas != null) {
253-
_canvas.setCanvasSize(width, height);
254-
}
255-
}
256-
});
234+
if ((System.currentTimeMillis() - _threadStopTime) < 1000) {
235+
return;
236+
}
257237

258-
final SSLState sslState = new SSLState();
238+
try {
239+
int canvasWidth = 1024;
240+
int canvasHeight = 768;
241+
setClientParam(param);
242+
243+
final String host = param.getHypervHost();
244+
final String password = param.getPassword();
245+
final String instanceId = param.getClientHostAddress();
246+
final int port = param.getClientHostPort();
247+
248+
final SSLState sslState = new SSLState();
249+
250+
final String username = param.getUsername();
251+
String name = null;
252+
String domain = null;
253+
if (username.contains("\\")) {
254+
String[] tokens = username.split("\\\\");
255+
name = tokens[1];
256+
domain = tokens[0];
257+
} else {
258+
name = username;
259+
domain = "Workgroup";
260+
}
259261

260-
final String username = param.getUsername();
261-
String name = null;
262-
String domain = null;
263-
if (username.contains("\\")) {
264-
String[] tokens = username.split("\\\\");
265-
name = tokens[1];
266-
domain = tokens[0];
267-
} else {
268-
name = username;
269-
domain = "Workgroup";
270-
}
262+
_screen = new ScreenDescription();
263+
_canvas = new RdpBufferedImageCanvas(this, canvasWidth, canvasHeight);
264+
onFramebufferSizeChange(canvasWidth, canvasHeight);
271265

272-
_client = new RdpClient("client", host, domain, name, password, instanceId, _screen, _canvas,
273-
sslState);
274-
275-
_mouseEventSource = _client.getMouseEventSource();
276-
_keyEventSource = _client.getKeyEventSource();
277-
278-
_worker = new Thread(new Runnable() {
279-
@Override
280-
public void run() {
281-
_socket = new AprSocketWrapperImpl("socket", sslState);
282-
Pipeline pipeline = new PipelineImpl("Client");
283-
pipeline.add(_socket, _client);
284-
pipeline.link("socket", _client.getId(), "socket");
285-
pipeline.validate();
286-
287-
InetSocketAddress address = new InetSocketAddress(host, port);
288-
ConsoleProxy.ensureRoute(host);
289-
290-
try {
291-
// Connect socket to remote server and run main loop(s)
292-
_socket.connect(address);
293-
} catch (IOException e) {
294-
e.printStackTrace();
295-
} finally {
296-
shutdown();
266+
_screen.addSizeChangeListener(new SizeChangeListener() {
267+
@Override
268+
public void sizeChanged(int width, int height) {
269+
if (_canvas != null) {
270+
_canvas.setCanvasSize(width, height);
271+
}
297272
}
298-
299-
s_logger.info("Receiver thread stopped.");
300-
_workerDone = true;
301-
}
302-
});
303-
_worker.setDaemon(true);
304-
_worker.start();
273+
});
274+
275+
s_logger.info("connecting to instance " + instanceId + " on host " + host);
276+
_client = new RdpClient("client", host, domain, name, password, instanceId, _screen, _canvas, sslState);
277+
278+
_mouseEventSource = _client.getMouseEventSource();
279+
_keyEventSource = _client.getKeyEventSource();
280+
281+
_worker = new Thread(new Runnable() {
282+
@Override
283+
public void run() {
284+
_socket = new AprSocketWrapperImpl("socket", sslState);
285+
Pipeline pipeline = new PipelineImpl("Client");
286+
pipeline.add(_socket, _client);
287+
pipeline.link("socket", _client.getId(), "socket");
288+
pipeline.validate();
289+
290+
InetSocketAddress address = new InetSocketAddress(host, port);
291+
ConsoleProxy.ensureRoute(host);
292+
293+
try {
294+
_workerDone = false;
295+
s_logger.info("Connecting socket to remote server and run main loop(s)");
296+
_socket.connect(address);
297+
} catch (Exception e) {
298+
s_logger.info(" error occurred in connecting to socket " + e.getMessage());
299+
} finally {
300+
shutdown();
301+
}
302+
303+
_threadStopTime = System.currentTimeMillis();
304+
s_logger.info("Receiver thread stopped.");
305+
_workerDone = true;
306+
}
307+
});
308+
_worker.setDaemon(true);
309+
_worker.start();
310+
} catch (Exception e) {
311+
_workerDone = true;
312+
s_logger.info("error occurred in initializing rdp client " + e.getMessage());
313+
}
305314
}
306315

307316
@Override

0 commit comments

Comments
 (0)