@Override @SuppressWarnings("unchecked") public void init(ProcessorContext context) { reservedStocksStore = (KeyValueStore<Product, Long>) context .getStateStore(RESERVED_STOCK_STORE_NAME); }
static void addTags(ProcessorContext processorContext, SpanCustomizer result) { result.tag(KafkaStreamsTags.KAFKA_STREAMS_APPLICATION_ID_TAG, processorContext.applicationId()); result.tag(KafkaStreamsTags.KAFKA_STREAMS_TASK_ID_TAG, processorContext.taskId().toString()); }
/** Processes the incoming message and forwards it to the appropriate * downstream processor based on the type. * The downstream processors are `type` + "-processor", where `type` is * the message type. * * {@inheritDoc} */ @Override public void process(String key, Message value) { switch(value.getType()) { case "FAST": context.forward(key, value, "FAST-processor"); break; case "MEDIUM": context.forward(key, value, "MEDIUM-processor"); break; case "SLOW": context.forward(key, value, "SLOW-processor"); break; default: throw new IllegalArgumentException("Invalid message type."); } // Close switch on type. } // Close process.
@SuppressWarnings("unchecked") @Override public void init(ProcessorContext context) { this.context = context; this.context.schedule(1000); this.kvStore = (KeyValueStore<String, Integer>) context.getStateStore("Counts"); }
@SuppressWarnings("unchecked") private void initInternal(final ProcessorContext context) { this.context = (InternalProcessorContext) context; this.serdes = new StateSerdes<>(ProcessorStateManager.storeChangelogTopic(context.applicationId(), underlying.name()), keySerde == null ? (Serde<K>) context.keySerde() : keySerde, valueSerde == null ? (Serde<V>) context.valueSerde() : valueSerde); this.cache = this.context.getCache(); this.cacheName = ThreadCache.nameSpaceFromTaskIdAndStore(context.taskId().toString(), underlying.name()); cache.addDirtyEntryFlushListener(cacheName, new ThreadCache.DirtyEntryFlushListener() { @Override public void apply(final List<ThreadCache.DirtyEntry> entries) { for (final ThreadCache.DirtyEntry entry : entries) { putAndMaybeForward(entry, (InternalProcessorContext) context); } } }); }
@Override @SuppressWarnings("unchecked") public void init(final ProcessorContext context, final StateStore root) { this.context = context; // construct the serde serdes = new StateSerdes<>(ProcessorStateManager.storeChangelogTopic(context.applicationId(), bytesStore.name()), keySerde == null ? (Serde<K>) context.keySerde() : keySerde, valueSerde == null ? (Serde<V>) context.valueSerde() : valueSerde); bytesStore.init(context, root); }
/** * {@inheritDoc} */ @Override public void process(K key, V value) { // If the key or value is null we don't need to proceed if (key == null || value == null) { return; } final NFA<K, V> nfa = loadNFA(this.stages, key); if (checkHighWaterMark()) { Event<K, V> event = new Event<>(key, value, context.timestamp(), context.topic(), context.partition(), context.offset()); List<Sequence<K, V>> sequences = nfa.matchPattern(event); Map<String, Long> latestOffsets = this.currentNFAState.getLatestOffsets(); latestOffsets.put(this.context.topic(), this.context.offset() + 1); this.currentNFAState = new NFAStates<>(nfa.getComputationStages(), nfa.getRuns(), latestOffsets); this.nfaStore.put(getRunned(key), this.currentNFAState); sequences.forEach(seq -> this.context.forward(key, seq)); } }
@SuppressWarnings("unchecked") @Override public void init(final ProcessorContext context) { internalProcessorContext = (InternalProcessorContext) context; keySerde = keySerde == null ? (Serde<K>) context.keySerde() : keySerde; valueSerde = valueSerde == null ? FullChangeSerde.castOrWrap(context.valueSerde()) : valueSerde; buffer = Objects.requireNonNull((TimeOrderedKeyValueBuffer) context.getStateStore(storeName)); }
@Override @SuppressWarnings("unchecked") public void init(final ProcessorContext context, final StateStore root) { // construct the serde this.serdes = new StateSerdes<>( ProcessorStateManager.storeChangelogTopic(context.applicationId(), name), keySerde == null ? (Serde<K>) context.keySerde() : keySerde, valueSerde == null ? (Serde<V>) context.valueSerde() : valueSerde); // register the store context.register(root, new StateRestoreCallback() { @Override public void restore(final byte[] key, final byte[] value) { restoring = true; // check value for null, to avoid deserialization error. if (value == null) { delete(serdes.keyFrom(key)); } else { put(serdes.keyFrom(key), serdes.valueFrom(value)); } restoring = false; } }); }
@Override public void init(final ProcessorContext context) { // Hold onto the context so that we can forward results. this.context = context; final String appId = context.applicationId(); final UUID queryId = UuidUtils.extractUuidFromStringEnd(appId); // Get a reference to the state store that keeps track of what can be joined with. final KeyValueStore<String, VisibilityBindingSet> stateStore = (KeyValueStore<String, VisibilityBindingSet>) context.getStateStore( stateStoreName ); joinStateStore = new KeyValueJoinStateStore( stateStore, queryId.toString(), joinVars, allVars ); }
@Override public String applicationId() { return delegate.applicationId(); }
@SuppressWarnings("unchecked") @Override public void init(final ProcessorContext context) { this.context = context; // TODO make interval configurable this.context.schedule(500, PunctuationType.STREAM_TIME, (timestamp) -> { if (scheduledFuture != null) { scheduledFuture.cancel(false); } // Assume stream is done if no activity after 5 seconds scheduledFuture = executor.schedule(() -> { this.context.commit(); return future.complete(true); }, 5000, TimeUnit.MILLISECONDS); }); }
@Override public void init(final ProcessorContext context, final StateStore root) { this.context = (InternalProcessorContext) context; final StreamsMetricsImpl metrics = this.context.metrics(); final String taskName = context.taskId().toString(); expiredRecordSensor = metrics.storeLevelSensor( taskName, name(), "expired-window-record-drop", Sensor.RecordingLevel.INFO ); addInvocationRateAndCount( expiredRecordSensor, "stream-" + metricScope + "-metrics", metrics.tagMap("task-id", taskName, metricScope + "-id", name()), "expired-window-record-drop" ); keySchema.init(ProcessorStateManager.storeChangelogTopic(context.applicationId(), root.name())); segments.openExisting(this.context); bulkLoadSegments = new HashSet<>(segments.allSegments()); // register and possibly restore the state from the logs context.register(root, new RocksDBSegmentsBatchingRestoreCallback()); open = true; }
private boolean isDuplicate(final E eventId) { long eventTime = context.timestamp(); WindowStoreIterator<Long> timeIterator = eventIdStore.fetch( eventId, eventTime - leftDurationMs, eventTime + rightDurationMs); boolean isDuplicate = timeIterator.hasNext(); timeIterator.close(); return isDuplicate; }
@Override public void commit() { delegate.commit(); }
@Override public Cancellable schedule(final Duration interval, final PunctuationType type, final Punctuator callback) throws IllegalArgumentException { return delegate.schedule(interval, type, callback); }
@Override public void init(final ProcessorContext context, final StateStore root) { context.register(root, (RecordBatchingStateRestoreCallback) this::restoreBatch); if (loggingEnabled) { collector = ((RecordCollector.Supplier) context).recordCollector(); changelogTopic = ProcessorStateManager.storeChangelogTopic(context.applicationId(), storeName); } open = true; }
@Override public TaskId taskId() { return delegate.taskId(); }
@Override public Serde<?> keySerde() { return delegate.keySerde(); }