2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
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.apex.core.infrastructure.messaging;
24 import java.io.Serializable;
25 import java.net.InetAddress;
26 import java.util.ArrayList;
27 import java.util.List;
28 import lombok.EqualsAndHashCode;
30 import lombok.ToString;
31 import org.slf4j.ext.XLogger;
32 import org.slf4j.ext.XLoggerFactory;
35 * The Class MessageHolder holds a set of messages to be sent as a single block of messages in this messaging
38 * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com)
39 * @param <M> the generic type of message being handled by a message holder instance
44 public class MessageHolder<M> implements Serializable {
47 private static final long serialVersionUID = 1235487535388793719L;
49 // Get a reference to the logger
50 private static final XLogger LOGGER = XLoggerFactory.getXLogger(MessageHolder.class);
52 // Properties of the message holder
53 private final long creationTime;
54 private final InetAddress senderHostAddress;
56 // Sequence of message in the message holder
58 private final List<M> messages;
61 * Constructor, create the message holder.
63 * @param senderHostAddress the host address of the sender of the message holder container
65 public MessageHolder(final InetAddress senderHostAddress) {
66 LOGGER.entry(senderHostAddress);
67 messages = new ArrayList<>();
68 this.senderHostAddress = senderHostAddress;
69 creationTime = System.currentTimeMillis();
73 * Adds a message to this message holder.
75 * @param message the message to add
77 public void addMessage(final M message) {
78 if (!messages.contains(message)) {
79 messages.add(message);
81 LOGGER.warn("duplicate message {} added to message holder", message);