Search in sources :

Example 1 with NamedListNode

use of org.apache.ignite.internal.configuration.tree.NamedListNode in project ignite-3 by apache.

the class ConfigurationUtil method findEx.

/**
 * Finds a node or a leaf by the given path.
 *
 * @param path     Path.
 * @param rootNode Root node.
 * @param <T>      Arbitrary result type.
 * @return Node or leaf.
 */
@Nullable
public static <T> T findEx(List<KeyPathNode> path, InnerNode rootNode) {
    try {
        var visitor = new ConfigurationVisitor<T>() {

            private final int pathSize = path.size();

            /**
             * Current index of the key in the {@code path}.
             */
            private int idx;

            /**
             * {@inheritDoc}
             */
            @Override
            public T visitLeafNode(String key, Serializable val) {
                if (idx != pathSize) {
                    throw new KeyNotFoundException("Configuration value '" + joinPath(path.subList(0, idx)) + "' is a leaf");
                } else {
                    return (T) val;
                }
            }

            /**
             * {@inheritDoc}
             */
            @Override
            public T visitInnerNode(String key, InnerNode node) {
                if (node == null) {
                    throw new KeyNotFoundException("Configuration node '" + joinPath(path.subList(0, idx)) + "' is null");
                } else if (idx == pathSize) {
                    return (T) node;
                } else {
                    try {
                        KeyPathNode pathNode = path.get(idx++);
                        assert !pathNode.unresolvedName;
                        if (INTERNAL_ID.equals(pathNode.key)) {
                            // It's impossible to get this value with a regular traversal. Just call a method.
                            return (T) node.internalId();
                        } else if (INJECTED_NAME.equals(pathNode.key)) {
                            // It's impossible to get this value with a regular traversal. Just call a method.
                            return (T) node.getInjectedNameFieldValue();
                        }
                        return node.traverseChild(pathNode.key, this, true);
                    } catch (NoSuchElementException e) {
                        throw new KeyNotFoundException("Configuration value '" + joinPath(path.subList(0, idx)) + "' has not been found");
                    } catch (ConfigurationWrongPolymorphicTypeIdException e) {
                        assert false : e;
                        return null;
                    }
                }
            }

            /**
             * {@inheritDoc}
             */
            @Override
            public T visitNamedListNode(String key, NamedListNode<?> node) {
                if (idx == pathSize) {
                    return (T) node;
                } else {
                    KeyPathNode pathNode = path.get(idx++);
                    assert pathNode.namedListEntry;
                    String name = pathNode.unresolvedName ? pathNode.key : node.keyByInternalId(UUID.fromString(pathNode.key));
                    return visitInnerNode(name, node.getInnerNode(name));
                }
            }
        };
        return rootNode.accept(null, visitor);
    } catch (KeyNotFoundException e) {
        throw new NoSuchElementException(joinPath(path));
    }
}
Also used : Serializable(java.io.Serializable) NamedListNode(org.apache.ignite.internal.configuration.tree.NamedListNode) ConfigurationWrongPolymorphicTypeIdException(org.apache.ignite.configuration.ConfigurationWrongPolymorphicTypeIdException) ConfigurationVisitor(org.apache.ignite.internal.configuration.tree.ConfigurationVisitor) KeyPathNode(org.apache.ignite.internal.configuration.direct.KeyPathNode) NoSuchElementException(java.util.NoSuchElementException) InnerNode(org.apache.ignite.internal.configuration.tree.InnerNode) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with NamedListNode

use of org.apache.ignite.internal.configuration.tree.NamedListNode in project ignite-3 by apache.

the class ConfigurationUtilTest method testFlattenedMapPolymorphicNamedConfig.

