Skip to content

Commit

Permalink
GEOS-8947 gwc cluster safe via events (fixes)
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsCharlier committed Oct 15, 2018
1 parent 966a8af commit cab2222
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public GeoServerTileLayerInfo delete(final String tileLayerId) {
Resource file = getFile(tileLayerId);
layersById.remove(tileLayerId);
layersByName.remove(info.getName());
stopToListen(file);
stopListening(file);
file.delete();
listenersByFileName.remove(file.name());
}
Expand Down Expand Up @@ -258,7 +258,7 @@ private GeoServerTileLayerInfoImpl load(Resource res) {
GeoServerTileLayerInfoImpl info;
try {
info = depersist(res);
startToListen(res, info.getId());
startListening(res, info.getId());
} catch (Exception e) {
LOGGER.log(
Level.SEVERE,
Expand All @@ -285,7 +285,7 @@ private void reload(String id, Resource res) {
load(res);
}

private void startToListen(Resource file, String tileLayerId) {
private void startListening(Resource file, String tileLayerId) {
ResourceListener existingLayerListener =
new ResourceListener() {
@Override
Expand All @@ -307,7 +307,7 @@ public void changed(ResourceNotification notify) {
file.addListener(existingLayerListener);
}

private void stopToListen(Resource file) {
private void stopListening(Resource file) {
ResourceListener existingLayerListener = listenersByFileName.get(file.name());
if (existingLayerListener != null) {
file.removeListener(existingLayerListener);
Expand All @@ -318,7 +318,7 @@ private void persist(GeoServerTileLayerInfo real) throws IOException {
final String tileLayerId = real.getId();
Resource file = getFile(tileLayerId);

stopToListen(file);
stopListening(file);

boolean cleanup = false;
if (file.getType() == Type.UNDEFINED) {
Expand Down Expand Up @@ -353,7 +353,7 @@ private void persist(GeoServerTileLayerInfo real) throws IOException {
}
rename(tmp, file);

startToListen(file, tileLayerId);
startListening(file, tileLayerId);
}

private GeoServerTileLayerInfoImpl loadInternal(final String tileLayerId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public void testSaveWithEmptyStyleParamFilter() {
public void testEvents() throws IOException, InterruptedException {

((FileSystemWatcher) resourceLoader.getResourceNotificationDispatcher())
.schedule(100, TimeUnit.MILLISECONDS);
.schedule(50, TimeUnit.MILLISECONDS);

AtomicBoolean hasBeenCreated = new AtomicBoolean(false);

Expand Down Expand Up @@ -211,6 +211,10 @@ public void onEvent(String layerId, Type type) {
assertEquals("originalname", info.getName());
assertNotNull(catalog.getLayerByName("originalname"));

// it is necessary to wait a second, otherwise
// the change is not detected because it is too soon after creation
Thread.sleep(1000);

FileUtils.writeStringToFile(
file,
"<org.geoserver.gwc.layer.GeoServerTileLayerInfoImpl><id>id1</id><name>newname</name></org.geoserver.gwc.layer.GeoServerTileLayerInfoImpl>");
Expand Down

0 comments on commit cab2222

Please sign in to comment.