Merge "Change recipe to operation to match type"
[policy/models.git] / models-interactions / model-actors / actorServiceProvider / src / main / java / org / onap / policy / controlloop / actorserviceprovider / controlloop / ControlLoopEventContext.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020 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.controlloop.actorserviceprovider.controlloop;
22
23 import java.io.Serializable;
24 import java.util.Map;
25 import java.util.concurrent.ConcurrentHashMap;
26 import lombok.AccessLevel;
27 import lombok.Getter;
28 import lombok.Setter;
29 import org.onap.policy.aai.AaiCqResponse;
30 import org.onap.policy.controlloop.VirtualControlLoopEvent;
31
32 /**
33  * Context associated with a control loop event.
34  */
35 @Getter
36 @Setter
37 public class ControlLoopEventContext implements Serializable {
38     private static final long serialVersionUID = 1L;
39
40     @Setter(AccessLevel.NONE)
41     private final VirtualControlLoopEvent event;
42
43     private AaiCqResponse aaiCqResponse;
44
45     // TODO may remove this if it proves not to be needed
46     @Getter(AccessLevel.NONE)
47     @Setter(AccessLevel.NONE)
48     private Map<String, Serializable> properties = new ConcurrentHashMap<>();
49
50     /**
51      * Constructs the object.
52      *
53      * @param event event with which this is associated
54      */
55     public ControlLoopEventContext(VirtualControlLoopEvent event) {
56         this.event = event;
57     }
58
59     /**
60      * Determines if the context contains a property.
61      *
62      * @param name name of the property of interest
63      * @return {@code true} if the context contains the property, {@code false} otherwise
64      */
65     public boolean contains(String name) {
66         return properties.containsKey(name);
67     }
68
69     /**
70      * Gets a property, casting it to the desired type.
71      *
72      * @param <T> desired type
73      * @param name name of the property whose value is to be retrieved
74      * @return the property's value, or {@code null} if it does not yet have a value
75      */
76     @SuppressWarnings("unchecked")
77     public <T> T getProperty(String name) {
78         return (T) properties.get(name);
79     }
80
81     /**
82      * Sets a property's value.
83      *
84      * @param name property name
85      * @param value new property value
86      */
87     public void setProperty(String name, Serializable value) {
88         properties.put(name, value);
89     }
90 }