(blacklist) Delay startup of blacklist
To help services start faster, the blacklist will no longer block until it's loaded. If such a behavior is desirable, a method was added to explicitly wait for the data.
This commit is contained in:
parent
f9b6ac03c6
commit
e61e7f44b9
@ -9,4 +9,5 @@ public interface DomainBlacklist {
|
|||||||
default TIntHashSet getSpamDomains() {
|
default TIntHashSet getSpamDomains() {
|
||||||
return new TIntHashSet();
|
return new TIntHashSet();
|
||||||
}
|
}
|
||||||
|
void waitUntilLoaded() throws InterruptedException;
|
||||||
}
|
}
|
||||||
|
@ -12,11 +12,13 @@ import java.util.concurrent.TimeUnit;
|
|||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class DomainBlacklistImpl implements DomainBlacklist {
|
public class DomainBlacklistImpl implements DomainBlacklist {
|
||||||
private volatile TIntHashSet spamDomainSet = new TIntHashSet();
|
|
||||||
private final HikariDataSource dataSource;
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
|
||||||
private final boolean blacklistDisabled = Boolean.getBoolean("blacklist.disable");
|
private final boolean blacklistDisabled = Boolean.getBoolean("blacklist.disable");
|
||||||
|
|
||||||
|
private final HikariDataSource dataSource;
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
|
|
||||||
|
private volatile TIntHashSet spamDomainSet = new TIntHashSet();
|
||||||
private volatile boolean isLoaded = false;
|
private volatile boolean isLoaded = false;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@ -63,20 +65,25 @@ public class DomainBlacklistImpl implements DomainBlacklist {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Block until the blacklist has been loaded */
|
/** Block until the blacklist has been loaded */
|
||||||
public boolean waitUntilLoaded() throws InterruptedException {
|
@Override
|
||||||
|
public void waitUntilLoaded() throws InterruptedException {
|
||||||
|
if (blacklistDisabled)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!isLoaded) {
|
if (!isLoaded) {
|
||||||
|
logger.info("Waiting for blacklist to be loaded");
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
while (!isLoaded) {
|
while (!isLoaded) {
|
||||||
wait(5000);
|
wait(5000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
logger.info("Blacklist loaded, size = {}", spamDomainSet.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public TIntHashSet getSpamDomains() {
|
public TIntHashSet getSpamDomains() {
|
||||||
final TIntHashSet result = new TIntHashSet(1_000_000);
|
final TIntHashSet result = new TIntHashSet(1_000_000);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user