use of org.apache.geode.cache.util.ObjectSizer in project geode by apache.
the class CacheXmlParser method endLRUHeapPercentage.
/**
* Complete the configuration of a <code>lru-heap-percentage</code> eviction controller. Check for
* the declaration of an {@link ObjectSizer}. Assign the attributes to the enclosed
* <code>region-attributes</code>
*/
private void endLRUHeapPercentage() {
Object declCheck = stack.peek();
Declarable d = null;
if (declCheck instanceof String || declCheck instanceof Parameter) {
d = createDeclarable();
if (!(d instanceof ObjectSizer)) {
String s = "A " + d.getClass().getName() + " is not an instance of a ObjectSizer";
throw new CacheXmlException(s);
}
}
EvictionAttributesImpl eai = (EvictionAttributesImpl) stack.pop();
if (d != null) {
eai.setObjectSizer((ObjectSizer) d);
}
RegionAttributesCreation regAttrs = peekRegionAttributesContext(LRU_HEAP_PERCENTAGE);
regAttrs.setEvictionAttributes(eai);
}
use of org.apache.geode.cache.util.ObjectSizer in project geode by apache.
the class CacheXmlGenerator method generate.
private void generate(EvictionAttributes ea) throws SAXException {
EvictionAction eAction = ea.getAction();
if (eAction.isNone()) {
return;
}
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", ACTION, "", eAction.toString());
handler.startElement("", EVICTION_ATTRIBUTES, EVICTION_ATTRIBUTES, EMPTY);
if (ea.getAlgorithm() == EvictionAlgorithm.LRU_ENTRY) {
atts.addAttribute("", "", MAXIMUM, "", String.valueOf(ea.getMaximum()));
handler.startElement("", LRU_ENTRY_COUNT, LRU_ENTRY_COUNT, atts);
handler.endElement("", LRU_ENTRY_COUNT, LRU_ENTRY_COUNT);
} else if (ea.getAlgorithm() == EvictionAlgorithm.LRU_MEMORY) {
atts.addAttribute("", "", MAXIMUM, "", String.valueOf(ea.getMaximum()));
handler.startElement("", LRU_MEMORY_SIZE, LRU_MEMORY_SIZE, atts);
ObjectSizer os = ea.getObjectSizer();
if (os != null && os != ObjectSizer.DEFAULT) {
generate((Declarable) os, false);
}
handler.endElement("", LRU_MEMORY_SIZE, LRU_MEMORY_SIZE);
} else if (ea.getAlgorithm() == EvictionAlgorithm.LRU_HEAP) {
handler.startElement("", LRU_HEAP_PERCENTAGE, LRU_HEAP_PERCENTAGE, atts);
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) {
ObjectSizer os = ea.getObjectSizer();
if (!(os instanceof SizeClassOnceObjectSizer)) {
if (os != null) {
generate((Declarable) os, false);
}
}
}
handler.endElement("", LRU_HEAP_PERCENTAGE, LRU_HEAP_PERCENTAGE);
} else {
// all other algos are ignored
}
handler.endElement("", EVICTION_ATTRIBUTES, EVICTION_ATTRIBUTES);
}
use of org.apache.geode.cache.util.ObjectSizer in project geode by apache.
the class TestDiskRegion method main4.
/**
* Byte arrays
*/
public static void main4(String[] args) throws Exception {
DistributedSystem system = DistributedSystem.connect(new java.util.Properties());
Cache cache = CacheFactory.create(system);
AttributesFactory factory = new AttributesFactory();
factory.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(2, (ObjectSizer) null, EvictionAction.OVERFLOW_TO_DISK));
LocalRegion region = (LocalRegion) cache.createRegion("TestDiskRegion", factory.create());
for (int i = 0; i < 100000; i++) {
System.out.println(i);
region.put(String.valueOf(i), String.valueOf(i).getBytes());
}
}
use of org.apache.geode.cache.util.ObjectSizer in project geode by apache.
the class TestDiskRegion method main1.
public static void main1(String[] args) throws Exception {
DistributedSystem system = DistributedSystem.connect(new java.util.Properties());
Cache cache = CacheFactory.create(system);
AttributesFactory factory = new AttributesFactory();
factory.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(2, (ObjectSizer) null, EvictionAction.OVERFLOW_TO_DISK));
factory.setCacheListener(new CacheListenerAdapter() {
public void afterUpdate(EntryEvent event) {
System.out.println("UPDATE: " + event.getKey() + " -> (" + event.getOldValue() + " -> " + event.getNewValue() + ")");
}
});
LocalRegion region = (LocalRegion) cache.createRegion("TestDiskRegion", factory.create());
DiskRegion dr = region.getDiskRegion();
DiskRegionStats diskStats = dr.getStats();
LRUStatistics lruStats = getLRUStats(region);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Hit enter to perform action");
for (int i = 0; true; i++) {
br.readLine();
// Thread.sleep(500);
Object key = new Integer(i);
Object value = new byte[200000];
region.put(key, value);
System.out.println(key + " -> " + value + " evictions = " + lruStats.getEvictions() + ", writes = " + diskStats.getWrites());
}
}
use of org.apache.geode.cache.util.ObjectSizer in project geode by apache.
the class CacheXmlParser method endLRUMemorySize.
/**
* Complete the configuration of a <code>lru-memory-size</code> eviction controller. Check for the
* declaration of an {@link ObjectSizer}. Assign the attributes to the enclose
* <code>region-attributes</code>
*/
private void endLRUMemorySize() {
Object declCheck = stack.peek();
Declarable d = null;
if (declCheck instanceof String || declCheck instanceof Parameter) {
d = createDeclarable();
if (!(d instanceof ObjectSizer)) {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_0_IS_NOT_AN_INSTANCE_OF_A_OBJECTSIZER.toLocalizedString(d.getClass().getName()));
}
}
EvictionAttributesImpl eai = (EvictionAttributesImpl) stack.pop();
if (d != null) {
eai.setObjectSizer((ObjectSizer) d);
}
RegionAttributesCreation regAttrs = peekRegionAttributesContext(LRU_MEMORY_SIZE);
regAttrs.setEvictionAttributes(eai);
}
Aggregations