public Map<String, Object> resolve() { if (resolved == null) { resolved = new HashMap<String, Object>(); for (String name : options.keySet()) { Object value = options.get(name); if (value instanceof AstValue) { value = ((AstValue<?>)value).getValue(); } resolved.put(name, value); } } return resolved; } }
@Override public Configuration visit(AstWriteValueNode node, State state) { List<MessageEncoder> messageEncoders = new ArrayList<>(); for (AstValue<?> val : node.getValues()) { messageEncoders.add(val.accept(new GenerateWriteEncoderVisitor(), null)); } WriteHandler handler = new WriteHandler(messageEncoders, state.writeMasker); handler.setRegionInfo(node.getRegionInfo()); String handlerName = String.format("write#%d", state.pipelineAsMap.size() + 1); state.pipelineAsMap.put(handlerName, handler); return state.configuration; }
protected int hashTo() { int hashCode = getClass().hashCode(); if (propertyName != null) { hashCode <<= 4; hashCode ^= propertyName.hashCode(); } if (propertyValue != null) { hashCode <<= 4; hashCode ^= propertyValue.hashCode(); } return hashCode; }
@Override public AstWriteValueNode visitWriteValue(WriteValueContext ctx) { AstValueVisitor<?> visitor = new AstValueVisitor<>(factory, environment, Object.class); AstValue<?> value = visitor.visit(ctx); node.addValue(value); childInfos().add(value.getRegionInfo()); return node; } }
@Override public AstValue<T> visitLiteralInteger(LiteralIntegerContext ctx) { AstLiteralIntegerValueVisitor visitor = new AstLiteralIntegerValueVisitor(factory, environment); AstLiteralIntegerValue literal = visitor.visit(ctx); AstValue<?> value = literal; if (expectedType == long.class || expectedType == Long.class) { value = new AstLiteralLongValue(literal.getValue().longValue()); } if (value != null) { childInfos().add(value.getRegionInfo()); } return (AstValue<T>) value; }
public Object resolve() { Object value = propertyValue.getValue(); ELResolver resolver = environment.getELResolver(); // ELResolver.setValue is not thread-safe synchronized (environment) { resolver.setValue(environment, null, propertyName, value); } return value; }
@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; } }
protected int hashTo() { int hashCode = getClass().hashCode(); if (optionName != null) { hashCode <<= 4; hashCode ^= optionName.hashCode(); } if (optionValue != null) { hashCode <<= 4; hashCode ^= optionValue.hashCode(); } return hashCode; }
@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 AstPropertyNode visitPropertyNode(PropertyNodeContext ctx) { AstValueVisitor<?> visitor = new AstValueVisitor<>(factory, environment, Object.class); AstValue<?> value = visitor.visit(ctx.value); childInfos().add(value.getRegionInfo()); node = new AstPropertyNode(); node.setRegionInfo(asSequentialRegion(childInfos, ctx)); node.setPropertyName(ctx.name.getText()); node.setPropertyValue(value); node.setEnvironment(environment); return node; }
@Override protected int hashTo() { int hashCode = getClass().hashCode(); if (location != null) { hashCode <<= 4; hashCode ^= location.hashCode(); } if (options != null) { hashCode <<= 4; hashCode ^= options.hashCode(); } if (awaitName != null) { hashCode <<= 4; hashCode ^= awaitName.hashCode(); } return hashCode; }
@Override public Configuration visit(AstReadOptionNode node, State state) { TypeInfo<?> optionType = node.getOptionType(); if (optionType == DefaultTypeSystem.OPTION_MASK) { AstValue<?> maskValue = node.getOptionValue(); state.readUnmasker = maskValue.accept(new GenerateMaskOptionValueVisitor(), state); } else { ChannelHandler handler = behaviorSystem.newReadOptionHandler(node); String optionName = node.getOptionName(); if (handler != null) { String handlerName = String.format("readOption#%d (%s)", state.pipelineAsMap.size() + 1, optionName); state.pipelineAsMap.put(handlerName, handler); } else { throw new IllegalArgumentException("Unrecognized read option : " + optionName); } } return state.configuration; }
@Override public AstWriteOptionNode visitWriteOptionNode(WriteOptionNodeContext ctx) { String optionQName = ctx.optionName().getText(); TypeInfo<?> optionType = TYPE_SYSTEM.writeOption(optionQName); Class<?> expectedType = optionType.getType(); AstValueVisitor<?> visitor = new AstValueVisitor<>(factory, environment, expectedType); AstValue<?> optionValue = visitor.visit(ctx); childInfos().add(optionValue.getRegionInfo()); node = new AstWriteOptionNode(); node.setOptionType(optionType); node.setOptionName(optionQName); node.setOptionValue(optionValue); node.setRegionInfo(asSequentialRegion(childInfos, ctx)); return node; } }
@Override protected int hashTo() { int hashCode = super.hashTo(); if (location != null) { hashCode <<= 4; hashCode ^= location.hashCode(); } if (options != null) { hashCode <<= 4; hashCode ^= options.hashCode(); } if (acceptName != null) { hashCode <<= 4; hashCode ^= acceptName.hashCode(); } if (notifyName != null) { hashCode <<= 4; hashCode ^= notifyName.hashCode(); } if (acceptables != null) { hashCode <<= 4; hashCode ^= acceptables.hashCode(); } return hashCode; }
@Override public Configuration visit(AstWriteOptionNode node, State state) { TypeInfo<?> optionType = node.getOptionType(); if (optionType == DefaultTypeSystem.OPTION_MASK) { AstValue<?> maskValue = node.getOptionValue(); state.writeMasker = maskValue.accept(new GenerateMaskOptionValueVisitor(), state); } else { ChannelHandler handler = behaviorSystem.newWriteOptionHandler(node); String optionName = node.getOptionName(); if (handler != null) { String handlerName = String.format("writeOption#%d (%s)", state.pipelineAsMap.size() + 1, optionName); state.pipelineAsMap.put(handlerName, handler); } else { throw new IllegalArgumentException("Unrecognized write option : " + optionName); } } return state.configuration; }
@Override public AstReadOptionNode visitReadOptionNode(ReadOptionNodeContext ctx) { String optionQName = ctx.optionName().getText(); TypeInfo<?> optionType = TYPE_SYSTEM.readOption(optionQName); Class<?> expectedType = optionType.getType(); AstValueVisitor<?> visitor = new AstValueVisitor<>(factory, environment, expectedType); AstValue<?> optionValue = visitor.visit(ctx); childInfos().add(optionValue.getRegionInfo()); node = new AstReadOptionNode(); node.setOptionType(optionType); node.setOptionName(optionQName); node.setOptionValue(optionValue); node.setRegionInfo(asSequentialRegion(childInfos, ctx)); return node; } }