Added CrawlCache expired feature.
This commit is contained in:
parent
f46b775833
commit
ac1527f2c4
2 changed files with 147 additions and 0 deletions
112
src/fr/devinsy/statoolinfosweb/CrawlCacheChecker.java
Normal file
112
src/fr/devinsy/statoolinfosweb/CrawlCacheChecker.java
Normal file
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* Copyright (C) 2021-2024 Christian Pierre MOMON christian.momon@devinsy.fr>>
|
||||
*
|
||||
* This file is part of StatoolInfosWeb, webapp to value service statistics.
|
||||
*
|
||||
* StatoolInfosWeb is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* StatoolInfosWeb is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with StatoolInfosWeb. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package fr.devinsy.statoolinfosweb;
|
||||
|
||||
import jakarta.servlet.ServletContextEvent;
|
||||
import jakarta.servlet.ServletContextListener;
|
||||
import jakarta.servlet.annotation.WebListener;
|
||||
|
||||
/**
|
||||
* The Class Checker.
|
||||
*/
|
||||
@WebListener
|
||||
public class CrawlCacheChecker implements ServletContextListener
|
||||
{
|
||||
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(CrawlCacheChecker.class);
|
||||
|
||||
private static final int CHECK_DELAY = 60 * 1000;
|
||||
|
||||
private Thread checker;
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent event)
|
||||
{
|
||||
logger.info("Starting checker thread…");
|
||||
this.checker = new Thread()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
// while (!Thread.currentThread().isInterrupted())
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// Thread.sleep(CHECK_DELAY);
|
||||
// StatoolInfosWeb.instance().check();
|
||||
// }
|
||||
// catch (InterruptedException exception)
|
||||
// {
|
||||
// Thread.currentThread().interrupt();
|
||||
// logger.error("Check sleep interrupted so ending checker: {}",
|
||||
// exception.getMessage());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// boolean ended = false;
|
||||
// while (!ended)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// Thread.sleep(CHECK_DELAY);
|
||||
// StatoolInfosWeb.instance().check();
|
||||
// if (Thread.currentThread().isInterrupted())
|
||||
// {
|
||||
// logger.error("Interrupted status detected so ending
|
||||
// checker.");
|
||||
// ended = true;
|
||||
// }
|
||||
// }
|
||||
// catch (InterruptedException exception)
|
||||
// {
|
||||
// logger.error("Check sleep interrupted so ending checker: {}",
|
||||
// exception.getMessage());
|
||||
// ended = true;
|
||||
// }
|
||||
// }
|
||||
|
||||
try
|
||||
{
|
||||
boolean ended = false;
|
||||
while (!ended)
|
||||
{
|
||||
Thread.sleep(CHECK_DELAY);
|
||||
StatoolInfosWeb.instance().check();
|
||||
if (Thread.currentThread().isInterrupted())
|
||||
{
|
||||
logger.error("Interrupted status detected so ending checker.");
|
||||
ended = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (InterruptedException exception)
|
||||
{
|
||||
logger.error("Check sleep interrupted so ending checker: {}", exception.getMessage());
|
||||
}
|
||||
}
|
||||
};
|
||||
this.checker.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent event)
|
||||
{
|
||||
logger.info("Stopping checker thread.");
|
||||
this.checker.interrupt();
|
||||
}
|
||||
}
|
|
@ -47,6 +47,7 @@ import fr.devinsy.statoolinfos.core.Organization;
|
|||
import fr.devinsy.statoolinfos.core.Service;
|
||||
import fr.devinsy.statoolinfos.core.Software;
|
||||
import fr.devinsy.statoolinfos.core.StatoolInfosContext;
|
||||
import fr.devinsy.statoolinfos.core.StatoolInfosException;
|
||||
import fr.devinsy.statoolinfos.crawl.CrawlCache;
|
||||
import fr.devinsy.statoolinfos.uptime.UptimeJournal;
|
||||
import fr.devinsy.xidyn.XidynException;
|
||||
|
@ -179,6 +180,40 @@ public class StatoolInfosWeb
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check.
|
||||
*/
|
||||
public void check()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (this.context.isExpired())
|
||||
{
|
||||
logger.info("Context expired, reloading context…");
|
||||
StatoolInfosContext newContext = new StatoolInfosContext(this.configurationFile);
|
||||
this.context = newContext;
|
||||
clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.info("Context expiration not detected.");
|
||||
}
|
||||
}
|
||||
catch (StatoolInfosException | IOException exception)
|
||||
{
|
||||
logger.error("Context update failed: {}", exception.getMessage());
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear caches.
|
||||
*/
|
||||
public void clear()
|
||||
{
|
||||
KissDispatcher.instance().clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the builds the information.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue