/** * Completely eliminates a {@link GeoServerTileLayer} from GWC. * * <p>This method is intended to be called whenever a {@link LayerInfo} or {@link * LayerGroupInfo} is removed from GeoServer, or it is configured not to create a cached layer * for it, in order to delete the cache for the layer. * * @param prefixedName the name of the layer to remove. * @return {@code true} if the removal of the entire cache for the layer has succeeded, {@code * false} if there wasn't a cache for that layer. */ public synchronized boolean layerRemoved(final String prefixedName) { try { return storageBroker.delete(prefixedName); } catch (StorageException e) { throw new RuntimeException(e); } }
public boolean retrieve(long maxAge) throws GeoWebCacheException { try { if (isMetaTileCacheOnly) { boolean cached = storageBroker.getTransient((TileObject) stObj); this.setCacheResult(cached ? CacheResult.HIT : CacheResult.MISS); return cached; } boolean ret = storageBroker.get((TileObject) stObj); // Do we use expiration, and if so, is the tile recent enough ? if (ret && maxAge > 0 && stObj.getCreated() + maxAge < System.currentTimeMillis()) { ret = false; } if (ret) { this.setCacheResult(CacheResult.HIT); } else { this.setCacheResult(CacheResult.MISS); } return ret; } catch (StorageException se) { log.warn(se.getMessage()); return false; } }
/** * Completely deletes the cache for a layer/gridset combination; differs from truncate that the * layer doesn't need to have a gridSubset associated for the given gridset at runtime (in order * to handle the deletion of a layer's gridsubset) * * @param layerName The layer name * @param gridSetId The gridset name @TODO: make async?, it may take a while to the metastore to * delete all tiles (sigh) */ public void deleteCacheByGridSetId(final String layerName, final String gridSetId) { try { storageBroker.deleteByGridSetId(layerName, gridSetId); } catch (StorageException e) { throw propagate(getRootCause(e)); } }
private void installMockBroker() throws Exception { expect(storageBroker.getTransient((TileObject) anyObject())) .andAnswer( new IAnswer<Boolean>() { .anyTimes(); storageBroker.putTransient( capture( new Capture<TileObject>() { storageBroker.put( capture( new Capture<TileObject>() { .andReturn(true) .anyTimes(); expect(storageBroker.get((TileObject) anyObject())) .andAnswer( new IAnswer<Boolean>() {
private void runBasicTileTest(StorageBroker sb, long run, String name) throws StorageException { long start = System.currentTimeMillis(); for (int i = 1; i < TILE_GET_COUNT; i++) { long tmp = (long) Math.log(i) + 1; long tmp2 = i % tmp; long[] xyz = {tmp2, tmp2, (long) Math.log10(i)}; TileObject queryObj2 = TileObject.createQueryTileObject( "test", xyz, "hefty-gridSet:id1", "image/jpeg", null); sb.get(queryObj2); } long stop = System.currentTimeMillis(); System.out.println( name + " - run " + run + ", " + TILE_GET_COUNT + " gets took " + Long.toString(stop - start) + "ms"); }
/** * Notification that a layer has been added; to be called by {@link CatalogConfiguration} * whenever {@link CatalogConfiguration#save() save} is called and a layer has been renamed. * <p> * NOTE: this should be hanlded by GWC itself somehow, like with a configuration listener of * some sort. * * @param oldLayerName * @param newLayerName */ public void layerRenamed(String oldLayerName, String newLayerName) { try { log.info("Renaming GWC TileLayer '" + oldLayerName + "' as '" + newLayerName + "'"); // /embeddedConfig.rename(oldLayerName, newLayerName); storageBroker.rename(oldLayerName, newLayerName); } catch (StorageException e) { log.log(Level.WARNING, e.getMessage(), e); throw new RuntimeException(e); } }
private Collection<String> getParameterIds( String layerName, Optional<Collection<String>> parameterIds) { return parameterIds.orElseGet( () -> { try { return sb.getCachedParameterIds(layerName); } catch (StorageException e) { log.error( "Error while retreiving cached parameter IDs for layer " + layerName, e); return Collections.emptySet(); } }); }
tileProto.getStorageBroker().putTransient(tile); } else { tileProto.getStorageBroker().put(tile);
public boolean persist() throws GeoWebCacheException { try { return storageBroker.put((TileObject) stObj); } catch (StorageException e) { throw new GeoWebCacheException(e); } }
@Override public boolean doTruncate(StorageBroker sb, TileBreeder breeder) throws StorageException, GeoWebCacheException { final Set<Map<String, String>> allParams = sb.getCachedParameters(layerName); final TileLayer tileLayer = breeder.findTileLayer(layerName); final Collection<MimeType> allFormats = tileLayer.getMimeTypes();
StorageBroker sb = mock(StorageBroker.class); Mockito.when(sb.get(argThat(Matchers.instanceOf(TileObject.class)))) .thenAnswer( invoc -> {
/** * Notification that a layer has been added; to be called by {@link CatalogConfiguration} * whenever {@link CatalogConfiguration#save() save} is called and a layer has been renamed. * * <p>NOTE: this should be hanlded by GWC itself somehow, like with a configuration listener of * some sort. * * @param oldLayerName * @param newLayerName */ public void layerRenamed(String oldLayerName, String newLayerName) { try { log.info("Renaming GWC TileLayer '" + oldLayerName + "' as '" + newLayerName + "'"); // /embeddedConfig.rename(oldLayerName, newLayerName); storageBroker.rename(oldLayerName, newLayerName); } catch (StorageException e) { log.log(Level.WARNING, e.getMessage(), e); throw new RuntimeException(e); } }
EasyMock.expect(storageBroker.getCachedParameterIds(EasyMock.capture(layerNameCap))) .andStubAnswer( () ->
private StorageBroker resetAndPrepStorageBroker() throws Exception { System.out.println("Deleting old test database."); String blobPath = findTempDir() + File.separator + TEST_BLOB_DIR_NAME; System.out.println("Creating new blobstore in " + blobPath); File blobDirs = new File(blobPath); if (!blobDirs.exists() && !blobDirs.mkdirs()) { throw new StorageException("Unable to create " + blobPath); } BlobStore blobStore = new FileBlobStore(blobPath); TransientCache transCache = new TransientCache(100, 1024, 2000); StorageBroker sb = new DefaultStorageBroker(blobStore); // long[] xyz = {1L,2L,3L}; Resource blob = new ByteArrayResource(new byte[20 * 1024]); System.out.println("Inserting into database, " + TILE_PUT_COUNT + " tiles"); long startInsert = System.currentTimeMillis(); for (int i = 1; i < TILE_PUT_COUNT; i++) { long tmp = (long) Math.log(i) + 1; long tmp2 = i % tmp; long[] xyz = {tmp2, tmp2, (long) Math.log10(i)}; TileObject completeObj = TileObject.createCompleteTileObject( "test", xyz, "hefty-gridSet:id1", "image/jpeg", null, blob); sb.put(completeObj); } long stopInsert = System.currentTimeMillis(); System.out.println( TILE_PUT_COUNT + " inserts took " + Long.toString(stopInsert - startInsert) + "ms"); return sb; }
EasyMock.expect(broker.getCachedParameters(layerName)) .andStubReturn(Collections.unmodifiableSet(allParams)); EasyMock.expect(breeder.findTileLayer(layerName)).andStubReturn(layer);
/** * Completely eliminates a {@link GeoServerTileLayer} from GWC. * <p> * This method is intended to be called whenever a {@link LayerInfo} or {@link LayerGroupInfo} * is removed from GeoServer, or it is configured not to create a cached layer for it, in order * to delete the cache for the layer. * </p> * * @param prefixedName * the name of the layer to remove. * @return {@code true} if the removal of the entire cache for the layer has succeeded, * {@code false} if there wasn't a cache for that layer. */ public synchronized boolean layerRemoved(final String prefixedName) { try { return storageBroker.delete(prefixedName); } catch (StorageException e) { throw new RuntimeException(e); } }
/** * Completely deletes the cache for a layer/gridset combination; differs from truncate that the * layer doesn't need to have a gridSubset associated for the given gridset at runtime (in order * to handle the deletion of a layer's gridsubset) * * @param layerName * @param removedGridset * @TODO: make async?, it may take a while to the metastore to delete all tiles (sigh) */ public void deleteCacheByGridSetId(final String layerName, final String gridSetId) { try { storageBroker.deleteByGridSetId(layerName, gridSetId); } catch (StorageException e) { throw propagate(getRootCause(e)); } }