Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Alternative Client Polling stop working when code migrated from 1.4 to 2.2
Alternative Client Polling stop working when code migrated from 1.4 to 2.2 [message #1350997] Mon, 12 May 2014 22:43 Go to next message
Xavipen Mising name is currently offline Xavipen Mising name
Messages: 49
Registered: March 2011
Member
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.
Re: Alternative Client Polling stop working when code migrated from 1.4 to 2.2 [message #1351831 is a reply to message #1350997] Tue, 13 May 2014 07:17 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan Furnadjiev
Messages: 1839
Registered: July 2009
Senior Member
Hi,
I don't know the reason why it's not working, but in RAP 2.2 the UI
session is terminated automatically after browser windows close.
You could use ServerPush and Timer to write similar code without javascript.
Best,
Ivan

--
Ivan Furnadjiev

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Alternative Client Polling stop working when code migrated from 1.4 to 2.2 [message #1351856 is a reply to message #1350997] Tue, 13 May 2014 07:33 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan Furnadjiev
Messages: 1839
Registered: July 2009
Senior Member
.... after looking into the JavaScript code carefully I found that you
are using org.eclipse.swt.Request.getInstance().send(). This class does
not exists anymore. In RAP 2.2+ you should use
rwt.remote.Connection.getInstance().send().
HTH,
Ivan

--
Ivan Furnadjiev

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Alternative Client Polling stop working when code migrated from 1.4 to 2.2 [message #1352456 is a reply to message #1351856] Tue, 13 May 2014 13:20 Go to previous messageGo to next message
Xavipen Mising name is currently offline Xavipen Mising name
Messages: 49
Registered: March 2011
Member
Thanks Ivan, that was it.

And thanks for the advice, i will have a look into ServerPush and a Timer as a solution, and the new beheviour of the UI
session is terminated automatically after browser windows close.
Re: Alternative Client Polling stop working when code migrated from 1.4 to 2.2 [message #1352550 is a reply to message #1352456] Tue, 13 May 2014 14:13 Go to previous messageGo to next message
Xavipen Mising name is currently offline Xavipen Mising name
Messages: 49
Registered: March 2011
Member
I was to quick in my previous answer. While testing i forgot to set again the setMaxInactiveInterval to 10 seconds.

Unfortunately, rwt.remote.Connection.getInstance().send() does not work.

After looking around a bit i have found:

rwt.remote.Server.getInstance().send()

and this seems to work.

Cheers,
Javi
Re: Alternative Client Polling stop working when code migrated from 1.4 to 2.2 [message #1352597 is a reply to message #1352550] Tue, 13 May 2014 14:35 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan Furnadjiev
Messages: 1839
Registered: July 2009
Senior Member
Hi Javi,
are you sure that you are using RAP 2.2. In RAP 2.2+ the class is named
Connection. In RAP 2.1 it was Server.

[1]
http://git.eclipse.org/c/rap/org.eclipse.rap.git/tree/bundles/org.eclipse.rap.rwt/js/rwt/remote?id=2.2.0-R
Best,
Ivan

--
Ivan Furnadjiev

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Alternative Client Polling stop working when code migrated from 1.4 to 2.2 [message #1352853 is a reply to message #1352597] Tue, 13 May 2014 17:08 Go to previous message
Xavipen Mising name is currently offline Xavipen Mising name
Messages: 49
Registered: March 2011
Member
Hi Ivan,

You are correct. I though i was using 2.2 when i was actually using 2.1.1

So for 2.1.1 i had to use: rwt.remote.Server.getInstance().send()

and if i had understood correctly, when i move to a version 2.2+ I would have to use:

rwt.remote.Connection.getInstance().send()

Thanks again!
Javi
Previous Topic:EMF Databinding Issue
Next Topic:TreeViewer RowTemplate Expander missing
Goto Forum:
  


Current Time: Thu Oct 23 04:36:16 GMT 2014

Powered by FUDForum. Page generated in 0.04001 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software