1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.configuration.reloading;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21
22 import java.io.File;
23 import java.util.Random;
24
25
26
27
28 public class FileRandomReloadingStrategy extends FileChangedReloadingStrategy
29 {
30 Random random = new Random();
31
32
33 private Log logger = LogFactory.getLog(FileRandomReloadingStrategy.class);
34
35
36
37
38
39
40 @Override
41 public boolean reloadingRequired()
42 {
43 boolean result = random.nextBoolean();
44 if (result)
45 {
46 if (logger.isDebugEnabled())
47 {
48 logger.debug("File change detected: " + getName());
49 }
50 }
51 return result;
52 }
53
54
55
56
57
58
59 public File getMonitoredFile()
60 {
61 return getFile();
62 }
63
64 private String getName()
65 {
66 return getName(getFile());
67 }
68
69 private String getName(File file)
70 {
71 String name = configuration.getURL().toString();
72 if (name == null)
73 {
74 if (file != null)
75 {
76 name = file.getAbsolutePath();
77 }
78 else
79 {
80 name = "base: " + configuration.getBasePath()
81 + "file: " + configuration.getFileName();
82 }
83 }
84 return name;
85 }
86 }