From 731d21deb750dc668c632cb94c4f9a08b9db39d5 Mon Sep 17 00:00:00 2001 From: PikaMug <2267126+PikaMug@users.noreply.github.com> Date: Sun, 9 Jan 2022 12:14:33 -0500 Subject: [PATCH] Add keepalive property to config, part 1 --- .../quests/storage/StorageFactory.java | 18 +++++++++--------- .../hikari/HikariConnectionFactory.java | 1 + .../storage/misc/StorageCredentials.java | 10 ++++++++-- api/src/main/resources/config.yml | 4 ++++ 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/api/src/main/java/me/blackvein/quests/storage/StorageFactory.java b/api/src/main/java/me/blackvein/quests/storage/StorageFactory.java index f766b77cb..9dc794ca0 100644 --- a/api/src/main/java/me/blackvein/quests/storage/StorageFactory.java +++ b/api/src/main/java/me/blackvein/quests/storage/StorageFactory.java @@ -12,7 +12,6 @@ package me.blackvein.quests.storage; -import com.google.common.collect.ImmutableSet; import me.blackvein.quests.Quests; import me.blackvein.quests.storage.implementation.StorageImplementation; import me.blackvein.quests.storage.implementation.custom.CustomStorageProviders; @@ -23,8 +22,8 @@ import me.blackvein.quests.storage.misc.StorageCredentials; import org.bukkit.configuration.file.FileConfiguration; import java.io.File; -import java.util.Collections; -import java.util.Set; +import java.util.HashMap; +import java.util.Map; public class StorageFactory { private final Quests plugin; @@ -33,11 +32,6 @@ public class StorageFactory { this.plugin = plugin; } - public Set getRequiredTypes() { - return ImmutableSet.of(StorageType.parse(plugin.getConfig().getString("storage-method.player-data", "yaml"), - StorageType.YAML)); - } - public Storage getInstance() { final Storage storage; final StorageType type = StorageType.parse(plugin.getConfig().getString("storage-method.player-data", "yaml"), @@ -71,14 +65,20 @@ public class StorageFactory { fc.getInt("storage-data.pool-size", 10)); final int minIdle = fc.getInt("storage-data.pool-settings.min-idle", maxPoolSize); final int maxLifetime = fc.getInt("storage-data.pool-settings.max-lifetime", 1800000); + final int keepAliveTime = fc.getInt("storage-data.pool-settings.keepalive-time", 0); final int connectionTimeout = fc.getInt("storage-data.pool-settings.connection-timeout", 5000); + final boolean useUnicode = fc.getBoolean("storage-data.pool-settings.properties.useUnicode", true); + final String characterEncoding = fc.getString("storage-data.pool-settings.properties.characterEncoding", "utf8"); + Map props = new HashMap<>(); + props.put("useUnicode", String.valueOf(useUnicode)); + props.put("characterEncoding", characterEncoding); return new StorageCredentials( fc.getString("storage-data.address", null), fc.getString("storage-data.database", null), fc.getString("storage-data.username", null), fc.getString("storage-data.password", null), - maxPoolSize, minIdle, maxLifetime, connectionTimeout, Collections.singletonMap("true", "utf8") + maxPoolSize, minIdle, maxLifetime, keepAliveTime, connectionTimeout, props ); } } diff --git a/api/src/main/java/me/blackvein/quests/storage/implementation/sql/connection/hikari/HikariConnectionFactory.java b/api/src/main/java/me/blackvein/quests/storage/implementation/sql/connection/hikari/HikariConnectionFactory.java index 74be1f8fc..90d8bbbff 100644 --- a/api/src/main/java/me/blackvein/quests/storage/implementation/sql/connection/hikari/HikariConnectionFactory.java +++ b/api/src/main/java/me/blackvein/quests/storage/implementation/sql/connection/hikari/HikariConnectionFactory.java @@ -101,6 +101,7 @@ public abstract class HikariConnectionFactory implements ConnectionFactory { config.setMaximumPoolSize(this.configuration.getMaxPoolSize()); config.setMinimumIdle(this.configuration.getMinIdleConnections()); config.setMaxLifetime(this.configuration.getMaxLifetime()); + //config.setKeepaliveTime(this.configuration.getKeepAliveTime()); config.setConnectionTimeout(this.configuration.getConnectionTimeout()); hikari = new HikariDataSource(config); diff --git a/api/src/main/java/me/blackvein/quests/storage/misc/StorageCredentials.java b/api/src/main/java/me/blackvein/quests/storage/misc/StorageCredentials.java index 01e5ed942..a3a85fd5c 100644 --- a/api/src/main/java/me/blackvein/quests/storage/misc/StorageCredentials.java +++ b/api/src/main/java/me/blackvein/quests/storage/misc/StorageCredentials.java @@ -24,12 +24,13 @@ public class StorageCredentials { private final int maxPoolSize; private final int minIdleConnections; private final int maxLifetime; + private final int keepAliveTime; private final int connectionTimeout; private final Map properties; public StorageCredentials(final String address, final String database, final String username, final String password, - final int maxPoolSize, final int minIdleConnections, final int maxLifetime, final int connectionTimeout, - final Map properties) { + final int maxPoolSize, final int minIdleConnections, final int maxLifetime, final int keepAliveTime, + final int connectionTimeout, final Map properties) { this.address = address; this.database = database; this.username = username; @@ -37,6 +38,7 @@ public class StorageCredentials { this.maxPoolSize = maxPoolSize; this.minIdleConnections = minIdleConnections; this.maxLifetime = maxLifetime; + this.keepAliveTime = keepAliveTime; this.connectionTimeout = connectionTimeout; this.properties = properties; } @@ -69,6 +71,10 @@ public class StorageCredentials { return maxLifetime; } + public int getKeepAliveTime() { + return keepAliveTime; + } + public int getConnectionTimeout() { return connectionTimeout; } diff --git a/api/src/main/resources/config.yml b/api/src/main/resources/config.yml index 92ec737d1..a3762b8df 100644 --- a/api/src/main/resources/config.yml +++ b/api/src/main/resources/config.yml @@ -29,7 +29,11 @@ storage-data: max-pool-size: 10 min-idle: 10 max-lifetime: 1800000 + keepalive-time: 0 connection-timeout: 5000 + properties: + useUnicode: true + characterEncoding: utf8 storage-method: player-data: yaml trial-save: false