mirror of https://github.com/zlatinb/muwire
do actual updating on in a threadpool
parent
44c880d911
commit
5cd1ca88c1
|
@ -2,6 +2,8 @@ package com.muwire.core.trust
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
import java.util.concurrent.ExecutorService
|
||||||
|
import java.util.concurrent.Executors
|
||||||
import java.util.logging.Level
|
import java.util.logging.Level
|
||||||
|
|
||||||
import com.muwire.core.EventBus
|
import com.muwire.core.EventBus
|
||||||
|
@ -26,6 +28,7 @@ class TrustSubscriber {
|
||||||
private final Object waitLock = new Object()
|
private final Object waitLock = new Object()
|
||||||
private volatile boolean shutdown
|
private volatile boolean shutdown
|
||||||
private volatile Thread thread
|
private volatile Thread thread
|
||||||
|
private final ExecutorService updateThreads = Executors.newCachedThreadPool()
|
||||||
|
|
||||||
TrustSubscriber(EventBus eventBus, I2PConnector i2pConnector, MuWireSettings settings) {
|
TrustSubscriber(EventBus eventBus, I2PConnector i2pConnector, MuWireSettings settings) {
|
||||||
this.eventBus = eventBus
|
this.eventBus = eventBus
|
||||||
|
@ -42,6 +45,7 @@ class TrustSubscriber {
|
||||||
void stop() {
|
void stop() {
|
||||||
shutdown = true
|
shutdown = true
|
||||||
thread?.interrupt()
|
thread?.interrupt()
|
||||||
|
updateThreads.shutdownNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
void onTrustSubscriptionEvent(TrustSubscriptionEvent e) {
|
void onTrustSubscriptionEvent(TrustSubscriptionEvent e) {
|
||||||
|
@ -66,11 +70,7 @@ class TrustSubscriber {
|
||||||
remoteTrustLists.values().each { trustList ->
|
remoteTrustLists.values().each { trustList ->
|
||||||
if (now - trustList.timestamp < settings.trustListInterval * 60 * 60 * 1000)
|
if (now - trustList.timestamp < settings.trustListInterval * 60 * 60 * 1000)
|
||||||
return
|
return
|
||||||
trustList.status = RemoteTrustList.Status.UPDATING
|
updateThreads.submit(new UpdateJob(trustList))
|
||||||
eventBus.publish(new TrustSubscriptionUpdatedEvent(trustList : trustList))
|
|
||||||
check(trustList, now)
|
|
||||||
trustList.status = RemoteTrustList.Status.UPDATED
|
|
||||||
eventBus.publish(new TrustSubscriptionUpdatedEvent(trustList : trustList))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
@ -79,6 +79,23 @@ class TrustSubscriber {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class UpdateJob implements Runnable {
|
||||||
|
|
||||||
|
private final RemoteTrustList trustList
|
||||||
|
|
||||||
|
UpdateJob(RemoteTrustList trustList) {
|
||||||
|
this.trustList = trustList
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
trustList.status = RemoteTrustList.Status.UPDATING
|
||||||
|
eventBus.publish(new TrustSubscriptionUpdatedEvent(trustList : trustList))
|
||||||
|
check(trustList, System.currentTimeMillis())
|
||||||
|
trustList.status = RemoteTrustList.Status.UPDATED
|
||||||
|
eventBus.publish(new TrustSubscriptionUpdatedEvent(trustList : trustList))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void check(RemoteTrustList trustList, long now) {
|
private void check(RemoteTrustList trustList, long now) {
|
||||||
log.info("fetching trust list from ${trustList.persona.getHumanReadableName()}")
|
log.info("fetching trust list from ${trustList.persona.getHumanReadableName()}")
|
||||||
Endpoint endpoint = null
|
Endpoint endpoint = null
|
||||||
|
|
Loading…
Reference in New Issue