public ChannelHandler newWriteConfigHandler( AstWriteConfigNode node, Function<AstValue<?>, MessageEncoder> encoderFactory) { StructuredTypeInfo type = node.getType(); WriteConfigFactory factory = writeConfigs.getOrDefault(type, (n, f) -> null); return factory.newHandler(node, encoderFactory); }
@Override public Configuration visit(AstWriteConfigNode node, State state) { Function<AstValue<?>, MessageEncoder> encoderFactory = v -> v.accept(new GenerateWriteEncoderVisitor(), null); ChannelHandler handler = behaviorSystem.newWriteConfigHandler(node, encoderFactory); if (handler != null) { Map<String, ChannelHandler> pipelineAsMap = state.pipelineAsMap; String handlerName = String.format("writeConfig#%d (%s)", pipelineAsMap.size() + 1, node.getType().getName()); pipelineAsMap.put(handlerName, handler); return state.configuration; } else { throw new IllegalStateException("Unrecognized configuration type: " + node.getType()); } }
@Override public AstWriteConfigNode visitWriteValue(WriteValueContext ctx) { AstValueVisitor<?> visitor = new AstValueVisitor<>(factory, environment, Object.class); AstValue<?> value = visitor.visit(ctx); if (value != null) { if (namedFields.hasNext()) { TypeInfo<?> field = namedFields.next(); node.setValue(field.getName(), value); } else if (anonymousFields > 0) { anonymousFields--; node.addValue(value); } else { throw new IllegalStateException(String.format("Unexpected %s syntax", node.getType())); } childInfos().add(value.getRegionInfo()); } return node; } }