Skip to content

Commit

Permalink
Startup DiskQuotaMonitor on context init, rather than immediatley aft…
Browse files Browse the repository at this point in the history
…er bean properties are set

This makes spring initialization much easier and avoids risk of xml configuration not yet being available
  • Loading branch information
jodygarnett authored and aaime committed Jul 8, 2023
1 parent 5636379 commit 4c28db4
Showing 1 changed file with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
import org.geowebcache.storage.DefaultStorageFinder;
import org.geowebcache.storage.StorageBroker;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
import org.springframework.util.Assert;

Expand All @@ -52,7 +53,8 @@
*
* @author Gabriel Roldan
*/
public class DiskQuotaMonitor implements InitializingBean, DisposableBean {
public class DiskQuotaMonitor
implements DisposableBean, ApplicationListener<ContextRefreshedEvent> {

private static final Logger log = Logging.getLogger(DiskQuotaMonitor.class.getName());

Expand Down Expand Up @@ -156,21 +158,21 @@ public boolean isRunning() {
return isRunning;
}

/**
* Called when the framework calls this bean for initialization
*
* <p>Defers to {@link #startUp()}, or does nothing if {@code isEnabled() == false}
*
* @see #isEnabled()
* @see #startUp()
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
/** Startup monitor once application is initialized. */
@Override
public void afterPropertiesSet() throws Exception {
public void onApplicationEvent(ContextRefreshedEvent event) {
if (!diskQuotaEnabled) {
return;
}
startUp();
if (isRunning) {
// monitor may already be running if application is refreshed
return;
}
try {
startUp();
} catch (Exception unableToStart) {
log.log(Level.WARNING, "Unable to start disk quota monitor", unableToStart);
}
}

/**
Expand Down

0 comments on commit 4c28db4

Please sign in to comment.