Skip to content

Commit

Permalink
update ngsild
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega committed Apr 11, 2024
1 parent 2ca53e6 commit 5eb6467
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public class NGSIPostgisSink extends NGSILDSink {
private static final String DEFAULT_DATABASE = "postgres";
private static final String DEFAULT_ENABLE_CACHE = "false";
private static final int DEFAULT_MAX_POOL_SIZE = 3;
private static final int DEFAULT_MAX_POOL_IDLE = 3;
private static final int DEFAULT_MIN_POOL_IDLE = 0;
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";
Expand All @@ -70,6 +72,8 @@ public class NGSIPostgisSink extends NGSILDSink {
private String postgisPassword;
private boolean rowAttrPersistence;
private int maxPoolSize;
private int maxPoolIdle;
private int minPoolIdle;
private SQLBackendImpl postgisPersistenceBackend;
private boolean enableCache;
private boolean swapCoordinates;
Expand Down Expand Up @@ -206,6 +210,12 @@ public void configure(Context context) {
maxPoolSize = context.getInteger("postgis_maxPoolSize", DEFAULT_MAX_POOL_SIZE);
LOGGER.debug("[" + this.getName() + "] Reading configuration (postgis_maxPoolSize=" + maxPoolSize + ")");

maxPoolIdle = context.getInteger("postgis_maxPoolIdle", DEFAULT_MAX_POOL_IDLE);
LOGGER.debug("[" + this.getName() + "] Reading configuration (postgis_maxPoolIdle=" + maxPoolIdle + ")");

minPoolIdle = context.getInteger("postgis_minPoolIdle", DEFAULT_MIN_POOL_IDLE);
LOGGER.debug("[" + this.getName() + "] Reading configuration (postgis_minPoolIdle=" + minPoolIdle + ")");

rowAttrPersistence = context.getString("attr_persistence", DEFAULT_ROW_ATTR_PERSISTENCE).equals("row");
String persistence = context.getString("attr_persistence", DEFAULT_ROW_ATTR_PERSISTENCE);

Expand Down Expand Up @@ -269,7 +279,7 @@ public void stop() {
@Override
public void start() {
try {
createPersistenceBackend(postgisHost, postgisPort, postgisUsername, postgisPassword, maxPoolSize, postgisOptions);
createPersistenceBackend(postgisHost, postgisPort, postgisUsername, postgisPassword, maxPoolSize, maxPoolIdle, minPoolIdle, postgisOptions);
} catch (Exception e) {
LOGGER.error("Error while creating the Postgis persistence backend. Details="
+ e.getMessage());
Expand All @@ -282,9 +292,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, String sqlOptions) {
private void createPersistenceBackend(String sqlHost, String sqlPort, String sqlUsername, String sqlPassword, int maxPoolSize, int maxPoolIdle, int minPoolIdle, String sqlOptions) {
if (postgisPersistenceBackend == null) {
postgisPersistenceBackend = new SQLBackendImpl(sqlHost, sqlPort, sqlUsername, sqlPassword, maxPoolSize, POSTGIS_INSTANCE_NAME, POSTGIS_DRIVER_NAME, sqlOptions);
postgisPersistenceBackend = new SQLBackendImpl(sqlHost, sqlPort, sqlUsername, sqlPassword, maxPoolSize, maxPoolIdle, minPoolIdle, POSTGIS_INSTANCE_NAME, POSTGIS_DRIVER_NAME, sqlOptions);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class NGSIPostgreSQLSink extends NGSILDSink {
private static final String DEFAULT_DATABASE = "postgres";
private static final String DEFAULT_ENABLE_CACHE = "false";
private static final int DEFAULT_MAX_POOL_SIZE = 3;
private static final int DEFAULT_MAX_POOL_IDLE = 3;
private static final int DEFAULT_MIN_POOL_IDLE = 0;
private static final String POSTGRESQL_DRIVER_NAME = "org.postgresql.Driver";
private static final SQLInstance POSTGRESQL_INSTANCE_NAME = SQLInstance.POSTGRESQL;

Expand All @@ -58,6 +60,8 @@ public class NGSIPostgreSQLSink extends NGSILDSink {
private String postgresqlUsername;
private String postgresqlPassword;
private int maxPoolSize;
private int maxPoolIdle;
private int minPoolIdle;
private boolean rowAttrPersistence;
private SQLBackendImpl postgreSQLPersistenceBackend;
private boolean enableCache;
Expand Down Expand Up @@ -184,6 +188,12 @@ public void configure(Context context) {
maxPoolSize = context.getInteger("postgresql_maxPoolSize", DEFAULT_MAX_POOL_SIZE);
LOGGER.debug("[" + this.getName() + "] Reading configuration (postgresql_maxPoolSize=" + maxPoolSize + ")");

maxPoolIdle = context.getInteger("postgresql_maxPoolIdle", DEFAULT_MAX_POOL_IDLE);
LOGGER.debug("[" + this.getName() + "] Reading configuration (postgresql_maxPoolIdle=" + maxPoolIdle + ")");

minPoolIdle = context.getInteger("postgresql_minPoolIdle", DEFAULT_MIN_POOL_IDLE);
LOGGER.debug("[" + this.getName() + "] Reading configuration (postgresql_minPoolIdle=" + minPoolIdle + ")");

rowAttrPersistence = context.getString("attr_persistence", DEFAULT_ROW_ATTR_PERSISTENCE).equals("row");
String persistence = context.getString("attr_persistence", DEFAULT_ROW_ATTR_PERSISTENCE);

Expand Down Expand Up @@ -213,7 +223,7 @@ public void configure(Context context) {
@Override
public void start() {
try {
createPersistenceBackend(postgresqlHost, postgresqlPort, postgresqlUsername, postgresqlPassword, maxPoolSize, postgresqlOptions);
createPersistenceBackend(postgresqlHost, postgresqlPort, postgresqlUsername, postgresqlPassword, maxPoolSize, maxPoolIdle, minPoolIdle, postgresqlOptions);
} catch (Exception e) {
LOGGER.error("Error while creating the PostgreSQL persistence backend. Details="
+ e.getMessage());
Expand All @@ -226,9 +236,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, String sqlOptions) {
private void createPersistenceBackend(String sqlHost, String sqlPort, String sqlUsername, String sqlPassword, int maxPoolSize, int maxPoolIdle, int minPoolIdle, String sqlOptions) {
if (postgreSQLPersistenceBackend == null) {
postgreSQLPersistenceBackend = new SQLBackendImpl(sqlHost, sqlPort, sqlUsername, sqlPassword, maxPoolSize, POSTGRESQL_INSTANCE_NAME, POSTGRESQL_DRIVER_NAME, sqlOptions);
postgreSQLPersistenceBackend = new SQLBackendImpl(sqlHost, sqlPort, sqlUsername, sqlPassword, maxPoolSize, maxPoolIdle, minPoolIdle, POSTGRESQL_INSTANCE_NAME, POSTGRESQL_DRIVER_NAME, sqlOptions);
}
}

Expand Down

0 comments on commit 5eb6467

Please sign in to comment.