Merge "Remove actor and recipe checks from ControlLoopCompiler.java"
[policy/models.git] / models-interactions / model-impl / cds / src / main / java / org / onap / policy / cds / api / CdsProcessorListener.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2019 Bell Canada.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ============LICENSE_END=========================================================
17  */
18
19 package org.onap.policy.cds.api;
20
21 import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput;
22
23 /**
24  * <p>
25  * In order for the caller of {@link org.onap.policy.cds.client.CdsProcessorGrpcClient} to manage the callback to handle
26  * the received messages appropriately, it needs to implement {@link CdsProcessorListener}.
27  * </p>
28  *
29  * <p>
30  * Here is a sample implementation of a listener:
31  *
32  * <pre>
33  * new CdsProcessorListener {
34  *
35  *     &#64;Override
36  *     public void onMessage(ExecutionServiceOutput message) {
37  *         log.info("Received notification from CDS: {}", message);
38  *     }
39  *
40  *     &#64;Override
41  *     public void onError(Throwable throwable) {
42  *         Status status = Status.fromThrowable(throwable);
43  *         log.error("Failed processing blueprint {}", status, throwable);
44  *     }
45  * }
46  * </pre>
47  * </p>
48  */
49 public interface CdsProcessorListener {
50
51     /**
52      * Implements the workflow upon receiving the message from the server side.
53      *
54      * <p>Note that the CDS client-server communication is configured to use a streaming approach, which means when a
55      * client sends an event, the server can reply with multiple sub-responses until full completion of the processing.
56      * Hence, it is up to the implementation of this method to process the received message using the
57      * getStatus().getEventType() method of {@link ExecutionServiceOutput}
58      *
59      * @param message ExecutionServiceOutput received by the CDS grpc server
60      */
61     void onMessage(ExecutionServiceOutput message);
62
63     /**
64      * Implements the workflow when an error is received from the server side.
65      *
66      * @param throwable Throwable object received from CDS grpc server upon error
67      */
68     void onError(Throwable throwable);
69
70 }