98865cd88ef266b09d2059d75e5191e62071b91a
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.context.parameters;
23
24 import org.onap.policy.common.parameters.ParameterGroupImpl;
25 import org.onap.policy.common.parameters.annotations.ClassName;
26 import org.onap.policy.common.parameters.annotations.NotNull;
27
28 /**
29  * A persistor parameter class that may be specialized by context persistor plugins that require
30  * plugin specific parameters.
31  *
32  * <p>The following parameters are defined:
33  * <ol>
34  * <li>pluginClass: the persistor plugin as the JVM local dummy ephemeral persistor
35  * <li>flushPeriod: Context is flushed to any persistor plugin that is defined periodically, and the
36  * period for flushing is the flush period.
37  * </ol>
38  *
39  * @author Liam Fallon (liam.fallon@ericsson.com)
40  */
41 @NotNull
42 public class PersistorParameters extends ParameterGroupImpl {
43     /** The default persistor is a dummy persistor that stubs the Persistor interface. */
44     public static final String DEFAULT_PERSISTOR_PLUGIN_CLASS =
45             "org.onap.policy.apex.context.impl.persistence.ephemeral.EphemeralPersistor";
46
47     /** Default periodic flushing interval, 5 minutes in milliseconds. */
48     public static final long DEFAULT_FLUSH_PERIOD = 300000;
49
50     private @ClassName String pluginClass = DEFAULT_PERSISTOR_PLUGIN_CLASS;
51
52     // Parameters for flushing
53     private long flushPeriod = DEFAULT_FLUSH_PERIOD;
54
55     /**
56      * Constructor to create a persistor parameters instance and register the instance with the
57      * parameter service.
58      */
59     public PersistorParameters() {
60         super(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
61     }
62
63     /**
64      * Gets the plugin class.
65      *
66      * @return the plugin class
67      */
68     public String getPluginClass() {
69         return pluginClass;
70     }
71
72     /**
73      * Sets the plugin class.
74      *
75      * @param pluginClass the plugin class
76      */
77     public void setPluginClass(final String pluginClass) {
78         this.pluginClass = pluginClass;
79     }
80
81     /**
82      * Gets the flush period in milliseconds.
83      *
84      * @return the flush period
85      */
86     public long getFlushPeriod() {
87         return flushPeriod;
88     }
89
90     /**
91      * Sets the flush period in milliseconds.
92      *
93      * @param flushPeriod the flush period
94      */
95     public void setFlushPeriod(final long flushPeriod) {
96         if (flushPeriod <= 0) {
97             this.flushPeriod = DEFAULT_FLUSH_PERIOD;
98         } else {
99             this.flushPeriod = flushPeriod;
100         }
101     }
102
103     @Override
104     public String toString() {
105         return "PersistorParameters [name=" + getName() + ", pluginClass=" + pluginClass + ", flushPeriod="
106                         + flushPeriod + "]";
107     }
108 }