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