@Override /* ConfigStore */ public synchronized String write(String name, String expectedContents, String newContents) throws IOException { // This is a no-op. if (isEquals(expectedContents, newContents)) return null; String currentContents = read(name); if (expectedContents != null && ! isEquals(currentContents, expectedContents)) return currentContents; update(name, newContents); return null; }
@Override /* ConfigStore */ public synchronized String write(String name, String expectedContents, String newContents) throws IOException { // This is a no-op. if (isEquals(expectedContents, newContents)) return null; String currentContents = read(name); if (expectedContents != null && ! isEquals(currentContents, expectedContents)) return currentContents; update(name, newContents); return null; }
@Override /* ConfigStore */ public synchronized String write(String name, String expectedContents, String newContents) throws IOException { // This is a no-op. if (isEquals(expectedContents, newContents)) return null; String currentContents = read(name); if (expectedContents != null && ! isEquals(currentContents, expectedContents)) return currentContents; update(name, newContents); return null; }
@Test public void testUpdate() throws Exception { ConfigClasspathStore fs = ConfigClasspathStore.create().build(); final CountDownLatch latch = new CountDownLatch(2); fs.register("X.cfg", new ConfigStoreListener() { @Override public void onChange(String contents) { if ("xxx".equals(contents)) latch.countDown(); } }); fs.register("Y.cfg", new ConfigStoreListener() { @Override public void onChange(String contents) { if ("yyy".equals(contents)) latch.countDown(); } }); fs.update("X.cfg", "xxx"); fs.update("Y.cfg", "yyy"); if (! latch.await(10, TimeUnit.SECONDS)) throw new Exception("CountDownLatch never reached zero."); }