@Test
void testFlattenedMapPolymorphicNamedConfig() {
    InnerNode polymorphicRootInnerNode = newNodeInstance(PolymorphicRootConfigurationSchema.class);
    PolymorphicRootChange polymorphicRootChange = ((PolymorphicRootChange) polymorphicRootInnerNode);
    polymorphicRootChange.changePolymorphicNamedCfg(c -> c.create("0", c1 -> {
    }));
    addDefaults(polymorphicRootInnerNode);
    RootKey<?, ?> rootKey = PolymorphicRootConfiguration.KEY;
    SuperRoot superRoot = new SuperRoot(key -> null, Map.of(rootKey, polymorphicRootInnerNode));
    final Map<String, Serializable> act = flattenedMap(superRoot, rootKey, node -> ((PolymorphicRootChange) node).changePolymorphicNamedCfg(c -> c.createOrUpdate("0", c1 -> c1.convert(SecondPolymorphicInstanceChange.class))));
    NamedListNode<?> polymorphicNamedCfgListNode = (NamedListNode<?>) polymorphicRootChange.polymorphicNamedCfg();
    UUID internalId = polymorphicNamedCfgListNode.internalId("0");
    Map<String, Serializable> exp = new HashMap<>();
    exp.put("rootPolymorphic.polymorphicNamedCfg." + internalId + ".typeId", "second");
    exp.put("rootPolymorphic.polymorphicNamedCfg." + internalId + ".longVal", 0L);
    exp.put("rootPolymorphic.polymorphicNamedCfg." + internalId + ".strVal", null);
    exp.put("rootPolymorphic.polymorphicNamedCfg." + internalId + ".intVal", 0);
    assertEquals(exp, act);
}
Also used : PolymorphicId(org.apache.ignite.configuration.annotation.PolymorphicId) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Arrays(java.util.Arrays) RootInnerNode(org.apache.ignite.internal.configuration.RootInnerNode) DISTRIBUTED(org.apache.ignite.configuration.annotation.ConfigurationType.DISTRIBUTED) NamedConfigValue(org.apache.ignite.configuration.annotation.NamedConfigValue) AfterAll(org.junit.jupiter.api.AfterAll) BeforeAll(org.junit.jupiter.api.BeforeAll) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) ConfigurationUtil.addDefaults(org.apache.ignite.internal.configuration.util.ConfigurationUtil.addDefaults) Matchers.allOf(org.hamcrest.Matchers.allOf) Set(java.util.Set) UUID(java.util.UUID) RootKey(org.apache.ignite.configuration.RootKey) Serializable(java.io.Serializable) ConfigurationUtil.removeLastKey(org.apache.ignite.internal.configuration.util.ConfigurationUtil.removeLastKey) Test(org.junit.jupiter.api.Test) ConfigValue(org.apache.ignite.configuration.annotation.ConfigValue) Matchers.matchesPattern(org.hamcrest.Matchers.matchesPattern) List(java.util.List) NAME(org.apache.ignite.internal.configuration.tree.NamedListNode.NAME) LOCAL(org.apache.ignite.configuration.annotation.ConfigurationType.LOCAL) ConfigurationUtil.checkConfigurationType(org.apache.ignite.internal.configuration.util.ConfigurationUtil.checkConfigurationType) ConfigurationUtil.collectSchemas(org.apache.ignite.internal.configuration.util.ConfigurationUtil.collectSchemas) ConfigurationFlattener.createFlattenedUpdatesMap(org.apache.ignite.internal.configuration.util.ConfigurationFlattener.createFlattenedUpdatesMap) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Config(org.apache.ignite.configuration.annotation.Config) Matchers.is(org.hamcrest.Matchers.is) NotNull(org.jetbrains.annotations.NotNull) ConfigurationAsmGenerator(org.apache.ignite.internal.configuration.asm.ConfigurationAsmGenerator) EMPTY_CFG_SRC(org.apache.ignite.internal.configuration.util.ConfigurationUtil.EMPTY_CFG_SRC) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Matchers.aMapWithSize(org.hamcrest.Matchers.aMapWithSize) NamedListNode(org.apache.ignite.internal.configuration.tree.NamedListNode) ORDER_IDX(org.apache.ignite.internal.configuration.tree.NamedListNode.ORDER_IDX) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) HashMap(java.util.HashMap) InnerNode(org.apache.ignite.internal.configuration.tree.InnerNode) ConfigurationUtil.internalSchemaExtensions(org.apache.ignite.internal.configuration.util.ConfigurationUtil.internalSchemaExtensions) TraversableTreeNode(org.apache.ignite.internal.configuration.tree.TraversableTreeNode) PolymorphicConfig(org.apache.ignite.configuration.annotation.PolymorphicConfig) Collections.singletonMap(java.util.Collections.singletonMap) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NoSuchElementException(java.util.NoSuchElementException) ConfigurationUtil.extensionsFields(org.apache.ignite.internal.configuration.util.ConfigurationUtil.extensionsFields) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) ConfigurationRoot(org.apache.ignite.configuration.annotation.ConfigurationRoot) ConfigurationUtil.compressDeletedEntries(org.apache.ignite.internal.configuration.util.ConfigurationUtil.compressDeletedEntries) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Consumer(java.util.function.Consumer) ConverterToMapVisitor(org.apache.ignite.internal.configuration.tree.ConverterToMapVisitor) Collectors.toList(java.util.stream.Collectors.toList) ConfigurationUtil.find(org.apache.ignite.internal.configuration.util.ConfigurationUtil.find) PolymorphicConfigInstance(org.apache.ignite.configuration.annotation.PolymorphicConfigInstance) SuperRoot(org.apache.ignite.internal.configuration.SuperRoot) ConfigurationUtil.polymorphicSchemaExtensions(org.apache.ignite.internal.configuration.util.ConfigurationUtil.polymorphicSchemaExtensions) TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) Matchers.anEmptyMap(org.hamcrest.Matchers.anEmptyMap) Value(org.apache.ignite.configuration.annotation.Value) InternalConfiguration(org.apache.ignite.configuration.annotation.InternalConfiguration) Serializable(java.io.Serializable) NamedListNode(org.apache.ignite.internal.configuration.tree.NamedListNode) HashMap(java.util.HashMap) SuperRoot(org.apache.ignite.internal.configuration.SuperRoot) Matchers.hasToString(org.hamcrest.Matchers.hasToString) RootInnerNode(org.apache.ignite.internal.configuration.RootInnerNode) InnerNode(org.apache.ignite.internal.configuration.tree.InnerNode) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 3 with NamedListNode

