本文整理了Java中org.apache.kafka.common.utils.Utils.notNull()
方法的一些代码示例,展示了Utils.notNull()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.notNull()
方法的具体详情如下:
包路径:org.apache.kafka.common.utils.Utils
类名称:Utils
方法名:notNull
[英]Check that the parameter t is not null
[中]检查参数t是否为空
代码示例来源:origin: apache/kafka
public TopicPartitionReplica(String topic, int partition, int brokerId) {
this.topic = Utils.notNull(topic);
this.partition = partition;
this.brokerId = brokerId;
}
代码示例来源:origin: apache/kafka
/**
* Please create MetricName by method {@link org.apache.kafka.common.metrics.Metrics#metricName(String, String, String, Map)}
*
* @param name The name of the metric
* @param group logical group name of the metrics to which this metric belongs
* @param description A human-readable description to include in the metric
* @param tags additional key/value attributes of the metric
*/
public MetricName(String name, String group, String description, Map<String, String> tags) {
this.name = Utils.notNull(name);
this.group = Utils.notNull(group);
this.description = Utils.notNull(description);
this.tags = Utils.notNull(tags);
}
代码示例来源:origin: apache/kafka
/**
* Create a new template. Note that the order of the tags will be preserved if the supplied
* {@code tagsNames} set has an order.
*
* @param name the name of the metric; may not be null
* @param group the name of the group; may not be null
* @param description the description of the metric; may not be null
* @param tagsNames the set of metric tag names, which can/should be a set that maintains order; may not be null
*/
public MetricNameTemplate(String name, String group, String description, Set<String> tagsNames) {
this.name = Utils.notNull(name);
this.group = Utils.notNull(group);
this.description = Utils.notNull(description);
this.tags = new LinkedHashSet<>(Utils.notNull(tagsNames));
}
代码示例来源:origin: apache/kafka
/**
* Get the sensor with the given name if it exists
* @param name The name of the sensor
* @return Return the sensor or null if no such sensor exists
*/
public Sensor getSensor(String name) {
return this.sensors.get(Utils.notNull(name));
}
代码示例来源:origin: apache/kafka
/**
* Add a MetricReporter
*/
public synchronized void addReporter(MetricsReporter reporter) {
Utils.notNull(reporter).init(new ArrayList<>(metrics.values()));
this.reporters.add(reporter);
}
代码示例来源:origin: apache/kafka
/**
* Add a metric to monitor an object that implements MetricValueProvider. This metric won't be associated with any
* sensor. This is a way to expose existing values as metrics. User is expected to add any additional
* synchronization to update and access metric values, if required.
*
* @param metricName The name of the metric
* @param metricValueProvider The metric value provider associated with this metric
*/
public void addMetric(MetricName metricName, MetricConfig config, MetricValueProvider<?> metricValueProvider) {
KafkaMetric m = new KafkaMetric(new Object(),
Utils.notNull(metricName),
Utils.notNull(metricValueProvider),
config == null ? this.config : config,
time);
registerMetric(m);
}
代码示例来源:origin: apache/kafka
Sensor(Metrics registry, String name, Sensor[] parents, MetricConfig config, Time time,
long inactiveSensorExpirationTimeSeconds, RecordingLevel recordingLevel) {
super();
this.registry = registry;
this.name = Utils.notNull(name);
this.parents = parents == null ? new Sensor[0] : parents;
this.metrics = new LinkedHashMap<>();
this.stats = new ArrayList<>();
this.config = config;
this.time = time;
this.inactiveSensorExpirationTimeMs = TimeUnit.MILLISECONDS.convert(inactiveSensorExpirationTimeSeconds, TimeUnit.SECONDS);
this.lastRecordTime = time.milliseconds();
this.recordingLevel = recordingLevel;
this.metricLock = new Object();
checkForest(new HashSet<Sensor>());
}
代码示例来源:origin: apache/kafka
/**
* Register a metric with this sensor
*
* @param metricName The name of the metric
* @param stat The statistic to keep
* @param config A special configuration for this metric. If null use the sensor default configuration.
* @return true if metric is added to sensor, false if sensor is expired
*/
public synchronized boolean add(final MetricName metricName, final MeasurableStat stat, final MetricConfig config) {
if (hasExpired()) {
return false;
} else if (metrics.containsKey(metricName)) {
return true;
} else {
final KafkaMetric metric = new KafkaMetric(
metricLock(),
Utils.notNull(metricName),
Utils.notNull(stat),
config == null ? this.config : config,
time
);
registry.registerMetric(metric);
metrics.put(metric.metricName(), metric);
stats.add(stat);
return true;
}
}
代码示例来源:origin: apache/kafka
this.metrics = new ConcurrentHashMap<>();
this.childrenSensors = new ConcurrentHashMap<>();
this.reporters = Utils.notNull(reporters);
this.time = time;
for (MetricsReporter reporter : reporters)
代码示例来源:origin: apache/kafka
/**
* Register a compound statistic with this sensor which yields multiple measurable quantities (like a histogram)
* @param stat The stat to register
* @param config The configuration for this stat. If null then the stat will use the default configuration for this
* sensor.
* @return true if stat is added to sensor, false if sensor is expired
*/
public synchronized boolean add(CompoundStat stat, MetricConfig config) {
if (hasExpired())
return false;
this.stats.add(Utils.notNull(stat));
Object lock = metricLock();
for (NamedMeasurable m : stat.stats()) {
final KafkaMetric metric = new KafkaMetric(lock, m.name(), m.stat(), config == null ? this.config : config, time);
if (!metrics.containsKey(metric.metricName())) {
registry.registerMetric(metric);
metrics.put(metric.metricName(), metric);
}
}
return true;
}
代码示例来源:origin: apache/kafka
public void updateProduceRequestMetrics(Map<Integer, List<ProducerBatch>> batches) {
long now = time.milliseconds();
for (List<ProducerBatch> nodeBatch : batches.values()) {
int records = 0;
for (ProducerBatch batch : nodeBatch) {
// register all per-topic metrics at once
String topic = batch.topicPartition.topic();
maybeRegisterTopicMetrics(topic);
// per-topic record send rate
String topicRecordsCountName = "topic." + topic + ".records-per-batch";
Sensor topicRecordCount = Utils.notNull(this.metrics.getSensor(topicRecordsCountName));
topicRecordCount.record(batch.recordCount);
// per-topic bytes send rate
String topicByteRateName = "topic." + topic + ".bytes";
Sensor topicByteRate = Utils.notNull(this.metrics.getSensor(topicByteRateName));
topicByteRate.record(batch.estimatedSizeInBytes());
// per-topic compression rate
String topicCompressionRateName = "topic." + topic + ".compression-rate";
Sensor topicCompressionRate = Utils.notNull(this.metrics.getSensor(topicCompressionRateName));
topicCompressionRate.record(batch.compressionRatio());
// global metrics
this.batchSizeSensor.record(batch.estimatedSizeInBytes(), now);
this.queueTimeSensor.record(batch.queueTimeMs(), now);
this.compressionRateSensor.record(batch.compressionRatio());
this.maxRecordSizeSensor.record(batch.maxRecordSize, now);
records += batch.recordCount;
}
this.recordsPerRequestSensor.record(records, now);
}
}
代码示例来源:origin: apache/kafka
FutureRecordMetadata future = Utils.notNull(batch.tryAppend(timestamp, key, value, headers, callback, time.milliseconds()));
代码示例来源:origin: me.jeffshaw.kafka/kafka-clients
/**
* @param name The name of the metric
* @param group logical group name of the metrics to which this metric belongs
* @param description A human-readable description to include in the metric
* @param tags additional key/value attributes of the metric
*/
public MetricName(String name, String group, String description, Map<String, String> tags) {
this.name = Utils.notNull(name);
this.group = Utils.notNull(group);
this.description = Utils.notNull(description);
this.tags = Utils.notNull(tags);
}
代码示例来源:origin: me.jeffshaw.kafka/kafka-clients
/**
* Get the sensor with the given name if it exists
* @param name The name of the sensor
* @return Return the sensor or null if no such sensor exists
*/
public Sensor getSensor(String name) {
return this.sensors.get(Utils.notNull(name));
}
代码示例来源:origin: me.jeffshaw.kafka/kafka-clients
/**
* Add a MetricReporter
*/
public synchronized void addReporter(MetricsReporter reporter) {
Utils.notNull(reporter).init(new ArrayList<KafkaMetric>(metrics.values()));
this.reporters.add(reporter);
}
代码示例来源:origin: me.jeffshaw.kafka/kafka-clients
Sensor(Metrics registry, String name, Sensor[] parents, MetricConfig config, Time time) {
super();
this.registry = registry;
this.name = Utils.notNull(name);
this.parents = parents == null ? new Sensor[0] : parents;
this.metrics = new ArrayList<KafkaMetric>();
this.stats = new ArrayList<Stat>();
this.config = config;
this.time = time;
checkForest(new HashSet<Sensor>());
}
代码示例来源:origin: me.jeffshaw.kafka/kafka-clients
/**
* Register a metric with this sensor
* @param metricName The name of the metric
* @param stat The statistic to keep
* @param config A special configuration for this metric. If null use the sensor default configuration.
*/
public synchronized void add(MetricName metricName, MeasurableStat stat, MetricConfig config) {
KafkaMetric metric = new KafkaMetric(new Object(),
Utils.notNull(metricName),
Utils.notNull(stat),
config == null ? this.config : config,
time);
this.registry.registerMetric(metric);
this.metrics.add(metric);
this.stats.add(stat);
}
代码示例来源:origin: me.jeffshaw.kafka/kafka-clients
/**
* Add a metric to monitor an object that implements measurable. This metric won't be associated with any sensor.
* This is a way to expose existing values as metrics.
* @param metricName The name of the metric
* @param config The configuration to use when measuring this measurable
* @param measurable The measurable that will be measured by this metric
*/
public synchronized void addMetric(MetricName metricName, MetricConfig config, Measurable measurable) {
KafkaMetric m = new KafkaMetric(new Object(),
Utils.notNull(metricName),
Utils.notNull(measurable),
config == null ? this.config : config,
time);
registerMetric(m);
}
代码示例来源:origin: me.jeffshaw.kafka/kafka-clients
/**
* Create a metrics repository with a default config and the given metric reporters
* @param defaultConfig The default config
* @param reporters The metrics reporters
* @param time The time instance to use with the metrics
*/
public Metrics(MetricConfig defaultConfig, List<MetricsReporter> reporters, Time time) {
this.config = defaultConfig;
this.sensors = new CopyOnWriteMap<String, Sensor>();
this.metrics = new CopyOnWriteMap<MetricName, KafkaMetric>();
this.reporters = Utils.notNull(reporters);
this.time = time;
for (MetricsReporter reporter : reporters)
reporter.init(new ArrayList<KafkaMetric>());
}
代码示例来源:origin: me.jeffshaw.kafka/kafka-clients
/**
* Register a compound statistic with this sensor which yields multiple measurable quantities (like a histogram)
* @param stat The stat to register
* @param config The configuration for this stat. If null then the stat will use the default configuration for this
* sensor.
*/
public synchronized void add(CompoundStat stat, MetricConfig config) {
this.stats.add(Utils.notNull(stat));
for (NamedMeasurable m : stat.stats()) {
KafkaMetric metric = new KafkaMetric(this, m.name(), m.stat(), config == null ? this.config : config, time);
this.registry.registerMetric(metric);
this.metrics.add(metric);
}
}
内容来源于网络,如有侵权,请联系作者删除!