0

ZK Eventqueue publish from Quartz job listener

asked 2012-10-15 14:03:57 +0800

danielgoodwin gravatar image danielgoodwin
76 2

ZK 6.5 CE
Quartz 1.8.X

Resurrecting an old topic (discussed here http://www.zkoss.org/forum/listComment/18771 )

Scenario..
- user is working on system front end and submits job to do in background - job could be a few mins to a few hours.
- I am implementing a messaging system similar to zksample2, (thanks terrytornado et al) which will show messages to user when job is finished ..
- event queue is user based, so only that user receives message

- event queue is EventQueues.Application

I dont use the job itself to try to post to the event queue but a job listener.
The message is sent fine from the jobtoBeExecuted part of the listener interface.. (in essence the user gets message "Job is submitted")
From the jobWasExecuted, the part meant to say "Job is complete" however I have got various errors relating to
- server push not enabled
- no execution available/Not in an execution


I dont have comet push available to me as using ZK CE.

Thanks for any pointers
Daniel

public void jobToBeExecuted(JobExecutionContext inContext) {
		//
		eventQueue = null;
		sendEventQueueMessage(inContext.getJobDetail().getJobDataMap(),
				inContext.getJobDetail().getName(),
				Labels.getLabel("eventQueue_JobSubmitted"));

	}

public void jobWasExecuted(JobExecutionContext inContext,
			JobExecutionException inException) {
		logger.debug(">>> jobWasExecuted");

		sendEventQueueMessage(inContext.getJobDetail().getJobDataMap(),
				inContext.getJobDetail().getName(),
				Labels.getLabel("eventQueue_JobSubmitted"));

 try {
			if (_desktop.isServerPushEnabled()) {

				Executions.activate(_desktop);
				Clients.clearBusy();
				Executions.deactivate(_desktop);
			}

		} catch (Exception ex) {
			logger.error("Error in completing job veto " + ex.getMessage());
		} finally {

			_desktop.enableServerPush(false);

		}
}

private void sendEventQueueMessage(JobDataMap dataMap, String jobName,
			String message) {
		
			try {
				String userName = null;
				if (dataMap.containsKey("submittedUserName")) {
					userName = (String) dataMap.get("submittedUserName");
					Desktop thisDesktop = (Desktop) dataMap.get("_desktop");
					if (thisDesktop != null) {

						if (eventQueue == null) {
							logger.debug("Create queue");
							eventQueue = EventQueues.lookup("User_" + userName
									+ "_EventQueue", EventQueues.APPLICATION,
									true);

						}
						if (!thisDesktop.isServerPushEnabled()) {
							logger.debug("Enable push " + thisDesktop.isAlive());
							thisDesktop.enableServerPush(true);
						}
						Executions.activate(_desktop);
						eventQueue.publish(new Event("onChangeSelectedObject",
								null, jobName + "> " + message));
						Executions.deactivate(_desktop);

						// _desktop.enableServerPush(false);
					}
				}
			} catch (Exception ex) {
				logger.error("Error in sending to event queue "
						+ ex.getMessage());
			}
		}
	}

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2012-10-15 21:38:56 +0800

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

for a first quick help: please read about Gekkio's AtmosphereServerPush. https://github.com/Gekkio/jawwa

best
Stephan

link publish delete flag offensive edit

answered 2012-10-16 07:52:12 +0800

danielgoodwin gravatar image danielgoodwin
76 2

Thanks Stephan
I'll review that and see if it helps me understand some more.
Daniel

link publish delete flag offensive edit

answered 2012-10-16 19:32:11 +0800

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

it runs in all editions.

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
2 followers

RSS

Stats

Asked: 2012-10-15 14:03:57 +0800

Seen: 98 times

Last updated: Oct 16 '12

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