@Override public Set<Run> consume(Message<Map<String, List<String>>> message) throws InterrogationException { RequestManager requestManager = message.getHeaders().get("handler", RequestManager.class); Assert.notNull( requestManager, "Cannot consume MISO notification messages without a RequestManager."); Map<String, List<String>> statuses = message.getPayload(); Set<Run> output = new HashSet<Run>(); for (String key : statuses.keySet()) { HealthType ht = HealthType.valueOf(key); JSONArray runs = (JSONArray) JSONArray.fromObject(statuses.get(key)).get(0); Map<String, Run> map = processRunJSON(ht, runs, requestManager); for (Run r : map.values()) { output.add(r); } } return output; }
private <T> Collection<T> random(Store<T> s, int rows, int sampleSize) { if (rows > 0) { Set<T> ret = new HashSet<T>(); Random r = new Random(); for (int i = 0; i < sampleSize; i++) { try { int rand = r.nextInt(rows); if (rand != 0) { T t; try { Method lazy = s.getClass().getDeclaredMethod("lazyGet", Long.TYPE); t = (T) lazy.invoke(s, new Long(rand)); } catch (NoSuchMethodException e) { System.out.println("WARN:: Unable to lazily get object. Using full get."); t = s.get(Integer.valueOf(rand).longValue()); } catch (InvocationTargetException e) { System.out.println("WARN:: Unable to lazily get object. Using full get."); t = s.get(Integer.valueOf(rand).longValue()); } catch (IllegalAccessException e) { System.out.println("WARN:: Unable to lazily get object. Using full get."); t = s.get(Integer.valueOf(rand).longValue()); } if (t != null) { ret.add(t); } } } catch (IOException e) { System.out.println("ERROR:: could not get random object from store"); } } return ret; } else { return Collections.emptySet(); } }