2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021-2025 OpenInfra Foundation Europe. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.clamp.models.acm.messages.kafka.participant;
23 import java.time.Instant;
24 import java.util.HashSet;
26 import java.util.UUID;
27 import lombok.AccessLevel;
29 import lombok.NonNull;
31 import lombok.ToString;
34 * Class to represent the base class for various messages that will be exchanged between the ACM runtime and
40 public class ParticipantMessage {
41 @Setter(AccessLevel.NONE)
42 private ParticipantMessageType messageType;
44 private UUID messageId = UUID.randomUUID();
47 * Time-stamp, in milliseconds, when the message was created. Defaults to the current time.
49 private Instant timestamp = Instant.now();
52 * Participant ID, or {@code null} for messages from participants.
54 private UUID participantId;
56 private UUID replicaId;
59 * Automation Composition ID, or {@code null} for messages to participants.
61 private UUID automationCompositionId;
63 private UUID compositionId;
65 private UUID revisionIdComposition;
66 private UUID revisionIdInstance;
69 * List of participantId that should receive the message.
71 private Set<UUID> participantIdList = new HashSet<>();
74 * Constructor for instantiating a participant message class.
76 * @param messageType the message type
78 public ParticipantMessage(final ParticipantMessageType messageType) {
79 this.messageType = messageType;
83 * Constructs the object, making a deep copy. Does <i>not</i> copy the request id or the time stamp.
85 * @param source source from which to copy
87 public ParticipantMessage(final ParticipantMessage source) {
88 this.messageId = source.messageId;
89 this.timestamp = source.timestamp;
90 this.messageType = source.messageType;
91 this.participantId = source.participantId;
92 this.replicaId = source.replicaId;
93 this.automationCompositionId = source.automationCompositionId;
94 this.compositionId = source.compositionId;
95 this.revisionIdComposition = source.revisionIdComposition;
96 this.revisionIdInstance = source.revisionIdInstance;
97 this.participantIdList = new HashSet<>(source.participantIdList);
101 * Determines if this message applies to this participant type.
103 * @param refParticipantId id of the participant from properties file to match against
104 * @param refReplicaId id of the replica from properties file to match against
105 * @return {@code true} if this message applies to this participant, {@code false} otherwise
107 public boolean appliesTo(@NonNull final UUID refParticipantId, @NonNull final UUID refReplicaId) {
108 // Broadcast message to specific list of participants
109 // or all participants when participantIdList is empty
110 // filter backward compatible with old ACM-r
111 if (participantIdList != null && !participantIdList.isEmpty()
112 && !participantIdList.contains(refParticipantId)) {
115 // Broadcast message to all participants and all replicas or specific participant and all replicas,
116 // filter backward compatible with old ACM-r
117 if ((this.participantId == null)
118 || (refParticipantId.equals(this.participantId) && this.replicaId == null)) {
121 // Targeted message at a specific participant and replica
122 return refReplicaId.equals(this.replicaId);