Remove jackson from feature-pooling-dmaap
[policy/drools-pdp.git] / feature-pooling-dmaap / src / main / java / org / onap / policy / drools / pooling / message / Forward.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.policy.drools.pooling.message;
22
23 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
24 import org.onap.policy.drools.pooling.PoolingFeatureException;
25
26 /**
27  * Message to forward an event to another host.
28  */
29 public class Forward extends Message {
30
31     /**
32      * Number of hops (i.e., number of times it's been forwarded) so far.
33      */
34     private int numHops;
35
36     /**
37      * Time, in milliseconds, at which the message was created.
38      */
39     private long createTimeMs;
40
41     /**
42      * Protocol of the receiving topic.
43      */
44     private CommInfrastructure protocol;
45
46     /**
47      * Topic on which the event was received.
48      */
49     private String topic;
50
51     /**
52      * The event pay load that was received on the topic.
53      */
54     private String payload;
55
56     /**
57      * The request id that was extracted from the event.
58      */
59     private String requestId;
60
61     /**
62      * Constructor.
63      */
64     public Forward() {
65         super();
66     }
67
68     /**
69      * Constructor.
70      * 
71      * @param source host on which the message originated
72      * @param protocol protocol
73      * @param topic topic
74      * @param payload the actual event data received on the topic
75      * @param requestId request id
76      */
77     public Forward(String source, CommInfrastructure protocol, String topic, String payload, String requestId) {
78         super(source);
79
80         this.numHops = 0;
81         this.createTimeMs = System.currentTimeMillis();
82         this.protocol = protocol;
83         this.topic = topic;
84         this.payload = payload;
85         this.requestId = requestId;
86     }
87
88     /**
89      * Increments {@link #numHops}.
90      */
91     public void bumpNumHops() {
92         ++numHops;
93     }
94
95     public int getNumHops() {
96         return numHops;
97     }
98
99     public void setNumHops(int numHops) {
100         this.numHops = numHops;
101     }
102
103     public long getCreateTimeMs() {
104         return createTimeMs;
105     }
106
107     public void setCreateTimeMs(long createTimeMs) {
108         this.createTimeMs = createTimeMs;
109     }
110
111     public CommInfrastructure getProtocol() {
112         return protocol;
113     }
114
115     public void setProtocol(CommInfrastructure protocol) {
116         this.protocol = protocol;
117     }
118
119     public String getTopic() {
120         return topic;
121     }
122
123     public void setTopic(String topic) {
124         this.topic = topic;
125     }
126
127     public String getPayload() {
128         return payload;
129     }
130
131     public void setPayload(String payload) {
132         this.payload = payload;
133     }
134
135     public String getRequestId() {
136         return requestId;
137     }
138
139     public void setRequestId(String requestId) {
140         this.requestId = requestId;
141     }
142
143     public boolean isExpired(long minCreateTimeMs) {
144         return (createTimeMs < minCreateTimeMs);
145
146     }
147
148     @Override
149     public void checkValidity() throws PoolingFeatureException {
150
151         super.checkValidity();
152
153         if (protocol == null) {
154             throw new PoolingFeatureException("missing message protocol");
155         }
156
157         if (topic == null || topic.isEmpty()) {
158             throw new PoolingFeatureException("missing message topic");
159         }
160
161         /*
162          * Note: an empty pay load is OK, as an empty message could have been
163          * received on the topic.
164          */
165
166         if (payload == null) {
167             throw new PoolingFeatureException("missing message payload");
168         }
169
170         if (requestId == null || requestId.isEmpty()) {
171             throw new PoolingFeatureException("missing message requestId");
172         }
173
174         if (numHops < 0) {
175             throw new PoolingFeatureException("invalid message hop count");
176         }
177     }
178
179 }