use of org.apache.ignite.internal.configuration.tree.NamedListNode in project ignite-3 by apache.

the class HoconListConfigurationSource method descend.

/**
 * {@inheritDoc}
 */
@Override
public void descend(ConstructableTreeNode node) {
    if (!(node instanceof NamedListNode)) {
        throw new IllegalArgumentException(format("'%s' configuration is expected to be a composite configuration node, not a list", join(path)));
    }
    String syntheticKeyName = ((NamedListNode<?>) node).syntheticKeyName();
    int idx = 0;
    for (Iterator<ConfigValue> iterator = hoconCfgList.iterator(); iterator.hasNext(); idx++) {
        ConfigValue next = iterator.next();
        if (next.valueType() != ConfigValueType.OBJECT) {
            throw new IllegalArgumentException(format("'%s' is expected to be a composite configuration node, not a single value", formatArrayPath(path, idx)));
        }
        ConfigObject hoconCfg = (ConfigObject) next;
        ConfigValue keyValue = hoconCfg.get(syntheticKeyName);
        if (keyValue == null || keyValue.valueType() != ConfigValueType.STRING) {
            throw new IllegalArgumentException(format("'%s' configuration value is mandatory and must be a String", formatArrayPath(path, idx) + KEY_SEPARATOR + syntheticKeyName));
        }
        String key = (String) keyValue.unwrapped();
        List<String> path = appendKey(this.path, syntheticKeyName);
        node.construct(key, new HoconObjectConfigurationSource(syntheticKeyName, path, hoconCfg), false);
    }
}
Also used : ConfigValue(com.typesafe.config.ConfigValue) NamedListNode(org.apache.ignite.internal.configuration.tree.NamedListNode) ConfigObject(com.typesafe.config.ConfigObject)

Example 4 with NamedListNode

use of org.apache.ignite.internal.configuration.tree.NamedListNode in project ignite-3 by apache.

the class ConfigurationAsmGenerator method addNodeChangePolymorphicTypeIdMethod.

/**
 * Adds a {@code Node#changeTypeId} for the polymorphic configuration case.
 *
 * @param classDef                  Definition of a polymorphic configuration class (parent).
 * @param fieldDefs                 Definitions for all fields in {@code classDef}.
 * @param polymorphicExtensions     Polymorphic configuration instance schemas (children).
 * @param polymorphicFields         Fields of polymorphic extensions.
 * @param polymorphicTypeIdFieldDef Identification field for the polymorphic configuration instance.
 * @return Method definition.
 */
