@Test public void fetchUrl() { ValueFilterFetchOnce fetch = new ValueFilterFetchOnce(5000); String result1 = fetch.filter("http: assertNotNull(result1); String result2 = fetch.filter("http: assertEquals(result1, result2); }
@Override public String filter(String input) { Preconditions.checkNotNull(input, "input to fetch-once filter must be non-null"); while (true) { String cacheRead = cache; if (cacheRead == null) { if (CACHE_UPDATER.compareAndSet(this, null, input)) { makeHttpRequest(input); } } else if (!cacheRead.equals(input)) { throw new IllegalStateException("fetch attempted on multiple urls " + cacheRead + " and " + input); } else { try { return result.get(timeout, TimeUnit.MILLISECONDS); } catch (ExecutionException ex) { throw Throwables.propagate(ex.getCause()); } catch (Exception ex) { throw Throwables.propagate(ex); } } } }
ValueFilterFetchOnce extends StringFilter { @Override public String filter(String input) { Preconditions.checkNotNull(input, "input to fetch-once filter must be non-null"); while (true) { String cacheRead = cache; if (cacheRead == null) { if (CACHE_UPDATER.compareAndSet(this, null, input)) { makeHttpRequest(input); } } else if (!cacheRead.equals(input)) { throw new IllegalStateException("fetch attempted on multiple urls " + cacheRead + " and " + input); } else { try { return result.get(timeout, TimeUnit.MILLISECONDS); } catch (ExecutionException ex) { throw Throwables.propagate(ex.getCause()); } catch (Exception ex) { throw Throwables.propagate(ex); } } } } }
ValueFilterFetchOnce extends StringFilter { @Override public String filter(String input) { Preconditions.checkNotNull(input, "input to fetch-once filter must be non-null"); while (true) { String cacheRead = cache; if (cacheRead == null) { if (CACHE_UPDATER.compareAndSet(this, null, input)) { makeHttpRequest(input); } } else if (!cacheRead.equals(input)) { throw new IllegalStateException("fetch attempted on multiple urls " + cacheRead + " and " + input); } else { try { return result.get(timeout, TimeUnit.MILLISECONDS); } catch (ExecutionException ex) { throw Throwables.propagate(ex.getCause()); } catch (Exception ex) { throw Throwables.propagate(ex); } } } } @JsonCreator  ValueFilterFetchOnce(@JsonProperty(value = "timeout", required = true)
                                @Time(TimeUnit.MILLISECONDS) int timeout); }
ValueFilterFetchOnce extends StringFilter { @Override public String filter(String input) { Preconditions.checkNotNull(input, "input to fetch-once filter must be non-null"); while (true) { String cacheRead = cache; if (cacheRead == null) { if (CACHE_UPDATER.compareAndSet(this, null, input)) { makeHttpRequest(input); } } else if (!cacheRead.equals(input)) { throw new IllegalStateException("fetch attempted on multiple urls " + cacheRead + " and " + input); } else { try { return result.get(timeout, TimeUnit.MILLISECONDS); } catch (ExecutionException ex) { throw Throwables.propagate(ex.getCause()); } catch (Exception ex) { throw Throwables.propagate(ex); } } } } @JsonCreator  ValueFilterFetchOnce(@JsonProperty(value = "timeout", required = true)
                                @Time(TimeUnit.MILLISECONDS) int timeout); @Override String filter(String input); }
ValueFilterFetchOnce extends StringFilter { @Override public String filter(String input) { Preconditions.checkNotNull(input, "input to fetch-once filter must be non-null"); while (true) { String cacheRead = cache; if (cacheRead == null) { if (CACHE_UPDATER.compareAndSet(this, null, input)) { makeHttpRequest(input); } } else if (!cacheRead.equals(input)) { throw new IllegalStateException("fetch attempted on multiple urls " + cacheRead + " and " + input); } else { try { return result.get(timeout, TimeUnit.MILLISECONDS); } catch (ExecutionException ex) { throw Throwables.propagate(ex.getCause()); } catch (Exception ex) { throw Throwables.propagate(ex); } } } } @JsonCreator  ValueFilterFetchOnce(@JsonProperty(value = "timeout", required = true)
                                @Time(TimeUnit.MILLISECONDS) int timeout); @Override String filter(String input);  }