|
19 | 19 | import java.awt.event.InputEvent; |
20 | 20 | import java.awt.event.KeyEvent; |
21 | 21 | import java.awt.event.MouseEvent; |
22 | | -import java.io.IOException; |
23 | 22 | import java.net.InetSocketAddress; |
24 | 23 |
|
25 | 24 | import org.apache.log4j.Logger; |
@@ -55,7 +54,8 @@ public class ConsoleProxyRdpClient extends ConsoleProxyClientBase { |
55 | 54 | private RdpBufferedImageCanvas _canvas = null; |
56 | 55 |
|
57 | 56 | private Thread _worker; |
58 | | - private volatile boolean _workerDone = false; |
| 57 | + private volatile boolean _workerDone = true; |
| 58 | + private volatile long _threadStopTime; |
59 | 59 |
|
60 | 60 | private AwtMouseEventSource _mouseEventSource = null; |
61 | 61 | private AwtKeyEventSource _keyEventSource = null; |
@@ -231,77 +231,86 @@ public int mapMouseButton(int code) { |
231 | 231 |
|
232 | 232 | @Override |
233 | 233 | 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 | + } |
257 | 237 |
|
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 | + } |
259 | 261 |
|
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); |
271 | 265 |
|
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 | + } |
297 | 272 | } |
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 | + } |
305 | 314 | } |
306 | 315 |
|
307 | 316 | @Override |
|
0 commit comments