0

Problem with events after adding zkmax

asked 2017-04-06 15:08:17 +0800

SimonZK gravatar image SimonZK
1

Hi,

after I added zkmax-7.0.8.1 to my project an event is not received anymore by a listener.

See code below....

Can anyone give a solution to this? Or is it a bug?

Greetings, Simon.

Class 1 (ViewModel):

// Excerpt from ViewModel
private void sendCustomerReportsInternal() {

    if(EventQueues.exists(SendCustomerReportsViewModel.QUEUE_SEND_REPORTS)) {
        Messagebox.show("Report Generator is busy. Please wait!");
        return;
    }

    Clients.showBusy("Sending reports...");
    LOG.info("Start sendCustomerReportsInternal");

    final EventQueue<Event> eq = EventQueues.lookup(SendCustomerReportsViewModel.QUEUE_SEND_REPORTS,
            EventQueues.DESKTOP, true);
    // subscribe start listener to the queue
    // it will start an asychronous thread 
    eq.subscribe(new SendReportsWorker(this.businessService), true);
    // subscribe an anyonymous eventlistener when the worker finishes.
    // CHECKSTYLE:OFF AnonInnerLength
    eq.subscribe(new EventListener<Event>() {
        @Override
        public void onEvent(Event event) throws Exception {
                            // END EVENT IS PUBLISHED BY CLASS2, NOT RECEIVED ANYMORE WITH zkmax-7.0.8.2.jar
            if(SendCustomerReportsViewModel.END_EVENT.equals(event.getName())) {
                LOG.info("Update done, start END event");
                EventQueues.remove(SendCustomerReportsViewModel.QUEUE_SEND_REPORTS);
                Clients.clearBusy();
                LOG.info("Work done, ending END event");
                                    // ....
                                    // ....
            }
        }
    });

    // CHECKSTYLE:ON AnonInnerLength
    eq.publish(new Event(SendCustomerReportsViewModel.START_EVENT));
}

Class 2 (Async Worker):

class SendReportsWorker implements EventListener<Event> {

private static final Logger LOG = LoggerFactory.getLogger(SendReportsWorker.class);

private BusinessService businessService;

private final EventQueue<Event> eq;

/**
 * Constructor
 * 
 * @param businessService BusinessService
 */
public SendReportsWorker(BusinessService businessService) {
    this.businessService = businessService;
    this.eq = EventQueues.lookup(SendCustomerReportsViewModel.QUEUE_SEND_REPORTS,
            EventQueues.DESKTOP, false);
}

/**
 * {@inheritDoc}
 * @see org.zkoss.zk.ui.event.EventListener#onEvent(org.zkoss.zk.ui.event.Event)
 */
@Override
public void onEvent(Event event) throws Exception {
    if(SendCustomerReportsViewModel.START_EVENT.equals(event.getName())) {
        SendCustomerReportResult result = null;
        try {
            LOG.info("Start sendCustomerReports in Event");
            result = this.businessService.sendCustomerReports();
        } catch(Exception e) {
            LOG.error("Exception Message: " + e.getMessage(), e);

        }
        LOG.info("Work done, now send END event");
        // THIS EVENT IS PUBLISHED, BUT NOT RECEIVED IN CLASS 1
        eq.publish(new Event(SendCustomerReportsViewModel.END_EVENT, null, result));
    }
}

}

delete flag offensive retag edit
Be the first one to reply this discussion!
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: 2017-04-06 15:08:17 +0800

Seen: 24 times

Last updated: Apr 06 '17

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