Fixes JIRA issues SGF-249 involving property placeholder values on Disk Store bean definition attributes, and specifically the compaction-threshold attribute, in the SDG XML namespace.
This commit is contained in:
@@ -24,40 +24,42 @@ import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.DiskStore;
|
||||
import com.gemstone.gemfire.cache.DiskStoreFactory;
|
||||
import com.gemstone.gemfire.cache.GemFireCache;
|
||||
|
||||
/**
|
||||
* FactoryBean for creating a DiskStore
|
||||
* FactoryBean for creating a GemFire DiskStore.
|
||||
* <p/>
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.BeanNameAware
|
||||
* @see org.springframework.beans.factory.FactoryBean
|
||||
* @see org.springframework.beans.factory.InitializingBean
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class DiskStoreFactoryBean implements FactoryBean<DiskStore>, InitializingBean, BeanNameAware {
|
||||
|
||||
private DiskStoreFactory diskStoreFactory;
|
||||
|
||||
private Boolean allowForceCompaction;
|
||||
private Boolean autoCompact;
|
||||
|
||||
private Boolean allowForceCompaction;
|
||||
|
||||
private Integer maxOplogSize;
|
||||
|
||||
private Integer timeInterval;
|
||||
|
||||
private Integer queueSize;
|
||||
|
||||
private Integer compactionThreshold;
|
||||
|
||||
private Integer writeBufferSize;
|
||||
private DiskStore diskStore;
|
||||
|
||||
private GemFireCache cache;
|
||||
|
||||
private String name;
|
||||
private Integer compactionThreshold;
|
||||
private Integer maxOplogSize;
|
||||
private Integer queueSize;
|
||||
private Integer timeInterval;
|
||||
private Integer writeBufferSize;
|
||||
|
||||
private List<DiskDir> diskDirs;
|
||||
|
||||
private DiskStore diskStore;
|
||||
|
||||
private String name;
|
||||
|
||||
@Override
|
||||
public DiskStore getObject() throws Exception {
|
||||
@@ -76,7 +78,9 @@ public class DiskStoreFactoryBean implements FactoryBean<DiskStore>, Initializin
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(cache, "Cache property must be set");
|
||||
Assert.state(cache != null, String.format("A reference to the GemFire Cache must be set for Disk Store '%1$s'.",
|
||||
getName()));
|
||||
|
||||
diskStoreFactory = cache.createDiskStoreFactory();
|
||||
|
||||
if (allowForceCompaction != null) {
|
||||
@@ -104,52 +108,32 @@ public class DiskStoreFactoryBean implements FactoryBean<DiskStore>, Initializin
|
||||
if (!CollectionUtils.isEmpty(diskDirs)) {
|
||||
File[] diskDirFiles = new File[diskDirs.size()];
|
||||
int[] diskDirSizes = new int[diskDirs.size()];
|
||||
|
||||
for (int i = 0; i < diskDirs.size(); i++) {
|
||||
DiskDir diskDir = diskDirs.get(i);
|
||||
diskDirFiles[i] = new File(diskDir.location);
|
||||
diskDirSizes[i] = diskDir.maxSize == null ? DiskStoreFactory.DEFAULT_DISK_DIR_SIZE : diskDir.maxSize;
|
||||
}
|
||||
|
||||
diskStoreFactory.setDiskDirsAndSizes(diskDirFiles, diskDirSizes);
|
||||
}
|
||||
|
||||
diskStore = diskStoreFactory.create(name == null ? DiskStoreFactory.DEFAULT_DISK_STORE_NAME : name);
|
||||
Assert.notNull(diskStore);
|
||||
|
||||
diskStore = diskStoreFactory.create(getName());
|
||||
|
||||
Assert.notNull(diskStore, String.format("The DiskStore with name '%1$s' failed to be created successfully.",
|
||||
diskStore.getName()));
|
||||
}
|
||||
|
||||
public void setCache(GemFireCache cache) {
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
public void setAutoCompact(Boolean autoCompact) {
|
||||
this.autoCompact = autoCompact;
|
||||
}
|
||||
|
||||
public void setAllowForceCompaction(Boolean allowForceCompaction) {
|
||||
this.allowForceCompaction = allowForceCompaction;
|
||||
}
|
||||
|
||||
public void setMaxOplogSize(Integer maxOplogSize) {
|
||||
this.maxOplogSize = maxOplogSize;
|
||||
}
|
||||
|
||||
public void setTimeInterval(Integer timeInterval) {
|
||||
this.timeInterval = timeInterval;
|
||||
}
|
||||
|
||||
public void setQueueSize(Integer queueSize) {
|
||||
this.queueSize = queueSize;
|
||||
}
|
||||
|
||||
public void setCompactionThreshold(Integer compactionThreshold) {
|
||||
this.compactionThreshold = compactionThreshold;
|
||||
}
|
||||
|
||||
public void setWriteBufferSize(Integer writeBufferSize) {
|
||||
this.writeBufferSize = writeBufferSize;
|
||||
}
|
||||
|
||||
public void setDiskDirs(List<DiskDir> diskDirs) {
|
||||
this.diskDirs = diskDirs;
|
||||
public void setAutoCompact(Boolean autoCompact) {
|
||||
this.autoCompact = autoCompact;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -157,10 +141,44 @@ public class DiskStoreFactoryBean implements FactoryBean<DiskStore>, Initializin
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static class DiskDir {
|
||||
final String location;
|
||||
public void setCompactionThreshold(Integer compactionThreshold) {
|
||||
validateCompactionThreshold(compactionThreshold);
|
||||
this.compactionThreshold = compactionThreshold;
|
||||
}
|
||||
|
||||
protected void validateCompactionThreshold(final Integer compactionThreshold) {
|
||||
Assert.isTrue(compactionThreshold == null || (compactionThreshold >= 0 && compactionThreshold <= 100),
|
||||
String.format("The DiskStore's (%1$s) compaction threshold (%2$d) must be an integer value between 0 and 100 inclusive.",
|
||||
this.name, compactionThreshold));
|
||||
}
|
||||
|
||||
public void setDiskDirs(List<DiskDir> diskDirs) {
|
||||
this.diskDirs = diskDirs;
|
||||
}
|
||||
|
||||
public void setMaxOplogSize(Integer maxOplogSize) {
|
||||
this.maxOplogSize = maxOplogSize;
|
||||
}
|
||||
|
||||
public void setQueueSize(Integer queueSize) {
|
||||
this.queueSize = queueSize;
|
||||
}
|
||||
|
||||
public void setTimeInterval(Integer timeInterval) {
|
||||
this.timeInterval = timeInterval;
|
||||
}
|
||||
|
||||
public void setWriteBufferSize(Integer writeBufferSize) {
|
||||
this.writeBufferSize = writeBufferSize;
|
||||
}
|
||||
|
||||
/* package-private */ final String getName() {
|
||||
return (StringUtils.hasText(name) ? name : DiskStoreFactory.DEFAULT_DISK_STORE_NAME);
|
||||
}
|
||||
|
||||
public static class DiskDir {
|
||||
final Integer maxSize;
|
||||
final String location;
|
||||
|
||||
public DiskDir(String location, int maxSize) {
|
||||
this.location = location;
|
||||
@@ -172,4 +190,5 @@ public class DiskStoreFactoryBean implements FactoryBean<DiskStore>, Initializin
|
||||
this.maxSize = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,11 +29,13 @@ import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parser for the <disk-store> definitions.
|
||||
* Parser for <disk-store> bean definitions.
|
||||
* <p/>
|
||||
* @author David Turanski
|
||||
*
|
||||
* @author John Blum
|
||||
*/
|
||||
public class DiskStoreParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return DiskStoreFactoryBean.class;
|
||||
@@ -42,29 +44,37 @@ public class DiskStoreParser extends AbstractSingleBeanDefinitionParser {
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
super.doParse(element, parserContext, builder);
|
||||
|
||||
builder.setLazyInit(false);
|
||||
|
||||
ParsingUtils.setPropertyReference(element, builder, "cache-ref", "cache");
|
||||
ParsingUtils.setPropertyValue(element, builder, "auto-compact");
|
||||
ParsingUtils.setPropertyValue(element, builder, "allow-force-compaction");
|
||||
ParsingUtils.setPropertyValue(element, builder, "max-oplog-size");
|
||||
ParsingUtils.setPropertyValue(element, builder, "time-interval");
|
||||
ParsingUtils.setPropertyValue(element, builder, "queue-size");
|
||||
ParsingUtils.setPropertyValue(element, builder, "auto-compact");
|
||||
ParsingUtils.setPropertyValue(element, builder, "compaction-threshold");
|
||||
ParsingUtils.setPropertyValue(element, builder, "max-oplog-size");
|
||||
ParsingUtils.setPropertyValue(element, builder, "queue-size");
|
||||
ParsingUtils.setPropertyValue(element, builder, "time-interval");
|
||||
ParsingUtils.setPropertyValue(element, builder, "write-buffer-size");
|
||||
|
||||
List<Element> diskDirElements = DomUtils.getChildElementsByTagName(element, "disk-dir");
|
||||
|
||||
if (!CollectionUtils.isEmpty(diskDirElements)) {
|
||||
ManagedList<AbstractBeanDefinition> diskDirs = new ManagedList<AbstractBeanDefinition>();
|
||||
|
||||
for (Element diskDirElement : diskDirElements) {
|
||||
BeanDefinitionBuilder diskDirBuilder = BeanDefinitionBuilder.genericBeanDefinition(DiskDir.class);
|
||||
|
||||
diskDirBuilder.addConstructorArgValue(diskDirElement.getAttribute("location"));
|
||||
|
||||
if (diskDirElement.hasAttribute("max-size")) {
|
||||
diskDirBuilder.addConstructorArgValue(diskDirElement.getAttribute("max-size"));
|
||||
}
|
||||
|
||||
diskDirs.add(diskDirBuilder.getBeanDefinition());
|
||||
}
|
||||
|
||||
builder.addPropertyValue("diskDirs", diskDirs);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user