From 1d4ab912a787952efdfaa478272e155dbca26582 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Tue, 16 Apr 2024 09:59:19 +0200 Subject: [PATCH] add minPoolIdleTimeMillis --- .../cygnus/backends/sql/SQLBackendImpl.java | 32 ++++++++++--------- .../backends/sql/SQLBackendImplTest.java | 26 +++++++-------- .../iot/cygnus/sinks/NGSIMySQLSink.java | 16 +++++----- .../iot/cygnus/sinks/NGSIOracleSQLSink.java | 16 +++++----- .../iot/cygnus/sinks/NGSIPostgisSink.java | 16 +++++----- .../iot/cygnus/sinks/NGSIPostgreSQLSink.java | 16 +++++----- 6 files changed, 62 insertions(+), 60 deletions(-) diff --git a/cygnus-common/src/main/java/com/telefonica/iot/cygnus/backends/sql/SQLBackendImpl.java b/cygnus-common/src/main/java/com/telefonica/iot/cygnus/backends/sql/SQLBackendImpl.java index 23fc6cb1b..461b6e422 100644 --- a/cygnus-common/src/main/java/com/telefonica/iot/cygnus/backends/sql/SQLBackendImpl.java +++ b/cygnus-common/src/main/java/com/telefonica/iot/cygnus/backends/sql/SQLBackendImpl.java @@ -67,14 +67,14 @@ public class SQLBackendImpl implements SQLBackend{ * @param maxPoolSize * @param maxPoolIdle * @param minPoolIdle - * @param maxPoolWait + * @param minPoolIdleTimeMillis * @param sqlInstance * @param sqlDriverName * @param persistErrors * @param maxLatestErrors */ - public SQLBackendImpl(String sqlHost, String sqlPort, String sqlUsername, String sqlPassword, int maxPoolSize, int maxPoolIdle, int minPoolIdle, int maxPoolWait, SQLInstance sqlInstance, String sqlDriverName, boolean persistErrors, int maxLatestErrors) { - this(sqlHost, sqlPort, sqlUsername, sqlPassword, maxPoolSize, maxPoolIdle, minPoolIdle, maxPoolWait, sqlInstance, sqlDriverName, null, persistErrors, maxLatestErrors); + public SQLBackendImpl(String sqlHost, String sqlPort, String sqlUsername, String sqlPassword, int maxPoolSize, int maxPoolIdle, int minPoolIdle, int minPoolIdleTimeMillis, SQLInstance sqlInstance, String sqlDriverName, boolean persistErrors, int maxLatestErrors) { + this(sqlHost, sqlPort, sqlUsername, sqlPassword, maxPoolSize, maxPoolIdle, minPoolIdle, minPoolIdleTimeMillis, sqlInstance, sqlDriverName, null, persistErrors, maxLatestErrors); } // SQLBackendImpl /** @@ -87,13 +87,13 @@ public SQLBackendImpl(String sqlHost, String sqlPort, String sqlUsername, String * @param maxPoolSize * @param maxPoolIdle * @param minPoolIdle - * @param maxPoolWait + * @param minPoolIdleTimeMillis * @param sqlInstance * @param sqlDriverName * @param sqlOptions */ - public SQLBackendImpl(String sqlHost, String sqlPort, String sqlUsername, String sqlPassword, int maxPoolSize, int maxPoolIdle, int minPoolIdle, int maxPoolWait, SQLInstance sqlInstance, String sqlDriverName, String sqlOptions) { - this(sqlHost, sqlPort, sqlUsername, sqlPassword, maxPoolSize, maxPoolIdle, minPoolIdle, maxPoolWait, sqlInstance, sqlDriverName, sqlOptions, true, DEFAULT_MAX_LATEST_ERRORS); + public SQLBackendImpl(String sqlHost, String sqlPort, String sqlUsername, String sqlPassword, int maxPoolSize, int maxPoolIdle, int minPoolIdle, int minPoolIdleTimeMillis, SQLInstance sqlInstance, String sqlDriverName, String sqlOptions) { + this(sqlHost, sqlPort, sqlUsername, sqlPassword, maxPoolSize, maxPoolIdle, minPoolIdle, minPoolIdleTimeMillis, sqlInstance, sqlDriverName, sqlOptions, true, DEFAULT_MAX_LATEST_ERRORS); } // SQLBackendImpl /** @@ -106,15 +106,15 @@ public SQLBackendImpl(String sqlHost, String sqlPort, String sqlUsername, String * @param maxPoolSize * @param maxPoolIdle * @param minPoolIdle - * @param maxPoolWait + * @param minPoolIdleTimeMillis * @param sqlInstance * @param sqlDriverName * @param sqlOptions * @param persistErrors * @param maxLatestErrors */ - public SQLBackendImpl(String sqlHost, String sqlPort, String sqlUsername, String sqlPassword, int maxPoolSize, int maxPoolIdle, int minPoolIdle, int maxPoolWait, SQLInstance sqlInstance, String sqlDriverName, String sqlOptions, boolean persistErrors, int maxLatestErrors) { - driver = new SQLBackendImpl.SQLDriver(sqlHost, sqlPort, sqlUsername, sqlPassword, maxPoolSize, maxPoolIdle, minPoolIdle, maxPoolWait, sqlInstance, sqlDriverName, sqlOptions); + public SQLBackendImpl(String sqlHost, String sqlPort, String sqlUsername, String sqlPassword, int maxPoolSize, int maxPoolIdle, int minPoolIdle, int minPoolIdleTimeMillis, SQLInstance sqlInstance, String sqlDriverName, String sqlOptions, boolean persistErrors, int maxLatestErrors) { + driver = new SQLBackendImpl.SQLDriver(sqlHost, sqlPort, sqlUsername, sqlPassword, maxPoolSize, maxPoolIdle, minPoolIdle, minPoolIdleTimeMillis, sqlInstance, sqlDriverName, sqlOptions); cache = new SQLCache(); this.sqlInstance = sqlInstance; this.persistErrors = persistErrors; @@ -946,7 +946,7 @@ public class SQLDriver { private final int maxPoolSize; private final int maxPoolIdle; private final int minPoolIdle; - private final int maxPoolWait; + private final int minPoolIdleTimeMillis; private final String sqlOptions; /** @@ -959,12 +959,12 @@ public class SQLDriver { * @param maxPoolSize * @param maxPoolIdle * @param minPoolIdle - * @param maxPoolWait + * @param minPoolIdleTimeMillis * @param sqlInstance * @param sqlDriverName * @param sqlOptions */ - public SQLDriver(String sqlHost, String sqlPort, String sqlUsername, String sqlPassword, int maxPoolSize, int maxPoolIdle, int minPoolIdle, int maxPoolWait, SQLInstance sqlInstance, String sqlDriverName, String sqlOptions) { + public SQLDriver(String sqlHost, String sqlPort, String sqlUsername, String sqlPassword, int maxPoolSize, int maxPoolIdle, int minPoolIdle, int minPoolIdleTimeMillis, SQLInstance sqlInstance, String sqlDriverName, String sqlOptions) { datasources = new HashMap<>(); pools = new HashMap<>(); this.sqlHost = sqlHost; @@ -974,7 +974,7 @@ public SQLDriver(String sqlHost, String sqlPort, String sqlUsername, String sqlP this.maxPoolSize = maxPoolSize; this.maxPoolIdle = maxPoolIdle; this.minPoolIdle = minPoolIdle; - this.maxPoolWait = maxPoolWait; + this.minPoolIdleTimeMillis = minPoolIdleTimeMillis; this.sqlInstance = sqlInstance; this.sqlDriverName = sqlDriverName; this.sqlOptions = sqlOptions; @@ -1120,8 +1120,10 @@ private DataSource createConnectionPool(String destination) throws Exception { gPool.setMaxIdle(this.maxPoolIdle); // Sets the minimum number of objects allowed in the pool before the evictor thread (if active) spawns new objects. gPool.setMinIdle(this.minPoolIdle); - // Sets the minimum amount of time an object may sit idle in the pool before it is eligible for eviction by the idle object evictor (if any), with the extra condition that at least "minIdle" object instances remain in the pool. - gPool.setSoftMinEvictableIdleTimeMillis(this.maxPoolWait); + // Sets the minimum amount of time an object may sit idle in the pool before it is eligible for eviction by the idle object evictor (if any) + gPool.setMinEvictableIdleTimeMillis(this.minPoolIdleTimeMillis); + // Sets the number of milliseconds to sleep between runs of the idle object evictor thread + gPool.setTimeBetweenEvictionRunsMillis(this.minPoolIdleTimeMillis*3); pools.put(destination, gPool); // Creates a ConnectionFactory Object Which Will Be Used by the Pool to Create the Connection Object! diff --git a/cygnus-common/src/test/java/com/telefonica/iot/cygnus/backends/sql/SQLBackendImplTest.java b/cygnus-common/src/test/java/com/telefonica/iot/cygnus/backends/sql/SQLBackendImplTest.java index 3272573e1..50c61eb7f 100644 --- a/cygnus-common/src/test/java/com/telefonica/iot/cygnus/backends/sql/SQLBackendImplTest.java +++ b/cygnus-common/src/test/java/com/telefonica/iot/cygnus/backends/sql/SQLBackendImplTest.java @@ -55,7 +55,7 @@ public class SQLBackendImplTest { private final int maxPoolSize = 2; private final int maxPoolIdle = 1; private final int minPoolIdle = 0; - private final int maxPoolWait = 10000; + private final int minPoolIdleTimeMillis = 10000; private final String host = "localhost"; private final String port = "3306"; private final String user = "root"; @@ -86,7 +86,7 @@ public class SQLBackendImplTest { @Before public void setUp() throws Exception { // set up the instance of the tested class - backend = new SQLBackendImpl(host, port, user, password, maxPoolSize, maxPoolIdle, minPoolIdle, maxPoolWait, MYSQL_INSTANCE_NAME, MYSQL_DRIVER_NAME, null, persistErrors, maxLatestErrors); + backend = new SQLBackendImpl(host, port, user, password, maxPoolSize, maxPoolIdle, minPoolIdle, minPoolIdleTimeMillis, MYSQL_INSTANCE_NAME, MYSQL_DRIVER_NAME, null, persistErrors, maxLatestErrors); // set up the behaviour of the mocked classes when(mockDriverDbCreate.getConnection(Mockito.anyString())).thenReturn(mockConnection); @@ -172,7 +172,7 @@ public void testJDBCUrlMySQL() { String sqlDriverName = "com.mysql.jdbc.Driver"; String destination = "dest"; - SQLBackendImpl backend = new SQLBackendImpl(sqlHost, sqlPort, user, password, maxPoolSize, maxPoolIdle, minPoolIdle, maxPoolWait, sqlInstance, sqlDriverName, null, persistErrors, maxLatestErrors); + SQLBackendImpl backend = new SQLBackendImpl(sqlHost, sqlPort, user, password, maxPoolSize, maxPoolIdle, minPoolIdle, minPoolIdleTimeMillis, sqlInstance, sqlDriverName, null, persistErrors, maxLatestErrors); SQLBackendImpl.SQLDriver driver = backend.getDriver(); assertEquals(driver.generateJDBCUrl(destination), "jdbc:mysql://localhost:3306/dest"); @@ -188,7 +188,7 @@ public void testJDBCUrlPostgreSQL() { String destination = "dest"; String defaultDataBase = "default"; - SQLBackendImpl backend = new SQLBackendImpl(sqlHost, sqlPort, user, password, maxPoolSize, maxPoolIdle, minPoolIdle, maxPoolWait, sqlInstance, sqlDriverName, defaultDataBase, persistErrors, maxLatestErrors); + SQLBackendImpl backend = new SQLBackendImpl(sqlHost, sqlPort, user, password, maxPoolSize, maxPoolIdle, minPoolIdle, minPoolIdleTimeMillis, sqlInstance, sqlDriverName, defaultDataBase, persistErrors, maxLatestErrors); SQLBackendImpl.SQLDriver driver = backend.getDriver(); assertEquals(driver.generateJDBCUrl(destination), "jdbc:postgresql://localhost:5432/default"); @@ -204,7 +204,7 @@ public void testJDBCUrlOracleSQL() { String destination = "dest"; String defaultDataBase = "default"; - SQLBackendImpl backend = new SQLBackendImpl(sqlHost, sqlPort, user, password, maxPoolSize, maxPoolIdle, minPoolIdle, maxPoolWait, sqlInstance, sqlDriverName, defaultDataBase, persistErrors, maxLatestErrors); + SQLBackendImpl backend = new SQLBackendImpl(sqlHost, sqlPort, user, password, maxPoolSize, maxPoolIdle, minPoolIdle, minPoolIdleTimeMillis, sqlInstance, sqlDriverName, defaultDataBase, persistErrors, maxLatestErrors); SQLBackendImpl.SQLDriver driver = backend.getDriver(); assertEquals(driver.generateJDBCUrl(destination), "jdbc:oracle:oci://localhost:1521/default"); @@ -220,7 +220,7 @@ public void testJDBCUrlMySQLWithOptions() { String destination = "dest"; String sqlOptions = "useSSL=true&requireSSL=false"; - SQLBackendImpl backend = new SQLBackendImpl(sqlHost, sqlPort, user, password, maxPoolSize, maxPoolIdle, minPoolIdle, maxPoolWait, sqlInstance, sqlDriverName, sqlOptions, persistErrors, maxLatestErrors); + SQLBackendImpl backend = new SQLBackendImpl(sqlHost, sqlPort, user, password, maxPoolSize, maxPoolIdle, minPoolIdle, minPoolIdleTimeMillis, sqlInstance, sqlDriverName, sqlOptions, persistErrors, maxLatestErrors); SQLBackendImpl.SQLDriver driver = backend.getDriver(); assertEquals(driver.generateJDBCUrl(destination), "jdbc:mysql://localhost:3306/dest?useSSL=true&requireSSL=false"); @@ -228,7 +228,7 @@ public void testJDBCUrlMySQLWithOptions() { System.out.println("Testing SQLBackendImpl.SQLDriver.generateJDBCUrl (sqlInstance:mysql, options:)"); sqlOptions = " \t"; - backend = new SQLBackendImpl(sqlHost, sqlPort, user, password, maxPoolSize, maxPoolIdle, minPoolIdle, maxPoolWait, sqlInstance, sqlDriverName, sqlOptions, persistErrors, maxLatestErrors); + backend = new SQLBackendImpl(sqlHost, sqlPort, user, password, maxPoolSize, maxPoolIdle, minPoolIdle, minPoolIdleTimeMillis, sqlInstance, sqlDriverName, sqlOptions, persistErrors, maxLatestErrors); driver = backend.getDriver(); assertEquals(driver.generateJDBCUrl(destination), "jdbc:mysql://localhost:3306/dest"); @@ -236,7 +236,7 @@ public void testJDBCUrlMySQLWithOptions() { System.out.println("Testing SQLBackendImpl.SQLDriver.generateJDBCUrl (sqlInstance:mysql, options:)"); sqlOptions = ""; - backend = new SQLBackendImpl(sqlHost, sqlPort, user, password, maxPoolSize, maxPoolIdle, minPoolIdle, maxPoolWait, sqlInstance, sqlDriverName, sqlOptions, persistErrors, maxLatestErrors); + backend = new SQLBackendImpl(sqlHost, sqlPort, user, password, maxPoolSize, maxPoolIdle, minPoolIdle, minPoolIdleTimeMillis, sqlInstance, sqlDriverName, sqlOptions, persistErrors, maxLatestErrors); driver = backend.getDriver(); assertEquals(driver.generateJDBCUrl(destination), "jdbc:mysql://localhost:3306/dest"); @@ -244,7 +244,7 @@ public void testJDBCUrlMySQLWithOptions() { System.out.println("Testing SQLBackendImpl.SQLDriver.generateJDBCUrl (sqlInstance:mysql, options:)"); sqlOptions = null; - backend = new SQLBackendImpl(sqlHost, sqlPort, user, password, maxPoolSize, maxPoolIdle, minPoolIdle, maxPoolWait, sqlInstance, sqlDriverName, sqlOptions, persistErrors, maxLatestErrors); + backend = new SQLBackendImpl(sqlHost, sqlPort, user, password, maxPoolSize, maxPoolIdle, minPoolIdle, minPoolIdleTimeMillis, sqlInstance, sqlDriverName, sqlOptions, persistErrors, maxLatestErrors); driver = backend.getDriver(); assertEquals(driver.generateJDBCUrl(destination), "jdbc:mysql://localhost:3306/dest"); @@ -261,7 +261,7 @@ public void testJDBCUrlPostgreSQLWithOptions() { String defaultDataBase = "default"; String sqlOptions = "sslmode=require"; - SQLBackendImpl backend = new SQLBackendImpl(sqlHost, sqlPort, user, password, maxPoolSize, maxPoolIdle, minPoolIdle, maxPoolWait, sqlInstance, sqlDriverName, sqlOptions, persistErrors, maxLatestErrors); + SQLBackendImpl backend = new SQLBackendImpl(sqlHost, sqlPort, user, password, maxPoolSize, maxPoolIdle, minPoolIdle, minPoolIdleTimeMillis, sqlInstance, sqlDriverName, sqlOptions, persistErrors, maxLatestErrors); SQLBackendImpl.SQLDriver driver = backend.getDriver(); assertEquals(driver.generateJDBCUrl(destination), "jdbc:postgresql://localhost:5432/default?sslmode=require"); @@ -269,7 +269,7 @@ public void testJDBCUrlPostgreSQLWithOptions() { System.out.println("Testing SQLBackendImpl.SQLDriver.generateJDBCUrl (sqlInstance:postgresql, options:)"); sqlOptions = ""; - backend = new SQLBackendImpl(sqlHost, sqlPort, user, password, maxPoolSize, maxPoolIdle, minPoolIdle, maxPoolWait, sqlInstance, sqlDriverName, sqlOptions, persistErrors, maxLatestErrors); + backend = new SQLBackendImpl(sqlHost, sqlPort, user, password, maxPoolSize, maxPoolIdle, minPoolIdle, minPoolIdleTimeMillis, sqlInstance, sqlDriverName, sqlOptions, persistErrors, maxLatestErrors); driver = backend.getDriver(); assertEquals(driver.generateJDBCUrl(destination), "jdbc:postgresql://localhost:5432/default"); @@ -285,7 +285,7 @@ public void testJDBCUrlPostgreSQLWithOptions() { System.out.println("Testing SQLBackendImpl.SQLDriver.generateJDBCUrl (sqlInstance:postgresql, options:)"); sqlOptions = null; - backend = new SQLBackendImpl(sqlHost, sqlPort, user, password, maxPoolSize, maxPoolIdle, minPoolIdle, maxPoolWait, sqlInstance, sqlDriverName, sqlOptions, persistErrors, maxLatestErrors); + backend = new SQLBackendImpl(sqlHost, sqlPort, user, password, maxPoolSize, maxPoolIdle, minPoolIdle, minPoolIdleTimeMillis, sqlInstance, sqlDriverName, sqlOptions, persistErrors, maxLatestErrors); driver = backend.getDriver(); assertEquals(driver.generateJDBCUrl(destination), "jdbc:postgresql://localhost:5432/default"); diff --git a/cygnus-ngsi/src/main/java/com/telefonica/iot/cygnus/sinks/NGSIMySQLSink.java b/cygnus-ngsi/src/main/java/com/telefonica/iot/cygnus/sinks/NGSIMySQLSink.java index f9d3c4222..8d87b370a 100644 --- a/cygnus-ngsi/src/main/java/com/telefonica/iot/cygnus/sinks/NGSIMySQLSink.java +++ b/cygnus-ngsi/src/main/java/com/telefonica/iot/cygnus/sinks/NGSIMySQLSink.java @@ -60,7 +60,7 @@ public class NGSIMySQLSink extends NGSISink { private static final int DEFAULT_MAX_POOL_SIZE = 3; private static final int DEFAULT_MAX_POOL_IDLE = 2; private static final int DEFAULT_MIN_POOL_IDLE = 0; - private static final int DEFAULT_MAX_POOL_WAIT = 10000; + private static final int DEFAULT_MIN_POOL_IDLE_TIME_MILLIS = 10000; private static final String DEFAULT_ATTR_NATIVE_TYPES = "false"; private static final String MYSQL_DRIVER_NAME = "com.mysql.jdbc.Driver"; private static final SQLInstance MYSQL_INSTANCE_NAME = SQLInstance.MYSQL; @@ -79,7 +79,7 @@ public class NGSIMySQLSink extends NGSISink { private int maxPoolSize; private int maxPoolIdle; private int minPoolIdle; - private int maxPoolWait; + private int minPoolIdleTimeMillis; private boolean rowAttrPersistence; private SQLBackendImpl mySQLPersistenceBackend; private boolean attrNativeTypes; @@ -205,8 +205,8 @@ public void configure(Context context) { minPoolIdle = context.getInteger("mysql_minPoolIdle", DEFAULT_MIN_POOL_IDLE); LOGGER.debug("[" + this.getName() + "] Reading configuration (mysql_minPoolIdle=" + minPoolIdle + ")"); - maxPoolWait = context.getInteger("mysql_maxPoolWait", DEFAULT_MAX_POOL_WAIT); - LOGGER.debug("[" + this.getName() + "] Reading configuration (mysql_maxPoolWait=" + maxPoolWait + ")"); + minPoolIdleTimeMillis = context.getInteger("mysql_minPoolIdleTimeMillis", DEFAULT_MIN_POOL_IDLE_TIME_MILLIS); + LOGGER.debug("[" + this.getName() + "] Reading configuration (mysql_minPoolIdleTimeMillis=" + minPoolIdleTimeMillis + ")"); rowAttrPersistence = context.getString("attr_persistence", DEFAULT_ROW_ATTR_PERSISTENCE).equals("row"); String persistence = context.getString("attr_persistence", DEFAULT_ROW_ATTR_PERSISTENCE); @@ -293,10 +293,10 @@ public void configure(Context context) { @Override public void start() { try { - createPersistenceBackend(mysqlHost, mysqlPort, mysqlUsername, mysqlPassword, maxPoolSize, maxPoolIdle, minPoolIdle, maxPoolWait, mysqlOptions, persistErrors, maxLatestErrors); + createPersistenceBackend(mysqlHost, mysqlPort, mysqlUsername, mysqlPassword, maxPoolSize, maxPoolIdle, minPoolIdle, minPoolIdleTimeMillis, mysqlOptions, persistErrors, maxLatestErrors); LOGGER.debug("[" + this.getName() + "] MySQL persistence backend created"); } catch (Exception e) { - String configParams = " mysqlHost " + mysqlHost + " mysqlPort " + mysqlPort + " mysqlUsername " + mysqlUsername + " mysqlPassword " + mysqlPassword + " maxPoolSize " + maxPoolSize + " maxPoolIdle " + maxPoolIdle + " minPoolIdle " + minPoolIdle + " maxPoolWait " + maxPoolWait + " mysqlOptions " + mysqlOptions + " persistErrors " + persistErrors + " maxLatestErrors " + maxLatestErrors; + String configParams = " mysqlHost " + mysqlHost + " mysqlPort " + mysqlPort + " mysqlUsername " + mysqlUsername + " mysqlPassword " + mysqlPassword + " maxPoolSize " + maxPoolSize + " maxPoolIdle " + maxPoolIdle + " minPoolIdle " + minPoolIdle + " minPoolIdleTimeMillis " + minPoolIdleTimeMillis + " mysqlOptions " + mysqlOptions + " persistErrors " + persistErrors + " maxLatestErrors " + maxLatestErrors; LOGGER.error("Error while creating the MySQL persistence backend. " + "Config params= " + configParams + "Details=" + e.getMessage() + @@ -315,9 +315,9 @@ public void stop() { /** * Initialices a lazy singleton to share among instances on JVM */ -private void createPersistenceBackend(String sqlHost, String sqlPort, String sqlUsername, String sqlPassword, int maxPoolSize, int maxPoolIdle, int minPoolIdle, int maxPoolWait, String sqlOptions, boolean persistErrors, int maxLatestErrors) { +private void createPersistenceBackend(String sqlHost, String sqlPort, String sqlUsername, String sqlPassword, int maxPoolSize, int maxPoolIdle, int minPoolIdle, int minPoolIdleTimeMillis, String sqlOptions, boolean persistErrors, int maxLatestErrors) { if (mySQLPersistenceBackend == null) { - mySQLPersistenceBackend = new SQLBackendImpl(sqlHost, sqlPort, sqlUsername, sqlPassword, maxPoolSize, maxPoolIdle, minPoolIdle, maxPoolWait, MYSQL_INSTANCE_NAME, MYSQL_DRIVER_NAME, sqlOptions, persistErrors, maxLatestErrors); + mySQLPersistenceBackend = new SQLBackendImpl(sqlHost, sqlPort, sqlUsername, sqlPassword, maxPoolSize, maxPoolIdle, minPoolIdle, minPoolIdleTimeMillis, MYSQL_INSTANCE_NAME, MYSQL_DRIVER_NAME, sqlOptions, persistErrors, maxLatestErrors); } } diff --git a/cygnus-ngsi/src/main/java/com/telefonica/iot/cygnus/sinks/NGSIOracleSQLSink.java b/cygnus-ngsi/src/main/java/com/telefonica/iot/cygnus/sinks/NGSIOracleSQLSink.java index 2bd6e5e17..eeb78cbd4 100644 --- a/cygnus-ngsi/src/main/java/com/telefonica/iot/cygnus/sinks/NGSIOracleSQLSink.java +++ b/cygnus-ngsi/src/main/java/com/telefonica/iot/cygnus/sinks/NGSIOracleSQLSink.java @@ -60,7 +60,7 @@ public class NGSIOracleSQLSink extends NGSISink { private static final int DEFAULT_MAX_POOL_SIZE = 3; private static final int DEFAULT_MAX_POOL_IDLE = 2; private static final int DEFAULT_MIN_POOL_IDLE = 0; - private static final int DEFAULT_MAX_POOL_WAIT = 10000; + private static final int DEFAULT_MIN_POOL_IDLE_TIME_MILLIS = 10000; private static final String DEFAULT_ATTR_NATIVE_TYPES = "false"; //private static final String ORACLE_DRIVER_NAME = "oracle.jdbc.OracleDriver"; private static final String ORACLE_DRIVER_NAME = "oracle.jdbc.driver.OracleDriver"; @@ -87,7 +87,7 @@ public class NGSIOracleSQLSink extends NGSISink { private int maxPoolSize; private int maxPoolIdle; private int minPoolIdle; - private int maxPoolWait; + private int minPoolIdleTimeMillis; private boolean rowAttrPersistence; private SQLBackendImpl oracleSQLPersistenceBackend; private boolean attrNativeTypes; @@ -228,8 +228,8 @@ public void configure(Context context) { minPoolIdle = context.getInteger("oracle_minPoolIdle", DEFAULT_MIN_POOL_IDLE); LOGGER.debug("[" + this.getName() + "] Reading configuration (oracle_minPoolIdle=" + minPoolIdle + ")"); - maxPoolWait = context.getInteger("oracle_maxPoolWait", DEFAULT_MAX_POOL_WAIT); - LOGGER.debug("[" + this.getName() + "] Reading configuration (oracle_maxPoolWait=" + maxPoolWait + ")"); + minPoolIdleTimeMillis = context.getInteger("oracle_minPoolIdleTimeMillis", DEFAULT_MIN_POOL_IDLE_TIME_MILLIS); + LOGGER.debug("[" + this.getName() + "] Reading configuration (oracle_minPoolIdleTimeMillis=" + minPoolIdleTimeMillis + ")"); rowAttrPersistence = context.getString("attr_persistence", DEFAULT_ROW_ATTR_PERSISTENCE).equals("row"); String persistence = context.getString("attr_persistence", DEFAULT_ROW_ATTR_PERSISTENCE); @@ -342,10 +342,10 @@ public void configure(Context context) { @Override public void start() { try { - createPersistenceBackend(oracleHost, oraclePort, oracleUsername, oraclePassword, maxPoolSize, maxPoolIdle, minPoolIdle, maxPoolWait, oracleOptions, persistErrors, maxLatestErrors); + createPersistenceBackend(oracleHost, oraclePort, oracleUsername, oraclePassword, maxPoolSize, maxPoolIdle, minPoolIdle, minPoolIdleTimeMillis, oracleOptions, persistErrors, maxLatestErrors); LOGGER.debug("[" + this.getName() + "] OracleSQL persistence backend created"); } catch (Exception e) { - String configParams = " oracleHost " + oracleHost + " oraclePort " + oraclePort + " oracleUsername " + oracleUsername + " oraclePassword " + oraclePassword + " maxPoolSize " + maxPoolSize + " maxPoolIdle " + maxPoolIdle + " minPoolIdle " + minPoolIdle + " maxPoolWait " + maxPoolWait + " oracleOptions " + oracleOptions + " persistErrors " + persistErrors + " maxLatestErrors " + maxLatestErrors; + String configParams = " oracleHost " + oracleHost + " oraclePort " + oraclePort + " oracleUsername " + oracleUsername + " oraclePassword " + oraclePassword + " maxPoolSize " + maxPoolSize + " maxPoolIdle " + maxPoolIdle + " minPoolIdle " + minPoolIdle + " minPoolIdleTimeMillis " + minPoolIdleTimeMillis + " oracleOptions " + oracleOptions + " persistErrors " + persistErrors + " maxLatestErrors " + maxLatestErrors; LOGGER.error("Error while creating the OracleSQL persistence backend. " + "Config params= " + configParams + "Details=" + e.getMessage() + @@ -364,9 +364,9 @@ public void stop() { /** * Initialices a lazy singleton to share among instances on JVM */ - private void createPersistenceBackend(String sqlHost, String sqlPort, String sqlUsername, String sqlPassword, int maxPoolSize, int maxPoolIdle, int minPoolIdle, int maxPoolWait, String sqlOptions, boolean persistErrors, int maxLatestErrors) { + private void createPersistenceBackend(String sqlHost, String sqlPort, String sqlUsername, String sqlPassword, int maxPoolSize, int maxPoolIdle, int minPoolIdle, int minPoolIdleTimeMillis, String sqlOptions, boolean persistErrors, int maxLatestErrors) { if (oracleSQLPersistenceBackend == null) { - oracleSQLPersistenceBackend = new SQLBackendImpl(sqlHost, sqlPort, sqlUsername, sqlPassword, maxPoolSize, maxPoolIdle, minPoolIdle, maxPoolWait, ORACLE_INSTANCE_NAME, ORACLE_DRIVER_NAME, sqlOptions, persistErrors, maxLatestErrors); + oracleSQLPersistenceBackend = new SQLBackendImpl(sqlHost, sqlPort, sqlUsername, sqlPassword, maxPoolSize, maxPoolIdle, minPoolIdle, minPoolIdleTimeMillis, ORACLE_INSTANCE_NAME, ORACLE_DRIVER_NAME, sqlOptions, persistErrors, maxLatestErrors); oracleSQLPersistenceBackend.setNlsTimestampFormat(nlsTimestampFormat); oracleSQLPersistenceBackend.setNlsTimestampTzFormat(nlsTimestampTzFormat); } diff --git a/cygnus-ngsi/src/main/java/com/telefonica/iot/cygnus/sinks/NGSIPostgisSink.java b/cygnus-ngsi/src/main/java/com/telefonica/iot/cygnus/sinks/NGSIPostgisSink.java index aa49da94a..ce6335016 100644 --- a/cygnus-ngsi/src/main/java/com/telefonica/iot/cygnus/sinks/NGSIPostgisSink.java +++ b/cygnus-ngsi/src/main/java/com/telefonica/iot/cygnus/sinks/NGSIPostgisSink.java @@ -56,7 +56,7 @@ public class NGSIPostgisSink extends NGSISink { private static final int DEFAULT_MAX_POOL_SIZE = 3; private static final int DEFAULT_MAX_POOL_IDLE = 2; private static final int DEFAULT_MIN_POOL_IDLE = 0; - private static final int DEFAULT_MAX_POOL_WAIT = 10000; + private static final int DEFAULT_MIN_POOL_IDLE_TIME_MILLIS = 10000; private static final String DEFAULT_POSTGIS_TYPE = "geometry"; private static final String DEFAULT_ATTR_NATIVE_TYPES = "false"; private static final String POSTGIS_DRIVER_NAME = "org.postgresql.Driver"; @@ -80,7 +80,7 @@ public class NGSIPostgisSink extends NGSISink { private int maxPoolSize; private int maxPoolIdle; private int minPoolIdle; - private int maxPoolWait; + private int minPoolIdleTimeMillis; private SQLBackendImpl postgisPersistenceBackend; private boolean enableCache; private boolean swapCoordinates; @@ -230,8 +230,8 @@ public void configure(Context context) { minPoolIdle = context.getInteger("postgis_minPoolIdle", DEFAULT_MIN_POOL_IDLE); LOGGER.debug("[" + this.getName() + "] Reading configuration (postgis_minPoolIdle=" + minPoolIdle + ")"); - maxPoolWait = context.getInteger("postgis_maxPoolWait", DEFAULT_MAX_POOL_WAIT); - LOGGER.debug("[" + this.getName() + "] Reading configuration (postgis_maxPoolWait=" + maxPoolWait + ")"); + minPoolIdleTimeMillis = context.getInteger("postgis_minPoolIdleTimeMillis", DEFAULT_MIN_POOL_IDLE_TIME_MILLIS); + LOGGER.debug("[" + this.getName() + "] Reading configuration (postgis_minPoolIdleTimeMillis=" + minPoolIdleTimeMillis + ")"); rowAttrPersistence = context.getString("attr_persistence", DEFAULT_ROW_ATTR_PERSISTENCE).equals("row"); String persistence = context.getString("attr_persistence", DEFAULT_ROW_ATTR_PERSISTENCE); @@ -338,11 +338,11 @@ public void stop() { @Override public void start() { try { - createPersistenceBackend(postgisHost, postgisPort, postgisUsername, postgisPassword, maxPoolSize, maxPoolIdle, minPoolIdle, maxPoolWait, postgisOptions, persistErrors, maxLatestErrors); + createPersistenceBackend(postgisHost, postgisPort, postgisUsername, postgisPassword, maxPoolSize, maxPoolIdle, minPoolIdle, minPoolIdleTimeMillis, postgisOptions, persistErrors, maxLatestErrors); LOGGER.debug("[" + this.getName() + "] POSTGIS persistence backend created"); } catch (Exception e) { String configParams = " postgisHost " + postgisHost + " postgisPort " + postgisPort + " postgisUsername " + - postgisUsername + " postgisPassword " + postgisPassword + " maxPoolSize " + maxPoolSize + " maxPoolIdle " + maxPoolIdle + " minPoolIdle " + minPoolIdle + " maxPoolWait " + maxPoolWait + " postgisOptions " + + postgisUsername + " postgisPassword " + postgisPassword + " maxPoolSize " + maxPoolSize + " maxPoolIdle " + maxPoolIdle + " minPoolIdle " + minPoolIdle + " minPoolIdleTimeMillis " + minPoolIdleTimeMillis + " postgisOptions " + postgisOptions + " persistErrors " + persistErrors + " maxLatestErrors " + maxLatestErrors; LOGGER.error("Error while creating the Postgis persistence backend. " + "Config params= " + configParams + @@ -357,9 +357,9 @@ public void start() { /** * Initialices a lazy singleton to share among instances on JVM */ - private void createPersistenceBackend(String sqlHost, String sqlPort, String sqlUsername, String sqlPassword, int maxPoolSize, int maxPoolIdle, int minPoolIdle, int maxPoolWait, String sqlOptions, boolean persistErrors, int maxLatestErrors) { + private void createPersistenceBackend(String sqlHost, String sqlPort, String sqlUsername, String sqlPassword, int maxPoolSize, int maxPoolIdle, int minPoolIdle, int minPoolIdleTimeMillis, String sqlOptions, boolean persistErrors, int maxLatestErrors) { if (postgisPersistenceBackend == null) { - postgisPersistenceBackend = new SQLBackendImpl(sqlHost, sqlPort, sqlUsername, sqlPassword, maxPoolSize, maxPoolIdle, minPoolIdle, maxPoolWait, POSTGIS_INSTANCE_NAME, POSTGIS_DRIVER_NAME, sqlOptions, persistErrors, maxLatestErrors); + postgisPersistenceBackend = new SQLBackendImpl(sqlHost, sqlPort, sqlUsername, sqlPassword, maxPoolSize, maxPoolIdle, minPoolIdle, minPoolIdleTimeMillis, POSTGIS_INSTANCE_NAME, POSTGIS_DRIVER_NAME, sqlOptions, persistErrors, maxLatestErrors); } } diff --git a/cygnus-ngsi/src/main/java/com/telefonica/iot/cygnus/sinks/NGSIPostgreSQLSink.java b/cygnus-ngsi/src/main/java/com/telefonica/iot/cygnus/sinks/NGSIPostgreSQLSink.java index d9d31fe4a..79b176fd8 100644 --- a/cygnus-ngsi/src/main/java/com/telefonica/iot/cygnus/sinks/NGSIPostgreSQLSink.java +++ b/cygnus-ngsi/src/main/java/com/telefonica/iot/cygnus/sinks/NGSIPostgreSQLSink.java @@ -58,7 +58,7 @@ public class NGSIPostgreSQLSink extends NGSISink { private static final int DEFAULT_MAX_POOL_SIZE = 3; private static final int DEFAULT_MAX_POOL_IDLE = 2; private static final int DEFAULT_MIN_POOL_IDLE = 0; - private static final int DEFAULT_MAX_POOL_WAIT = 10000; + private static final int DEFAULT_MIN_POOL_IDLE_TIME_MILLIS = 10000; private static final String DEFAULT_ATTR_NATIVE_TYPES = "false"; private static final String POSTGRESQL_DRIVER_NAME = "org.postgresql.Driver"; private static final SQLInstance POSTGRESQL_INSTANCE_NAME = SQLInstance.POSTGRESQL; @@ -80,7 +80,7 @@ public class NGSIPostgreSQLSink extends NGSISink { private int maxPoolSize; private int maxPoolIdle; private int minPoolIdle; - private int maxPoolWait; + private int minPoolIdleTimeMillis; private boolean rowAttrPersistence; private SQLBackendImpl postgreSQLPersistenceBackend; private boolean enableCache; @@ -230,8 +230,8 @@ public void configure(Context context) { minPoolIdle = context.getInteger("postgresql_minPoolIdle", DEFAULT_MIN_POOL_IDLE); LOGGER.debug("[" + this.getName() + "] Reading configuration (postgresql_minPoolIdle=" + minPoolIdle + ")"); - maxPoolWait = context.getInteger("postgresql_maxPoolWait", DEFAULT_MAX_POOL_WAIT); - LOGGER.debug("[" + this.getName() + "] Reading configuration (postgresql_maxPoolWait=" + maxPoolWait + ")"); + minPoolIdleTimeMillis = context.getInteger("postgresql_minPoolIdleTimeMillis", DEFAULT_MIN_POOL_IDLE_TIME_MILLIS); + LOGGER.debug("[" + this.getName() + "] Reading configuration (postgresql_minPoolIdleTimeMillis=" + minPoolIdleTimeMillis + ")"); rowAttrPersistence = context.getString("attr_persistence", DEFAULT_ROW_ATTR_PERSISTENCE).equals("row"); String persistence = context.getString("attr_persistence", DEFAULT_ROW_ATTR_PERSISTENCE); @@ -330,12 +330,12 @@ public void configure(Context context) { @Override public void start() { try { - createPersistenceBackend(postgresqlHost, postgresqlPort, postgresqlUsername, postgresqlPassword, maxPoolSize, maxPoolIdle, minPoolIdle, maxPoolWait, postgresqlOptions, persistErrors, maxLatestErrors); + createPersistenceBackend(postgresqlHost, postgresqlPort, postgresqlUsername, postgresqlPassword, maxPoolSize, maxPoolIdle, minPoolIdle, minPoolIdleTimeMillis, postgresqlOptions, persistErrors, maxLatestErrors); LOGGER.debug("[" + this.getName() + "] Postgresql persistence backend created"); } catch (Exception e) { String configParams = " postgresqlHost " + postgresqlHost + " postgresqlPort " + postgresqlPort + " postgresqlUsername " + postgresqlUsername + " postgresqlPassword " + postgresqlPassword + - " maxPoolSize " + maxPoolSize + " maxPoolIdle " + maxPoolIdle + " minPoolIdle " + minPoolIdle + " maxPoolWait " + maxPoolWait + " postgresqlOptions " + + " maxPoolSize " + maxPoolSize + " maxPoolIdle " + maxPoolIdle + " minPoolIdle " + minPoolIdle + " minPoolIdleTimeMillis " + minPoolIdleTimeMillis + " postgresqlOptions " + postgresqlOptions + " persistErrors " + persistErrors + " maxLatestErrors " + maxLatestErrors; LOGGER.error("Error while creating the Postgresql persistence backend. " + "Config params= " + configParams + @@ -350,9 +350,9 @@ public void start() { /** * Initialices a lazy singleton to share among instances on JVM */ - private void createPersistenceBackend(String sqlHost, String sqlPort, String sqlUsername, String sqlPassword, int maxPoolSize, int maxPoolIdle, int minPoolIdle, int maxPoolWait, String sqlOptions, boolean persistErrors, int maxLatestErrors) { + private void createPersistenceBackend(String sqlHost, String sqlPort, String sqlUsername, String sqlPassword, int maxPoolSize, int maxPoolIdle, int minPoolIdle, int minPoolIdleTimeMillis, String sqlOptions, boolean persistErrors, int maxLatestErrors) { if (postgreSQLPersistenceBackend == null) { - postgreSQLPersistenceBackend = new SQLBackendImpl(sqlHost, sqlPort, sqlUsername, sqlPassword, maxPoolSize, maxPoolIdle, minPoolIdle, maxPoolWait, POSTGRESQL_INSTANCE_NAME, POSTGRESQL_DRIVER_NAME, sqlOptions, persistErrors, maxLatestErrors); + postgreSQLPersistenceBackend = new SQLBackendImpl(sqlHost, sqlPort, sqlUsername, sqlPassword, maxPoolSize, maxPoolIdle, minPoolIdle, minPoolIdleTimeMillis, POSTGRESQL_INSTANCE_NAME, POSTGRESQL_DRIVER_NAME, sqlOptions, persistErrors, maxLatestErrors); } }