3093ad4938bfff26dd7969b96b5564b7a843ad63
[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  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.distributed.locking;
22
23 import java.util.Properties;
24 import lombok.Getter;
25 import lombok.Setter;
26 import org.eclipse.persistence.config.PersistenceUnitProperties;
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     public static final String DB_DRIVER = PersistenceUnitProperties.JDBC_DRIVER;
38     public static final String DB_URL = PersistenceUnitProperties.JDBC_URL;
39     public static final String DB_USER = PersistenceUnitProperties.JDBC_USER;
40     public static final String DB_PASS = PersistenceUnitProperties.JDBC_PASSWORD;
41     public static final String EXPIRE_CHECK_SEC = PREFIX + "expire.check.seconds";
42     public static final String RETRY_SEC = PREFIX + "retry.seconds";
43     public static final String MAX_RETRIES = PREFIX + "max.retries";
44
45     /**
46      * Database driver.
47      */
48     @Property(name = DB_DRIVER)
49     private String dbDriver;
50
51     /**
52      * Database url.
53      */
54     @Property(name = DB_URL)
55     private String dbUrl;
56
57     /**
58      * Database user.
59      */
60     @Property(name = DB_USER)
61     private String dbUser;
62
63     /**
64      * Database password.
65      */
66     @Property(name = DB_PASS)
67     private String dbPwd;
68
69     /**
70      * Time, in seconds, to wait between checks for expired locks.
71      */
72     @Property(name = EXPIRE_CHECK_SEC, defaultValue = "900")
73     private int expireCheckSec;
74
75     /**
76      * Number of seconds to wait before retrying, after a DB error.
77      */
78     @Property(name = RETRY_SEC, defaultValue = "60")
79     private int retrySec;
80
81     /**
82      * Maximum number of times to retry a DB operation.
83      */
84     @Property(name = MAX_RETRIES, defaultValue = "2")
85     private int maxRetries;
86
87     /**
88      * Constructs the object, populating fields from the properties.
89      *
90      * @param props properties from which to configure this
91      * @throws PropertyException if an error occurs
92      */
93     public DistributedLockProperties(Properties props) throws PropertyException {
94         new BeanConfigurator().configureFromProperties(this, props);
95     }
96 }