How to use server push effectively

Hi All
I am using Vaadin 7.4 to create a web application. I need to use Server push to show realtime alert at my homepage. Alert should be shown based on the user level and no need to show alert for all users. I have managed to push the alert to all UIs. What I need is push to specific UIs, so that the load of iteration can be reduced.
Is there any effective way to push to specific UIs only?

Hi,

You can try
Broadcasting to Other Users
in
https://vaadin.com/book/-/page/advanced.push.html#advanced.push.pusharound
. Only register the appropriate UI’s to the Broadcaster.

@Override     
protected void init(VaadinRequest request) {         
                  
 // Register to receive broadcasts         
 Broadcaster.register(this);     
}

can be changed into:

@Override     
protected void init(VaadinRequest request) {         
               
 // Register to receive broadcasts if user is permitted
 if (isUserPermitted) {   
  Broadcaster.register(this);     
 }
}

But in your case the most appropriate time to check the user and register the UI to the Broadcaster is after login.

Thank you Victoria for your quick response.
I have another scenario where other users get alerts also. So I need to register almost all UIs. Is there any other way?
Waiting for your valuable suggestions.

Yes you need to register almost all UI’s - UI’s that have Users with appropriate user level.

  1. User logs in into the application.
  2. Check user’s level.
  3. If user’s level is high enough like an admin level, register the UI to the Broadcaster so you can receive messages.
  4. If user’s level is not high enough, don’t register the UI.

For me there is no other way than this which is like a publish-subscribe pattern. Checking the user’s level and registering the UI upon login won’t even degrade your application’s performance, as these are not big operations.

I was following almost the same way. I thought It will affect my application performance.
Thank you Victoria for your valuable suggestion.

Hi,

I guess that’s one way to do it, although it is a bit problematic from security viewpoint to check authorization only when the session is created. While it might not be a huge problem to log out and in if access rights are increased, it is a security problem if reduction in access rights is not applied immediately. Therefore, I’d recommend checking for the authorization in the access() calls to the UIs. If it’s not needed to check for increase of access rights immediately, use in combination to what was suggested above.

Hi,
That was something I didn’t noticed. The security part.
I need to consider that also. Need to check the access rights. Complex but this is the only way to do it I guess.