Generate notifications when policies change
[policy/pap.git] / main / src / main / java / org / onap / policy / pap / main / comm / msgdata / Request.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP PAP
4  * ================================================================================
5  * Copyright (C) 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.pap.main.comm.msgdata;
22
23 import org.onap.policy.models.pdp.concepts.PdpMessage;
24 import org.onap.policy.models.pdp.concepts.PdpStatus;
25 import org.onap.policy.pap.main.comm.QueueToken;
26 import org.onap.policy.pap.main.notification.PolicyNotifier;
27
28 /**
29  * Request data, whose message may be changed at any point, possibly triggering a restart
30  * of the publishing.
31  */
32 public interface Request {
33
34     /**
35      * Gets the request priority. Higher priority requests are published before lower
36      * priority requests.
37      *
38      * @return the request priority
39      */
40     public int getPriority();
41
42     /**
43      * Gets the name with which this data is associated, used for logging purposes. This
44      * may be changed when this is reconfigured.
45      *
46      * @return the name with which this data is associated
47      */
48     public String getName();
49
50     /**
51      * Gets the current message.
52      *
53      * @return the current message
54      */
55     public PdpMessage getMessage();
56
57     /**
58      * Sets the listener that will receive request events.
59      *
60      * @param listener the request listener
61      */
62     public void setListener(RequestListener listener);
63
64     /**
65      * Sets the notifier to track responses to the request.
66      *
67      * @param notifier notifier used to publish notifications
68      */
69     public void setNotifier(PolicyNotifier notifier);
70
71     /**
72      * Determines if this request is currently being published.
73      *
74      * @return {@code true} if this request is being published, {@code false} otherwise
75      */
76     public boolean isPublishing();
77
78     /**
79      * Starts the publishing process, registering any listeners or timeout handlers, and
80      * adding the request to the publisher queue.
81      */
82     public void startPublishing();
83
84     /**
85      * Starts the publishing process.
86      *
87      * @param token2 token that can be used when publishing, or {@code null} to allocate a
88      *        new token
89      */
90     public void startPublishing(QueueToken<PdpMessage> token2);
91
92     /**
93      * Unregisters the listener, cancels the timer, and removes the message from the
94      * queue.
95      */
96     public void stopPublishing();
97
98     /**
99      * Unregisters the listener and cancels the timer.
100      *
101      * @param removeFromQueue {@code true} if the message should be removed from the
102      *        queue, {@code false} otherwise
103      * @return the token that was being used to publish the message, or {@code null} if
104      *         the request was not being published
105      */
106     public QueueToken<PdpMessage> stopPublishing(boolean removeFromQueue);
107
108     /**
109      * Reconfigures the fields based on the {@link #message} type. Suspends publishing,
110      * updates the configuration, and then resumes publishing.
111      *
112      * @param newMessage the new message
113      * @param token2 token to use when publishing, or {@code null} to allocate a new token
114      */
115     public void reconfigure(PdpMessage newMessage, QueueToken<PdpMessage> token2);
116
117     /**
118      * Checks the response to ensure it is as expected.
119      *
120      * @param response the response to check
121      * @return an error message, if a fatal error has occurred, {@code null} otherwise
122      */
123     public String checkResponse(PdpStatus response);
124
125     /**
126      * Determines if this request has the same content as another request.
127      *
128      * @param other request against which to compare
129      * @return {@code true} if the requests have the same content, {@code false} otherwise
130      */
131     public boolean isSameContent(Request other);
132 }