/** * Queues an event for later processing. * * @param page Page owning the target queue. * @param event The event to queue. */ public static void post(Page page, Event event) { page.getEventQueue().queue(event); }
/** * Invoked by the background thread when it has completed the target operation, even if aborted. * This schedules a notification on the desktop's event thread where the requester is notified * of the completion. */ protected void done() { try { page.getEventQueue().queue(event); } catch (Exception e) { log.error(e); } }
/** * Flushes and processes any event on the event queue. * * @return True if events were flushed. */ public boolean flushEvents() { EventQueue queue = session.getPage().getEventQueue(); boolean flushed = !queue.isEmpty(); queue.processAll(); return flushed; }
private void processRequest(Session session, Map<String, Object> map) throws Exception { session._init((String) map.get("pid")); session.updateLastActivity(); ClientRequest request = new ClientRequest(session, map); IRequestHandler handler = handlers.get(request.getType()); if (handler == null) { throw new IllegalArgumentException("No registered handler for request type: " + request.getType()); } ExecutionContext.clear(); ExecutionContext.put(ExecutionContext.ATTR_REQUEST, request); ExecutionContext.put(ExecutionContext.ATTR_PROCESSING, true); try { handler.handleRequest(request); session.notifySessionListeners(request); request.getPage().getEventQueue().processAll(); } catch (Exception e) { request.getPage().getEventQueue().clearAll(); log.error("Unexpected exception", e); sendError(session.getSocket(), e); } finally { ExecutionContext.clear(); } }
/** * Fires an event to the specified listener, deferring delivery if the page of the target is not * currently active. * * @param event The event to fire. * @param listener The listener to receive the event. */ public static void fireEvent(Event event, IEventListener listener) { Page page = event.getTarget() == null ? null : event.getTarget().getPage(); if (page != null && page != ExecutionContext.getPage()) { page.getEventQueue().queue(event); } else { try { listener.onEvent(event); } catch (Exception e) { throw MiscUtil.toUnchecked(e); } } }