Initial TCA commit into DCAEGEN2
[dcaegen2/analytics/tca.git] / dcae-analytics-common / src / main / java / org / openecomp / dcae / apod / analytics / common / service / processor / AbstractProcessorContext.java
1 /*
2  * ===============================LICENSE_START======================================
3  *  dcae-analytics
4  * ================================================================================
5  *    Copyright © 2017 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.openecomp.dcae.apod.analytics.common.service.processor;
22
23 import com.google.common.base.Objects;
24
25 import java.util.LinkedList;
26 import java.util.List;
27
28 /**
29  * <p>
30  *      An abstract implementation for {@link ProcessorContext} which other DCAE Analytics Modules
31  *      can extend to add module specific functionality
32  * </p>
33  *
34  * @author Rajiv Singla . Creation Date: 11/7/2016.
35  */
36 public abstract class AbstractProcessorContext implements ProcessorContext {
37
38     private final String message;
39     private List<? super MessageProcessor<? extends ProcessorContext>> messageProcessors;
40     private boolean canProcessingContinue;
41
42     public AbstractProcessorContext(final String message,
43                                     boolean canProcessingContinue) {
44         this.message = message;
45         this.canProcessingContinue = canProcessingContinue;
46         this.messageProcessors = new LinkedList<>();
47     }
48
49     /**
50      * Returns JSON String of incoming CEF Message that needs to be processed
51      *
52      * @return incoming CEF message that needs to be processed
53      */
54     @Override
55     public String getMessage() {
56         return message;
57     }
58
59     /**
60      * Sets if it is ok to continue processing normally
61      *
62      * @return boolean which determines if it is ok to continue processing normally
63      */
64     @Override
65     public boolean canProcessingContinue() {
66         return canProcessingContinue;
67     }
68
69
70     /**
71      * Set if it is ok to continue processing normally
72      *
73      * @param canProcessingContinue sets boolean which determines if it is ok to continue processing normally
74      */
75     @Override
76     public void setProcessingContinueFlag(boolean canProcessingContinue) {
77         this.canProcessingContinue = canProcessingContinue;
78     }
79
80     /**
81      * Provides List of message processors which were used in processing CEF message
82      *
83      * @return List of message processors which were used in processing CEF message
84      */
85     @Override
86     public List<? super MessageProcessor<? extends ProcessorContext>> getMessageProcessors() {
87         return messageProcessors;
88     }
89
90     @Override
91     public String toString() {
92         return Objects.toStringHelper(this)
93                 .add("canProcessingContinue", canProcessingContinue)
94                 .toString();
95     }
96 }