Search in sources :

Example 16 with Declarable

use of org.apache.geode.cache.Declarable in project geode by apache.

the class CacheXmlGenerator method generate.

/**
   * Generates XML for a <code>CacheCallback</code>
   */
private void generate(String kind, Object callback) throws SAXException {
    if (callback == null) {
        return;
    }
    handler.startElement("", kind, kind, EMPTY);
    String className = callback.getClass().getName();
    handler.startElement("", CLASS_NAME, CLASS_NAME, EMPTY);
    handler.characters(className.toCharArray(), 0, className.length());
    handler.endElement("", CLASS_NAME, CLASS_NAME);
    Properties props = null;
    if (callback instanceof Declarable2) {
        props = ((Declarable2) callback).getConfig();
    } else if (callback instanceof ReflectionBasedAutoSerializer) {
        props = ((ReflectionBasedAutoSerializer) callback).getConfig();
    } else if (callback instanceof Declarable && cache instanceof GemFireCacheImpl) {
        props = ((InternalCache) cache).getDeclarableProperties((Declarable) callback);
    }
    generate(props, null);
    handler.endElement("", kind, kind);
}
Also used : Declarable(org.apache.geode.cache.Declarable) ReflectionBasedAutoSerializer(org.apache.geode.pdx.ReflectionBasedAutoSerializer) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Properties(java.util.Properties)

Example 17 with Declarable

use of org.apache.geode.cache.Declarable in project geode by apache.

the class CacheXmlGenerator method generateFunctionService.

/**
   * @throws SAXException
   */
private void generateFunctionService() throws SAXException {
    Map<String, Function> functions = FunctionService.getRegisteredFunctions();
    if (!generateDefaults() && functions.isEmpty()) {
        return;
    }
    handler.startElement("", FUNCTION_SERVICE, FUNCTION_SERVICE, EMPTY);
    for (Function function : functions.values()) {
        if (function instanceof Declarable) {
            handler.startElement("", FUNCTION, FUNCTION, EMPTY);
            generate((Declarable) function, false);
            handler.endElement("", FUNCTION, FUNCTION);
        }
    }
    handler.endElement("", FUNCTION_SERVICE, FUNCTION_SERVICE);
}
Also used : Function(org.apache.geode.cache.execute.Function) Declarable(org.apache.geode.cache.Declarable)

Example 18 with Declarable

use of org.apache.geode.cache.Declarable in project geode by apache.

the class CacheXmlParser method endPdxSerializer.

/**
   * 
   */
private void endPdxSerializer() {
    Declarable d = createDeclarable();
    if (!(d instanceof PdxSerializer)) {
        throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_0_IS_NOT_AN_INSTANCE_OF_A_PDX_SERIALIZER.toLocalizedString(d.getClass().getName()));
    }
    PdxSerializer serializer = (PdxSerializer) d;
    this.cache.setPdxSerializer(serializer);
}
Also used : PdxSerializer(org.apache.geode.pdx.PdxSerializer) Declarable(org.apache.geode.cache.Declarable) CacheXmlException(org.apache.geode.cache.CacheXmlException)

Example 19 with Declarable

use of org.apache.geode.cache.Declarable in project geode by apache.

the class CacheXmlParser method endCacheWriter.

/**
   * When a <code>cache-writer</code> element is finished, the {@link Parameter}s and class names
   * are popped off the stack. The cache writer is instantiated and initialized with the parameters,
   * if appropriate.
   * <p>
   * A cache-writer may be created in the context of region-attributes or dynamic-region-factory. In
   * the latter case, there may be a disk-dir on top of the stack, represented by a File object.
   */
