6fd3200018adef1be7504a1ea2283c6aefbeff72
[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.apex.model.basicmodel.service.AbstractParameters;
24 import org.onap.policy.apex.model.basicmodel.service.ParameterService;
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 extends AbstractParameters {
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     // Plugin class names
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(PersistorParameters.class.getCanonicalName());
59         ParameterService.registerParameters(PersistorParameters.class, this);
60     }
61
62     /**
63      * Constructor to create a persistor parameters instance with the name of a sub class of this
64      * class and register the instance with the parameter service.
65      *
66      * @param parameterClassName the class name of a sub class of this class
67      */
68     public PersistorParameters(final String parameterClassName) {
69         super(parameterClassName);
70     }
71
72     /**
73      * Gets the plugin class.
74      *
75      * @return the plugin class
76      */
77     public String getPluginClass() {
78         return pluginClass;
79     }
80
81     /**
82      * Sets the plugin class.
83      *
84      * @param pluginClass the plugin class
85      */
86     public void setPluginClass(final String pluginClass) {
87         this.pluginClass = pluginClass;
88     }
89
90     /**
91      * Gets the flush period in milliseconds.
92      *
93      * @return the flush period
94      */
95     public long getFlushPeriod() {
96         return flushPeriod;
97     }
98
99     /**
100      * Sets the flush period in milliseconds.
101      *
102      * @param flushPeriod the flush period
103      */
104     public void setFlushPeriod(final long flushPeriod) {
105         if (flushPeriod <= 0) {
106             this.flushPeriod = DEFAULT_FLUSH_PERIOD;
107         } else {
108             this.flushPeriod = flushPeriod;
109         }
110     }
111
112     /*
113      * (non-Javadoc)
114      *
115      * @see org.onap.policy.apex.model.basicmodel.service.AbstractParameters#toString()
116      */
117     @Override
118     public String toString() {
119         return "PersistorParameters [pluginClass=" + pluginClass + ", flushPeriod=" + flushPeriod + "]";
120     }
121 }