2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation.
4 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
20 * SPDX-License-Identifier: Apache-2.0
21 * ============LICENSE_END=========================================================
24 package org.onap.policy.clamp.controlloop.participant.intermediary.comm;
26 import java.util.function.Consumer;
27 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantAckMessage;
28 import org.onap.policy.clamp.controlloop.participant.intermediary.handler.Listener;
29 import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
30 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
31 import org.onap.policy.common.endpoints.listeners.ScoListener;
32 import org.onap.policy.common.utils.coder.StandardCoderObject;
35 * Abstract Listener for Participant Ack messages sent by runtime.
37 public abstract class ParticipantAckListener<T extends ParticipantAckMessage> extends ScoListener<T>
38 implements Listener<T> {
40 private final ParticipantHandler participantHandler;
41 private final Consumer<T> consumer;
44 * Constructs the object.
46 * @param clazz class of message this handles
47 * @param participantHandler ParticipantHandler
48 * @param consumer function that handles the message
50 protected ParticipantAckListener(Class<T> clazz, ParticipantHandler participantHandler, Consumer<T> consumer) {
52 this.participantHandler = participantHandler;
53 this.consumer = consumer;
57 public void onTopicEvent(CommInfrastructure infra, String topic, StandardCoderObject sco, T message) {
58 if (participantHandler.appliesTo(message)) {
59 consumer.accept(message);
64 public ScoListener<T> getScoListener() {