private void endCacheWriter() {
    Declarable d = createDeclarable();
    if (!(d instanceof CacheWriter)) {
        throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_0_IS_NOT_AN_INSTANCE_OF_A_CACHEWRITER.toLocalizedString(d.getClass().getName()));
    }
    Object a = stack.peek();
    // check for disk-dir
    if ((a instanceof File)) {
        Object sav = stack.pop();
        // pop out disk size
        Object size = stack.pop();
        a = stack.peek();
        //
        if (!(a instanceof RegionAttributesCreation)) {
            throw new CacheXmlException(LocalizedStrings.CacheXmlParser_0_MUST_BE_DEFINED_IN_THE_CONTEXT_OF_1.toLocalizedString(new Object[] { CACHE_WRITER, DYNAMIC_REGION_FACTORY }));
        }
        stack.push(size);
        stack.push(sav);
    } else // check for normal region-attributes
    if (!(a instanceof RegionAttributesCreation)) {
        throw new CacheXmlException(LocalizedStrings.CacheXmlParser_0_MUST_BE_DEFINED_IN_THE_CONTEXT_OF_REGIONATTRIBUTES.toLocalizedString(CACHE_WRITER));
    }
    RegionAttributesCreation attrs = (RegionAttributesCreation) a;
    attrs.setCacheWriter((CacheWriter) d);
}
Also used : Declarable(org.apache.geode.cache.Declarable) CacheXmlException(org.apache.geode.cache.CacheXmlException) CacheWriter(org.apache.geode.cache.CacheWriter) File(java.io.File)

Example 20 with Declarable

use of org.apache.geode.cache.Declarable in project geode by apache.

the class CacheXmlParser method endFunctionName.

/**
   * When we have finished a function element, we create the Declarable and push it onto stack
   */
private void endFunctionName() {
    Declarable d = createDeclarable();
    if (!(d instanceof Function)) {
        String s = LocalizedStrings.CacheXmlParser_A_0_IS_NOT_AN_INSTANCE_OF_A_FUNCTION.toLocalizedString(d.getClass().getName());
        throw new CacheXmlException(s);
    }
    Object fs = stack.peek();
    if (!(fs instanceof FunctionServiceCreation)) {
        throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_0_IS_ONLY_ALLOWED_IN_THE_CONTEXT_OF_1_MJTDEBUG_E_2.toLocalizedString(new Object[] { FUNCTION, FUNCTION_SERVICE, fs }));
    }
    FunctionServiceCreation funcService = (FunctionServiceCreation) fs;
    funcService.registerFunction((Function) d);
}
Also used : Function(org.apache.geode.cache.execute.Function) Declarable(org.apache.geode.cache.Declarable) CacheXmlException(org.apache.geode.cache.CacheXmlException)

Aggregations

Declarable (org.apache.geode.cache.Declarable)29 CacheXmlException (org.apache.geode.cache.CacheXmlException)22 Properties (java.util.Properties)5 PartitionAttributesImpl (org.apache.geode.internal.cache.PartitionAttributesImpl)4 ObjectSizer (org.apache.geode.cache.util.ObjectSizer)3 GatewaySenderFactory (org.apache.geode.cache.wan.GatewaySenderFactory)3 File (java.io.File)2 IOException (java.io.IOException)2 EmptyStackException (java.util.EmptyStackException)2 InternalGemFireException (org.apache.geode.InternalGemFireException)2 CacheException (org.apache.geode.cache.CacheException)2 CacheWriterException (org.apache.geode.cache.CacheWriterException)2 ExpirationAttributes (org.apache.geode.cache.ExpirationAttributes)2 GatewayException (org.apache.geode.cache.GatewayException)2 RegionExistsException (org.apache.geode.cache.RegionExistsException)2 TimeoutException (org.apache.geode.cache.TimeoutException)2 Function (org.apache.geode.cache.execute.Function)2 DiskWriteAttributesImpl (org.apache.geode.internal.cache.DiskWriteAttributesImpl)2 EvictionAttributesImpl (org.apache.geode.internal.cache.EvictionAttributesImpl)2 FixedPartitionAttributesImpl (org.apache.geode.internal.cache.FixedPartitionAttributesImpl)2