2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 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 com.fasterxml.jackson.annotation.JsonIgnore;
24 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
25 import org.onap.policy.drools.pooling.PoolingFeatureException;
28 * Message to forward an event to another host.
30 public class Forward extends Message {
33 * Number of hops (i.e., number of times it's been forwarded) so far.
38 * Time, in milliseconds, at which the message was created.
40 private long createTimeMs;
43 * Protocol of the receiving topic.
45 private CommInfrastructure protocol;
48 * Topic on which the event was received.
53 * The event pay load that was received on the topic.
55 private String payload;
58 * The request id that was extracted from the event.
60 private String requestId;
72 * @param source host on which the message originated
73 * @param protocol protocol
75 * @param payload the actual event data received on the topic
76 * @param requestId request id
78 public Forward(String source, CommInfrastructure protocol, String topic, String payload, String requestId) {
82 this.createTimeMs = System.currentTimeMillis();
83 this.protocol = protocol;
85 this.payload = payload;
86 this.requestId = requestId;
90 * Increments {@link #numHops}.
92 public void bumpNumHops() {
96 public int getNumHops() {
100 public void setNumHops(int numHops) {
101 this.numHops = numHops;
104 public long getCreateTimeMs() {
108 public void setCreateTimeMs(long createTimeMs) {
109 this.createTimeMs = createTimeMs;
112 public CommInfrastructure getProtocol() {
116 public void setProtocol(CommInfrastructure protocol) {
117 this.protocol = protocol;
120 public String getTopic() {
124 public void setTopic(String topic) {
128 public String getPayload() {
132 public void setPayload(String payload) {
133 this.payload = payload;
136 public String getRequestId() {
140 public void setRequestId(String requestId) {
141 this.requestId = requestId;
145 public boolean isExpired(long minCreateTimeMs) {
146 return (createTimeMs < minCreateTimeMs);
152 public void checkValidity() throws PoolingFeatureException {
154 super.checkValidity();
156 if (protocol == null) {
157 throw new PoolingFeatureException("missing message protocol");
160 if (topic == null || topic.isEmpty()) {
161 throw new PoolingFeatureException("missing message topic");
165 * Note: an empty pay load is OK, as an empty message could have been
166 * received on the topic.
169 if (payload == null) {
170 throw new PoolingFeatureException("missing message payload");
173 if (requestId == null || requestId.isEmpty()) {
174 throw new PoolingFeatureException("missing message requestId");
178 throw new PoolingFeatureException("invalid message hop count");