Search in sources :

Example 21 with Compressor

use of org.apache.geode.compression.Compressor in project geode by apache.

the class CacheXmlParser method endCompressor.

/**
   * Ending the <code>compressor</code> registration should leave us with a class name on the stack.
   * Pull it off and setup the {@link Compressor} on the region attributes.
   */
private void endCompressor() {
    Class<?> klass = getClassFromStack();
    if (!Compressor.class.isAssignableFrom(klass)) {
        throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_0_IS_NOT_AN_INSTANCE_OF_A_COMPRESSOR.toLocalizedString(klass.getName()));
    }
    Compressor compressor;
    try {
        compressor = (Compressor) klass.newInstance();
    } catch (Exception ex) {
        throw new CacheXmlException(LocalizedStrings.CacheXmlParser_WHILE_INSTANTIATING_A_0.toLocalizedString(klass.getName()), ex);
    }
    Object a = stack.peek();
    if (a instanceof RegionAttributesCreation) {
        RegionAttributesCreation attrs = (RegionAttributesCreation) a;
        attrs.setCompressor(compressor);
    } else {
        throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_0_MUST_BE_DEFINED_IN_THE_CONTEXT_OF_REGIONATTRIBUTES_OR_1.toLocalizedString(new Object[] { COMPRESSOR, DYNAMIC_REGION_FACTORY }));
    }
}
Also used : CacheXmlException(org.apache.geode.cache.CacheXmlException) Compressor(org.apache.geode.compression.Compressor) TimeoutException(org.apache.geode.cache.TimeoutException) InternalGemFireException(org.apache.geode.InternalGemFireException) EmptyStackException(java.util.EmptyStackException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) RegionExistsException(org.apache.geode.cache.RegionExistsException) CacheXmlException(org.apache.geode.cache.CacheXmlException) SAXException(org.xml.sax.SAXException) GatewayException(org.apache.geode.cache.GatewayException) CacheWriterException(org.apache.geode.cache.CacheWriterException) SAXParseException(org.xml.sax.SAXParseException)

Example 22 with Compressor

use of org.apache.geode.compression.Compressor in project geode by apache.

the class PartitionedRegionCompressionDUnitTest method getRegionAttributes.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected RegionAttributes getRegionAttributes(String type) {
    Compressor compressor = null;
    try {
        compressor = SnappyCompressor.getDefaultInstance();
    } catch (Throwable t) {
        // Not a supported OS
        return super.getRegionAttributes(type);
    }
    RegionAttributes ra = super.getRegionAttributes(type);
    AttributesFactory factory = new AttributesFactory(ra);
    if (!ra.getDataPolicy().isEmpty()) {
        factory.setCompressor(compressor);
    }
    return factory.create();
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) Compressor(org.apache.geode.compression.Compressor) SnappyCompressor(org.apache.geode.compression.SnappyCompressor)

Example 23 with Compressor

use of org.apache.geode.compression.Compressor in project geode by apache.

the class PartitionedRegionCompressionDUnitTest method getRegionAttributes.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected RegionAttributes getRegionAttributes() {
    Compressor compressor = null;
    try {
        compressor = SnappyCompressor.getDefaultInstance();
    } catch (Throwable t) {
        // Not a supported OS
        return super.getRegionAttributes();
    }
    RegionAttributes attrs = super.getRegionAttributes();
    AttributesFactory factory = new AttributesFactory(attrs);
    factory.setCompressor(compressor);
    return factory.create();
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) Compressor(org.apache.geode.compression.Compressor) SnappyCompressor(org.apache.geode.compression.SnappyCompressor)

Aggregations

Compressor (org.apache.geode.compression.Compressor)23 SnappyCompressor (org.apache.geode.compression.SnappyCompressor)13 Test (org.junit.Test)13 RegionEntryContext (org.apache.geode.internal.cache.RegionEntryContext)7 UnitTest (org.apache.geode.test.junit.categories.UnitTest)7 CachePerfStats (org.apache.geode.internal.cache.CachePerfStats)6 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 AttributesFactory (org.apache.geode.cache.AttributesFactory)4 RegionAttributes (org.apache.geode.cache.RegionAttributes)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 RegionShortcut (org.apache.geode.cache.RegionShortcut)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 EmptyStackException (java.util.EmptyStackException)1 InternalGemFireException (org.apache.geode.InternalGemFireException)1 CacheException (org.apache.geode.cache.CacheException)1 CacheListener (org.apache.geode.cache.CacheListener)1 CacheLoader (org.apache.geode.cache.CacheLoader)1 CacheWriter (org.apache.geode.cache.CacheWriter)1 CacheWriterException (org.apache.geode.cache.CacheWriterException)1