Kafka中ConsumerConfig源码介绍

来源:互联网 发布:openfire源码下载 编辑:程序博客网 时间:2024/06/06 05:03

Kafka中ConsumerConfig源码

public class ConsumerConfig extends AbstractConfig {    private static final ConfigDef config;    public static final String GROUP_ID_CONFIG = "group.id";    public static final String SESSION_TIMEOUT_MS = "session.timeout.ms";    public static final String HEARTBEAT_FREQUENCY = "heartbeat.frequency";    public static final String BOOTSTRAP_SERVERS_CONFIG = "bootstrap.servers";    public static final String ENABLE_AUTO_COMMIT_CONFIG = "enable.auto.commit";    public static final String PARTITION_ASSIGNMENT_STRATEGY = "partition.assignment.strategy";    public static final String AUTO_COMMIT_INTERVAL_MS_CONFIG = "auto.commit.interval.ms";    public static final String AUTO_OFFSET_RESET_CONFIG = "auto.offset.reset";    public static final String FETCH_MIN_BYTES_CONFIG = "fetch.min.bytes";    public static final String FETCH_MAX_WAIT_MS_CONFIG = "fetch.max.wait.ms";    public static final String METADATA_FETCH_TIMEOUT_CONFIG = "metadata.fetch.timeout.ms";    public static final String TOTAL_BUFFER_MEMORY_CONFIG = "total.memory.bytes";    public static final String FETCH_BUFFER_CONFIG = "fetch.buffer.bytes";    public static final String CLIENT_ID_CONFIG = "client.id";    public static final String SOCKET_RECEIVE_BUFFER_CONFIG = "socket.receive.buffer.bytes";    public static final String RECONNECT_BACKOFF_MS_CONFIG = "reconnect.backoff.ms";    public static final String METRICS_SAMPLE_WINDOW_MS_CONFIG = "metrics.sample.window.ms";    private static final String METRICS_SAMPLE_WINDOW_MS_DOC = "The metrics system maintains a configurable number of samples over a fixed window size. This configuration controls the size of the window. For example we might maintain two samples each measured over a 30 second period. When a window expires we erase and overwrite the oldest window.";    public static final String METRICS_NUM_SAMPLES_CONFIG = "metrics.num.samples";    private static final String METRICS_NUM_SAMPLES_DOC = "The number of samples maintained to compute metrics.";    public static final String METRIC_REPORTER_CLASSES_CONFIG = "metric.reporters";    private static final String METRIC_REPORTER_CLASSES_DOC = "A list of classes to use as metrics reporters. Implementing the <code>MetricReporter</code> interface allows plugging in classes that will be notified of new metric creation. The JmxReporter is always included to register JMX statistics.";    public static final String KEY_DESERIALIZER_CLASS_CONFIG = "key.deserializer";    private static final String KEY_DESERIALIZER_CLASS_DOC = "Deserializer class for key that implements the <code>Deserializer</code> interface.";    public static final String VALUE_DESERIALIZER_CLASS_CONFIG = "value.deserializer";    private static final String VALUE_DESERIALIZER_CLASS_DOC = "Deserializer class for value that implements the <code>Deserializer</code> interface.";    ConsumerConfig(Map<? extends Object, ? extends Object> props) {        super(config, props);    }    static {        config = (new ConfigDef()).define("bootstrap.servers", Type.LIST, Importance.HIGH, "blah blah").define("group.id", Type.STRING, Importance.HIGH, "blah blah").define("session.timeout.ms", Type.LONG, Integer.valueOf(1000), Importance.HIGH, "blah blah").define("heartbeat.frequency", Type.INT, Integer.valueOf(3), Importance.MEDIUM, "blah blah").define("partition.assignment.strategy", Type.STRING, Importance.MEDIUM, "blah blah").define("metadata.fetch.timeout.ms", Type.LONG, Integer.valueOf('\uea60'), Range.atLeast(Integer.valueOf(0)), Importance.MEDIUM, "blah blah").define("enable.auto.commit", Type.BOOLEAN, Boolean.valueOf(true), Importance.MEDIUM, "blah blah").define("auto.commit.interval.ms", Type.LONG, Integer.valueOf(5000), Range.atLeast(Integer.valueOf(0)), Importance.LOW, "blah blah").define("client.id", Type.STRING, "", Importance.LOW, "blah blah").define("total.memory.bytes", Type.LONG, Long.valueOf(33554432L), Range.atLeast(Long.valueOf(0L)), Importance.LOW, "blah blah").define("fetch.buffer.bytes", Type.INT, Integer.valueOf(1048576), Range.atLeast(Integer.valueOf(0)), Importance.HIGH, "blah blah").define("socket.receive.buffer.bytes", Type.INT, Integer.valueOf(131072), Range.atLeast(Integer.valueOf(0)), Importance.LOW, "blah blah").define("fetch.min.bytes", Type.LONG, Integer.valueOf(1024), Range.atLeast(Integer.valueOf(0)), Importance.HIGH, "blah blah").define("fetch.max.wait.ms", Type.LONG, Integer.valueOf(500), Range.atLeast(Integer.valueOf(0)), Importance.LOW, "blah blah").define("reconnect.backoff.ms", Type.LONG, Long.valueOf(10L), Range.atLeast(Long.valueOf(0L)), Importance.LOW, "blah blah").define("auto.offset.reset", Type.STRING, "largest", Importance.MEDIUM, "blah blah").define("metrics.sample.window.ms", Type.LONG, Integer.valueOf(30000), Range.atLeast(Integer.valueOf(0)), Importance.LOW, "The metrics system maintains a configurable number of samples over a fixed window size. This configuration controls the size of the window. For example we might maintain two samples each measured over a 30 second period. When a window expires we erase and overwrite the oldest window.").define("metrics.num.samples", Type.INT, Integer.valueOf(2), Range.atLeast(Integer.valueOf(1)), Importance.LOW, "The number of samples maintained to compute metrics.").define("metric.reporters", Type.LIST, "", Importance.LOW, "A list of classes to use as metrics reporters. Implementing the <code>MetricReporter</code> interface allows plugging in classes that will be notified of new metric creation. The JmxReporter is always included to register JMX statistics.").define("key.deserializer", Type.CLASS, Importance.HIGH, "Deserializer class for key that implements the <code>Deserializer</code> interface.").define("value.deserializer", Type.CLASS, Importance.HIGH, "Deserializer class for value that implements the <code>Deserializer</code> interface.");    }}
AbstractConfig源码

