Alternative Client Polling stop working when code migrated from 1.4 to 2.2 [message #1350997] |
Mon, 12 May 2014 18:43  |
Eclipse User |
|
|
|
Hi,
We are using RAP in a equipment monitoring application. That is the reason why it was decided to use the:
String code = "window.setInterval( function() {\n"
+ " org.eclipse.swt.Request.getInstance().send();\n"
+ "}, 10000 );"; // polling interval in ms
JSExecutor.executeJS( code );
It also helped us to detect when the browser(tab) was closed, as the USer will normally not interact much with the application.
The code was working perfectly in 1.4. Now I am migrating the application to 2.2 and the polling has stop working. Symthoms are that the UI does not get updated and that setMaxInactiveInterval is set to 10 seconds and i get a timeout after 10 seconds if i do not interact with the application.
Hear is the class
public class ClientPolling {
public ClientPolling(Display display, int mSeconds) {
if ( mSeconds > 0){
this.mSeconds = mSeconds;
} else {
this.mSeconds = 100;
}
this.display = display;
}
final private Display display;
final private int mSeconds;
private boolean polling = false;
final static Logger log = LoggerFactory.getLogger(ClientPolling.class);
synchronized void stopPolling(){
if ( !polling ) return;
polling = false;
Job job = new Job( "Stop Polling" ) {
protected IStatus run( IProgressMonitor monitor ) {
display.asyncExec(new Runnable() {
@Override
public void run() {
JavaScriptExecutor executor = RWT.getClient().getService( JavaScriptExecutor.class );
if( executor != null ) {
executor.execute("window.clearInterval(aktiv);");
}else{
log.error("Could not run stop polling script on client.");
}
}
});
return Status.OK_STATUS;
}
};
job.schedule();
}
synchronized void startPolling(){
if ( polling ) return;
polling = true;
Job job = new Job( "Start Polling" ) {
protected IStatus run( IProgressMonitor monitor ) {
display.asyncExec(new Runnable() {
@Override
public void run() {
JavaScriptExecutor executor = RWT.getClient().getService( JavaScriptExecutor.class );
if( executor != null ) {
executor.execute("var aktiv = window.setInterval( function() {\n"
+ " org.eclipse.swt.Request.getInstance().send();\n"
+ "}, " + mSeconds + " );");
log.info("started polling script on client.");
}else{
log.error("Could not run start polling script on client.");
}
}
});
return Status.OK_STATUS;
}
};
job.schedule();
}
}
startPolling is called in the preStartup() method of the WorkbenchAdvisor.
Have I missed something? Or is there a new way to implement this Altenative Polling in RAP 2?
Cheers,
Javi
P.S: The log message "started polling script on client." appears on the console on start up.
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.51394 seconds