1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.registry;
17
18 import java.util.logging.Level;
19 import java.util.logging.Logger;
20
21
22
23
24
25
26 public class RegistryMaintainer implements Runnable {
27
28 private static Logger log = Logger.getLogger(RegistryMaintainer.class.getName());
29
30 final private RegistryImpl registry;
31 final private int sleepIntervalMillis;
32
33 private volatile boolean stopped = false;
34
35 public RegistryMaintainer(RegistryImpl registry, int sleepIntervalMillis) {
36 this.registry = registry;
37 this.sleepIntervalMillis = sleepIntervalMillis;
38 }
39
40 public void stop() {
41 if (log.isLoggable(Level.FINE))
42 log.fine("Setting stopped status on thread");
43 stopped = true;
44 }
45
46 public void run() {
47 stopped = false;
48 if (log.isLoggable(Level.FINE))
49 log.fine("Running registry maintenance loop every milliseconds: " + sleepIntervalMillis);
50 while (!stopped) {
51
52 try {
53 registry.maintain();
54 Thread.sleep(sleepIntervalMillis);
55 } catch (InterruptedException ex) {
56 stopped = true;
57 }
58
59 }
60 log.fine("Stopped status on thread received, ending maintenance loop");
61 }
62
63 }