| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.cache.infinispan.internal; |
| 21 |
|
|
| 22 |
|
import org.apache.commons.lang3.StringUtils; |
| 23 |
|
import org.infinispan.commons.configuration.Builder; |
| 24 |
|
import org.infinispan.commons.configuration.ConfigurationUtils; |
| 25 |
|
import org.infinispan.configuration.cache.Configuration; |
| 26 |
|
import org.infinispan.configuration.cache.ConfigurationBuilder; |
| 27 |
|
import org.infinispan.configuration.cache.PersistenceConfiguration; |
| 28 |
|
import org.infinispan.configuration.cache.PersistenceConfigurationBuilder; |
| 29 |
|
import org.infinispan.configuration.cache.SingleFileStoreConfiguration; |
| 30 |
|
import org.infinispan.configuration.cache.SingleFileStoreConfigurationBuilder; |
| 31 |
|
import org.infinispan.configuration.cache.StoreConfiguration; |
| 32 |
|
import org.infinispan.configuration.cache.StoreConfigurationBuilder; |
| 33 |
|
import org.infinispan.eviction.EvictionStrategy; |
| 34 |
|
import org.infinispan.eviction.EvictionType; |
| 35 |
|
import org.xwiki.cache.config.CacheConfiguration; |
| 36 |
|
import org.xwiki.cache.eviction.EntryEvictionConfiguration; |
| 37 |
|
import org.xwiki.cache.eviction.LRUEvictionConfiguration; |
| 38 |
|
import org.xwiki.cache.util.AbstractCacheConfigurationLoader; |
| 39 |
|
import org.xwiki.environment.Environment; |
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
@version |
| 45 |
|
|
| |
|
| 92.4% |
Uncovered Elements: 9 (119) |
Complexity: 35 |
Complexity Density: 0.48 |
|
| 46 |
|
public class InfinispanConfigurationLoader extends AbstractCacheConfigurationLoader |
| 47 |
|
{ |
| 48 |
|
|
| 49 |
|
@link |
| 50 |
|
|
| 51 |
|
public static final String CONFX_EXPIRATION_WAKEUPINTERVAL = "infinispan.expiration.wakeupinterval"; |
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
private static final String DEFAULT_SINGLEFILESTORE_LOCATION = "Infinispan-SingleFileStore"; |
| 57 |
|
|
| 58 |
|
|
| 59 |
|
@param |
| 60 |
|
@param |
| 61 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 62 |
1339 |
public InfinispanConfigurationLoader(CacheConfiguration configuration, Environment environment)... |
| 63 |
|
{ |
| 64 |
1339 |
super(configuration, environment, null); |
| 65 |
|
} |
| 66 |
|
|
| 67 |
|
|
| 68 |
|
@param |
| 69 |
|
@param |
| 70 |
|
@return |
| 71 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 72 |
541 |
private ConfigurationBuilder builder(ConfigurationBuilder builder, Configuration isconfiguration)... |
| 73 |
|
{ |
| 74 |
541 |
if (builder != null) { |
| 75 |
111 |
return builder; |
| 76 |
|
} |
| 77 |
|
|
| 78 |
430 |
ConfigurationBuilder newBuilder = new ConfigurationBuilder(); |
| 79 |
|
|
| 80 |
430 |
if (isconfiguration != null) { |
| 81 |
32 |
newBuilder.read(isconfiguration); |
| 82 |
|
} |
| 83 |
|
|
| 84 |
430 |
return newBuilder; |
| 85 |
|
} |
| 86 |
|
|
| 87 |
|
|
| 88 |
|
@param |
| 89 |
|
@return@link |
| 90 |
|
|
| |
|
| 83.3% |
Uncovered Elements: 2 (12) |
Complexity: 4 |
Complexity Density: 0.5 |
|
| 91 |
192 |
private boolean containsIncompleteFileLoader(Configuration isconfiguration)... |
| 92 |
|
{ |
| 93 |
192 |
PersistenceConfiguration persistenceConfiguration = isconfiguration.persistence(); |
| 94 |
|
|
| 95 |
192 |
for (StoreConfiguration storeConfiguration : persistenceConfiguration.stores()) { |
| 96 |
32 |
if (storeConfiguration instanceof SingleFileStoreConfiguration) { |
| 97 |
32 |
SingleFileStoreConfiguration singleFileStoreConfiguration = |
| 98 |
|
(SingleFileStoreConfiguration) storeConfiguration; |
| 99 |
|
|
| 100 |
32 |
String location = singleFileStoreConfiguration.location(); |
| 101 |
|
|
| 102 |
|
|
| 103 |
32 |
if (StringUtils.isBlank(location) || location.equals(DEFAULT_SINGLEFILESTORE_LOCATION)) { |
| 104 |
32 |
return true; |
| 105 |
|
} |
| 106 |
|
} |
| 107 |
|
} |
| 108 |
|
|
| 109 |
160 |
return false; |
| 110 |
|
} |
| 111 |
|
|
| 112 |
|
|
| 113 |
|
|
| 114 |
|
|
| 115 |
|
@param |
| 116 |
|
@param |
| 117 |
|
@return |
| 118 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
| 119 |
1147 |
private ConfigurationBuilder customizeEviction(ConfigurationBuilder currentBuilder, Configuration configuration)... |
| 120 |
|
{ |
| 121 |
1147 |
ConfigurationBuilder builder = currentBuilder; |
| 122 |
|
|
| 123 |
1147 |
EntryEvictionConfiguration eec = |
| 124 |
|
(EntryEvictionConfiguration) getCacheConfiguration().get(EntryEvictionConfiguration.CONFIGURATIONID); |
| 125 |
|
|
| 126 |
1147 |
if (eec != null && eec.getAlgorithm() == EntryEvictionConfiguration.Algorithm.LRU) { |
| 127 |
|
|
| 128 |
|
|
| 129 |
|
|
| 130 |
468 |
builder = customizeEvictionMaxEntries(builder, configuration, eec); |
| 131 |
|
|
| 132 |
|
|
| 133 |
|
|
| 134 |
|
|
| 135 |
468 |
builder = customizeExpirationWakeUpInterval(builder, configuration, eec); |
| 136 |
|
|
| 137 |
|
|
| 138 |
468 |
builder = customizeExpirationMaxIdle(builder, configuration, eec); |
| 139 |
|
|
| 140 |
|
|
| 141 |
468 |
builder = customizeExpirationLifespan(builder, configuration, eec); |
| 142 |
|
} |
| 143 |
|
|
| 144 |
1147 |
return builder; |
| 145 |
|
} |
| 146 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 5 |
Complexity Density: 0.62 |
|
| 147 |
468 |
private ConfigurationBuilder customizeEvictionMaxEntries(ConfigurationBuilder currentBuilder,... |
| 148 |
|
Configuration configuration, EntryEvictionConfiguration eec) |
| 149 |
|
{ |
| 150 |
468 |
ConfigurationBuilder builder = currentBuilder; |
| 151 |
|
|
| 152 |
468 |
if (eec.containsKey(LRUEvictionConfiguration.MAXENTRIES_ID)) { |
| 153 |
461 |
int maxEntries = ((Number) eec.get(LRUEvictionConfiguration.MAXENTRIES_ID)).intValue(); |
| 154 |
461 |
if (configuration.eviction() == null || configuration.eviction().strategy() != EvictionStrategy.LRU |
| 155 |
|
|| configuration.eviction().maxEntries() != maxEntries) { |
| 156 |
395 |
builder = builder(builder, null); |
| 157 |
395 |
builder.eviction().strategy(EvictionStrategy.LRU); |
| 158 |
395 |
builder.eviction().type(EvictionType.COUNT).size(maxEntries); |
| 159 |
|
} |
| 160 |
|
} |
| 161 |
|
|
| 162 |
468 |
return builder; |
| 163 |
|
} |
| 164 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 165 |
468 |
private ConfigurationBuilder customizeExpirationWakeUpInterval(ConfigurationBuilder currentBuilder,... |
| 166 |
|
Configuration configuration, EntryEvictionConfiguration eec) |
| 167 |
|
{ |
| 168 |
468 |
ConfigurationBuilder builder = currentBuilder; |
| 169 |
|
|
| 170 |
468 |
if (eec.get(CONFX_EXPIRATION_WAKEUPINTERVAL) instanceof Number) { |
| 171 |
4 |
builder = builder(builder, null); |
| 172 |
4 |
builder.expiration().wakeUpInterval(((Number) eec.get(CONFX_EXPIRATION_WAKEUPINTERVAL)).longValue()); |
| 173 |
|
} |
| 174 |
|
|
| 175 |
468 |
return builder; |
| 176 |
|
} |
| 177 |
|
|
| |
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
| 178 |
468 |
private ConfigurationBuilder customizeExpirationMaxIdle(ConfigurationBuilder currentBuilder,... |
| 179 |
|
Configuration configuration, EntryEvictionConfiguration eec) |
| 180 |
|
{ |
| 181 |
468 |
ConfigurationBuilder builder = currentBuilder; |
| 182 |
|
|
| 183 |
468 |
if (eec.getTimeToLive() > 0) { |
| 184 |
102 |
long maxIdle = eec.getTimeToLive() * 1000L; |
| 185 |
102 |
if (configuration.expiration() == null || configuration.expiration().maxIdle() != maxIdle) { |
| 186 |
102 |
builder = builder(builder, null); |
| 187 |
102 |
builder.expiration().maxIdle(eec.getTimeToLive() * 1000L); |
| 188 |
|
} |
| 189 |
|
} |
| 190 |
|
|
| 191 |
468 |
return builder; |
| 192 |
|
} |
| 193 |
|
|
| |
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
| 194 |
468 |
private ConfigurationBuilder customizeExpirationLifespan(ConfigurationBuilder currentBuilder,... |
| 195 |
|
Configuration configuration, EntryEvictionConfiguration eec) |
| 196 |
|
{ |
| 197 |
468 |
ConfigurationBuilder builder = currentBuilder; |
| 198 |
|
|
| 199 |
468 |
if (eec.containsKey(LRUEvictionConfiguration.LIFESPAN_ID)) { |
| 200 |
8 |
long lifespan = (Integer) eec.get(LRUEvictionConfiguration.LIFESPAN_ID) * 1000L; |
| 201 |
8 |
if (configuration.expiration() == null || configuration.expiration().lifespan() != lifespan) { |
| 202 |
8 |
builder = builder(builder, null); |
| 203 |
8 |
builder.expiration().lifespan(lifespan); |
| 204 |
|
} |
| 205 |
|
} |
| 206 |
|
|
| 207 |
468 |
return builder; |
| 208 |
|
} |
| 209 |
|
|
| 210 |
|
|
| 211 |
|
|
| 212 |
|
|
| 213 |
|
@param |
| 214 |
|
@param |
| 215 |
|
@return |
| 216 |
|
|
| |
|
| 78.3% |
Uncovered Elements: 5 (23) |
Complexity: 5 |
Complexity Density: 0.29 |
|
| 217 |
192 |
private ConfigurationBuilder completeFilesystem(ConfigurationBuilder currentBuilder, Configuration configuration)... |
| 218 |
|
{ |
| 219 |
192 |
ConfigurationBuilder builder = currentBuilder; |
| 220 |
|
|
| 221 |
192 |
if (containsIncompleteFileLoader(configuration)) { |
| 222 |
32 |
builder = builder(builder, configuration); |
| 223 |
|
|
| 224 |
32 |
PersistenceConfigurationBuilder persistence = builder.persistence(); |
| 225 |
|
|
| 226 |
32 |
persistence.clearStores(); |
| 227 |
|
|
| 228 |
32 |
for (StoreConfiguration storeConfiguration : configuration.persistence().stores()) { |
| 229 |
32 |
if (storeConfiguration instanceof SingleFileStoreConfiguration) { |
| 230 |
32 |
SingleFileStoreConfiguration singleFileStoreConfiguration = |
| 231 |
|
(SingleFileStoreConfiguration) storeConfiguration; |
| 232 |
|
|
| 233 |
32 |
String location = singleFileStoreConfiguration.location(); |
| 234 |
|
|
| 235 |
|
|
| 236 |
32 |
if (StringUtils.isBlank(location) || location.equals(DEFAULT_SINGLEFILESTORE_LOCATION)) { |
| 237 |
32 |
SingleFileStoreConfigurationBuilder singleFileStoreConfigurationBuilder = |
| 238 |
|
persistence.addSingleFileStore(); |
| 239 |
32 |
singleFileStoreConfigurationBuilder.read(singleFileStoreConfiguration); |
| 240 |
32 |
singleFileStoreConfigurationBuilder.location(createTempDir()); |
| 241 |
|
} |
| 242 |
|
} else { |
| 243 |
|
|
| 244 |
0 |
Class<? extends StoreConfigurationBuilder<?, ?>> storeBuilderClass = |
| 245 |
|
(Class<? extends StoreConfigurationBuilder<?, ?>>) ConfigurationUtils |
| 246 |
|
.<StoreConfiguration>builderFor(storeConfiguration); |
| 247 |
0 |
Builder<StoreConfiguration> storeBuilder = |
| 248 |
|
(Builder<StoreConfiguration>) persistence.addStore(storeBuilderClass); |
| 249 |
0 |
storeBuilder.read(storeConfiguration); |
| 250 |
|
} |
| 251 |
|
} |
| 252 |
|
} |
| 253 |
|
|
| 254 |
192 |
return builder; |
| 255 |
|
} |
| 256 |
|
|
| 257 |
|
|
| 258 |
|
|
| 259 |
|
|
| 260 |
|
@param |
| 261 |
|
@param |
| 262 |
|
@return |
| 263 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 4 |
Complexity Density: 0.67 |
|
| 264 |
1339 |
public Configuration customize(Configuration defaultConfiguration, Configuration namedConfiguration)... |
| 265 |
|
{ |
| 266 |
|
|
| 267 |
|
|
| 268 |
1339 |
ConfigurationBuilder builder = null; |
| 269 |
|
|
| 270 |
1339 |
if (namedConfiguration == null) { |
| 271 |
1147 |
builder = customizeEviction(builder, defaultConfiguration); |
| 272 |
|
} |
| 273 |
|
|
| 274 |
|
|
| 275 |
|
|
| 276 |
1339 |
if (namedConfiguration != null) { |
| 277 |
192 |
builder = completeFilesystem(builder, namedConfiguration); |
| 278 |
|
} |
| 279 |
|
|
| 280 |
1339 |
return builder != null ? builder.build() : null; |
| 281 |
|
} |
| 282 |
|
} |