Remove the isAcceptingLogins storage state in favour of just throwing exceptions on usage
This commit is contained in:
@@ -61,7 +61,7 @@ public class ApiStorage implements Storage {
|
||||
|
||||
@Override
|
||||
public boolean isAcceptingLogins() {
|
||||
return handle.isAcceptingLogins();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -28,7 +28,6 @@ package me.lucko.luckperms.common.storage;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.experimental.Delegate;
|
||||
|
||||
import me.lucko.luckperms.api.HeldPermission;
|
||||
import me.lucko.luckperms.api.LogEntry;
|
||||
@@ -64,8 +63,6 @@ public class AbstractStorage implements Storage {
|
||||
}
|
||||
|
||||
private final LuckPermsPlugin plugin;
|
||||
|
||||
@Delegate(types = Delegated.class)
|
||||
private final AbstractDao dao;
|
||||
|
||||
@Getter
|
||||
@@ -81,11 +78,41 @@ public class AbstractStorage implements Storage {
|
||||
return CompletableFuture.supplyAsync(supplier, dao.getPlugin().getScheduler().async());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return dao.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Storage noBuffer() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
try {
|
||||
dao.init();
|
||||
} catch (Exception e) {
|
||||
plugin.getLog().severe("Failed to init storage dao");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
try {
|
||||
dao.shutdown();
|
||||
} catch (Exception e) {
|
||||
plugin.getLog().severe("Failed to shutdown storage dao");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getMeta() {
|
||||
return dao.getMeta();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> logAction(LogEntry entry) {
|
||||
return makeFuture(() -> dao.logAction(entry));
|
||||
@@ -259,13 +286,4 @@ public class AbstractStorage implements Storage {
|
||||
public CompletableFuture<String> getName(UUID uuid) {
|
||||
return makeFuture(() -> dao.getName(uuid));
|
||||
}
|
||||
|
||||
private interface Delegated {
|
||||
String getName();
|
||||
boolean isAcceptingLogins();
|
||||
void setAcceptingLogins(boolean b);
|
||||
void init();
|
||||
void shutdown();
|
||||
Map<String, String> getMeta();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,10 +51,6 @@ public interface Storage {
|
||||
|
||||
String getName();
|
||||
|
||||
boolean isAcceptingLogins();
|
||||
|
||||
void setAcceptingLogins(boolean acceptingLogins);
|
||||
|
||||
Storage noBuffer();
|
||||
|
||||
void init();
|
||||
|
||||
@@ -28,7 +28,6 @@ package me.lucko.luckperms.common.storage.dao;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import me.lucko.luckperms.api.HeldPermission;
|
||||
import me.lucko.luckperms.api.LogEntry;
|
||||
@@ -54,10 +53,6 @@ public abstract class AbstractDao {
|
||||
@Getter
|
||||
public final String name;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean acceptingLogins = false;
|
||||
|
||||
public abstract void init();
|
||||
|
||||
public abstract void shutdown();
|
||||
|
||||
@@ -54,12 +54,18 @@ public class SplitStorageDao extends AbstractDao {
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
boolean success = true;
|
||||
boolean failed = false;
|
||||
for (AbstractDao ds : backing.values()) {
|
||||
ds.init();
|
||||
success = success && ds.isAcceptingLogins();
|
||||
try {
|
||||
ds.init();
|
||||
} catch (Exception ex) {
|
||||
failed = true;
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (failed) {
|
||||
throw new RuntimeException("One of the backing failed to init");
|
||||
}
|
||||
setAcceptingLogins(success);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -192,8 +192,6 @@ public abstract class ConfigurateDao extends AbstractDao {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
setAcceptingLogins(true);
|
||||
}
|
||||
|
||||
private static void mkdir(File file) throws IOException {
|
||||
|
||||
@@ -117,7 +117,6 @@ public class MongoDao extends AbstractDao {
|
||||
}
|
||||
|
||||
database = mongoClient.getDatabase(configuration.getDatabase());
|
||||
setAcceptingLogins(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -207,10 +207,9 @@ public class SqlDao extends AbstractDao {
|
||||
}
|
||||
}
|
||||
|
||||
setAcceptingLogins(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
plugin.getLog().severe("Error occurred whilst initialising the database.");
|
||||
e.printStackTrace();
|
||||
shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
+4
@@ -91,6 +91,10 @@ public abstract class HikariConnectionFactory extends AbstractConnectionFactory
|
||||
// The drivers are really old in some of the older Spigot binaries, so Connection#isValid doesn't work.
|
||||
config.setConnectionTestQuery("/* LuckPerms ping */ SELECT 1");
|
||||
|
||||
// don't perform any initial connection validation - we subsequently call #getConnection
|
||||
// to setup the schema anyways
|
||||
config.setInitializationFailTimeout(-1);
|
||||
|
||||
hikari = new HikariDataSource(config);
|
||||
}
|
||||
|
||||
|
||||
+20
-11
@@ -27,7 +27,6 @@ package me.lucko.luckperms.common.storage.wrappings;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.experimental.Delegate;
|
||||
|
||||
import me.lucko.luckperms.api.HeldPermission;
|
||||
import me.lucko.luckperms.api.LogEntry;
|
||||
@@ -59,16 +58,30 @@ public class PhasedStorage implements Storage {
|
||||
return new PhasedStorage(storage);
|
||||
}
|
||||
|
||||
@Delegate(types = Delegated.class)
|
||||
private final Storage delegate;
|
||||
|
||||
private final Phaser phaser = new Phaser();
|
||||
|
||||
@Override
|
||||
public ApiStorage getDelegate() {
|
||||
return delegate.getDelegate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return delegate.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Storage noBuffer() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
delegate.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
// Wait for other threads to finish.
|
||||
@@ -81,6 +94,11 @@ public class PhasedStorage implements Storage {
|
||||
delegate.shutdown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getMeta() {
|
||||
return delegate.getMeta();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> logAction(LogEntry entry) {
|
||||
phaser.register();
|
||||
@@ -290,13 +308,4 @@ public class PhasedStorage implements Storage {
|
||||
phaser.arriveAndDeregister();
|
||||
}
|
||||
}
|
||||
|
||||
private interface Delegated {
|
||||
ApiStorage getDelegate();
|
||||
String getName();
|
||||
boolean isAcceptingLogins();
|
||||
void setAcceptingLogins(boolean b);
|
||||
void init();
|
||||
Map<String, String> getMeta();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user