Search in sources :

Example 6 with InnerNode

use of org.apache.ignite.internal.configuration.tree.InnerNode 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 7 with InnerNode

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

the class ConfigurationAsmGenerator method compileRootSchema.

/**
 * Generates, defines, loads and initializes all dynamic classes required for the given configuration schema.
 *
 * @param rootSchemaClass             Class of the root configuration schema.
 * @param internalSchemaExtensions    Internal extensions ({@link InternalConfiguration}) of configuration schemas ({@link
 *                                    ConfigurationRoot} and {@link Config}). Mapping: original schema -> extensions.
 * @param polymorphicSchemaExtensions Polymorphic extensions ({@link PolymorphicConfigInstance}) of configuration schemas ({@link
 *                                    PolymorphicConfig}). Mapping: original schema -> extensions.
 */
public synchronized void compileRootSchema(Class<?> rootSchemaClass, Map<Class<?>, Set<Class<?>>> internalSchemaExtensions, Map<Class<?>, Set<Class<?>>> polymorphicSchemaExtensions) {
    if (schemasInfo.containsKey(rootSchemaClass)) {
        // Already compiled.
        return;
    }
    Queue<Class<?>> compileQueue = new ArrayDeque<>();
    compileQueue.add(rootSchemaClass);
    schemasInfo.put(rootSchemaClass, new SchemaClassesInfo(rootSchemaClass));
    Set<Class<?>> schemas = new HashSet<>();
    List<ClassDefinition> classDefs = new ArrayList<>();
    while (!compileQueue.isEmpty()) {
        Class<?> schemaClass = compileQueue.poll();
        assert schemaClass.isAnnotationPresent(ConfigurationRoot.class) || schemaClass.isAnnotationPresent(Config.class) || isPolymorphicConfig(schemaClass) : schemaClass + " is not properly annotated";
        assert schemasInfo.containsKey(schemaClass) : schemaClass;
        Set<Class<?>> internalExtensions = internalSchemaExtensions.getOrDefault(schemaClass, Set.of());
        Set<Class<?>> polymorphicExtensions = polymorphicSchemaExtensions.getOrDefault(schemaClass, Set.of());
        assert internalExtensions.isEmpty() || polymorphicExtensions.isEmpty() : "Internal and polymorphic extensions are not allowed at the same time: " + schemaClass;
        if (isPolymorphicConfig(schemaClass) && polymorphicExtensions.isEmpty()) {
            throw new IllegalArgumentException(schemaClass + " is polymorphic but polymorphic extensions are absent");
        }
        List<Field> schemaFields = schemaFields(schemaClass);
        Collection<Field> internalExtensionsFields = extensionsFields(internalExtensions, true);
        Collection<Field> polymorphicExtensionsFields = extensionsFields(polymorphicExtensions, false);
        Field internalIdField = internalIdField(schemaClass, internalExtensions);
        for (Field schemaField : concat(schemaFields, internalExtensionsFields, polymorphicExtensionsFields)) {
            if (isConfigValue(schemaField) || isNamedConfigValue(schemaField)) {
                Class<?> subSchemaClass = schemaField.getType();
                if (!schemasInfo.containsKey(subSchemaClass)) {
                    compileQueue.offer(subSchemaClass);
                    schemasInfo.put(subSchemaClass, new SchemaClassesInfo(subSchemaClass));
                }
            }
        }
        for (Class<?> polymorphicExtension : polymorphicExtensions) {
            schemasInfo.put(polymorphicExtension, new SchemaClassesInfo(polymorphicExtension));
        }
        schemas.add(schemaClass);
        ClassDefinition innerNodeClassDef = createNodeClass(schemaClass, internalExtensions, polymorphicExtensions, schemaFields, internalExtensionsFields, polymorphicExtensionsFields, internalIdField);
        classDefs.add(innerNodeClassDef);
        ClassDefinition cfgImplClassDef = createCfgImplClass(schemaClass, internalExtensions, polymorphicExtensions, schemaFields, internalExtensionsFields, polymorphicExtensionsFields, internalIdField);
        classDefs.add(cfgImplClassDef);
        for (Class<?> polymorphicExtension : polymorphicExtensions) {
            // Only the fields of a specific instance of a polymorphic configuration.
            Collection<Field> polymorphicFields = polymorphicExtensionsFields.stream().filter(f -> f.getDeclaringClass() == polymorphicExtension).collect(toList());
            classDefs.add(createPolymorphicExtensionNodeClass(schemaClass, polymorphicExtension, innerNodeClassDef, schemaFields, polymorphicFields, internalIdField));
            classDefs.add(createPolymorphicExtensionCfgImplClass(schemaClass, polymorphicExtension, cfgImplClassDef, schemaFields, polymorphicFields, internalIdField));
        }
        ClassDefinition directProxyClassDef = new DirectProxyAsmGenerator(this, schemaClass, internalExtensions, schemaFields, internalExtensionsFields, internalIdField).generate();
        classDefs.add(directProxyClassDef);
    }
    Map<String, Class<?>> definedClasses = generator.defineClasses(classDefs);
    for (Class<?> schemaClass : schemas) {
        SchemaClassesInfo info = schemasInfo.get(schemaClass);
        info.nodeClass = (Class<? extends InnerNode>) definedClasses.get(info.nodeClassName);
        info.cfgImplClass = (Class<? extends DynamicConfiguration<?, ?>>) definedClasses.get(info.cfgImplClassName);
    }
}
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) ArrayList(java.util.ArrayList) BytecodeExpressions.constantString(com.facebook.presto.bytecode.expression.BytecodeExpressions.constantString) ClassDefinition(com.facebook.presto.bytecode.ClassDefinition) ArrayDeque(java.util.ArrayDeque) Field(java.lang.reflect.Field) BytecodeExpressions.constantClass(com.facebook.presto.bytecode.expression.BytecodeExpressions.constantClass) HashSet(java.util.HashSet)