private MethodDefinition addNodeChangePolymorphicTypeIdMethod(ClassDefinition classDef, Map<String, FieldDefinition> fieldDefs, Set<Class<?>> polymorphicExtensions, Collection<Field> polymorphicFields, FieldDefinition polymorphicTypeIdFieldDef) {
    MethodDefinition changePolymorphicTypeIdMtd = classDef.declareMethod(of(PUBLIC), changeMethodName(polymorphicTypeIdFieldDef.getName()), type(void.class), arg("typeId", String.class));
    Variable typeIdVar = changePolymorphicTypeIdMtd.getScope().getVariable("typeId");
    StringSwitchBuilder switchBuilder = new StringSwitchBuilder(changePolymorphicTypeIdMtd.getScope()).expression(typeIdVar).defaultCase(throwException(ConfigurationWrongPolymorphicTypeIdException.class, typeIdVar));
    for (Class<?> polymorphicExtension : polymorphicExtensions) {
        // Fields that need to be cleared when changing the type of the polymorphic configuration instance.
        Collection<Field> resetFields = polymorphicFields.stream().filter(f -> !polymorphicExtension.equals(f.getDeclaringClass())).collect(toList());
        // this.typeId = typeId;
        BytecodeBlock codeBlock = new BytecodeBlock().append(setThisFieldCode(changePolymorphicTypeIdMtd, typeIdVar, polymorphicTypeIdFieldDef));
        // Reset fields.
        for (Field resetField : resetFields) {
            FieldDefinition fieldDef = fieldDefs.get(fieldName(resetField));
            if (isValue(resetField) || isConfigValue(resetField)) {
                // this.field = null;
                codeBlock.append(setThisFieldCode(changePolymorphicTypeIdMtd, constantNull(fieldDef.getType()), fieldDef));
            } else {
                // this.field = new NamedListNode<>(key, ValueNode::new, "polymorphicIdFieldName");
                codeBlock.append(setThisFieldCode(changePolymorphicTypeIdMtd, newNamedListNode(resetField), fieldDef));
            }
        }
        // ConfigurationUtil.addDefaults(this);
        codeBlock.append(changePolymorphicTypeIdMtd.getThis()).invokeStatic(ADD_DEFAULTS_MTD);
        switchBuilder.addCase(polymorphicInstanceId(polymorphicExtension), codeBlock);
    }
    // if(typeId.equals(this.typeId)) return;
    // else switch(typeId)...
    changePolymorphicTypeIdMtd.getBody().append(typeIdVar).append(getThisFieldCode(changePolymorphicTypeIdMtd, polymorphicTypeIdFieldDef)).append(new IfStatement().condition(new BytecodeBlock().invokeVirtual(STRING_EQUALS_MTD)).ifTrue(new BytecodeBlock().ret()).ifFalse(switchBuilder.build().ret()));
    return changePolymorphicTypeIdMtd;
}
Also used : PolymorphicId(org.apache.ignite.configuration.annotation.PolymorphicId) BytecodeExpression(com.facebook.presto.bytecode.expression.BytecodeExpression) Arrays(java.util.Arrays) DirectPropertyProxy(org.apache.ignite.internal.configuration.direct.DirectPropertyProxy) BytecodeExpressions.isNotNull(com.facebook.presto.bytecode.expression.BytecodeExpressions.isNotNull) MethodDefinition(com.facebook.presto.bytecode.MethodDefinition) ConfigurationUtil.isPolymorphicConfigInstance(org.apache.ignite.internal.configuration.util.ConfigurationUtil.isPolymorphicConfigInstance) NamedConfigValue(org.apache.ignite.configuration.annotation.NamedConfigValue) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) DirectProxyAsmGenerator.newDirectProxyLambda(org.apache.ignite.internal.configuration.asm.DirectProxyAsmGenerator.newDirectProxyLambda) NamedConfigurationTree(org.apache.ignite.configuration.NamedConfigurationTree) IfStatement(com.facebook.presto.bytecode.control.IfStatement) DynamicConfigurationChanger(org.apache.ignite.internal.configuration.DynamicConfigurationChanger) Variable(com.facebook.presto.bytecode.Variable) DynamicConfiguration(org.apache.ignite.internal.configuration.DynamicConfiguration) Type.getType(org.objectweb.asm.Type.getType) Set(java.util.Set) BytecodeExpressions.constantBoolean(com.facebook.presto.bytecode.expression.BytecodeExpressions.constantBoolean) ConfigurationUtil.isConfigValue(org.apache.ignite.internal.configuration.util.ConfigurationUtil.isConfigValue) Serializable(java.io.Serializable) ConfigurationUtil.isPolymorphicId(org.apache.ignite.internal.configuration.util.ConfigurationUtil.isPolymorphicId) FINAL(com.facebook.presto.bytecode.Access.FINAL) Stream(java.util.stream.Stream) Config(org.apache.ignite.configuration.annotation.Config) ConfigurationSource(org.apache.ignite.internal.configuration.tree.ConfigurationSource) ConfigurationUtil(org.apache.ignite.internal.configuration.util.ConfigurationUtil) BytecodeExpressions.invokeStatic(com.facebook.presto.bytecode.expression.BytecodeExpressions.invokeStatic) MethodHandle(java.lang.invoke.MethodHandle) CollectionUtils.concat(org.apache.ignite.internal.util.CollectionUtils.concat) SYNTHETIC(com.facebook.presto.bytecode.Access.SYNTHETIC) NamedListNode(org.apache.ignite.internal.configuration.tree.NamedListNode) Constructor(java.lang.reflect.Constructor) Supplier(java.util.function.Supplier) ConfigurationTree(org.apache.ignite.configuration.ConfigurationTree) InnerNode(org.apache.ignite.internal.configuration.tree.InnerNode) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Lookup(java.lang.invoke.MethodHandles.Lookup) PolymorphicConfig(org.apache.ignite.configuration.annotation.PolymorphicConfig) H_NEWINVOKESPECIAL(org.objectweb.asm.Opcodes.H_NEWINVOKESPECIAL) BytecodeExpressions.constantNull(com.facebook.presto.bytecode.expression.BytecodeExpressions.constantNull) BytecodeExpressions.set(com.facebook.presto.bytecode.expression.BytecodeExpressions.set) Opcodes(org.objectweb.asm.Opcodes) SchemaClassesInfo.viewClassName(org.apache.ignite.internal.configuration.asm.SchemaClassesInfo.viewClassName) ConfigurationUtil.polymorphicInstanceId(org.apache.ignite.internal.configuration.util.ConfigurationUtil.polymorphicInstanceId) NamedListView(org.apache.ignite.configuration.NamedListView) Field(java.lang.reflect.Field) BytecodeExpressions.constantString(com.facebook.presto.bytecode.expression.BytecodeExpressions.constantString) Handle(org.objectweb.asm.Handle) Type.getMethodDescriptor(org.objectweb.asm.Type.getMethodDescriptor) BytecodeExpressions.isNull(com.facebook.presto.bytecode.expression.BytecodeExpressions.isNull) EnumSet.of(java.util.EnumSet.of) ArrayDeque(java.util.ArrayDeque) ConfigurationUtil.isInternalId(org.apache.ignite.internal.configuration.util.ConfigurationUtil.isInternalId) ParameterizedType(com.facebook.presto.bytecode.ParameterizedType) ArrayUtils.nullOrEmpty(org.apache.ignite.internal.util.ArrayUtils.nullOrEmpty) BytecodeExpressions.newArray(com.facebook.presto.bytecode.expression.BytecodeExpressions.newArray) LambdaMetafactory(java.lang.invoke.LambdaMetafactory) BiFunction(java.util.function.BiFunction) ConstructableTreeNode(org.apache.ignite.internal.configuration.tree.ConstructableTreeNode) BytecodeExpressions.invokeDynamic(com.facebook.presto.bytecode.expression.BytecodeExpressions.invokeDynamic) Type(org.objectweb.asm.Type) Collections.singleton(java.util.Collections.singleton) Collectors.toMap(java.util.stream.Collectors.toMap) ParameterizedType.type(com.facebook.presto.bytecode.ParameterizedType.type) ParameterizedType.typeFromJavaClassName(com.facebook.presto.bytecode.ParameterizedType.typeFromJavaClassName) ConfigurationUtil.isInjectedName(org.apache.ignite.internal.configuration.util.ConfigurationUtil.isInjectedName) ConfigurationNode(org.apache.ignite.internal.configuration.ConfigurationNode) Method(java.lang.reflect.Method) ConfigurationProperty(org.apache.ignite.configuration.ConfigurationProperty) Name(org.apache.ignite.configuration.annotation.Name) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) NamedListConfiguration(org.apache.ignite.internal.configuration.NamedListConfiguration) TypeUtils(org.apache.ignite.internal.configuration.TypeUtils) UUID(java.util.UUID) RootKey(org.apache.ignite.configuration.RootKey) SchemaClassesInfo.nodeClassName(org.apache.ignite.internal.configuration.asm.SchemaClassesInfo.nodeClassName) SchemaClassesInfo.configurationClassName(org.apache.ignite.internal.configuration.asm.SchemaClassesInfo.configurationClassName) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) ClassDefinition(com.facebook.presto.bytecode.ClassDefinition) List(java.util.List) Type.getMethodType(org.objectweb.asm.Type.getMethodType) Function.identity(java.util.function.Function.identity) Queue(java.util.Queue) NotNull(org.jetbrains.annotations.NotNull) Parameter.arg(com.facebook.presto.bytecode.Parameter.arg) ConfigurationUtil.schemaFields(org.apache.ignite.internal.configuration.util.ConfigurationUtil.schemaFields) DynamicProperty(org.apache.ignite.internal.configuration.DynamicProperty) BytecodeExpressions.constantInt(com.facebook.presto.bytecode.expression.BytecodeExpressions.constantInt) ConfigurationVisitor(org.apache.ignite.internal.configuration.tree.ConfigurationVisitor) PRIVATE(com.facebook.presto.bytecode.Access.PRIVATE) ConfigurationUtil.containsNameAnnotation(org.apache.ignite.internal.configuration.util.ConfigurationUtil.containsNameAnnotation) HashMap(java.util.HashMap) ConfigurationUtil.isNamedConfigValue(org.apache.ignite.internal.configuration.util.ConfigurationUtil.isNamedConfigValue) BytecodeExpressions.not(com.facebook.presto.bytecode.expression.BytecodeExpressions.not) Function(java.util.function.Function) HashSet(java.util.HashSet) Collectors.toCollection(java.util.stream.Collectors.toCollection) BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock) NoSuchElementException(java.util.NoSuchElementException) BytecodeExpressions.constantClass(com.facebook.presto.bytecode.expression.BytecodeExpressions.constantClass) ConfigurationUtil.extensionsFields(org.apache.ignite.internal.configuration.util.ConfigurationUtil.extensionsFields) MethodType.methodType(java.lang.invoke.MethodType.methodType) PUBLIC(com.facebook.presto.bytecode.Access.PUBLIC) BytecodeExpressions.inlineIf(com.facebook.presto.bytecode.expression.BytecodeExpressions.inlineIf) ConfigurationRoot(org.apache.ignite.configuration.annotation.ConfigurationRoot) CollectionUtils.union(org.apache.ignite.internal.util.CollectionUtils.union) SchemaClassesInfo.changeClassName(org.apache.ignite.internal.configuration.asm.SchemaClassesInfo.changeClassName) ClassGenerator(com.facebook.presto.bytecode.ClassGenerator) BytecodeExpressions.newInstance(com.facebook.presto.bytecode.expression.BytecodeExpressions.newInstance) ConfigurationUtil.isPolymorphicConfig(org.apache.ignite.internal.configuration.util.ConfigurationUtil.isPolymorphicConfig) ConfigurationValue(org.apache.ignite.configuration.ConfigurationValue) Consumer(java.util.function.Consumer) Collectors.toList(java.util.stream.Collectors.toList) BytecodeNode(com.facebook.presto.bytecode.BytecodeNode) STATIC(com.facebook.presto.bytecode.Access.STATIC) MethodType(java.lang.invoke.MethodType) InjectedName(org.apache.ignite.configuration.annotation.InjectedName) ConfigurationUtil.isValue(org.apache.ignite.internal.configuration.util.ConfigurationUtil.isValue) PolymorphicConfigInstance(org.apache.ignite.configuration.annotation.PolymorphicConfigInstance) FieldDefinition(com.facebook.presto.bytecode.FieldDefinition) BRIDGE(com.facebook.presto.bytecode.Access.BRIDGE) ConfigurationUtil.hasDefault(org.apache.ignite.internal.configuration.util.ConfigurationUtil.hasDefault) Collections(java.util.Collections) ConfigurationTreeWrapper(org.apache.ignite.internal.configuration.ConfigurationTreeWrapper) ConfigurationWrongPolymorphicTypeIdException(org.apache.ignite.configuration.ConfigurationWrongPolymorphicTypeIdException) InternalConfiguration(org.apache.ignite.configuration.annotation.InternalConfiguration) Field(java.lang.reflect.Field) IfStatement(com.facebook.presto.bytecode.control.IfStatement) Variable(com.facebook.presto.bytecode.Variable) MethodDefinition(com.facebook.presto.bytecode.MethodDefinition) FieldDefinition(com.facebook.presto.bytecode.FieldDefinition) ConfigurationWrongPolymorphicTypeIdException(org.apache.ignite.configuration.ConfigurationWrongPolymorphicTypeIdException) BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock) BytecodeExpressions.constantString(com.facebook.presto.bytecode.expression.BytecodeExpressions.constantString)

