Open Kilda Java Documentation
KafkaNamingForConfigurationValueProcessor.java
Go to the documentation of this file.
1 /* Copyright 2018 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.config.naming;
17 
18 import static java.util.Objects.requireNonNull;
19 
25 
26 import com.sabre.oss.conf4j.processor.ConfigurationValue;
27 import com.sabre.oss.conf4j.processor.ConfigurationValueProcessor;
28 
29 import java.util.function.UnaryOperator;
30 
41 public class KafkaNamingForConfigurationValueProcessor implements ConfigurationValueProcessor {
42  private MappingConfigurationValueProcessor mappingProcessor;
43 
45  SingleMappingStrategy kafkaTopicMapping = new SingleMappingStrategy(
46  KafkaTopicsConfig.KAFKA_TOPIC_MAPPING, namingStrategy::kafkaTopicName);
47  SingleMappingStrategy kafkaGroupMapping = new SingleMappingStrategy(
48  KafkaConsumerGroupConfig.KAFKA_CONSUMER_GROUP_MAPPING, namingStrategy::kafkaConsumerGroupName);
49 
50  mappingProcessor = new MappingConfigurationValueProcessor(kafkaTopicMapping, kafkaGroupMapping);
51  }
52 
53 
54  @Override
55  public ConfigurationValue process(ConfigurationValue value) {
56  return mappingProcessor.process(value);
57  }
58 
62  private static class SingleMappingStrategy implements MappingStrategy {
63 
64  private final String target;
65  private final UnaryOperator<String> mappingOperator;
66 
67  SingleMappingStrategy(String target, UnaryOperator<String> mappingOperator) {
68  this.target = requireNonNull(target, "target cannot be null");
69  this.mappingOperator = requireNonNull(mappingOperator, "mappingOperator cannot be null");
70  }
71 
72  @Override
73  public boolean isApplicable(String mappingTarget) {
74  return target.equals(mappingTarget);
75  }
76 
77  @Override
78  public String apply(String mappingTarget, String value) {
79  return isApplicable(mappingTarget) ? mappingOperator.apply(value) : value;
80  }
81  }
82 }
value
Definition: nodes.py:62
target
Definition: nodes.py:50