public StreamNested(R builder) { super(new AstReadConfigNode(), builder); }
public StreamNested<R> addMatcherFixedLengthBytes(int valueLength, String valueCaptureName, ExpressionContext environment) { node.addMatcher(new AstFixedLengthBytesMatcher(valueLength, valueCaptureName, environment)); return this; }
@Override protected boolean equalTo(AstRegion that) { return that instanceof AstReadConfigNode && equalTo((AstReadConfigNode) that); }
private static ReadConfigHandler newReadHttpHeaderHandler( AstReadConfigNode node, Function<AstValueMatcher, MessageDecoder> decoderFactory) { AstExactTextMatcher name = (AstExactTextMatcher) node.getMatcher("name"); requireNonNull(name); if (node.isMissing()) { HttpHeaderMissingDecoder decoder = new HttpHeaderMissingDecoder(name.getValue()); decoder.setRegionInfo(node.getRegionInfo()); ReadConfigHandler handler = new ReadConfigHandler(decoder); handler.setRegionInfo(node.getRegionInfo()); return handler; } else { List<MessageDecoder> valueDecoders = new ArrayList<>(); for (AstValueMatcher matcher : node.getMatchers()) { valueDecoders.add(decoderFactory.apply(matcher)); } HttpHeaderDecoder decoder = new HttpHeaderDecoder(name.getValue(), valueDecoders); decoder.setRegionInfo(node.getRegionInfo()); ReadConfigHandler handler = new ReadConfigHandler(decoder); handler.setRegionInfo(node.getRegionInfo()); return handler; } }
private static ReadConfigHandler newReadHttpParameterHandler( AstReadConfigNode node, Function<AstValueMatcher, MessageDecoder> decoderFactory) { AstExactTextMatcher name = (AstExactTextMatcher) node.getMatcher("name"); requireNonNull(name); List<MessageDecoder> valueDecoders = new ArrayList<>(); for (AstValueMatcher matcher : node.getMatchers()) { valueDecoders.add(decoderFactory.apply(matcher)); } HttpParameterDecoder decoder = new HttpParameterDecoder(name.getValue(), valueDecoders); decoder.setRegionInfo(node.getRegionInfo()); ReadConfigHandler handler = new ReadConfigHandler(decoder); handler.setRegionInfo(node.getRegionInfo()); return handler; }
private static ReadConfigHandler newReadHttpStatusHandler( AstReadConfigNode node, Function<AstValueMatcher, MessageDecoder> decoderFactory) { AstValueMatcher code = node.getMatcher("code"); AstValueMatcher reason = node.getMatcher("reason"); MessageDecoder codeDecoder = decoderFactory.apply(code); MessageDecoder reasonDecoder = decoderFactory.apply(reason); HttpStatusDecoder decoder = new HttpStatusDecoder(codeDecoder, reasonDecoder); ReadConfigHandler handler = new ReadConfigHandler(decoder); handler.setRegionInfo(node.getRegionInfo()); return handler; }
@Override public AstReadConfigNode visitReadConfigNode(ReadConfigNodeContext ctx) { String configQName = ctx.QualifiedName().getText(); boolean missing = ctx.MissingKeyword() != null; node = new AstReadConfigNode(); node.setMissing(missing); StructuredTypeInfo configType = TYPE_SYSTEM.readConfig(configQName); namedFields = configType.getNamedFields().iterator(); anonymousFields = configType.getAnonymousFields(); node.setType(configType); super.visitReadConfigNode(ctx); node.setRegionInfo(asSequentialRegion(childInfos, ctx)); return node; }
@Override public AstReadConfigNode visitMatcher(MatcherContext ctx) { AstValueMatcherVisitor visitor = new AstValueMatcherVisitor(factory, environment); AstValueMatcher matcher = visitor.visit(ctx); if (matcher != null) { if (namedFields.hasNext()) { TypeInfo<?> field = namedFields.next(); node.setMatcher(field.getName(), matcher); } else if (anonymousFields > 0) { anonymousFields--; node.addMatcher(matcher); } else { throw new IllegalStateException(String.format("Unexpected %s syntax", node.getType())); } childInfos().add(matcher.getRegionInfo()); } return node; } }
public AstReadConfigNodeBuilder setMatcherFixedLengthBytes(String name, int valueLength, String valueCaptureName, ExpressionContext environment) { node.setMatcher(name, new AstFixedLengthBytesMatcher(valueLength, valueCaptureName, environment)); return this; }
@Override public AstReadConfigNode visitReadConfigNode(ReadConfigNodeContext ctx) { AstReadConfigNodeVisitor visitor = new AstReadConfigNodeVisitor(factory, environment); AstReadConfigNode readConfigNode = visitor.visitReadConfigNode(ctx); if (readConfigNode != null) { childInfos().add(readConfigNode.getRegionInfo()); } return readConfigNode; }
public ChannelHandler newReadConfigHandler( AstReadConfigNode node, Function<AstValueMatcher, MessageDecoder> decoderFactory) { StructuredTypeInfo type = node.getType(); ReadConfigFactory factory = readConfigs.getOrDefault(type, (n, f) -> null); return factory.newHandler(node, decoderFactory); }
public AstReadConfigNodeBuilder setMissing(boolean missing) { node.setMissing(missing); return this; }
private static ReadHttpTrailersHandler newReadHttpTrailerHandler( AstReadConfigNode node, Function<AstValueMatcher, MessageDecoder> decoderFactory) { AstExactTextMatcher name = (AstExactTextMatcher) node.getMatcher("name"); List<MessageDecoder> valueDecoders = new ArrayList<>(); for (AstValueMatcher matcher : node.getMatchers()) { valueDecoders.add(decoderFactory.apply(matcher)); } HttpTrailerDecoder decoder = new HttpTrailerDecoder(name.getValue(), valueDecoders); decoder.setRegionInfo(node.getRegionInfo()); // Ideally we could use a ReadConfigHandler as follows, but the trailers come in-sync with // with the channel close, which completes the composite future of all handlers and checks // the ReadConfigHandler to see if it completed. // HttpTrailerDecoder decoder = new HttpTrailerDecoder(name.getValue(), valueDecoders); // decoder.setRegionInfo(node.getRegionInfo()); // ReadConfigHandler handler = new ReadConfigHandler(decoder); ReadHttpTrailersHandler handler = new ReadHttpTrailersHandler(decoder); handler.setRegionInfo(node.getRegionInfo()); return handler; }
private static ReadConfigHandler newReadHttpMethodHandler( AstReadConfigNode node, Function<AstValueMatcher, MessageDecoder> decoderFactory) { AstValueMatcher methodName = node.getMatcher(); requireNonNull(methodName); MessageDecoder methodValueDecoder = decoderFactory.apply(methodName); HttpMethodDecoder decoder = new HttpMethodDecoder(methodValueDecoder); ReadConfigHandler handler = new ReadConfigHandler(decoder); handler.setRegionInfo(node.getRegionInfo()); return handler; }
public AstReadConfigNodeBuilder setMatcherVariableLengthBytes(String name, ValueExpression valueLength, String valueCaptureName, ExpressionContext environment) { node.setMatcher(name, new AstVariableLengthBytesMatcher(valueLength, valueCaptureName, environment)); return this; }
@Override public AstScriptNode visit(AstReadConfigNode node, State state) { switch (state.writeState) { case CONFIG_ONLY: AstWriteFlushNode flush = new AstWriteFlushNode(); flush.setRegionInfo(node.getRegionInfo()); visit(flush, state); break; default: break; } state.streamables.add(node); switch (state.readState) { case NONE: case CONFIG_ONLY: case CONFIG_OR_VALUE: break; default: state.readState = ReadWriteState.CONFIG_ONLY; break; } return null; }
@Override public Configuration visit(AstReadConfigNode node, State state) { Function<AstValueMatcher, MessageDecoder> decoderFactory = m -> m.accept(new GenerateReadDecoderVisitor(), state.configuration); ChannelHandler handler = behaviorSystem.newReadConfigHandler(node, decoderFactory); if (handler != null) { Map<String, ChannelHandler> pipelineAsMap = state.pipelineAsMap; String handlerName = String.format("readConfig#%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 StreamNested<R> setMissing(boolean missing) { node.setMissing(missing); return this; }
private static ReadConfigHandler newReadHttpVersionHandler( AstReadConfigNode node, Function<AstValueMatcher, MessageDecoder> decoderFactory) { AstValueMatcher version = node.getMatcher(); MessageDecoder versionDecoder = decoderFactory.apply(version); HttpVersionDecoder decoder = new HttpVersionDecoder(versionDecoder); ReadConfigHandler handler = new ReadConfigHandler(decoder); handler.setRegionInfo(node.getRegionInfo()); return handler; }
public StreamNested<R> setMatcherVariableLengthBytes(String name, ValueExpression valueLength, ExpressionContext environment) { node.setMatcher(name, new AstVariableLengthBytesMatcher(valueLength, environment)); return this; }