T-Plan Robot Enterprise 5.0.1
Build No. 5.0.1-20190308.1

com.tplan.robot.scripting
Interface DisconnectListener

All Known Implementing Classes:
ExecutionFallBackManager

public interface DisconnectListener

Interface declaring fall back methods to be called when a connection to the desktop is unexpectedly interrupted during a script execution. This allows to set up central point of I/O error handling and/or eventual custom connection recovery.

This interface can be used in two ways:

As the execution context is passed as a method argument, the listener may for example get the client using ScriptingContext.getClient() and make an attempt to reconnect it through RemoteDesktopClient.connect(). Be however aware that reconnecting doesn't keep other registered listeners from being called. That is why it is recommended to test the client connection once again before calling its connect() to avoid repeated reconnection. The reconnection must be called from a separate thread and it is also recommended to wait a second or two to give the event system a chance to finish processing of the client disconnect event. A typical global listener may look like this:

   ExecutionFallBackManager.addDisconnectListener(new DisconnectListener() {
       public void disconnectFallback(ScriptingContext context) {
           final ScriptingContext ctx = context;
           Runnable connect = new Runnable() {
               public void run() {
                   try {
                       Thread.sleep(1000);
                   } catch (InterruptedException ex) {
                       ex.printStackTrace();
                   }
                   try {
                       if (ctx.getClient() != null && !ctx.getClient().isConnected()) {
                           ctx.getClient().connect();
                       }
                   } catch (Exception ex) {
                       ex.printStackTrace();
                   }
               }
           };
           new Thread(connect).start();
       }
   });
 

The same listener implemented implemented for a single test script may look like this:

    import com.tplan.robot.*;
    import com.tplan.robot.scripting.*;
    import java.io.IOException;

    public class MouseMove extends DefaultJavaTestScript implements JavaTestScript, DisconnectListener {

       public void test() {
          try {
             connect("rfb://localhost:5901", "password");

             // Some test code to follow
             // ...

          } catch (IOException ex) {
             ex.printStackTrace();
          }
       }

       public void disconnectFallback(ScriptingContext context) {
           final ScriptingContext ctx = context;
           Runnable connect = new Runnable() {
               public void run() {
                   try {
                       Thread.sleep(1000);
                   } catch (InterruptedException ex) {
                       ex.printStackTrace();
                   }
                   try {
                       if (ctx.getClient() != null && !ctx.getClient().isConnected()) {
                           ctx.getClient().connect();
                       }
                   } catch (Exception ex) {
                       ex.printStackTrace();
                   }
               }
           };
           new Thread(connect).start();
       }
   });
 

To enable safe recovery all test script methods involved in desktop I/O such as mouseMove(), mouseClick(), press() or type() were updated to hold on on I/O errors for a short time if the connection gets restored. Details are available in the ConnectionTimeout class which is used by the commands internally for this operation.


T-Plan Robot Enterprise, (C) 2009-2019 T-Plan Limited. All rights reserved.


Method Summary
 void disconnectFallback(ScriptingContext context)
          Method to be called when connection to a desktop client crashes in the middle of script execution.
 

Method Detail

disconnectFallback

void disconnectFallback(ScriptingContext context)
Method to be called when connection to a desktop client crashes in the middle of script execution.

Parameters:
context - a context associated with the executed script.

T-Plan Robot Enterprise 5.0.1
Build No. 5.0.1-20190308.1