2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.ccsdk.cds.blueprintsprocessor.dmaap
23 import com.att.nsa.mr.client.MRBatchingPublisher
24 import com.att.nsa.mr.client.MRPublisher
25 import org.slf4j.LoggerFactory
26 import java.io.IOException
27 import java.util.concurrent.TimeUnit
30 * Abstraction of DMAAP client services that could form DMAAP client from the
31 * properties provided. This abstraction also provides a mechanism to send
32 * messages with the given partition in a session and closing the same.
34 interface BluePrintDmaapClientService {
37 * Static variable for logging.
41 var log = LoggerFactory.getLogger(
42 BluePrintDmaapClientService::class.java
47 * Returns the properly constructed DMAAP client with the type.
49 fun getDmaapClient(): MutableList<MRBatchingPublisher>
52 * Sends messages to the sessions created by the information provided from
53 * application.properties and event.properties file
55 fun sendMessage(msgs: Collection<String>): Boolean {
57 val clients = getDmaapClient()
58 val dmaapMsgs = mutableListOf<MRPublisher.message>()
60 dmaapMsgs.add(MRPublisher.message("1", m))
62 log.info("Sending messages to the DMAAP Server")
63 for (client in clients) {
65 client.send(dmaapMsgs)
66 } catch (e: IOException) {
68 log.error(e.message, e)
75 * Sends message to the sessions created by the information provided from
76 * application.properties and event.properties file
78 fun sendMessage(msg: String): Boolean {
79 val msgs = mutableListOf<String>()
81 return sendMessage(msgs)
85 * Closes the opened session that was used for sending messages.
87 fun close(timeout: Long): MutableList<MutableList<MRPublisher.message>>? {
88 log.debug("Closing the DMAAP producer clients")
89 var msgs: MutableList<MutableList<MRPublisher.message>> =
91 val clients = getDmaapClient()
92 for (client in clients) {
94 var ms = client.close(timeout, TimeUnit.SECONDS)
96 } catch (e: IOException) {
98 "Unable to cleanly close the connection from the " +