List of usage examples for com.google.gwt.json.client JSONValue isObject
public JSONObject isObject()
From source file:tsd.client.QueryUi.java
License:Open Source License
private void refreshVersion() { asyncGetJson(VERSION_URL, new GotJsonCallback() { public void got(final JSONValue json) { final JSONObject bd = json.isObject(); final JSONString shortrev = bd.get("short_revision").isString(); final JSONString status = bd.get("repo_status").isString(); final JSONString stamp = bd.get("timestamp").isString(); final JSONString user = bd.get("user").isString(); final JSONString host = bd.get("host").isString(); final JSONString repo = bd.get("repo").isString(); final JSONString version = bd.get("version").isString(); build_data.setHTML("OpenTSDB version [" + version.stringValue() + "] built from revision " + shortrev.stringValue() + " in a " + status.stringValue() + " state<br/>" + "Built on " + new Date((Long.parseLong(stamp.stringValue()) * 1000)) + " by " + user.stringValue() + '@' + host.stringValue() + ':' + repo.stringValue()); }// w w w .j a v a 2s . c o m }); }
From source file:tsd.client.QueryUi.java
License:Open Source License
private void refreshGraph() { final Date start = start_datebox.getValue(); if (start == null) { graphstatus.setText("Please specify a start time."); return;//www. jav a 2s .c o m } final Date end = end_datebox.getValue(); if (end != null && !autoreload.getValue()) { if (end.getTime() <= start.getTime()) { end_datebox.addStyleName("dateBoxFormatError"); graphstatus.setText("End time must be after start time!"); return; } } final StringBuilder url = new StringBuilder(); url.append("/q?start="); final String start_text = start_datebox.getTextBox().getText(); if (start_text.endsWith(" ago") || start_text.endsWith("-ago")) { url.append(start_text); } else { url.append(FULLDATE.format(start)); } if (end != null && !autoreload.getValue()) { url.append("&end="); final String end_text = end_datebox.getTextBox().getText(); if (end_text.endsWith(" ago") || end_text.endsWith("-ago")) { url.append(end_text); } else { url.append(FULLDATE.format(end)); } } else { // If there's no end-time, the graph may change while the URL remains // the same. No browser seems to re-fetch an image once it's been // fetched, even if we destroy the DOM object and re-created it with the // same src attribute. This has nothing to do with caching headers sent // by the server. The browsers simply won't retrieve the same URL again // through JavaScript manipulations, period. So as a workaround, we add // a special parameter that the server will delete from the query. url.append("&ignore=" + nrequests++); } if (!addAllMetrics(url)) { return; } addLabels(url); addFormats(url); addYRanges(url); addLogscales(url); if (nokey.getValue()) { url.append("&nokey"); } else if (!keypos.isEmpty() || horizontalkey.getValue()) { url.append("&key="); if (!keypos.isEmpty()) { url.append(keypos); } if (horizontalkey.getValue()) { url.append(" horiz"); } if (keybox.getValue()) { url.append(" box"); } } url.append("&wxh=").append(wxh.getText()); if (smooth.getValue()) { url.append("&smooth=csplines"); } final String unencodedUri = url.toString(); final String uri = URL.encode(unencodedUri); if (uri.equals(lastgraphuri)) { return; // Don't re-request the same graph. } else if (pending_requests++ > 0) { return; } lastgraphuri = uri; graphstatus.setText("Loading graph..."); asyncGetJson(uri + "&json", new GotJsonCallback() { public void got(final JSONValue json) { if (autoreoload_timer != null) { autoreoload_timer.cancel(); autoreoload_timer = null; } final JSONObject result = json.isObject(); final JSONValue err = result.get("err"); String msg = ""; if (err != null) { displayError("An error occurred while generating the graph: " + err.isString().stringValue()); graphstatus.setText("Please correct the error above."); } else { clearError(); String history = unencodedUri.substring(3) // Remove "/q?". .replaceFirst("ignore=[^&]*&", ""); // Unnecessary cruft. if (autoreload.getValue()) { history += "&autoreload=" + autoreoload_interval.getText(); } if (!history.equals(URL.decode(History.getToken()))) { History.newItem(history, false); } final JSONValue nplotted = result.get("plotted"); final JSONValue cachehit = result.get("cachehit"); if (cachehit != null) { msg += "Cache hit (" + cachehit.isString().stringValue() + "). "; } if (nplotted != null && nplotted.isNumber().doubleValue() > 0) { graph.setUrl(uri + "&png"); graph.setVisible(true); msg += result.get("points").isNumber() + " points retrieved, " + nplotted + " points plotted"; } else { graph.setVisible(false); msg += "Your query didn't return anything"; } final JSONValue timing = result.get("timing"); if (timing != null) { msg += " in " + timing + "ms."; } else { msg += '.'; } } final JSONValue info = result.get("info"); if (info != null) { if (!msg.isEmpty()) { msg += ' '; } msg += info.isString().stringValue(); } graphstatus.setText(msg); if (result.get("etags") != null) { final JSONArray etags = result.get("etags").isArray(); final int netags = etags.size(); for (int i = 0; i < netags; i++) { if (i >= metrics.getWidgetCount()) { break; } final Widget widget = metrics.getWidget(i); if (!(widget instanceof MetricForm)) { break; } final MetricForm metric = (MetricForm) widget; final JSONArray tags = etags.get(i).isArray(); // Skip if no tags were associated with the query. if (null != tags) { for (int j = 0; j < tags.size(); j++) { metric.autoSuggestTag(tags.get(j).isString().stringValue()); } } } } if (autoreload.getValue()) { final int reload_in = Integer.parseInt(autoreoload_interval.getValue()); if (reload_in >= 5) { autoreoload_timer = new Timer() { public void run() { // Verify that we still want auto reload and that the graph // hasn't been updated in the mean time. if (autoreload.getValue() && lastgraphuri == uri) { // Force refreshGraph to believe that we want a new graph. lastgraphuri = ""; refreshGraph(); } } }; autoreoload_timer.schedule(reload_in * 1000); } } if (--pending_requests > 0) { pending_requests = 0; refreshGraph(); } } }); }
From source file:viewer.Main.java
License:Open Source License
private void onModuleLoadReal() { server = getServer();/* w ww .ja v a2 s . c o m*/ indexname = getIndexName(); if (server == null) { promptForServerUi(); return; } status.setText("Checking server health..."); root.add(status); root.add(charts); removeLoadingMessage(); RootPanel.get().add(root); ajax("/" + indexname + "/_status", new AjaxCallback() { public void onSuccess(final JSONValue response) { final JSONObject resp = response.isObject(); if (resp.containsKey("ok") && resp.get("ok").isBoolean().booleanValue()) { status.setText("Server is ready, " + (resp.get("indices").isObject().get(currentIndexName()) .isObject().get("docs").isObject().get("num_docs")) + " traces available." + " Loading ..."); setupUi(); setupHistory(); } else if (resp.containsKey("error") && resp.containsKey("status")) { status.setText( "Server health check failed: error " + resp.get("status") + ": " + resp.get("error")); } else { status.setText("Incomprehensible response from server: " + resp); } } }); }
From source file:viewer.Main.java
License:Open Source License
private void loadTraces() { status.setText("Loading..."); final Json request_ts = object().add("from", toMillis(start_datebox)); if (end_datebox.getValue() != null) { request_ts.add("to", toMillis(end_datebox)); }/*from w w w . j a v a 2 s. c om*/ final String json = object().add("size", nresults) .add("sort", Json.array().add(sortby.getValue(sortby.getSelectedIndex()), object("order", "desc"))) .add("query", object("filtered", object("query", getESQuery()).add("filter", object("numeric_range", object("request_ts", request_ts))))) .add("facets", object().add("slowbe", object("terms", object("field", "prev_connect.host"))) .add("betype", object("terms", object("field", "prev_connect.type"))) //.add("lathisto", object("histogram", // object("field", "end_to_end").add("interval", 30))) ).toString(); ajax(indicesToSearch() + "/summary/_search", json, new AjaxCallback() { public void onSuccess(final JSONValue response) { final ESResponse<Summary> resp = ESResponse.fromJson(response.isObject()); status.setText("Found " + resp.hits().total() + " traces in " + resp.took() + "ms"); charts.clear(); renderChart(resp.<ESResponse.TermFacet>facets("slowbe"), "Slowest Backend Hosts", "host"); renderChart(resp.<ESResponse.TermFacet>facets("betype"), "Slowest Backend Types", "type"); renderLatencyHistogram(resp.<ESResponse.HistoFacet>facets("lathisto")); renderTraces(resp.hits()); } }); }
From source file:viewer.Main.java
License:Open Source License
private void expandTrace(final TreeItem parent, final String index, final String traceid, final Summary summary) { ajax('/' + index + "/trace/" + traceid, new AjaxCallback() { public void onSuccess(final JSONValue response) { final ESResponse.Hit<Trace> hit = ESResponse.Hit.fromJson(response.isObject()); parent.removeItems();/*from ww w .j a v a 2s. c om*/ parent.addItem(hit.source().widget(summary)); } }); }
From source file:virtuozo.infra.HttpMethod.java
License:Apache License
public <J extends JavaScriptObject> void send(JSOCallback<J> callback) { this.defaultAcceptType(MediaType.JSON); this.send(new CallbackProxy<J>(this, callback) { @SuppressWarnings("unchecked") protected J parse(String content) { try { JSONValue val = JSONParser.parseStrict(content); if (val.isObject() != null) { return (J) val.isObject().getJavaScriptObject(); }// ww w .ja v a2 s . c o m if (val.isArray() != null) { return (J) val.isArray().getJavaScriptObject(); } throw new AsyncException("Response was not a JSON object"); } catch (Exception e) { throw new AsyncException("Response was not a valid JSON document", e); } } }); }