blob: 61a18ca1132cb0125588773d4b2452fe5b1be603 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
package org.openslx.bwlp.sat.maintenance;
import java.util.concurrent.TimeUnit;
import org.apache.log4j.Logger;
import org.openslx.bwlp.sat.mail.MailQueue;
import org.openslx.util.QuickTimer;
import org.openslx.util.QuickTimer.Task;
public class MailFlusher implements Runnable {
private static final Logger LOGGER = Logger.getLogger(MailFlusher.class);
private static final MailFlusher instance = new MailFlusher();
private static long blockedUntil = 0;
/**
* Initialize the task. This schedules a timer that runs
* every 6 minutes.
*/
public synchronized static void init() {
if (blockedUntil != 0)
return;
LOGGER.debug("Initializing mail flusher");
blockedUntil = 1;
QuickTimer.scheduleAtFixedRate(new Task() {
@Override
public void fire() {
if (blockedUntil > System.currentTimeMillis())
return;
start();
}
}, TimeUnit.MINUTES.toMillis(6), TimeUnit.MINUTES.toMillis(10));
}
public synchronized static void start() {
if (blockedUntil > System.currentTimeMillis())
return;
if (Maintenance.trySubmit(instance)) {
blockedUntil = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(10);
}
}
@Override
public void run() {
try {
MailQueue.flush();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
|