List of usage examples for org.apache.solr.client.solrj.io.stream.expr StreamFactory getFunctionName
public String getFunctionName(Class<? extends Expressible> clazz) throws IOException
From source file:com.dennisgove.streaming.expressions.kafka.KafkaTopicConsumerStream.java
License:Apache License
/** * Accepts a valid {@link StreamExpression} adhering to the form above and constructs * a new instance of the KafkaTopicConsumerStream. * * @param expression A valid kafkaConsume {@link StreamExpression} * @param factory A valid {@link StreamFactory} * @throws IOException If unable to parse or deal with the incoming expression *//* ww w . j ava 2 s . c o m*/ public KafkaTopicConsumerStream(StreamExpression expression, StreamFactory factory) throws IOException { String bootstrapServers = getStringParameter("bootstrapServers", expression, factory); String groupId = getStringParameter("groupId", expression, factory); String topic = getStringParameter("topic", expression, factory); // List<String> partitions = getMultiStringParameter("partitions", expression, factory); Map<String, String> otherParams = new HashMap<>(); for (StreamExpressionNamedParameter param : factory.getNamedOperands(expression).stream() .filter(item -> !knownParameters.contains(item.getName())).collect(Collectors.toList())) { if (param.getParameter() instanceof StreamExpressionValue) { otherParams.put(param.getName(), ((StreamExpressionValue) param.getParameter()).getValue()); } } if (null == bootstrapServers) { throw new IOException(String.format(Locale.ROOT, "Invalid %s expressions '%s' - expecting a list of bootstrapServers but found none", factory.getFunctionName(getClass()), expression)); } if (null == topic) { throw new IOException(String.format(Locale.ROOT, "Invalid %s expressions '%s' - expecting a single topic but found none", factory.getFunctionName(getClass()), expression)); } this.bootstrapServers = bootstrapServers; this.otherConsumerParams = otherParams; this.groupId = groupId; this.topic = topic; // this.partitions = partitions; }
From source file:com.dennisgove.streaming.expressions.kafka.KafkaTopicConsumerStream.java
License:Apache License
/** * Returns a valid expression for this instance. *//*from w w w. ja va 2s .c o m*/ @Override public StreamExpressionParameter toExpression(StreamFactory factory) throws IOException { StreamExpression expression = new StreamExpression(factory.getFunctionName(getClass())); expression.addParameter(new StreamExpressionNamedParameter("bootstrapServers", bootstrapServers)); expression.addParameter(new StreamExpressionNamedParameter("topic", topic)); if (null != groupId) { expression.addParameter(new StreamExpressionNamedParameter("groupId", groupId)); } return expression; }
From source file:com.dennisgove.streaming.expressions.kafka.KafkaTopicConsumerStream.java
License:Apache License
/** * Returns a valid explanation of this stream instance *//*from w w w .j a v a2 s . co m*/ @Override public Explanation toExplanation(StreamFactory factory) throws IOException { StreamExplanation explanation = new StreamExplanation(getStreamNodeId().toString()); explanation.setFunctionName(String.format(Locale.ROOT, factory.getFunctionName(getClass()))); explanation.setImplementingClass(getClass().getName()); explanation.setExpressionType(ExpressionType.STREAM_SOURCE); // child is a kafka topic so add it at this point StreamExplanation child = new StreamExplanation(getStreamNodeId() + "-kafka-topic"); child.setFunctionName(String.format(Locale.ROOT, "kafka (%s)", topic)); child.setImplementingClass("Kafka"); child.setExpressionType(ExpressionType.DATASTORE); child.setExpression("Consuming from " + bootstrapServers); explanation.addChild(child); return explanation; }