4153ee8977aaf6b804ffaa2d0e6b003e38a789d4
[policy/drools-pdp.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * feature-distributed-locking
4  * ================================================================================
5  * Copyright (C) 2018-2019, 2021 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2023 Nordix Foundation.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.distributed.locking;
23
24 import java.util.Properties;
25 import lombok.Getter;
26 import lombok.Setter;
27 import org.onap.policy.common.utils.properties.BeanConfigurator;
28 import org.onap.policy.common.utils.properties.Property;
29 import org.onap.policy.common.utils.properties.exception.PropertyException;
30
31
32 @Getter
33 @Setter
34 public class DistributedLockProperties {
35     public static final String PREFIX = "distributed.locking.";
36
37     // @formatter:off
38     public static final String DB_DRIVER = "javax.persistence.jdbc.driver";
39     public static final String DB_URL    = "javax.persistence.jdbc.url";
40     public static final String DB_USER   = "javax.persistence.jdbc.user";
41     public static final String DB_PASS   = "javax.persistence.jdbc.password";
42     public static final String EXPIRE_CHECK_SEC = PREFIX + "expire.check.seconds";
43     public static final String RETRY_SEC = PREFIX + "retry.seconds";
44     public static final String MAX_RETRIES = PREFIX + "max.retries";
45     // @formatter:on
46
47     /**
48      * Database driver.
49      */
50     @Property(name = DB_DRIVER)
51     private String dbDriver;
52
53     /**
54      * Database url.
55      */
56     @Property(name = DB_URL)
57     private String dbUrl;
58
59     /**
60      * Database user.
61      */
62     @Property(name = DB_USER)
63     private String dbUser;
64
65     /**
66      * Database password.
67      */
68     @Property(name = DB_PASS)
69     private String dbPwd;
70
71     /**
72      * Time, in seconds, to wait between checks for expired locks.
73      */
74     @Property(name = EXPIRE_CHECK_SEC, defaultValue = "900")
75     private int expireCheckSec;
76
77     /**
78      * Number of seconds to wait before retrying, after a DB error.
79      */
80     @Property(name = RETRY_SEC, defaultValue = "60")
81     private int retrySec;
82
83     /**
84      * Maximum number of times to retry a DB operation.
85      */
86     @Property(name = MAX_RETRIES, defaultValue = "2")
87     private int maxRetries;
88
89     /**
90      * Constructs the object, populating fields from the properties.
91      *
92      * @param props properties from which to configure this
93      * @throws PropertyException if an error occurs
94      */
95     public DistributedLockProperties(Properties props) throws PropertyException {
96         new BeanConfigurator().configureFromProperties(this, props);
97     }
98 }