2 * Copyright © 2018-2019 AT&T Intellectual Property.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.cds.blueprintsprocessor.message.kafka
19 import kotlinx.coroutines.Dispatchers
20 import kotlinx.coroutines.runBlocking
21 import org.apache.kafka.streams.processor.Processor
22 import org.apache.kafka.streams.processor.ProcessorContext
23 import org.apache.kafka.streams.processor.Punctuator
24 import org.onap.ccsdk.cds.controllerblueprints.core.logger
26 /** CDS Kafka Stream Processor abstract class to implement */
27 abstract class AbstractBluePrintMessageProcessor<K, V> : Processor<K, V> {
29 private val log = logger(AbstractBluePrintMessageProcessor::class)
31 lateinit var processorContext: ProcessorContext
33 override fun process(key: K, value: V) = runBlocking(Dispatchers.IO) {
36 } catch (e: Exception) {
37 log.error("failed in processor(${this.javaClass.simpleName}) message(${this.javaClass.simpleName} :", e)
41 override fun init(context: ProcessorContext) {
42 log.info("initializing processor (${this.javaClass.simpleName})")
43 this.processorContext = context
46 override fun close() {
47 log.info("closing processor (${this.javaClass.simpleName})")
50 abstract suspend fun processNB(key: K, value: V)
53 /** CDS Kafka Stream Punctuator abstract class to implement */
54 abstract class AbstractBluePrintMessagePunctuator : Punctuator {
56 lateinit var processorContext: ProcessorContext
58 override fun punctuate(timestamp: Long) = runBlocking(Dispatchers.IO) {
59 punctuateNB(timestamp)
62 abstract suspend fun punctuateNB(timestamp: Long)