List of usage examples for com.google.gson JsonObject get
public JsonElement get(String memberName)
From source file:com.app.smarthome.SmartHomeApplication.java
private void Sdkinit() { JsonObject initJsonObjectIn = new JsonObject(); JsonObject initJsonObjectOut = new JsonObject(); String initOut;//from ww w .ja va2 s. c o m initJsonObjectIn.addProperty("typelicense", typelicense); initJsonObjectIn.addProperty("userlicense", userlicense); initJsonObjectIn.addProperty("filepath", filepath); String string = initJsonObjectIn.toString(); initOut = mBlNetwork.SDKInit(string); initJsonObjectOut = new JsonParser().parse(initOut).getAsJsonObject(); if (initJsonObjectOut.get("code").getAsInt() != 0) { Log.i("Sdkinit failed", initJsonObjectOut.get("msg").getAsString()); } // ?? HC_DVRManager.getInstance().initSDK(); }
From source file:com.appdynamics.extensions.couchbase.CouchBaseWrapper.java
License:Apache License
/** * Gathers Cluster and Node stats. Cluster stats as Map of CLUSTER_STATS_KEY * and Map of MetricName, MetricValue and NodeStats as Map of NodeName, Map * of MetricName, MetricValue//from w w w .j a v a 2 s . c o m * * @param httpClient * @return */ public Map<String, Map<String, Double>> gatherClusterNodeMetrics(SimpleHttpClient httpClient) { JsonElement clusterNodeResponse = getResponse(httpClient, CLUSTER_NODE_URI); Map<String, Map<String, Double>> clusterNodeMetrics = new HashMap<String, Map<String, Double>>(); if (clusterNodeResponse != null && clusterNodeResponse.isJsonObject()) { JsonObject clusterNodeJsonObject = clusterNodeResponse.getAsJsonObject(); JsonObject storageTotals = clusterNodeJsonObject.getAsJsonObject("storageTotals"); clusterNodeMetrics = populateClusterMetrics(clusterNodeMetrics, storageTotals); JsonArray nodes = (JsonArray) clusterNodeJsonObject.get("nodes"); clusterNodeMetrics.putAll(populateNodeMetrics(nodes)); } return clusterNodeMetrics; }
From source file:com.appdynamics.extensions.couchbase.CouchBaseWrapper.java
License:Apache License
/** * Populates the node metrics hashmap//from w w w . jav a 2s . c o m * * @param nodes * @return */ private Map<String, Map<String, Double>> populateNodeMetrics(JsonArray nodes) { Map<String, Map<String, Double>> nodeMetrics = new HashMap<String, Map<String, Double>>(); for (JsonElement node : nodes) { JsonObject nodeObject = node.getAsJsonObject(); Map<String, Double> metrics = new HashMap<String, Double>(); nodeMetrics.put(nodeObject.get("hostname").getAsString(), metrics); JsonObject interestingStats = nodeObject.getAsJsonObject("interestingStats"); Iterator<Entry<String, JsonElement>> iterator = interestingStats.entrySet().iterator(); populateMetricsMapHelper(iterator, metrics, ""); JsonObject systemStats = nodeObject.getAsJsonObject("systemStats"); iterator = systemStats.entrySet().iterator(); populateMetricsMapHelper(iterator, metrics, ""); iterator = nodeObject.entrySet().iterator(); populateMetricsMapHelper(iterator, metrics, ""); } return nodeMetrics; }
From source file:com.appdynamics.extensions.couchbase.CouchBaseWrapper.java
License:Apache License
/** * Populates the bucket metrics hashmap//from www .j a v a 2 s.c o m * * @param buckets * @return */ private Map<String, Map<String, Double>> populateBucketMetrics(JsonArray buckets) { Map<String, Map<String, Double>> bucketMetrics = new HashMap<String, Map<String, Double>>(); for (JsonElement bucket : buckets) { JsonObject bucketObject = bucket.getAsJsonObject(); Map<String, Double> metrics = new HashMap<String, Double>(); bucketMetrics.put(bucketObject.get("name").getAsString(), metrics); JsonObject interestingStats = bucketObject.getAsJsonObject("quota"); Iterator<Entry<String, JsonElement>> iterator = interestingStats.entrySet().iterator(); populateMetricsMapHelper(iterator, metrics, ""); JsonObject systemStats = bucketObject.getAsJsonObject("basicStats"); iterator = systemStats.entrySet().iterator(); populateMetricsMapHelper(iterator, metrics, ""); } return bucketMetrics; }
From source file:com.appdynamics.extensions.couchdb.CouchDBWrapper.java
License:Apache License
/** * Constructs a HashMap of metrics based on the JSON Response received upon * executing CouchDB's /_stats REST API request * /*from w ww . ja v a 2 s.c om*/ * @param metricsObject * @return */ public List<CouchDBMetric> constructMetricsList(JsonObject metricsObject) { // 1st level: Metric Category // 2nd level: Metric Name // 3rd level: MetricAggregationType List<CouchDBMetric> metricsList = Lists.newArrayList(); for (Entry<String, JsonElement> category : metricsObject.entrySet()) { JsonObject categoryMetrics = category.getValue().getAsJsonObject(); for (Entry<String, JsonElement> metric : categoryMetrics.entrySet()) { CouchDBMetric couchDBMetric = new CouchDBMetric(); couchDBMetric.setMetricCategory(category.getKey()); couchDBMetric.setMetricName(metric.getKey()); JsonObject jsonObject = metric.getValue().getAsJsonObject(); Map<MetricAggregationType, BigDecimal> values = Maps.newHashMap(); for (MetricAggregationType type : MetricAggregationType.values()) { if (!jsonObject.get(type.getAggregationType()).isJsonNull()) { BigDecimal metricValue = jsonObject.get(type.getAggregationType()).getAsBigDecimal(); logger.debug("Category:" + couchDBMetric.getMetricCategory() + " MetricName:" + couchDBMetric.getMetricName() + " " + type + ":" + metricValue); values.put(type, metricValue); } } couchDBMetric.setValues(values); metricsList.add(couchDBMetric); } } return metricsList; }
From source file:com.appdynamics.monitors.boundary.BoundaryWrapper.java
License:Apache License
/** * Retrieves observation domain ids from the /meters REST request * @return Map A map containing the name of the meter and it's corresponding observationDomainId *//*from w w w . j ava 2 s . c o m*/ private void populateObservationDomainIds() throws Exception { HttpGet httpGet = new HttpGet(constructMetersURL()); httpGet.addHeader(BasicScheme.authenticate(new UsernamePasswordCredentials(apiKey, ""), "UTF-8", false)); HttpClient httpClient = new DefaultHttpClient(); HttpResponse response = httpClient.execute(httpGet); HttpEntity entity = response.getEntity(); BufferedReader bufferedReader2 = new BufferedReader(new InputStreamReader(entity.getContent())); StringBuilder responseString = new StringBuilder(); String line = ""; while ((line = bufferedReader2.readLine()) != null) { responseString.append(line); } JsonArray responseArray = new JsonParser().parse(responseString.toString()).getAsJsonArray(); for (int i = 0; i < responseArray.size(); i++) { JsonObject obj = responseArray.get(i).getAsJsonObject(); meterIds.put(obj.get("name").getAsString(), obj.get("obs_domain_id").getAsString()); } }
From source file:com.appdynamics.monitors.varnish.VarnishWrapper.java
License:Apache License
/** * Constructs the metrics hashmap by iterating over the JSON response retrieved from the /stats url * @param responseData the JSON response retrieved from hitting the /stats url * @return HashMap containing all metrics for Varnish * @throws Exception/*from w w w . j a v a 2 s . c om*/ */ private HashMap<String, Long> constructMetricsMap(JsonObject responseData) throws Exception { HashMap<String, Long> metrics = new HashMap<String, Long>(); Iterator iterator = responseData.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<String, JsonElement> entry = (Map.Entry<String, JsonElement>) iterator.next(); if (!entry.getValue().isJsonPrimitive()) { String metricName = entry.getKey(); JsonObject metricObject = entry.getValue().getAsJsonObject(); Long metricValue = metricObject.get("value").getAsLong(); metrics.put(metricName, metricValue); } } return metrics; }
From source file:com.appspot.bitlyminous.gateway.DiggGateway.java
License:Apache License
/** * Gets the popular stories.// w w w. ja v a2s.co m * * @param tag the tag * @param count the count * * @return the popular stories */ public List<Story> getPopularStories(String tag, int count) { GatewayApiUrlBuilder builder = createApiUrlBuilder(ApplicationConstants.DIGG_SEARCH_URL); String apiUrl = builder.withParameter("query", tag).withParameter("count", String.valueOf(count)) .buildUrl(); JsonObject json = parseJson(callApiGet(apiUrl)).getAsJsonObject(); return unmarshall(new TypeToken<List<Story>>() { }, json.get("stories")); }
From source file:com.appspot.bitlyminous.gateway.FoursquareGateway.java
License:Apache License
/** * Gets the nearby tips.//from w w w. ja va 2 s . c o m * * @param location the location * @param limit the limit * * @return the nearby tips */ public List<Tip> getNearbyTips(GeoLocation location, int limit) { GatewayApiUrlBuilder builder = createApiUrlBuilder(ApplicationConstants.FOURSQUARE_NEAR_BY_TIPS_URL); String apiUrl = builder.withParameter("geolat", String.valueOf(location.getLatitude())) .withParameter("geolong", String.valueOf(location.getLongitude())) .withParameter("l", String.valueOf(limit)).withParameter("filter", "nearby").buildUrl(); JsonObject json = parseJson(callApiGet(apiUrl)).getAsJsonObject(); return unmarshall(new TypeToken<List<Tip>>() { }, json.get("tips")); }
From source file:com.appspot.bitlyminous.gateway.FoursquareGateway.java
License:Apache License
/** * Gets the nearby venues.//from w ww .j a v a2 s.c o m * * @param location the location * @param query the query * @param limit the limit * * @return the nearby venues */ public List<Venue> getNearbyVenues(GeoLocation location, String query, int limit) { GatewayApiUrlBuilder builder = createApiUrlBuilder(ApplicationConstants.FOURSQUARE_NEAR_BY_VENUES_URL); String apiUrl = builder.withParameter("geolat", String.valueOf(location.getLatitude())) .withParameter("geolong", String.valueOf(location.getLongitude())) .withParameter("l", String.valueOf(limit)).withParameter("q", query).buildUrl(); JsonObject json = parseJson(callApiGet(apiUrl)).getAsJsonObject(); JsonArray groups = json.get("groups").getAsJsonArray(); if (groups.iterator().hasNext()) { return unmarshall(new TypeToken<List<Venue>>() { }, groups.iterator().next().getAsJsonObject().get("venues")); } else { return new ArrayList<Venue>(); } }