Example 5 with NamedListNode

use of org.apache.ignite.internal.configuration.tree.NamedListNode in project ignite-3 by apache.

the class ConfigurationAsmGenerator method addNodeField.

/**
 * Declares field that corresponds to configuration value. Depending on the schema, 5 options possible:
 * <ul>
 *     <li>
 *         {@code @Value public type fieldName}<br/>becomes<br/>
 *         {@code public BoxedType fieldName}
 *     </li>
 *     <li>
 *         {@code @ConfigValue public MyConfigurationSchema fieldName}<br/>becomes<br/>
 *         {@code public MyNode fieldName}
 *     </li>
 *     <li>
 *         {@code @NamedConfigValue public type fieldName}<br/>becomes<br/>
 *         {@code public NamedListNode fieldName}
 *     </li>
 *     <li>
 *         {@code @PolymorphicId public String fieldName}<br/>becomes<br/>
 *         {@code public String fieldName}
 *     </li>
 *     <li>
 *         {@code @InjectedName public String fieldName}<br/>becomes<br/>
 *         {@code public String fieldName}
 *     </li>
 * </ul>
 *
 * @param classDef    Node class definition.
 * @param schemaField Configuration Schema class field.
 * @param fieldName   Field name.
 * @return Declared field definition.
 * @throws IllegalArgumentException If an unsupported {@code schemaField} was passed.
 */
