public BackgroundMonitorEvent() { WebEventManager.getAppEvManager() .addListener( ServerSentEventNames.SVR_BACKGROUND_REPORT, new WebEventListener<String>() { public void eventNotify(WebEvent<String> ev) { BackgroundStatus bgStat = BackgroundStatus.parse(ev.getData()); if (bgStat != null) setStatus(bgStat); else GwtUtil.getClientLogger() .log(Level.INFO, "failed to parse BackgroundStatus:" + ev.getData()); } }); DeferredCommand.addCommand( new Command() { public void execute() { if (BrowserCache.isPerm()) { BrowserCache.addHandlerForKey( STATE_KEY, new StorageEvent.Handler() { public void onStorageChange(StorageEvent ev) { // syncWithCache(ev); } }); } } }); }
public void removeItem(MonitorItem item) { if (_monitorMap.containsKey(item.getID())) { _monitorMap.remove(item.getID()); _deletedItems.add(item.getID()); } syncWithCache(null); WebEvent<MonitorItem> ev = new WebEvent<MonitorItem>(this, Name.MONITOR_ITEM_REMOVED, item); WebEventManager.getAppEvManager().fireEvent(ev); }
public static void onMessage(String msg) { try { GwtUtil.getClientLogger().log(Level.INFO, "onMessage: " + msg); ServerEvent sEvent = parseJsonEvent(msg); Name name = sEvent == null ? null : sEvent.getName(); Serializable data = sEvent.getData(); if (name == null) { GwtUtil.getClientLogger().log(Level.INFO, "Failed to evaluate: " + msg); } if (name.equals(Name.EVT_CONN_EST)) { JSONObject dataJ = JSONParser.parseStrict(sEvent.getData().toString()).isObject(); String sEventInfo = dataJ.get("connID").isString().stringValue() + "_" + dataJ.get("channel").isString().stringValue(); Cookies.setCookie("seinfo", sEventInfo); GwtUtil.getClientLogger() .log(Level.INFO, "Websocket connection established: " + sEventInfo); } else if (data instanceof BackgroundStatus) { WebEvent<String> ev = new WebEvent<String>( ClientEventQueue.class, name, ((BackgroundStatus) data).serialize()); WebEventManager.getAppEvManager().fireEvent(ev); GwtUtil.getClientLogger() .log(Level.INFO, "Event: Name:" + name.getName() + ", Data: " + ev.getData()); } else { WebEvent<String> ev = new WebEvent<String>(ClientEventQueue.class, name, String.valueOf(data)); WebEventManager.getAppEvManager().fireEvent(ev); GwtUtil.getClientLogger() .log(Level.INFO, "Event: Name:" + name.getName() + ", Data: " + sEvent.getData()); } } catch (Exception e) { GwtUtil.getClientLogger() .log(Level.WARNING, "Exception interpreting incoming message: " + msg, e); } }