Search in sources :

Example 1 with ObjectSizer

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);
}
Also used : Declarable(org.apache.geode.cache.Declarable) CacheXmlException(org.apache.geode.cache.CacheXmlException) EvictionAttributesImpl(org.apache.geode.internal.cache.EvictionAttributesImpl) ObjectSizer(org.apache.geode.cache.util.ObjectSizer)

Example 2 with ObjectSizer

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);
}
Also used : EvictionAction(org.apache.geode.cache.EvictionAction) DiskWriteAttributesImpl(org.apache.geode.internal.cache.DiskWriteAttributesImpl) PartitionAttributesImpl(org.apache.geode.internal.cache.PartitionAttributesImpl) AttributesImpl(org.xml.sax.helpers.AttributesImpl) Declarable(org.apache.geode.cache.Declarable) ObjectSizer(org.apache.geode.cache.util.ObjectSizer) SizeClassOnceObjectSizer(org.apache.geode.internal.size.SizeClassOnceObjectSizer) SizeClassOnceObjectSizer(org.apache.geode.internal.size.SizeClassOnceObjectSizer)

Example 3 with ObjectSizer

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());
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) ObjectSizer(org.apache.geode.cache.util.ObjectSizer) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedSystem(org.apache.geode.distributed.DistributedSystem) Cache(org.apache.geode.cache.Cache)

Example 4 with ObjectSizer

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());
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) DiskRegionStats(org.apache.geode.internal.cache.DiskRegionStats) ObjectSizer(org.apache.geode.cache.util.ObjectSizer) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedSystem(org.apache.geode.distributed.DistributedSystem) AttributesFactory(org.apache.geode.cache.AttributesFactory) DiskRegion(org.apache.geode.internal.cache.DiskRegion) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) EntryEvent(org.apache.geode.cache.EntryEvent) LRUStatistics(org.apache.geode.internal.cache.lru.LRUStatistics) BufferedReader(java.io.BufferedReader) Cache(org.apache.geode.cache.Cache)

Example 5 with ObjectSizer

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);
}
Also used : Declarable(org.apache.geode.cache.Declarable) CacheXmlException(org.apache.geode.cache.CacheXmlException) EvictionAttributesImpl(org.apache.geode.internal.cache.EvictionAttributesImpl) ObjectSizer(org.apache.geode.cache.util.ObjectSizer)

Aggregations

ObjectSizer (org.apache.geode.cache.util.ObjectSizer)8 AttributesFactory (org.apache.geode.cache.AttributesFactory)4 Cache (org.apache.geode.cache.Cache)4 DistributedSystem (org.apache.geode.distributed.DistributedSystem)4 LocalRegion (org.apache.geode.internal.cache.LocalRegion)4 Declarable (org.apache.geode.cache.Declarable)3 LRUStatistics (org.apache.geode.internal.cache.lru.LRUStatistics)3 CacheXmlException (org.apache.geode.cache.CacheXmlException)2 DiskRegion (org.apache.geode.internal.cache.DiskRegion)2 DiskRegionStats (org.apache.geode.internal.cache.DiskRegionStats)2 EvictionAttributesImpl (org.apache.geode.internal.cache.EvictionAttributesImpl)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 InputStreamReader (java.io.InputStreamReader)1 DiskStore (org.apache.geode.cache.DiskStore)1 DiskStoreFactory (org.apache.geode.cache.DiskStoreFactory)1 EntryEvent (org.apache.geode.cache.EntryEvent)1 EvictionAction (org.apache.geode.cache.EvictionAction)1 EvictionAttributes (org.apache.geode.cache.EvictionAttributes)1 CacheListenerAdapter (org.apache.geode.cache.util.CacheListenerAdapter)1