Example 8 with InnerNode

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

the class ConfigurationAsmGenerator method addCfgAddMembersMethod.

/**
 * Adds a {@code DynamicConfiguration#addMembers} override for the polymorphic configuration case.
 *
 * @param classDef                  Definition of a polymorphic configuration class (parent).
 * @param schemaClass               Polymorphic configuration schema (parent).
 * @param polymorphicExtensions     Polymorphic configuration instance schemas (children).
 * @param fieldDefs                 Field definitions for all fields of {@code classDef}.
 * @param polymorphicFields         Fields of polymorphic extensions.
 * @param polymorphicTypeIdFieldDef Identification field for the polymorphic configuration instance.
 */
private void addCfgAddMembersMethod(ClassDefinition classDef, Class<?> schemaClass, Set<Class<?>> polymorphicExtensions, Map<String, FieldDefinition> fieldDefs, Collection<Field> polymorphicFields, FieldDefinition polymorphicTypeIdFieldDef) {
    MethodDefinition removeMembersMtd = classDef.declareMethod(of(PUBLIC), "addMembers", type(void.class), arg("newValue", type(Object.class)), arg("members", type(Map.class)));
    // InnerNode newValue;
    Variable newValueVar = removeMembersMtd.getScope().getVariable("newValue");
    // Map members;
    Variable membersVar = removeMembersMtd.getScope().getVariable("members");
    // String tmpStr;
    Variable tmpStrVar = removeMembersMtd.getScope().createTempVariable(String.class);
    StringSwitchBuilder switchBuilder = new StringSwitchBuilder(removeMembersMtd.getScope()).expression(tmpStrVar).defaultCase(throwException(ConfigurationWrongPolymorphicTypeIdException.class, tmpStrVar));
    for (Class<?> polymorphicExtension : polymorphicExtensions) {
        Collection<Field> addFields = polymorphicFields.stream().filter(f -> polymorphicExtension.equals(f.getDeclaringClass())).collect(toList());
        BytecodeBlock blockCode = new BytecodeBlock();
        for (Field addField : addFields) {
            // this.addMember(members, this.field);
            blockCode.append(removeMembersMtd.getThis()).append(membersVar).append(getThisFieldCode(removeMembersMtd, fieldDefs.get(fieldName(addField)))).invokeVirtual(ADD_MEMBER_MTD);
        }
        switchBuilder.addCase(polymorphicInstanceId(polymorphicExtension), blockCode);
    }
    // ConfigNode
    ParameterizedType nodeType = typeFromJavaClassName(schemasInfo.get(schemaClass).nodeClassName);
    // tmpStr = ((ConfigNode) newValue).typeId;
    // switch(tmpStr) ...
    removeMembersMtd.getBody().append(tmpStrVar.set(newValueVar.cast(nodeType).getField(polymorphicTypeIdFieldDef.getName(), String.class))).append(switchBuilder.build()).ret();
}
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) ParameterizedType(com.facebook.presto.bytecode.ParameterizedType) Field(java.lang.reflect.Field) Variable(com.facebook.presto.bytecode.Variable) MethodDefinition(com.facebook.presto.bytecode.MethodDefinition) ConfigurationWrongPolymorphicTypeIdException(org.apache.ignite.configuration.ConfigurationWrongPolymorphicTypeIdException) BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock)

