diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2021-08-18 15:25:59 +0100 |
---|---|---|
committer | FrancescoFioraEst <francesco.fiora@est.tech> | 2021-08-26 13:44:57 +0100 |
commit | 6d02de6b9ea3f4e6fc588813fd2177c732a2af92 (patch) | |
tree | 71d74f431b35e950767be889a2b6d7ed1de7af45 /models/src/main/java/org | |
parent | 281a36c50d68f29e0e47dfec10ee8be38f5e5761 (diff) |
Fix issue in event handling in participants
Fix issue in event handling in participants
and refactor Participant Publisher and Listener
Issue-ID: POLICY-3544
Change-Id: Ic92ffa79d303adfb1c3319fbfefb1faef911a9d4
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'models/src/main/java/org')
2 files changed, 34 insertions, 7 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantAckMessage.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantAckMessage.java index 8b59a1801..c6f5c61b9 100644 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantAckMessage.java +++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantAckMessage.java @@ -22,6 +22,7 @@ package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant; import java.util.UUID; import lombok.Getter; +import lombok.NonNull; import lombok.Setter; import lombok.ToString; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; @@ -77,4 +78,31 @@ public class ParticipantAckMessage { this.participantType = source.participantType; this.participantId = source.participantId; } + + /** + * Determines if this message applies to this participant type. + * + * @param participantType type of the participant to match against + * @param participantId id of the participant to match against + * @return {@code true} if this message applies to this participant, {@code false} otherwise + */ + public boolean appliesTo(@NonNull final ToscaConceptIdentifier participantType, + @NonNull final ToscaConceptIdentifier participantId) { + // Broadcast message to all participants + if (this.participantType == null) { + return true; + } + + if (!participantType.equals(this.participantType)) { + return false; + } + + // Broadcast message to all control loop elements on this participant + if (this.participantId == null) { + return true; + } + + // Targeted message at this specific participant + return participantId.equals(this.participantId); + } } diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessage.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessage.java index 3ca4d3d34..f98a88c3b 100644 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessage.java +++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessage.java @@ -97,17 +97,16 @@ public class ParticipantMessage { return true; } - // Broadcast message to all control loop elements on this participant - if (participantType.equals(this.participantType) && this.participantId == null) { - return true; + if (!participantType.equals(this.participantType)) { + return false; } - // Targeted message at this specific participant - if (participantType.equals(this.participantType) && participantId.equals(this.participantId)) { + // Broadcast message to all control loop elements on this participant + if (this.participantId == null) { return true; } - // Message is not for this participant - return false; + // Targeted message at this specific participant + return participantId.equals(this.participantId); } } |