/**
 * Copyright Beijing Daheng Soft technology co. LTD
 * All right reserved.
 * 项目名称: 大恒泰山系统
 * 创建日期:2021/11/25
 */
package org.ts.ddcs.kafkaStream.source;


import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.streams.KeyValue;
import org.apache.kafka.streams.processor.Processor;
import org.apache.kafka.streams.processor.ProcessorContext;
import org.apache.kafka.streams.processor.PunctuationType;
import org.apache.kafka.streams.state.KeyValueIterator;
import org.apache.kafka.streams.state.KeyValueStore;
import org.springframework.data.redis.connection.stream.Record;
import org.ts.ddcs.kafka.KafkaClient;
import org.ts.ddcs.kafka.KafkaClientHolder;

import java.time.Duration;


/***
 * Date:2021/11/25
 * Title: 数据流处理器模块
 * Description：数据源
 * @author dylan
 * @version 1.0
 * Remark：认为有必要的其他信息
 */
@Slf4j
public class DataStreamSourceProcessor implements Processor<String, String> {

    private ProcessorContext context;
   // private KeyValueStore<String, String> kvStore;

    @Override
    public void init(final ProcessorContext context) {
        context.schedule(Duration.ofMillis(100), PunctuationType.STREAM_TIME, timestamp -> {
//            try (final KeyValueIterator<String, String> iter = kvStore.all()) {
//                while (iter.hasNext()) {
//                    final KeyValue<String, String> entry = iter.next();
//                    context.forward(entry.key, entry.value);
//                }
//                kvStore.
//            }
            context.commit();
        });
      //  kvStore = (KeyValueStore<String, String>) context.getStateStore("blockStoreCache");
        this.context = context;
    }

    @Override
    public void process(String s, String s2) {

       // KafkaClient.messageSubmit(s,s2);

        this.context.forward(s, s2);

    }


    @Override
    public void close() {

    }
}
