本文整理汇总了Java中org.apache.kafka.common.utils.SystemTime类的典型用法代码示例。如果您正苦于以下问题:Java SystemTime类的具体用法?Java SystemTime怎么用?Java SystemTime使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SystemTime类属于org.apache.kafka.common.utils包,在下文中一共展示了SystemTime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: KafkaCruiseControl
import org.apache.kafka.common.utils.SystemTime; //导入依赖的package包/类
/**
* Construct the Cruise Control
*
* @param config the configuration of Cruise Control.
*/
public KafkaCruiseControl(KafkaCruiseControlConfig config) {
_config = config;
_time = new SystemTime();
// initialize some of the static state of Kafka Cruise Control;
Load.init(config);
ModelUtils.init(config);
ModelParameters.init(config);
_dropwizardMetricRegistry = new MetricRegistry();
_reporter = JmxReporter.forRegistry(_dropwizardMetricRegistry).inDomain(_metricsPrefix).build();
// Instantiate the components.
_loadMonitor = new LoadMonitor(config, _time, _dropwizardMetricRegistry);
_goalOptimizerExecutor =
Executors.newSingleThreadExecutor(new KafkaCruiseControlThreadFactory("GoalOptimizerExecutor", true, null));
_goalOptimizer = new GoalOptimizer(config, _loadMonitor, _time, _dropwizardMetricRegistry);
_executor = new Executor(config, _time, _dropwizardMetricRegistry);
_anomalyDetector = new AnomalyDetector(config, _loadMonitor, this, _time, _dropwizardMetricRegistry);
}
示例2: testShouldRecord
import org.apache.kafka.common.utils.SystemTime; //导入依赖的package包/类
@Test
public void testShouldRecord() {
MetricConfig debugConfig = new MetricConfig().recordLevel(Sensor.RecordingLevel.DEBUG);
MetricConfig infoConfig = new MetricConfig().recordLevel(Sensor.RecordingLevel.INFO);
Sensor infoSensor = new Sensor(null, "infoSensor", null, debugConfig, new SystemTime(),
0, Sensor.RecordingLevel.INFO);
assertTrue(infoSensor.shouldRecord());
infoSensor = new Sensor(null, "infoSensor", null, debugConfig, new SystemTime(),
0, Sensor.RecordingLevel.DEBUG);
assertTrue(infoSensor.shouldRecord());
Sensor debugSensor = new Sensor(null, "debugSensor", null, infoConfig, new SystemTime(),
0, Sensor.RecordingLevel.INFO);
assertTrue(debugSensor.shouldRecord());
debugSensor = new Sensor(null, "debugSensor", null, infoConfig, new SystemTime(),
0, Sensor.RecordingLevel.DEBUG);
assertFalse(debugSensor.shouldRecord());
}
示例3: ConnectEmbedded
import org.apache.kafka.common.utils.SystemTime; //导入依赖的package包/类
public ConnectEmbedded(Properties workerConfig, Properties... connectorConfigs) throws Exception {
Time time = new SystemTime();
DistributedConfig config = new DistributedConfig(Utils.propsToStringMap(workerConfig));
KafkaOffsetBackingStore offsetBackingStore = new KafkaOffsetBackingStore();
offsetBackingStore.configure(config);
//not sure if this is going to work but because we don't have advertised url we can get at least a fairly random
String workerId = UUID.randomUUID().toString();
worker = new Worker(workerId, time, config, offsetBackingStore);
StatusBackingStore statusBackingStore = new KafkaStatusBackingStore(time, worker.getInternalValueConverter());
statusBackingStore.configure(config);
ConfigBackingStore configBackingStore = new KafkaConfigBackingStore(worker.getInternalValueConverter());
configBackingStore.configure(config);
//advertisedUrl = "" as we don't have the rest server - hopefully this will not break anything
herder = new DistributedHerder(config, time, worker, statusBackingStore, configBackingStore, "");
this.connectorConfigs = connectorConfigs;
shutdownHook = new ShutdownHook();
}
示例4: beforeTest
import org.apache.kafka.common.utils.SystemTime; //导入依赖的package包/类
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override protected void beforeTest() throws Exception {
kafkaBroker = new TestKafkaBroker();
for (String topic : TOPICS)
kafkaBroker.createTopic(topic, PARTITIONS, REPLICATION_FACTOR);
WorkerConfig workerCfg = new StandaloneConfig(makeWorkerProps());
OffsetBackingStore offBackingStore = mock(OffsetBackingStore.class);
offBackingStore.configure(workerCfg);
worker = new Worker(WORKER_ID, new SystemTime(), workerCfg, offBackingStore);
worker.start();
herder = new StandaloneHerder(worker);
herder.start();
}
示例5: main
import org.apache.kafka.common.utils.SystemTime; //导入依赖的package包/类
public static void main(String[] argv) throws Exception {
//TODO: probably need to save this in the original model file
Properties props = CruiseControlUnitTestUtils.getCruiseControlProperties();
KafkaCruiseControlConfig config = new KafkaCruiseControlConfig(props);
Load.init(config);
ModelUtils.init(config);
ModelParameters.init(config);
BalancingConstraint balancingConstraint = new BalancingConstraint(config);
long start = System.currentTimeMillis();
ClusterModel clusterModel = clusterModelFromFile(argv[0]);
long end = System.currentTimeMillis();
double duration = (end - start) / 1000.0;
System.out.println("Model loaded in " + duration + "s.");
ClusterModelStats origStats = clusterModel.getClusterStats(balancingConstraint);
String loadBeforeOptimization = clusterModel.brokerStats().toString();
// Instantiate the components.
GoalOptimizer goalOptimizer = new GoalOptimizer(config, null, new SystemTime(), new MetricRegistry());
start = System.currentTimeMillis();
GoalOptimizer.OptimizerResult optimizerResult = goalOptimizer.optimizations(clusterModel);
end = System.currentTimeMillis();
duration = (end - start) / 1000.0;
String loadAfterOptimization = clusterModel.brokerStats().toString();
System.out.println("Optimize goals in " + duration + "s.");
System.out.println(optimizerResult.goalProposals().size());
System.out.println(loadBeforeOptimization);
System.out.println(loadAfterOptimization);
ClusterModelStats optimizedStats = clusterModel.getClusterStats(balancingConstraint);
double[] testStatistics = AnalyzerUtils.testDifference(origStats.utilizationMatrix(), optimizedStats.utilizationMatrix());
System.out.println(Arrays.stream(RawAndDerivedResource.values()).map(x -> x.toString()).collect(Collectors.joining(", ")));
System.out.println(Arrays.stream(testStatistics).boxed().map(pValue -> Double.toString(pValue)).collect(Collectors.joining(", ")));
}
示例6: MeteredSegmentedBytesStore
import org.apache.kafka.common.utils.SystemTime; //导入依赖的package包/类
MeteredSegmentedBytesStore(final SegmentedBytesStore inner,
final String metricScope,
final Time time) {
super(inner);
this.inner = inner;
this.metricScope = metricScope;
this.time = time != null ? time : new SystemTime();
}
示例7: ProcessorNode
import org.apache.kafka.common.utils.SystemTime; //导入依赖的package包/类
public ProcessorNode(String name, Processor<K, V> processor, Set<String> stateStores) {
this.name = name;
this.processor = processor;
this.children = new ArrayList<>();
this.stateStores = stateStores;
this.time = new SystemTime();
}
示例8: JkesDocumentDeleter
import org.apache.kafka.common.utils.SystemTime; //导入依赖的package包/类
JkesDocumentDeleter(
JestClient client,
boolean ignoreSchema,
Set<String> ignoreSchemaTopics,
String versionType,
long flushTimeoutMs,
int maxBufferedRecords,
int maxInFlightRequests,
int batchSize,
long lingerMs,
int maxRetries,
long retryBackoffMs
) {
this.client = client;
this.ignoreSchema = ignoreSchema;
this.ignoreSchemaTopics = ignoreSchemaTopics;
this.versionType = versionType;
this.flushTimeoutMs = flushTimeoutMs;
bulkProcessor = new BulkProcessor<>(
new SystemTime(),
new BulkDeletingClient(client),
maxBufferedRecords,
maxInFlightRequests,
batchSize,
lingerMs,
maxRetries,
retryBackoffMs
);
existingMappings = new HashSet<>();
}
示例9: KafkaMonitor
import org.apache.kafka.common.utils.SystemTime; //导入依赖的package包/类
public KafkaMonitor(Map<String, Map> testProps) throws Exception {
_apps = new ConcurrentHashMap<>();
_services = new ConcurrentHashMap<>();
for (Map.Entry<String, Map> entry : testProps.entrySet()) {
String name = entry.getKey();
Map props = entry.getValue();
if (!props.containsKey(CLASS_NAME_CONFIG))
throw new IllegalArgumentException(name + " is not configured with " + CLASS_NAME_CONFIG);
String className = (String) props.get(CLASS_NAME_CONFIG);
Class<?> cls = Class.forName(className);
if (App.class.isAssignableFrom(cls)) {
App test = (App) Class.forName(className).getConstructor(Map.class, String.class).newInstance(props, name);
_apps.put(name, test);
} else if (Service.class.isAssignableFrom(cls)) {
Service service = (Service) Class.forName(className).getConstructor(Map.class, String.class).newInstance(props, name);
_services.put(name, service);
} else {
throw new IllegalArgumentException(className + " should implement either " + App.class.getSimpleName() + " or " + Service.class.getSimpleName());
}
}
_executor = Executors.newSingleThreadScheduledExecutor();
_offlineRunnables = new ConcurrentHashMap<>();
List<MetricsReporter> reporters = new ArrayList<>();
reporters.add(new JmxReporter(JMX_PREFIX));
Metrics metrics = new Metrics(new MetricConfig(), reporters, new SystemTime());
metrics.addMetric(metrics.metricName("offline-runnable-count", METRIC_GROUP_NAME, "The number of Service/App that are not fully running"),
new Measurable() {
@Override
public double measure(MetricConfig config, long now) {
return _offlineRunnables.size();
}
}
);
}
示例10: flushing
import org.apache.kafka.common.utils.SystemTime; //导入依赖的package包/类
@Test
public void flushing() {
final int maxBufferedRecords = 100;
final int maxInFlightBatches = 5;
final int batchSize = 5;
final int lingerMs = 100000; // super high on purpose to make sure flush is what's causing the request
final int maxRetries = 0;
final int retryBackoffMs = 0;
final BulkProcessor<Integer, ?> bulkProcessor = new BulkProcessor<>(
new SystemTime(),
client,
maxBufferedRecords,
maxInFlightBatches,
batchSize,
lingerMs,
maxRetries,
retryBackoffMs
);
client.expect(Arrays.asList(1, 2, 3), BulkResponse.success());
bulkProcessor.start();
final int addTimeoutMs = 10;
bulkProcessor.add(1, addTimeoutMs);
bulkProcessor.add(2, addTimeoutMs);
bulkProcessor.add(3, addTimeoutMs);
assertFalse(client.expectationsMet());
final int flushTimeoutMs = 100;
bulkProcessor.flush(flushTimeoutMs);
}
示例11: addBlocksWhenBufferFull
import org.apache.kafka.common.utils.SystemTime; //导入依赖的package包/类
@Test
public void addBlocksWhenBufferFull() {
final int maxBufferedRecords = 1;
final int maxInFlightBatches = 1;
final int batchSize = 1;
final int lingerMs = 10;
final int maxRetries = 0;
final int retryBackoffMs = 0;
final BulkProcessor<Integer, ?> bulkProcessor = new BulkProcessor<>(
new SystemTime(),
client,
maxBufferedRecords,
maxInFlightBatches,
batchSize,
lingerMs,
maxRetries,
retryBackoffMs
);
final int addTimeoutMs = 10;
bulkProcessor.add(42, addTimeoutMs);
assertEquals(1, bulkProcessor.bufferedRecords());
try {
// BulkProcessor not started, so this add should timeout & throw
bulkProcessor.add(43, addTimeoutMs);
fail();
} catch (ConnectException good) {
}
}
示例12: retriableErrors
import org.apache.kafka.common.utils.SystemTime; //导入依赖的package包/类
@Test
public void retriableErrors() throws InterruptedException, ExecutionException {
final int maxBufferedRecords = 100;
final int maxInFlightBatches = 5;
final int batchSize = 2;
final int lingerMs = 5;
final int maxRetries = 3;
final int retryBackoffMs = 1;
client.expect(Arrays.asList(42, 43), BulkResponse.failure(true, "a retiable error"));
client.expect(Arrays.asList(42, 43), BulkResponse.failure(true, "a retriable error again"));
client.expect(Arrays.asList(42, 43), BulkResponse.success());
final BulkProcessor<Integer, ?> bulkProcessor = new BulkProcessor<>(
new SystemTime(),
client,
maxBufferedRecords,
maxInFlightBatches,
batchSize,
lingerMs,
maxRetries,
retryBackoffMs
);
final int addTimeoutMs = 10;
bulkProcessor.add(42, addTimeoutMs);
bulkProcessor.add(43, addTimeoutMs);
assertTrue(bulkProcessor.submitBatchWhenReady().get().succeeded);
}
示例13: retriableErrorsHitMaxRetries
import org.apache.kafka.common.utils.SystemTime; //导入依赖的package包/类
@Test
public void retriableErrorsHitMaxRetries() throws InterruptedException, ExecutionException {
final int maxBufferedRecords = 100;
final int maxInFlightBatches = 5;
final int batchSize = 2;
final int lingerMs = 5;
final int maxRetries = 2;
final int retryBackoffMs = 1;
final String errorInfo = "a final retriable error again";
client.expect(Arrays.asList(42, 43), BulkResponse.failure(true, "a retiable error"));
client.expect(Arrays.asList(42, 43), BulkResponse.failure(true, "a retriable error again"));
client.expect(Arrays.asList(42, 43), BulkResponse.failure(true, errorInfo));
final BulkProcessor<Integer, ?> bulkProcessor = new BulkProcessor<>(
new SystemTime(),
client,
maxBufferedRecords,
maxInFlightBatches,
batchSize,
lingerMs,
maxRetries,
retryBackoffMs
);
final int addTimeoutMs = 10;
bulkProcessor.add(42, addTimeoutMs);
bulkProcessor.add(43, addTimeoutMs);
try {
bulkProcessor.submitBatchWhenReady().get();
fail();
} catch (ExecutionException e) {
assertTrue(e.getCause().getMessage().contains(errorInfo));
}
}
示例14: unretriableErrors
import org.apache.kafka.common.utils.SystemTime; //导入依赖的package包/类
@Test
public void unretriableErrors() throws InterruptedException {
final int maxBufferedRecords = 100;
final int maxInFlightBatches = 5;
final int batchSize = 2;
final int lingerMs = 5;
final int maxRetries = 3;
final int retryBackoffMs = 1;
final String errorInfo = "an unretriable error";
client.expect(Arrays.asList(42, 43), BulkResponse.failure(false, errorInfo));
final BulkProcessor<Integer, ?> bulkProcessor = new BulkProcessor<>(
new SystemTime(),
client,
maxBufferedRecords,
maxInFlightBatches,
batchSize,
lingerMs,
maxRetries,
retryBackoffMs
);
final int addTimeoutMs = 10;
bulkProcessor.add(42, addTimeoutMs);
bulkProcessor.add(43, addTimeoutMs);
try {
bulkProcessor.submitBatchWhenReady().get();
fail();
} catch (ExecutionException e) {
assertTrue(e.getCause().getMessage().contains(errorInfo));
}
}
示例15: KafkaEmbedded
import org.apache.kafka.common.utils.SystemTime; //导入依赖的package包/类
/**
* Creates and starts an embedded Kafka broker.
*
* @param config Broker configuration settings. Used to modify, for example, on which port the
* broker should listen to. Note that you cannot change some settings such as
* `log.dirs`, `port`.
*/
public KafkaEmbedded(Properties config) throws IOException {
tmpFolder = new TemporaryFolder();
tmpFolder.create();
logDir = tmpFolder.newFolder();
effectiveConfig = effectiveConfigFrom(config);
boolean loggingEnabled = true;
KafkaConfig kafkaConfig = new KafkaConfig(effectiveConfig, loggingEnabled);
log.debug("Starting embedded Kafka broker (with log.dirs={} and ZK ensemble at {}) ...",
logDir, zookeeperConnect());
kafka = TestUtils.createServer(kafkaConfig, new SystemTime());
log.debug("Startup of embedded Kafka broker at {} completed (with ZK ensemble at {}) ...",
brokerList(), zookeeperConnect());
}