0

Publish Event from non-ZK class

asked 2012-11-30 11:50:58 +0800

takach gravatar image takach
30 2

Hi all,

My web application get notification from outside, and I want to display this info for the logged in users. I tried an EventQue based solution as follows:

EventQueue<Event> queue = EventQueues.lookup("myQueue", EventQueues.APPLICATION, true);
queue.publish(new Event("myEvent", null, someData));

Unfortunately it is not working in a non-ZK message listener class.

What would be the suggested way to trigger a(n application scoped) ZK Event from a non-ZK class?

delete flag offensive retag edit

8 Replies

Sort by » oldest newest

answered 2012-12-06 10:53:46 +0800

takach gravatar image takach
30 2

Thank you gganassin,

your magic hat is really magic. This looks like an appropriate solution. I will test it.

link publish delete flag offensive edit

answered 2012-12-06 09:08:44 +0800

gganassin gravatar image gganassin flag of Luxembourg
540 6
http://www.hybris.com/

updated 2012-12-06 09:09:53 +0800

I had the same problem once... and due to the deadline i had... the fastest ignorant solution i was able to get out from my magic hat was to place a secured .zul file like:

<zk>
	<div id="resultContainer" apply="duty.core.services.rest.ServicesController" ></div>
</zk>

public class ServicesController extends GenericAutowireComposer {

	private final static Logger _log = Logger.getLogger(ServicesController.class);	
	private final static String SERVICE = "service";
	
	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		String service = Executions.getCurrent().getParameter(SERVICE);
		if (StringUtils.isEmpty(service)) {
			_log.error("no service specified");
			throw new IllegalArgumentException("invalid service called - empty");
		} else {
			ServiceDescriptor serviceDescriptor = (ServiceDescriptor) SpringUtil.getBean(service);
			// ... WHATEVAH like yours:
			EventQueue<Event> queue = EventQueues.lookup("myQueue", EventQueues.APPLICATION, true);
			queue.publish(new Event("myEvent", null, someData));
		}
	}
}

So... i was able to call via a simple HttpURLConnection my .zul file which is finally able to trigger the EventQueue for example.
For sure is not elegant… but it damn worked for me :D
Giovanni

link publish delete flag offensive edit

answered 2012-12-05 11:22:23 +0800

takach gravatar image takach
30 2

Thank you terrtornado,

Unfortunately HTML5 is not an option for us, by browser compatibility and because it is not a new application and I am restricted to the existing architecture.

The event what I wan to push to the client ZK pages comes either from an administrator page (also ZK), or from outside through a Quartz Job. I can publish an Event to an EventQueue on the admin page, and I can also capture it on the client pages. I want to complete this solution.

So my question is: is it possible to reach the ZK EventQueue from the non-ZK Code.

link publish delete flag offensive edit

answered 2012-12-05 09:48:32 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

Read about HTML5 WebSockets. There are a few OS frameworks out (jWebsocket, Atmosphere) that can help you.

link publish delete flag offensive edit

answered 2012-12-05 08:43:34 +0800

takach gravatar image takach
30 2

Outside notification means notification from an other application through a database interface, so it has also nothing to do with ZK.

link publish delete flag offensive edit

answered 2012-12-05 08:42:10 +0800

takach gravatar image takach
30 2

ZK version is (unfortunately) 3.6.3, but the next major release will use 6.0.1, I can postpone this problem to this release, if necessary.

link publish delete flag offensive edit

answered 2012-12-05 08:35:56 +0800

takach gravatar image takach
30 2

Hi jimmyshiau,

My application rus on Tomcat, and a Quartz Job listens for outside notifications. It is a thread dedicated to this (or all Quartz) Job. At present it has nothing to do with ZK. would like to make possible to reach a ZK EventQueue from this Job and publish an event to it.

link publish delete flag offensive edit

answered 2012-12-05 02:22:28 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

Hi takach,

When do you want to publish an event? in a thread?

link publish delete flag offensive edit
Your reply
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

RSS

Stats

Asked: 2012-11-30 11:50:58 +0800

Seen: 100 times

Last updated: Dec 06 '12

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