/** * Truncates the cache for the given layer/style combination * * @param layerName * @param styleName */ public void truncateByLayerAndStyle(final String layerName, final String styleName) { // check if the given style is actually cached if (log.isLoggable(Level.FINE)) { log.fine("Truncate for layer/style called. Checking if style '" + styleName + "' is cached for layer '" + layerName + "'"); } if (!isStyleCached(layerName, styleName)) { log.fine("Style '" + styleName + "' is not cached for layer " + layerName + "'. No need to truncate."); return; } log.fine("truncating '" + layerName + "' for style '" + styleName + "'"); String gridSetId = null; // all of them BoundingBox bounds = null;// all of them String format = null;// all of them truncate(layerName, styleName, gridSetId, bounds, format); }
/** * Options are: * <ul> * <li>A {@link LayerInfo} has {@code modifiedStyle} as either its default or style or as one of * its alternate styles * <li>A {@link LayerGroupInfo} contains a layer using {@code modifiedStyle} * <li>{@code modifiedStyle} is explicitly assigned to a {@link LayerGroupInfo} * </ul> * * @param modifiedStyle */ private void handleStyleChange(final StyleInfo modifiedStyle) { final String styleName = modifiedStyle.getName(); log.finer("Handling style modification: " + styleName); // First we collect all the layers that use this style for (LayerInfo affectedLayer : mediator.getLayerInfosFor(modifiedStyle)) { // If the style name changes, we need to update the layer's parameter filter String prefixedName = tileLayerName(affectedLayer); log.info("Truncating layer '" + prefixedName + "' due to a change in style '" + styleName + "'"); mediator.truncateByLayerAndStyle(prefixedName, styleName); } // Now we check for layer groups that are affected for (LayerGroupInfo layerGroup : mediator.getLayerGroupsFor(modifiedStyle)) { String layerGroupName = tileLayerName(layerGroup); log.info("Truncating layer group '" + layerGroupName + "' due to a change in style '" + styleName + "'"); mediator.truncate(layerGroupName); } }
truncate(layerName, styleName, gridSetId, bounds, format);
+ styleName + "'"); mediator.truncate(layerGroupName);
private void handleLayerGroupInfoChange(final List<String> changedProperties, final List<Object> oldValues, final List<Object> newValues, final LayerGroupInfo lgInfo, final GeoServerTileLayerInfo tileLayerInfo) { checkNotNull(lgInfo); checkNotNull(tileLayerInfo); final String layerName = tileLayerName(lgInfo); boolean truncate = false; if (changedProperties.contains("layers")) { final int layersIndex = changedProperties.indexOf("layers"); Object oldLayers = oldValues.get(layersIndex); Object newLayers = newValues.get(layersIndex); truncate = !oldLayers.equals(newLayers); } if (!truncate && changedProperties.contains("styles")) { final int stylesIndex = changedProperties.indexOf("styles"); Object oldStyles = oldValues.get(stylesIndex); Object newStyles = newValues.get(stylesIndex); truncate = !oldStyles.equals(newStyles); } if (truncate) { log.info("Truncating TileLayer for layer group '" + layerName + "' due to a change in its layers or styles"); mediator.truncate(layerName); } }
String gridSetName = null; BoundingBox bounds = null; mediator.truncate(layerName, styleName, gridSetName, bounds, removedFormat);
private void handleLayerGroupInfoChange( final List<String> changedProperties, final List<Object> oldValues, final List<Object> newValues, final LayerGroupInfo lgInfo, final GeoServerTileLayerInfo tileLayerInfo) { checkNotNull(lgInfo); checkNotNull(tileLayerInfo); final String layerName = tileLayerName(lgInfo); boolean truncate = false; if (changedProperties.contains("layers")) { final int layersIndex = changedProperties.indexOf("layers"); Object oldLayers = oldValues.get(layersIndex); Object newLayers = newValues.get(layersIndex); truncate = !oldLayers.equals(newLayers); } if (!truncate && changedProperties.contains("styles")) { final int stylesIndex = changedProperties.indexOf("styles"); Object oldStyles = oldValues.get(stylesIndex); Object newStyles = newValues.get(stylesIndex); truncate = !oldStyles.equals(newStyles); } if (truncate) { log.info( "Truncating TileLayer for layer group '" + layerName + "' due to a change in its layers or styles"); mediator.truncate(layerName); } }
String gridSetName = null; BoundingBox bounds = null; mediator.truncate(layerName, styleName, gridSetName, bounds, removedFormat);
private void afterTransactionInternal(final TransactionType transaction, boolean committed) { final Map<String, List<ReferencedEnvelope>> byLayerDirtyRegions = getByLayerDirtyRegions(transaction); if (byLayerDirtyRegions.isEmpty()) { return; } for (String tileLayerName : byLayerDirtyRegions.keySet()) { List<ReferencedEnvelope> dirtyList = byLayerDirtyRegions.get(tileLayerName); ReferencedEnvelope dirtyRegion; try { dirtyRegion = merge(tileLayerName, dirtyList); } catch (Exception e) { log.log(Level.WARNING, e.getMessage(), e); continue; } if (dirtyRegion == null) { continue; } try { gwc.truncate(tileLayerName, dirtyRegion); } catch (GeoWebCacheException e) { log.warning("Error truncating tile layer " + tileLayerName + " for transaction affected bounds " + dirtyRegion); } } }
private void afterTransactionInternal(final TransactionRequest transaction, boolean committed) { final Map<String, List<ReferencedEnvelope>> byLayerDirtyRegions = getByLayerDirtyRegions(transaction); if (byLayerDirtyRegions.isEmpty()) { return; } for (String tileLayerName : byLayerDirtyRegions.keySet()) { List<ReferencedEnvelope> dirtyList = byLayerDirtyRegions.get(tileLayerName); ReferencedEnvelope dirtyRegion; try { dirtyRegion = merge(tileLayerName, dirtyList); } catch (Exception e) { log.log(Level.WARNING, e.getMessage(), e); continue; } if (dirtyRegion == null) { continue; } try { gwc.truncate(tileLayerName, dirtyRegion); } catch (GeoWebCacheException e) { log.warning( "Error truncating tile layer " + tileLayerName + " for transaction affected bounds " + dirtyRegion); } } }
public void testAfterTransaction() throws Exception { Map<Object, Object> extendedProperties = new HashMap<Object, Object>(); ReferencedEnvelope affectedBounds1 = new ReferencedEnvelope(-180, 0, 0, 90, WGS84); ReferencedEnvelope affectedBounds2 = new ReferencedEnvelope(0, 180, 0, 90, WGS84); issueInsert(extendedProperties, affectedBounds1); issueInsert(extendedProperties, affectedBounds2); TransactionType request = mock(TransactionType.class); TransactionResponseType result = mock(TransactionResponseType.class); when(request.getExtendedProperties()).thenReturn(extendedProperties); when(mediator.getDeclaredCrs(anyString())).thenReturn(WGS84); listener.afterTransaction(request, result, true); ReferencedEnvelope expectedEnv = new ReferencedEnvelope(affectedBounds1); expectedEnv.expandToInclude(affectedBounds2); verify(mediator, times(1)).truncate(eq("theLayer"), eq(expectedEnv)); verify(mediator, times(1)).truncate(eq("theGroup"), eq(expectedEnv)); }
public void testTruncateLayerFully() throws Exception { when(tld.getTileLayer(eq(tileLayerGroup.getName()))).thenThrow( new GeoWebCacheException("fake")); mediator.truncate(tileLayerGroup.getName()); verify(storageBroker, never()).deleteByGridSetId(anyString(), anyString()); mediator.truncate(tileLayer.getName()); verify(storageBroker, times(tileLayer.getGridSubsets().size())).deleteByGridSetId( anyString(), anyString()); }
mediator.truncate(((FeatureTypeInfo) source).prefixedName());
truncate(layer, bounds, gridSubset, formatName, parameters);
public void truncate(final String layerName, final ReferencedEnvelope bounds) throws GeoWebCacheException { final TileLayer tileLayer = tld.getTileLayer(layerName); final Collection<String> gridSubSets = tileLayer.getGridSubsets(); /* * Create a truncate task for each gridSubset (CRS), format and style */ for (String gridSetId : gridSubSets) { GridSubset layerGrid = tileLayer.getGridSubset(gridSetId); BoundingBox intersectingBounds = getIntersectingBounds(layerName, layerGrid, bounds); if (intersectingBounds == null) { continue; } String styleName = null;// all of them String format = null;// all of them truncate(layerName, styleName, gridSetId, intersectingBounds, format); } }
@SuppressWarnings("unchecked") public void testLayerGroupInfoImplicitOrExplicitStyleChanged() throws Exception { LayerGroupInfo mockGroup = mock(LayerGroupInfo.class); when(GWC.tileLayerName(mockGroup)).thenReturn("mockGroup"); when(mockMediator.getLayerInfosFor(same(mockStyle))).thenReturn(Collections.EMPTY_LIST); when(mockMediator.getLayerGroupsFor(same(mockStyle))).thenReturn( Collections.singleton(mockGroup)); CatalogPostModifyEventImpl postModifyEvent = new CatalogPostModifyEventImpl(); postModifyEvent.setSource(mockStyle); listener.handlePostModifyEvent(postModifyEvent); verify(mockMediator, times(1)).truncate(eq("mockGroup")); } }
/** * Truncates the cache for the default style of the given layer * * @param layerName */ public void truncateByLayerDefaultStyle(final String layerName) { checkNotNull(layerName, "layerName can't be null"); log.fine("truncating '" + layerName + "' for default style"); final TileLayer layer = getTileLayerByName(layerName); final Set<String> gridSetIds = layer.getGridSubsets(); // all of them final List<MimeType> mimeTypes = layer.getMimeTypes(); // all of them final BoundingBox bounds = null; // all of them final Map<String, String> parameters = null; // only default style for (String gridSetId : gridSetIds) { GridSubset gridSubset = layer.getGridSubset(gridSetId); if (gridSubset == null) { // layer may no longer have this gridsubset, but we want to truncate any remaining // tiles GridSet gridSet = gridSetBroker.get(gridSetId); gridSubset = GridSubsetFactory.createGridSubSet(gridSet); } for (MimeType mime : mimeTypes) { String formatName = mime.getFormat(); truncate(layer, bounds, gridSubset, formatName, parameters); } } }
public void testLayerGroupInfoStylesChanged() throws Exception { CatalogModifyEvent modifyEvent = mock(CatalogModifyEvent.class); when(modifyEvent.getSource()).thenReturn(mockLayerGroupInfo); when(modifyEvent.getPropertyNames()).thenReturn(Arrays.asList("styles")); List<StyleInfo> oldStyles = Collections.emptyList(); StyleInfo newStyle = mock(StyleInfo.class); List<StyleInfo> newStyles = Collections.singletonList(newStyle); when(modifyEvent.getOldValues()).thenReturn(Collections.singletonList((Object) oldStyles)); when(modifyEvent.getNewValues()).thenReturn(Collections.singletonList((Object) newStyles)); // the tile layer must exist on the layer metadata otherwise the event will be ignored GeoServerTileLayerInfo info = TileLayerInfoUtil.loadOrCreate(mockLayerGroupInfo, GWCConfig.getOldDefaults()); GeoServerTileLayer tileLayer = mock(GeoServerTileLayer.class); when(tileLayer.getInfo()).thenReturn(info); when(mockMediator.hasTileLayer(same(mockLayerGroupInfo))).thenReturn(true); when(mockMediator.getTileLayer(same(mockLayerGroupInfo))).thenReturn(tileLayer); listener.handleModifyEvent(modifyEvent); CatalogPostModifyEvent postModifyEvent = mock(CatalogPostModifyEvent.class); when(postModifyEvent.getSource()).thenReturn(mockLayerGroupInfo); listener.handlePostModifyEvent(postModifyEvent); verify(mockMediator).truncate(eq(LAYER_GROUP_NAME)); }
public void testLayerGroupInfoLayersChanged() throws Exception { CatalogModifyEvent modifyEvent = mock(CatalogModifyEvent.class); when(modifyEvent.getSource()).thenReturn(mockLayerGroupInfo); when(modifyEvent.getPropertyNames()).thenReturn(Arrays.asList("layers")); List<LayerInfo> oldLayers = Collections.emptyList(); List<LayerInfo> newLayers = Collections.singletonList(mockLayerInfo); when(modifyEvent.getOldValues()).thenReturn(Collections.singletonList((Object) oldLayers)); when(modifyEvent.getNewValues()).thenReturn(Collections.singletonList((Object) newLayers)); // the tile layer must exist otherwise the event will be ignored GeoServerTileLayerInfo tileLayerInfo = TileLayerInfoUtil.loadOrCreate(mockLayerGroupInfo, mockMediator.getConfig()); GridSetBroker gridsets = new GridSetBroker(true, true); GeoServerTileLayer tileLayer = new GeoServerTileLayer(mockLayerGroupInfo, gridsets, tileLayerInfo); when(mockMediator.hasTileLayer(same(mockLayerGroupInfo))).thenReturn(true); when(mockMediator.getTileLayer(same(mockLayerGroupInfo))).thenReturn(tileLayer); listener.handleModifyEvent(modifyEvent); CatalogPostModifyEvent postModifyEvent = mock(CatalogPostModifyEvent.class); when(postModifyEvent.getSource()).thenReturn(mockLayerGroupInfo); listener.handlePostModifyEvent(postModifyEvent); verify(mockMediator).truncate(eq(LAYER_GROUP_NAME)); }
assertFalse(bounds.intersects(layerBounds.getMaxX(), layerBounds.getMaxY())); mediator.truncate(layerName, bounds); mediator.truncate(layerName, bounds); mediator.truncate(layerName, bounds); verify(tileBreeder, times(expected)).dispatchTasks(any(GWCTask[].class)); mediator.truncate(layerName, bounds); verify(tileBreeder, never()).dispatchTasks(any(GWCTask[].class)); mediator.truncate(layerName, bounds); verify(tileBreeder, times(expected)).dispatchTasks(any(GWCTask[].class));