Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » client notification
client notification [message #727232] Tue, 20 September 2011 16:47 Go to next message
Li Hao is currently offline Li HaoFriend
Messages: 28
Registered: August 2011
Junior Member
Is there any example on the client notification?

For example I added a dynamic code type in database, but the client side will not reflect this new code type until client restarted. Also if backend batch job modify the database it will not reflect on client side also. I try to turn on the client notification in Desktop, but it does not seems to work.

Re: client notification [message #727258 is a reply to message #727232] Tue, 20 September 2011 18:25 Go to previous messageGo to next message
Arthur vD is currently offline Arthur vDFriend
Messages: 52
Registered: March 2010
Member
Hi

You have to call: CODES.reloadCodeType(MyCodeType.class);

If you're interested in the details of how this triggers a client notification, you can look at the class CodeTypeChangedNotification and at CodeTypeStore.unloadCodeTypeCache() where SERVICES.getService(IClientNotificationService.class).putNotification(new CodeTypeChangedNotification(types), new AllUserFilter(120000L)); is called.


Edit: Ah, yes, what Ivan says below: Turn on client notifications at ClientSession.execLoadSession().

[Updated on: Tue, 20 September 2011 19:13]

Report message to a moderator

Re: client notification [message #727259 is a reply to message #727232] Tue, 20 September 2011 18:29 Go to previous messageGo to next message
Ivan Motsch is currently offline Ivan MotschFriend
Messages: 154
Registered: March 2010
Senior Member
Thanks for your post, I'm glad to help:

check the class ClientSession:

public class ClientSession extends AbstractClientSession {

...

@Override
protected void execLoadSession() throws ProcessingException {
setServiceTunnel(new HttpServiceTunnel(this,getBundle().getBundleContext().getProperty("server.url")));
setDesktop(new Desktop());
getServiceTunnel().setClientNotificationPollInterval(2000L);
}

Does that help?

Details (for debugging):
when you change code data in the database (for example using a scout/osgi service) call SERVICES.getService(ICodeService.class).reloadCodeType(Class<T> type);

This will trigger a client notification inside
CodeTypeStore.java

public void unloadCodeTypeCache(Class... types) {
...
// notify clients
SERVICES.getService(IClientNotificationService.class).putNotification(new CodeTypeChangedNotification(types), new AllUserFilter(120000L));
}

The client receives this notification on the next ping that is issued to fetch the notifications:
CodeServiceClientProxy.java at line 96ff.

Was that useful help?
Re: client notification [message #728573 is a reply to message #727259] Fri, 23 September 2011 13:44 Go to previous messageGo to next message
Li Hao is currently offline Li HaoFriend
Messages: 28
Registered: August 2011
Junior Member
Thanks, the reload of code type works.

How about other backend process modified the database other than code type? Can I set the client to auto refresh every 3s? I have backend process modify the database every 10s.
Re: client notification [message #728610 is a reply to message #728573] Fri, 23 September 2011 14:35 Go to previous messageGo to next message
Arthur vD is currently offline Arthur vDFriend
Messages: 52
Registered: March 2010
Member
Hi

You can set the interval with getServiceTunnel().setClientNotificationPollInterval(3000L) in the ClientSession.execLoadSession() method.

Your application data usually isn't cached, so your pages and forms with data are as fresh as the latest refresh. Depending on your use case you can trigger e.g. a periodic reload from the client itself (you could e.g. create your own AbstractAutorefreshingTablePage or some such) or you could trigger a refresh from the server using the above mentioned ClientNotificationService. But it really depends on what you want to do. I hope this helps.
Re: client notification [message #728637 is a reply to message #728610] Fri, 23 September 2011 15:13 Go to previous messageGo to next message
Li Hao is currently offline Li HaoFriend
Messages: 28
Registered: August 2011
Junior Member
I have a outline with 3 table page showing data, I have backend job updating the table data, I need some way to auto-refresh the table data. The backend job updating the data every 10s. so I would like the table page to auto refresh every 10s also.

I have set the getServiceTunnel().setClientNotificationPollInterval(2000L) in the ClientSession.execLoadSession() method when I added in code type refresh and it works. but this does not refresh table page data. so I guess I need to call something similar to notify the client.

I use execPageActivated() in the table page to reload the page:

@Override
protected void execPageActivated() throws ProcessingException {
reloadPage();
}

So now the page will reload when activate. I think this is not the most efficient way for this, but at least it is working.
Re: client notification [message #728722 is a reply to message #728637] Fri, 23 September 2011 19:09 Go to previous messageGo to next message
Arthur vD is currently offline Arthur vDFriend
Messages: 52
Registered: March 2010
Member
getServiceTunnel().setClientNotificationPollInterval(2000L) just sets the client notification interval to 2 seconds. That's for all types of ClientNotifications. You could write an instance of AbstractSchedulerJob to run on the server and inside it send a client notification with SERVICES.getService(IClientNotificationService.class).putNotification(new MyClientNotification(), new AllUserFilter(120000L)); to all clients. On the client side you would have to register a handler with SERVICES.getService(IClientNotificationConsumerService.class).addGlobalClientNotificationConsumerListener() to handle the page updates. All in all that sounds a bit like overkill.

An easier but probably less elegant way would be starting a ClientAsyncJob which would always wait for whatever interval and reload the pages (independently from any server notifications).
Re: client notification [message #732172 is a reply to message #728722] Tue, 04 October 2011 06:39 Go to previous message
Daniel Wiehl is currently offline Daniel WiehlFriend
Messages: 1
Registered: May 2016
Junior Member
The most easiest way to get your page refreshed is to register a data-changed listener on the page. To to so, register the listener in execInitPage by calling registerDataChangeListener(xy). Thereby, xy is the type of data you are interested in receiving update notifications for. Typically, this is an enum represententing e.g. entities. For instance, that would be EntityEnum.Company or EntityEnum.Person.
Furthermore, you have to write the consumer to handle client notifications you are interested in. That is done as mentioned above by
SERVICES.getService(IClientNotificationConsumerService.class).addGlobalClientNotificationConsumerListener(new IClientNotificationConsumerListener() { .. }

In handleEvent of that listener, you simply call ClientSession.get().getDesktop().dataChanged(EntityEnum.Company) unless the notification is not of interest for that data. In turn, the page gets updated automatically without calling reloadPage() manually.

I hope that helped.

[Updated on: Tue, 04 October 2011 06:40] by Moderator

Report message to a moderator

Previous Topic:Multi-Module Applications
Next Topic:transaction management
Goto Forum:
  


Current Time: Sat Apr 20 03:00:48 GMT 2024

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

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

Back to the top