<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jettyVersion>9.3.8.RC0</jettyVersion>
<eelf.version>0.0.1</eelf.version>
- <artifact.version>1.0.15-SNAPSHOT</artifact.version>
+ <artifact.version>1.0.16-SNAPSHOT</artifact.version>
<!-- SONAR -->
<jacoco.version>0.7.7.201606060606</jacoco.version>
<sonar-jacoco-listeners.version>3.2</sonar-jacoco-listeners.version>
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
+import java.util.concurrent.TimeUnit;
import org.onap.dmaap.dbcapi.util.DmaapConfig;
public class ConnectionFactory {
static final EELFLogger errorLogger = EELFManager.getInstance().getErrorLogger();
static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
static final EELFLogger serverLogger = EELFManager.getInstance().getServerLogger();
+ static final int PREPARE_PSQL_CONNECTION_ATTEMPTS = 5;
static {
try {
Properties p = new Properties();
p.put("user", dbuser);
p.put("password", dbcr);
+ for (int i=1; i<PREPARE_PSQL_CONNECTION_ATTEMPTS; i++){
+ try{
+ return(DriverManager.getConnection("jdbc:postgresql://" + host + "/" + dbname, p));
+ }catch(SQLException e){
+ logger.error("Unable to connect to the postgres server. " + i + "attempt failed. ", e);
+ waitFor(1);
+ }
+ }
return(DriverManager.getConnection("jdbc:postgresql://" + host + "/" + dbname, p));
}
public String getSchema() {
logger.error("Error", e);
}
}
+ private void waitFor(long seconds){
+ try {
+ TimeUnit.SECONDS.sleep(seconds);
+ } catch (InterruptedException e) {
+ logger.debug("Waiting interrupted. ", e);
+ }
+ }
}