Search in sources :

Example 11 with InternalProcessorContext

use of org.apache.kafka.streams.processor.internals.InternalProcessorContext in project kafka by apache.

the class MeteredWindowStore method init.

@Override
public void init(final StateStoreContext context, final StateStore root) {
    this.context = context instanceof InternalProcessorContext ? (InternalProcessorContext<?, ?>) context : null;
    taskId = context.taskId();
    initStoreSerde(context);
    streamsMetrics = (StreamsMetricsImpl) context.metrics();
    registerMetrics();
    final Sensor restoreSensor = StateStoreMetrics.restoreSensor(taskId.toString(), metricsScope, name(), streamsMetrics);
    // register and possibly restore the state from the logs
    maybeMeasureLatency(() -> super.init(context, root), time, restoreSensor);
}
Also used : InternalProcessorContext(org.apache.kafka.streams.processor.internals.InternalProcessorContext) Sensor(org.apache.kafka.common.metrics.Sensor)

Example 12 with InternalProcessorContext

use of org.apache.kafka.streams.processor.internals.InternalProcessorContext in project kafka by apache.

the class MeteredKeyValueStore method init.

@Deprecated
@Override
public void init(final ProcessorContext context, final StateStore root) {
    this.context = context instanceof InternalProcessorContext ? (InternalProcessorContext) context : null;
    taskId = context.taskId();
    initStoreSerde(context);
    streamsMetrics = (StreamsMetricsImpl) context.metrics();
    registerMetrics();
    final Sensor restoreSensor = StateStoreMetrics.restoreSensor(taskId.toString(), metricsScope, name(), streamsMetrics);
    // register and possibly restore the state from the logs
    maybeMeasureLatency(() -> super.init(context, root), time, restoreSensor);
}
Also used : InternalProcessorContext(org.apache.kafka.streams.processor.internals.InternalProcessorContext) Sensor(org.apache.kafka.common.metrics.Sensor)

Example 13 with InternalProcessorContext

use of org.apache.kafka.streams.processor.internals.InternalProcessorContext in project kafka by apache.

the class StreamThreadStateStoreProviderTest method createStreamsTask.

private StreamTask createStreamsTask(final StreamsConfig streamsConfig, final MockClientSupplier clientSupplier, final ProcessorTopology topology, final TaskId taskId) {
    final Metrics metrics = new Metrics();
    final LogContext logContext = new LogContext("test-stream-task ");
    final Set<TopicPartition> partitions = Collections.singleton(new TopicPartition(topicName, taskId.partition()));
    final ProcessorStateManager stateManager = new ProcessorStateManager(taskId, Task.TaskType.ACTIVE, StreamsConfigUtils.eosEnabled(streamsConfig), logContext, stateDirectory, new StoreChangelogReader(new MockTime(), streamsConfig, logContext, clientSupplier.adminClient, clientSupplier.restoreConsumer, new MockStateRestoreListener()), topology.storeToChangelogTopic(), partitions);
    final RecordCollector recordCollector = new RecordCollectorImpl(logContext, taskId, new StreamsProducer(streamsConfig, "threadId", clientSupplier, new TaskId(0, 0), UUID.randomUUID(), logContext, Time.SYSTEM), streamsConfig.defaultProductionExceptionHandler(), new MockStreamsMetrics(metrics));
    final StreamsMetricsImpl streamsMetrics = new MockStreamsMetrics(metrics);
    final InternalProcessorContext context = new ProcessorContextImpl(taskId, streamsConfig, stateManager, streamsMetrics, null);
    return new StreamTask(taskId, partitions, topology, clientSupplier.consumer, new TopologyConfig(null, streamsConfig, new Properties()).getTaskConfig(), streamsMetrics, stateDirectory, EasyMock.createNiceMock(ThreadCache.class), new MockTime(), stateManager, recordCollector, context, logContext);
}
Also used : TaskId(org.apache.kafka.streams.processor.TaskId) RecordCollector(org.apache.kafka.streams.processor.internals.RecordCollector) StreamsProducer(org.apache.kafka.streams.processor.internals.StreamsProducer) InternalProcessorContext(org.apache.kafka.streams.processor.internals.InternalProcessorContext) LogContext(org.apache.kafka.common.utils.LogContext) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) MockStateRestoreListener(org.apache.kafka.test.MockStateRestoreListener) ProcessorContextImpl(org.apache.kafka.streams.processor.internals.ProcessorContextImpl) Properties(java.util.Properties) RecordCollectorImpl(org.apache.kafka.streams.processor.internals.RecordCollectorImpl) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) TopicPartition(org.apache.kafka.common.TopicPartition) StreamsMetricsImpl(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl) StoreChangelogReader(org.apache.kafka.streams.processor.internals.StoreChangelogReader) ProcessorStateManager(org.apache.kafka.streams.processor.internals.ProcessorStateManager) MockTime(org.apache.kafka.common.utils.MockTime) StreamTask(org.apache.kafka.streams.processor.internals.StreamTask) TopologyConfig(org.apache.kafka.streams.processor.internals.namedtopology.TopologyConfig)

Aggregations

InternalProcessorContext (org.apache.kafka.streams.processor.internals.InternalProcessorContext)13 Sensor (org.apache.kafka.common.metrics.Sensor)8 TopicPartition (org.apache.kafka.common.TopicPartition)5 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)4 ProcessorRecordContext (org.apache.kafka.streams.processor.internals.ProcessorRecordContext)3 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)2 Bytes (org.apache.kafka.common.utils.Bytes)2 ProcessorContextImpl (org.apache.kafka.streams.processor.internals.ProcessorContextImpl)2 ProcessorStateManager (org.apache.kafka.streams.processor.internals.ProcessorStateManager)2 RecordCollector (org.apache.kafka.streams.processor.internals.RecordCollector)2 RecordCollectorImpl (org.apache.kafka.streams.processor.internals.RecordCollectorImpl)2 StreamTask (org.apache.kafka.streams.processor.internals.StreamTask)2 StreamsMetricsImpl (org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 NoSuchElementException (java.util.NoSuchElementException)1 Objects (java.util.Objects)1