private FieldDefinition addNodeField(ClassDefinition classDef, Field schemaField, String fieldName) {
    Class<?> schemaFieldClass = schemaField.getType();
    ParameterizedType nodeFieldType;
    if (isValue(schemaField) || isPolymorphicId(schemaField) || isInjectedName(schemaField)) {
        nodeFieldType = type(box(schemaFieldClass));
    } else if (isConfigValue(schemaField)) {
        nodeFieldType = typeFromJavaClassName(schemasInfo.get(schemaFieldClass).nodeClassName);
    } else if (isNamedConfigValue(schemaField)) {
        nodeFieldType = type(NamedListNode.class);
    } else {
        throw new IllegalArgumentException("Unsupported field: " + schemaField);
    }
    return classDef.declareField(of(PUBLIC), fieldName, nodeFieldType);
}
Also used : ParameterizedType(com.facebook.presto.bytecode.ParameterizedType) NamedListNode(org.apache.ignite.internal.configuration.tree.NamedListNode)

Aggregations

NamedListNode (org.apache.ignite.internal.configuration.tree.NamedListNode)6 Serializable (java.io.Serializable)4 InnerNode (org.apache.ignite.internal.configuration.tree.InnerNode)4 List (java.util.List)3 ConfigurationVisitor (org.apache.ignite.internal.configuration.tree.ConfigurationVisitor)3 ParameterizedType (com.facebook.presto.bytecode.ParameterizedType)2 ArrayList (java.util.ArrayList)2 NoSuchElementException (java.util.NoSuchElementException)2 BRIDGE (com.facebook.presto.bytecode.Access.BRIDGE)1 FINAL (com.facebook.presto.bytecode.Access.FINAL)1 PRIVATE (com.facebook.presto.bytecode.Access.PRIVATE)1 PUBLIC (com.facebook.presto.bytecode.Access.PUBLIC)1 STATIC (com.facebook.presto.bytecode.Access.STATIC)1 SYNTHETIC (com.facebook.presto.bytecode.Access.SYNTHETIC)1 BytecodeBlock (com.facebook.presto.bytecode.BytecodeBlock)1 BytecodeNode (com.facebook.presto.bytecode.BytecodeNode)1 ClassDefinition (com.facebook.presto.bytecode.ClassDefinition)1 ClassGenerator (com.facebook.presto.bytecode.ClassGenerator)1 FieldDefinition (com.facebook.presto.bytecode.FieldDefinition)1 MethodDefinition (com.facebook.presto.bytecode.MethodDefinition)1