2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.models.pdp.concepts;
24 import java.util.UUID;
25 import lombok.AccessLevel;
26 import lombok.EqualsAndHashCode;
28 import lombok.NonNull;
30 import lombok.ToString;
31 import org.onap.policy.models.pdp.enums.PdpMessageType;
34 * Class to represent the base class for various messages that will be exchanged between
37 * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
43 public class PdpMessage {
45 @Setter(AccessLevel.NONE)
46 private PdpMessageType messageName;
48 private String requestId = UUID.randomUUID().toString();
51 * Time-stamp, in milliseconds, when the message was created. Defaults to the current
54 private long timestampMs = System.currentTimeMillis();
57 * PDP name, or {@code null} for state-change broadcast messages.
62 * Group associated with the PDP. For state-change messages, this may be {@code null},
63 * if the {@link #name} is provided. Also {@code null} for topic-check messages.
65 private String pdpGroup;
68 * Group associated with the PDP. For state-change messages, this may be {@code null},
69 * if the {@link #name} is provided. Also {@code null} for topic-check messages.
71 private String pdpSubgroup;
75 * Constructor for instantiating PdpMessage class with message name.
77 * @param messageName the message name
79 public PdpMessage(final PdpMessageType messageName) {
80 this.messageName = messageName;
84 * Constructs the object, making a deep copy. Does <i>not</i> copy the request id or
87 * @param source source from which to copy
89 public PdpMessage(final PdpMessage source) {
90 this.messageName = source.messageName;
91 this.name = source.name;
92 this.pdpGroup = source.pdpGroup;
93 this.pdpSubgroup = source.pdpSubgroup;
97 * Determines if this message applies to this PDP.
99 * @param pdpName name of this PDP
100 * @param group group to which this PDP has been assigned, or {@code null} if the PDP
101 * has not been assigned to a group yet
102 * @param subgroup group to which this PDP has been assigned, or {@code null} if the
103 * PDP has not been assigned to a subgroup yet
104 * @return {@code true} if this message applies to this PDP, {@code false} otherwise
106 public boolean appliesTo(@NonNull String pdpName, String group, String subgroup) {
107 if (pdpName.equals(name)) {
112 // message included a PDP name, but it does not match
116 // message does not provide a PDP name - must be a broadcast
118 if (group == null || subgroup == null) {
119 // this PDP has no assignment yet, thus should ignore broadcast messages
123 if (!group.equals(pdpGroup)) {
127 if (pdpSubgroup == null) {
128 // message was broadcast to entire group
132 return subgroup.equals(pdpSubgroup);