@Override public StageStatus getLatestStatus() { Preferences node = Preferences.userRoot().node(STAGE_PATH); try { String statusString = node.get(STAGE_STATUS_KEY, ""); if (isNotBlank(statusString)) { return JSON.std.beanFrom(StageStatus.class, statusString); } } catch (IOException e) { LOG.error("Unable to get latest stage status", e); } return StageStatus.NULL; }
public List<ModuleUsage> getUsages() { Preferences prefs = Preferences.userRoot().node(USAGE_PATH); List<ModuleUsage> retList = new ArrayList<>(); try { List<String> jsons = Arrays.stream(prefs.childrenNames()).parallel().map(name -> prefs.node(name)) .map(node -> node.get(MODULE_USAGE_KEY, "")).filter(json -> isNotBlank(json)).collect(toList()); for (String json : jsons) { retList.add(JSON.std.beanFrom(ModuleUsage.class, json)); } } catch (BackingStoreException | IOException e) { LOG.error("Unable to get modules usage statistics", e); } return retList; }
public void incrementUsageFor(String moduleId) { Preferences node = Preferences.userRoot().node(USAGE_PATH).node(moduleId); String json = node.get(MODULE_USAGE_KEY, ""); try { if (isNotBlank(json)) { node.put(MODULE_USAGE_KEY, JSON.std.asString(JSON.std.beanFrom(ModuleUsage.class, json).inc())); } else { node.put(MODULE_USAGE_KEY, JSON.std.asString(ModuleUsage.fistUsage(moduleId))); } LOG.trace("Usage incremented for module {}", moduleId); } catch (IOException e) { LOG.error("Unable to increment modules usage statistics", e); } finally { incrementTotalUsage(); } }
@Override public MeasurementPOJO _readItems(String input) throws Exception { return json.beanFrom(MeasurementPOJO.class, input); } }
@Override public MeasurementPOJO _readItems(byte[] input) throws Exception { return json.beanFrom(MeasurementPOJO.class, input); }
@Override public MeasurementPOJO _readItems(InputStream input) throws Exception { return json.beanFrom(MeasurementPOJO.class, input); }
private static Partitions loadPartitionFromStream(File stream, String location) { try { return JSON.std.with(JSON.Feature.FAIL_ON_UNKNOWN_BEAN_PROPERTY) .with(JSON.Feature.USE_IS_GETTERS) .beanFrom(Partitions.class, stream); } catch (IOException | RuntimeException e) { throw new RuntimeException("Error while loading partitions file from " + location, e); } } }
private static Partitions loadPartitionFromStream(File stream, String location) { try { return JSON.std.with(JSON.Feature.FAIL_ON_UNKNOWN_BEAN_PROPERTY) .with(JSON.Feature.USE_IS_GETTERS) .beanFrom(Partitions.class, stream); } catch (IOException | RuntimeException e) { throw new RuntimeException("Error while loading partitions file from " + location, e); } } }