3616b526ef7ae8a5aa30a5654c2d8e718838074d
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
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  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.context.parameters;
22
23 import org.onap.policy.common.parameters.GroupValidationResult;
24 import org.onap.policy.common.parameters.ParameterGroup;
25
26 /**
27  * A persistor parameter class that may be specialized by context persistor plugins that require
28  * plugin specific parameters.
29  *
30  * <p>The following parameters are defined:
31  * <ol>
32  * <li>pluginClass: the persistor plugin as the JVM local dummy ephemeral persistor
33  * <li>flushPeriod: Context is flushed to any persistor plugin that is defined periodically, and the
34  * period for flushing is the flush period.
35  * </ol>
36  *
37  * @author Liam Fallon (liam.fallon@ericsson.com)
38  */
39 public class PersistorParameters implements ParameterGroup {
40     /** The default persistor is a dummy persistor that stubs the Persistor interface. */
41     public static final String DEFAULT_PERSISTOR_PLUGIN_CLASS =
42             "org.onap.policy.apex.context.impl.persistence.ephemeral.EphemeralPersistor";
43
44     /** Default periodic flushing interval, 5 minutes in milliseconds. */
45     public static final long DEFAULT_FLUSH_PERIOD = 300000;
46
47     private String name;
48     private String pluginClass = DEFAULT_PERSISTOR_PLUGIN_CLASS;
49
50     // Parameters for flushing
51     private long flushPeriod = DEFAULT_FLUSH_PERIOD;
52
53     /**
54      * Constructor to create a persistor parameters instance and register the instance with the
55      * parameter service.
56      */
57     public PersistorParameters() {
58         super();
59
60         // Set the name for the parameters
61         this.name = ContextParameterConstants.PERSISTENCE_GROUP_NAME;
62     }
63
64     /**
65      * Gets the plugin class.
66      *
67      * @return the plugin class
68      */
69     public String getPluginClass() {
70         return pluginClass;
71     }
72
73     /**
74      * Sets the plugin class.
75      *
76      * @param pluginClass the plugin class
77      */
78     public void setPluginClass(final String pluginClass) {
79         this.pluginClass = pluginClass;
80     }
81
82     /**
83      * Gets the flush period in milliseconds.
84      *
85      * @return the flush period
86      */
87     public long getFlushPeriod() {
88         return flushPeriod;
89     }
90
91     /**
92      * Sets the flush period in milliseconds.
93      *
94      * @param flushPeriod the flush period
95      */
96     public void setFlushPeriod(final long flushPeriod) {
97         if (flushPeriod <= 0) {
98             this.flushPeriod = DEFAULT_FLUSH_PERIOD;
99         } else {
100             this.flushPeriod = flushPeriod;
101         }
102     }
103
104     @Override
105     public String toString() {
106         return "PersistorParameters [name=" + name + ", pluginClass=" + pluginClass + ", flushPeriod=" + flushPeriod
107                         + "]";
108     }
109
110     @Override
111     public String getName() {
112         return name;
113     }
114
115     @Override
116     public void setName(final String name) {
117         this.name = name;
118     }
119
120     @Override
121     public GroupValidationResult validate() {
122         return new GroupValidationResult(this);
123     }
124 }