Example 9 with InnerNode

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

the class ConfigurationAsmGenerator method addCfgRemoveMembersMethod.

/**
 * Adds a {@code DynamicConfiguration#removeMembers} override for the polymorphic configuration case.
 *
 * @param classDef                  Definition of a polymorphic configuration class (parent).
 * @param schemaClass               Polymorphic configuration schema (parent).
 * @param polymorphicExtensions     Polymorphic configuration instance schemas (children).
 * @param fieldDefs                 Field definitions for all fields of {@code classDef}.
 * @param polymorphicFields         Fields of polymorphic extensions.
 * @param polymorphicTypeIdFieldDef Identification field for the polymorphic configuration instance.
 */
private void addCfgRemoveMembersMethod(ClassDefinition classDef, Class<?> schemaClass, Set<Class<?>> polymorphicExtensions, Map<String, FieldDefinition> fieldDefs, Collection<Field> polymorphicFields, FieldDefinition polymorphicTypeIdFieldDef) {
    MethodDefinition removeMembersMtd = classDef.declareMethod(of(PUBLIC), "removeMembers", type(void.class), arg("oldValue", type(Object.class)), arg("members", type(Map.class)));
    // InnerNode oldValue;
    Variable oldValueVar = removeMembersMtd.getScope().getVariable("oldValue");
    // Map members;
    Variable membersVar = removeMembersMtd.getScope().getVariable("members");
    // String tmpStr;
    Variable tmpStrVar = removeMembersMtd.getScope().createTempVariable(String.class);
    StringSwitchBuilder switchBuilder = new StringSwitchBuilder(removeMembersMtd.getScope()).expression(tmpStrVar).defaultCase(throwException(ConfigurationWrongPolymorphicTypeIdException.class, tmpStrVar));
    for (Class<?> polymorphicExtension : polymorphicExtensions) {
        Collection<Field> removeFields = polymorphicFields.stream().filter(f -> !polymorphicExtension.equals(f.getDeclaringClass())).collect(toList());
        BytecodeBlock blockCode = new BytecodeBlock();
        for (Field removeField : removeFields) {
            // this.removeMember(members, this.field);
            blockCode.append(removeMembersMtd.getThis()).append(membersVar).append(getThisFieldCode(removeMembersMtd, fieldDefs.get(fieldName(removeField)))).invokeVirtual(REMOVE_MEMBER_MTD);
        }
        switchBuilder.addCase(polymorphicInstanceId(polymorphicExtension), blockCode);
    }
    // ConfigNode
    ParameterizedType nodeType = typeFromJavaClassName(schemasInfo.get(schemaClass).nodeClassName);
    // tmpStr = ((ConfigNode) oldValue).typeId;
    // switch(tmpStr) ...
    removeMembersMtd.getBody().append(tmpStrVar.set(oldValueVar.cast(nodeType).getField(polymorphicTypeIdFieldDef.getName(), String.class))).append(switchBuilder.build()).ret();
}
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) ParameterizedType(com.facebook.presto.bytecode.ParameterizedType) Field(java.lang.reflect.Field) Variable(com.facebook.presto.bytecode.Variable) MethodDefinition(com.facebook.presto.bytecode.MethodDefinition) ConfigurationWrongPolymorphicTypeIdException(org.apache.ignite.configuration.ConfigurationWrongPolymorphicTypeIdException) BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock)

