final Cache.Handler<DatumShiftGridFile<?,?>> handler = DatumShiftGridFile.CACHE.lock(key); try { grid = handler.peek(); if (grid == null) { final Loader loader; handler.putAndUnlock(grid);
if (handler == null || (op = handler.peek()) == null) { final AuthorityFactory registry = USE_EPSG_FACTORY ? CRS.getAuthorityFactory(Constants.EPSG) : null; op = createOperationFinder((registry instanceof CoordinateOperationAuthorityFactory) ? handler.putAndUnlock(op);
handler.putAndUnlock(valueByMainThread); thread.join(); TestUtilities.rethrownIfNotNull(thread.failure);
if (handler == null || (op = handler.peek()) == null) { final AuthorityFactory registry = USE_EPSG_FACTORY ? CRS.getAuthorityFactory(Constants.EPSG) : null; op = createOperationFinder((registry instanceof CoordinateOperationAuthorityFactory) ? handler.putAndUnlock(op);
final Handler<V> handler = lock(key); try { value = handler.peek(); if (value == null) { value = creator.call(); handler.putAndUnlock(value);
final Handler<V> handler = lock(key); try { value = handler.peek(); if (value == null) { value = creator.apply(key); handler.putAndUnlock(value);
final Cache.Handler<DatumShiftGridFile<?,?>> handler = DatumShiftGridFile.CACHE.lock(key); try { grid = handler.peek(); if (grid == null) { final Loader loader; handler.putAndUnlock(grid);
final Cache.Handler<Object> handler = cache.lock(key); try { value = handler.peek(); if (!(value instanceof Set<?>)) { final DAO factory = getDataAccess(); handler.putAndUnlock(value);
final Cache.Handler<Object> handler = cache.lock(key); try { value = handler.peek(); if (!(value instanceof Set<?>)) { final DAO factory = getDataAccess(); handler.putAndUnlock(value);
final Cache.Handler<Object> handler = cache.lock(key); try { value = handler.peek(); if (!type.isInstance(value)) { final T result; handler.putAndUnlock(value);
final Cache.Handler<Object> handler = cache.lock(key); try { value = handler.peek(); if (!type.isInstance(value)) { final T result; handler.putAndUnlock(value);
final Cache.Handler<DatumShiftGridFile<?,?>> handler = DatumShiftGridFile.CACHE.lock(resolved); try { grid = handler.peek(); if (grid == null) { try (ReadableByteChannel in = Files.newByteChannel(resolved)) { handler.putAndUnlock(grid);
final Cache.Handler<DatumShiftGridFile<?,?>> handler = DatumShiftGridFile.CACHE.lock(resolved); try { grid = handler.peek(); if (grid == null) { try (ReadableByteChannel in = Files.newByteChannel(resolved)) { handler.putAndUnlock(grid);
final Cache.Handler<DatumShiftGridFile<?,?>> handler = DatumShiftGridFile.CACHE.lock(resolved); try { grid = handler.peek(); if (grid == null) { try (BufferedReader in = JDK8.newBufferedReader(resolved)) { handler.putAndUnlock(grid);
final Cache.Handler<DatumShiftGridFile<?,?>> handler = DatumShiftGridFile.CACHE.lock(resolved); try { grid = handler.peek(); if (grid == null) { try (BufferedReader in = Files.newBufferedReader(resolved)) { handler.putAndUnlock(grid);
/** * Returns the value for the given key. If a value already exists in the cache, then it * is returned immediately. Otherwise the {@code creator.call()} method is invoked and * its result is saved in this cache for future reuse. * * @param key the key for which to get the cached or created value. * @param creator a method for creating a value, to be invoked only if no value are cached for the given key. * @return the value for the given key, which may have been created as a result of this method call. * @throws Exception if an exception occurred during the execution of {@code creator.call()}. */ public V getOrCreate(final K key, final Callable<? extends V> creator) throws Exception { V value = peek(key); if (value == null) { final Handler<V> handler = lock(key); try { value = handler.peek(); if (value == null) { value = creator.call(); } } finally { handler.putAndUnlock(value); } } return value; }
/** * Tests adding a single value using the {@link Cache.Handler#putAndUnlock(Object)} method. * This method does all the operations in a single thread. */ @Test public void testPutAndUnlock() { final String key = "The key"; final String value = "The value"; final Cache<String,String> cache = new Cache<>(); assertTrue("No initial value expected.", cache.isEmpty()); assertNull("No initial value expected.", cache.peek(key)); final Cache.Handler<String> handler = cache.lock(key); assertNull("No initial value expected.", handler.peek()); handler.putAndUnlock(value); assertEquals(1, cache.size()); assertEquals(value, cache.peek(key)); assertEquals(singleton(key), cache.keySet()); assertEquals(singleton(new SimpleEntry<>(key, value)), cache.entrySet()); }