public class AbstractConfig {    private final Logger log = LoggerFactory.getLogger(this.getClass());    private final Set<String> used;    private final Map<String, ?> originals;    private final Map<String, Object> values;    public AbstractConfig(ConfigDef definition, Map<?, ?> originals) {...}    protected Object get(String key) {        if(!this.values.containsKey(key)) {            throw new ConfigException(String.format("Unknown configuration \'%s\'", new Object[]{key}));        } else {            this.used.add(key);            return this.values.get(key);        }    }    public int getInt(String key) {        return ((Integer)this.get(key)).intValue();    }    public long getLong(String key) {        return ((Long)this.get(key)).longValue();    }    public double getDouble(String key) {        return ((Double)this.get(key)).doubleValue();    }    public List<String> getList(String key) {        return (List)this.get(key);    }    public boolean getBoolean(String key) {        return ((Boolean)this.get(key)).booleanValue();    }    public String getString(String key) {        return (String)this.get(key);    }    public Class<?> getClass(String key) {        return (Class)this.get(key);    }    public Set<String> unused() {        HashSet keys = new HashSet(this.originals.keySet());        keys.removeAll(this.used);        return keys;    }    public Map<String, ?> originals() {        HashMap copy = new HashMap();        copy.putAll(this.originals);        return copy;    }    private void logAll() {...}    public void logUnused() {        Iterator i$ = this.unused().iterator();        while(i$.hasNext()) {            String key = (String)i$.next();            this.log.warn("The configuration {} = {} was supplied but isn\'t a known config.", key, this.values.get(key));        }    }    public <T> T getConfiguredInstance(String key, Class<T> t) {...}    public <T> List<T> getConfiguredInstances(String key, Class<T> t) {...}
<pre><pre name="code" class="java">public class ConfigDef {    private static final Object NO_DEFAULT_VALUE = new String("");    private final Map<String, ConfigDef.ConfigKey> configKeys = new HashMap();    public ConfigDef() {    }    public ConfigDef define(String name, ConfigDef.Type type, Object defaultValue, ConfigDef.Validator validator, ConfigDef.Importance importance, String documentation) {        if(this.configKeys.containsKey(name)) {            throw new ConfigException("Configuration " + name + " is defined twice.");        } else {            Object parsedDefault = defaultValue == NO_DEFAULT_VALUE?NO_DEFAULT_VALUE:this.parseType(name, defaultValue, type);            this.configKeys.put(name, new ConfigDef.ConfigKey(name, type, parsedDefault, validator, importance, documentation));            return this;        }    }    public ConfigDef define(String name, ConfigDef.Type type, Object defaultValue, ConfigDef.Importance importance, String documentation) {        return this.define(name, type, defaultValue, (ConfigDef.Validator)null, importance, documentation);    }    public ConfigDef define(String name, ConfigDef.Type type, ConfigDef.Validator validator, ConfigDef.Importance importance, String documentation) {        return this.define(name, type, NO_DEFAULT_VALUE, validator, importance, documentation);    }    public ConfigDef define(String name, ConfigDef.Type type, ConfigDef.Importance importance, String documentation) {        return this.define(name, type, NO_DEFAULT_VALUE, (ConfigDef.Validator)null, importance, documentation);    }    public Map<String, Object> parse(Map<?, ?> props) {...}    private Object parseType(String name, Object value, ConfigDef.Type type){...}    public String toHtmlTable() {...}    private static class ConfigKey {        public final String name;        public final ConfigDef.Type type;        public final String documentation;        public final Object defaultValue;        public final ConfigDef.Validator validator;        public final ConfigDef.Importance importance;        public ConfigKey(String name, ConfigDef.Type type, Object defaultValue, ConfigDef.Validator validator, ConfigDef.Importance importance, String documentation) {            this.name = name;            this.type = type;            this.defaultValue = defaultValue;            this.validator = validator;            this.importance = importance;            if(this.validator != null) {                this.validator.ensureValid(name, defaultValue);            }            this.documentation = documentation;        }        public boolean hasDefault() {            return this.defaultValue != ConfigDef.NO_DEFAULT_VALUE;        }    }    public static class ValidString implements ConfigDef.Validator {        List<String> validStrings;        private ValidString(List<String> validStrings) {            this.validStrings = validStrings;        }        public static ConfigDef.ValidString in(List<String> validStrings) {            return new ConfigDef.ValidString(validStrings);        }        public void ensureValid(String name, Object o) {            String s = (String)o;            if(!this.validStrings.contains(s)) {                throw new ConfigException(name, o, "String must be one of:" + this.join(this.validStrings));            }        }        public String toString() {            return "[" + this.join(this.validStrings) + "]";        }        private String join(List<String> list) {...}    public static class Range implements ConfigDef.Validator {        private final Number min;        private final Number max;        private Range(Number min, Number max) {            this.min = min;            this.max = max;        }        public static ConfigDef.Range atLeast(Number min) {            return new ConfigDef.Range(min, (Number)null);        }        public static ConfigDef.Range between(Number min, Number max) {            return new ConfigDef.Range(min, max);        }        public void ensureValid(String name, Object o) {...}        public String toString() {            return this.min == null?"[...," + this.max + "]":(this.max == null?"[" + this.min + ",...]":"[" + this.min + ",...," + this.max + "]");        }    }    public interface Validator {        void ensureValid(String var1, Object var2);    }    public static enum Importance {        HIGH,        MEDIUM,        LOW;        private Importance() {        }    }    public static enum Type {        BOOLEAN,        STRING,        INT,        LONG,        DOUBLE,        LIST,        CLASS;        private Type() {        }    }}


0 0
原创粉丝点击