private VersionedKey loadKeyFromCouchbase() { Optional<String> optionalKey = connection.get(key); return optionalKey.flatMap(val -> Optional.of(JacksonUtil.convertFromJson(val, VersionedKey.class))) .orElse(newKey(0L)); }
@SuppressWarnings("unchecked") private Object nonAtomicload(String newVersionedKey) throws Throwable { Data data = (Data) connection.get(newVersionedKey) .orElseThrow(() -> { return new ManifestComparatorKeyNotFoundException( "Missing versioned key " + newVersionedKey + " - likely data changed during read"); }); logger.info("Loaded new data with date {} for key {}, versionedKey {}, versionedKey from data ", new Object[] { data.getDate(), key, newVersionedKey, data.getVersionedKey() }); return data.getData(); }
@GET @Path("/get") public String bucket() { return client.get("hello") .toString(); }
@GET @Path("/get") public String bucket() { return client.get("hello") .toString(); }
@GET @Path("/get") public String bucket() { return client.get("hello") .toString(); }
@GET @Path("/get") public String bucket() { return client.get("hello").toString(); }
@GET @Path("/get") public String bucket() { return client.get("hello").toString(); }
/** * Load data from remote store if stale */ @Override public synchronized boolean load() { Either<Void, T> oldData = data; String oldKey = versionedKey; try { if (isOutOfDate()) { String newVersionedKey = (String) connection.get(key) .get(); data = Either.right((T) nonAtomicload(newVersionedKey)); versionedKey = newVersionedKey; } else { return false; } } catch (Throwable e) { data = oldData; versionedKey = oldKey; logger.debug(e.getMessage(), e); throw ExceptionSoftener.throwSoftenedException(e); } return true; }
@Test public void createDistributedCacheMemcachedOff() throws IOException, URISyntaxException { config.setCouchbaseClientEnabled(false); DistributedMap<Object> cache = config.simpleCouchbaseClient(); assertThat(cache.get("hello"), is(Optional.empty())); }