Example 10 with InnerNode

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

the class ConfigurationChanger method start.

/**
 * Start component.
 */
// ConfigurationChangeException, really?
public void start() throws ConfigurationChangeException {
    Data data;
    try {
        data = storage.readAll();
    } catch (StorageException e) {
        throw new ConfigurationChangeException("Failed to initialize configuration: " + e.getMessage(), e);
    }
    SuperRoot superRoot = new SuperRoot(rootCreator());
    Map<String, ?> dataValuesPrefixMap = toPrefixMap(data.values());
    for (RootKey<?, ?> rootKey : rootKeys.values()) {
        Map<String, ?> rootPrefixMap = (Map<String, ?>) dataValuesPrefixMap.get(rootKey.key());
        InnerNode rootNode = createRootNode(rootKey);
        if (rootPrefixMap != null) {
            fillFromPrefixMap(rootNode, rootPrefixMap);
        }
        superRoot.addRoot(rootKey, rootNode);
    }
    // Workaround for distributed configuration.
    addDefaults(superRoot);
    storageRoots = new StorageRoots(superRoot, data.changeId());
    storage.registerConfigurationListener(this::updateFromListener);
}
Also used : ConfigurationChangeException(org.apache.ignite.configuration.ConfigurationChangeException) Data(org.apache.ignite.internal.configuration.storage.Data) StorageException(org.apache.ignite.internal.configuration.storage.StorageException) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConfigurationUtil.fillFromPrefixMap(org.apache.ignite.internal.configuration.util.ConfigurationUtil.fillFromPrefixMap) ConfigurationFlattener.createFlattenedUpdatesMap(org.apache.ignite.internal.configuration.util.ConfigurationFlattener.createFlattenedUpdatesMap) HashMap(java.util.HashMap) ConfigurationUtil.toPrefixMap(org.apache.ignite.internal.configuration.util.ConfigurationUtil.toPrefixMap) InnerNode(org.apache.ignite.internal.configuration.tree.InnerNode)

Aggregations

InnerNode (org.apache.ignite.internal.configuration.tree.InnerNode)20 HashMap (java.util.HashMap)13 Serializable (java.io.Serializable)12 List (java.util.List)12 Map (java.util.Map)12 NoSuchElementException (java.util.NoSuchElementException)11 Set (java.util.Set)11 NamedListNode (org.apache.ignite.internal.configuration.tree.NamedListNode)11 Collectors.toList (java.util.stream.Collectors.toList)10 RootKey (org.apache.ignite.configuration.RootKey)10 RootInnerNode (org.apache.ignite.internal.configuration.RootInnerNode)10 Test (org.junit.jupiter.api.Test)10 Arrays (java.util.Arrays)9 UUID (java.util.UUID)9 Consumer (java.util.function.Consumer)9 Config (org.apache.ignite.configuration.annotation.Config)9 ConfigurationRoot (org.apache.ignite.configuration.annotation.ConfigurationRoot)9 InternalConfiguration (org.apache.ignite.configuration.annotation.InternalConfiguration)9 NamedConfigValue (org.apache.ignite.configuration.annotation.NamedConfigValue)9 PolymorphicConfig (org.apache.ignite.configuration.annotation.PolymorphicConfig)9