1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.ehcache.distribution;
18
19 import net.sf.ehcache.bootstrap.BootstrapCacheLoaderFactory;
20 import net.sf.ehcache.bootstrap.BootstrapCacheLoader;
21 import net.sf.ehcache.util.PropertyUtil;
22
23 import java.util.Properties;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27
28
29
30
31
32
33 public class RMIBootstrapCacheLoaderFactory extends BootstrapCacheLoaderFactory {
34
35
36
37
38
39 public static final String BOOTSTRAP_ASYNCHRONOUSLY = "bootstrapAsynchronously";
40
41
42
43
44 public static final String MAXIMUM_CHUNK_SIZE_BYTES = "maximumChunkSizeBytes";
45
46
47
48
49 protected static final int DEFAULT_MAXIMUM_CHUNK_SIZE_BYTES = 5000000;
50
51
52
53
54 protected static final int ONE_HUNDRED_MB = 100000000;
55
56
57
58
59 protected static final int FIVE_KB = 5000;
60
61 private static final Log LOG = LogFactory.getLog(RMIBootstrapCacheLoaderFactory.class.getName());
62
63
64
65
66
67
68
69
70
71 public BootstrapCacheLoader createBootstrapCacheLoader(Properties properties) {
72 boolean bootstrapAsynchronously = extractBootstrapAsynchronously(properties);
73 int maximumChunkSizeBytes = extractMaximumChunkSizeBytes(properties);
74 return new RMIBootstrapCacheLoader(bootstrapAsynchronously, maximumChunkSizeBytes);
75 }
76
77
78
79
80
81 protected int extractMaximumChunkSizeBytes(Properties properties) {
82 int maximumChunkSizeBytes = 0;
83 String maximumChunkSizeBytesString = PropertyUtil.extractAndLogProperty(MAXIMUM_CHUNK_SIZE_BYTES, properties);
84 if (maximumChunkSizeBytesString != null) {
85 try {
86 int maximumChunkSizeBytesCandidate = Integer.parseInt(maximumChunkSizeBytesString);
87 if ((maximumChunkSizeBytesCandidate < FIVE_KB) || (maximumChunkSizeBytesCandidate > ONE_HUNDRED_MB)) {
88 LOG.warn("Trying to set the chunk size to an unreasonable number. Using the default instead.");
89 maximumChunkSizeBytes = DEFAULT_MAXIMUM_CHUNK_SIZE_BYTES;
90 } else {
91 maximumChunkSizeBytes = maximumChunkSizeBytesCandidate;
92 }
93 } catch (NumberFormatException e) {
94 LOG.warn("Number format exception trying to set chunk size. Using the default instead.");
95 maximumChunkSizeBytes = DEFAULT_MAXIMUM_CHUNK_SIZE_BYTES;
96 }
97
98 } else {
99 maximumChunkSizeBytes = DEFAULT_MAXIMUM_CHUNK_SIZE_BYTES;
100 }
101 return maximumChunkSizeBytes;
102 }
103
104
105
106
107
108
109
110 protected boolean extractBootstrapAsynchronously(Properties properties) {
111 boolean bootstrapAsynchronously;
112 String bootstrapAsynchronouslyString = PropertyUtil.extractAndLogProperty(BOOTSTRAP_ASYNCHRONOUSLY, properties);
113 if (bootstrapAsynchronouslyString != null) {
114 bootstrapAsynchronously = PropertyUtil.parseBoolean(bootstrapAsynchronouslyString);
115 } else {
116 bootstrapAsynchronously = true;
117 }
118 return bootstrapAsynchronously;
119 }
120 }