2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.drools.pooling.message;
23 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
24 import org.onap.policy.drools.pooling.PoolingFeatureException;
27 * Message to forward an event to another host.
29 public class Forward extends Message {
32 * Number of hops (i.e., number of times it's been forwarded) so far.
37 * Time, in milliseconds, at which the message was created.
39 private long createTimeMs;
42 * Protocol of the receiving topic.
44 private CommInfrastructure protocol;
47 * Topic on which the event was received.
52 * The event pay load that was received on the topic.
54 private String payload;
57 * The request id that was extracted from the event.
59 private String requestId;
71 * @param source host on which the message originated
72 * @param protocol protocol
74 * @param payload the actual event data received on the topic
75 * @param requestId request id
77 public Forward(String source, CommInfrastructure protocol, String topic, String payload, String requestId) {
81 this.createTimeMs = System.currentTimeMillis();
82 this.protocol = protocol;
84 this.payload = payload;
85 this.requestId = requestId;
89 * Increments {@link #numHops}.
91 public void bumpNumHops() {
95 public int getNumHops() {
99 public void setNumHops(int numHops) {
100 this.numHops = numHops;
103 public long getCreateTimeMs() {
107 public void setCreateTimeMs(long createTimeMs) {
108 this.createTimeMs = createTimeMs;
111 public CommInfrastructure getProtocol() {
115 public void setProtocol(CommInfrastructure protocol) {
116 this.protocol = protocol;
119 public String getTopic() {
123 public void setTopic(String topic) {
127 public String getPayload() {
131 public void setPayload(String payload) {
132 this.payload = payload;
135 public String getRequestId() {
139 public void setRequestId(String requestId) {
140 this.requestId = requestId;
143 public boolean isExpired(long minCreateTimeMs) {
144 return (createTimeMs < minCreateTimeMs);
149 public void checkValidity() throws PoolingFeatureException {
151 super.checkValidity();
153 if (protocol == null) {
154 throw new PoolingFeatureException("missing message protocol");
157 if (topic == null || topic.isEmpty()) {
158 throw new PoolingFeatureException("missing message topic");
162 * Note: an empty pay load is OK, as an empty message could have been
163 * received on the topic.
166 if (payload == null) {
167 throw new PoolingFeatureException("missing message payload");
170 if (requestId == null || requestId.isEmpty()) {
171 throw new PoolingFeatureException("missing message requestId");
175 throw new PoolingFeatureException("invalid message hop count");