public void onPortalLayoutChanged(PortalLayoutChanged event, IOSubchannel channel) throws IOException { persisted.put("previewLayout", event.previewLayout()); persisted.put("tabsLayout", event.tabsLayout()); persisted.put("xtraInfo", event.xtraInfo()); // Now store. JsonBeanEncoder encoder = JsonBeanEncoder.create(); encoder.writeObject(persisted); fire(new KeyValueStoreUpdate() .update(storagePath, encoder.toJson()), channel); }
/** * Creates a JSON notification from the given data. * Closes the `writer`. * * @param writer the writer * @throws IOException */ protected void toJson(Writer writer, String method, Object... params) throws IOException { JsonRpc rpc = JsonRpc.create(); rpc.setMethod(method); if (params.length > 0) { for (Object obj : params) { rpc.addParam(obj); } } JsonBeanEncoder.create(writer).writeObject(rpc).flush(); } }
/** * Merges and saves configuration updates. * * @param event the event * @throws IOException Signals that an I/O exception has occurred. */ @Handler(dynamic = true) @SuppressWarnings({ "PMD.DataflowAnomalyAnalysis", "PMD.AvoidLiteralsInIfCondition", "PMD.AvoidInstantiatingObjectsInLoops" }) public void onConfigurationUpdate(ConfigurationUpdate event) throws IOException { boolean changed = false; for (String path : event.paths()) { if ("/".equals(path) && !event.values(path).isPresent()) { // Special case, "remove root", i.e. all configuration data cache.clear(); changed = true; } changed = changed || handleSegment(cache, new StringTokenizer(path, "/"), event.values(path)); } if (changed) { try (Writer out = new OutputStreamWriter( Files.newOutputStream(file.toPath()), "utf-8"); JsonBeanEncoder enc = JsonBeanEncoder.create(out)) { enc.writeObject(cache); } } }
public void onPortalLayoutChanged(PortalLayoutChanged event, IOSubchannel channel) throws IOException { persisted.put("previewLayout", event.previewLayout()); persisted.put("tabsLayout", event.tabsLayout()); persisted.put("xtraInfo", event.xtraInfo()); // Now store. JsonBeanEncoder encoder = JsonBeanEncoder.create(); encoder.writeObject(persisted); fire(new KeyValueStoreUpdate() .update(storagePath, encoder.toJson()), channel); }
/** * Creates a JSON notification from the given data. * Closes the `writer`. * * @param writer the writer * @throws IOException */ protected void toJson(Writer writer, String method, Object... params) throws IOException { JsonRpc rpc = JsonRpc.create(); rpc.setMethod(method); if (params.length > 0) { for (Object obj : params) { rpc.addParam(obj); } } JsonBeanEncoder.create(writer).writeObject(rpc).flush(); } }