0

sending server side events to all clients

asked 2016-11-16 08:55:12 +0800

GioCortez gravatar image GioCortez
1

Hello everyone, i have a zk web application that is a backend tool for looking customers in my application.

What i need to achieve, is to fire an event to the zk client (a popup needs to appear in the frontend, which will open another page) from an external application. Basically i need to send an event from the server to all the zk clients opened.

How do i achieve that?

Tried with the eventqueue, but i'm getting "not in an execution" exception...

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-11-17 02:02:01 +0800

cor3000 gravatar image cor3000
4351 2 7
ZK Team

updated 2016-11-17 02:03:43 +0800

if you want to notify all users on the server you need to lookup/create an application scoped event queue.

EventQueue eq = EventQueues.lookup("testqueue", "application", true);

It is allowed to publish events to an application (or session) scoped event queue outside an execution.

Here also a short example: If you open this in multiple browsers you'll see how every browser (=different user): receives a notification after a new user joined. The background thread can be any kind of thread. All it needs is a reference to the eventqueue in order to publish events.

EventQueue eq = EventQueues.lookup("testqueue", "application", true);

Thread a = new Thread() {
    public void run() {
        org.zkoss.lang.Threads.sleep(5000);
        eq.publish(new Event("onMyEvent", null, "some_redirect_url"));
    }
};
a.start();

eq.subscribe(new EventListener() {
    public void onEvent(Event evt) {
        alert(evt.getData());
        //open your popup based on the url
    }
});
link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2016-11-16 08:55:12 +0800

Seen: 25 times

Last updated: Nov 17 '16

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More