Experimental: Run I/O after commands in a new thread

This commit is contained in:
Luck 2016-10-26 17:55:38 +01:00
parent 0f04c06e13
commit 7deeaf305d
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
5 changed files with 44 additions and 22 deletions

View File

@ -162,32 +162,44 @@ public abstract class SubCommand<T> {
} }
public static void save(User user, Sender sender, LuckPermsPlugin plugin) { public static void save(User user, Sender sender, LuckPermsPlugin plugin) {
if (plugin.getDatastore().saveUser(user).getUnchecked()) { plugin.doAsync(() -> {
boolean success = plugin.getDatastore().saveUser(user).getUnchecked();
user.getRefreshBuffer().request().getUnchecked();
if (success) {
Message.USER_SAVE_SUCCESS.send(sender); Message.USER_SAVE_SUCCESS.send(sender);
} else { } else {
Message.USER_SAVE_ERROR.send(sender); Message.USER_SAVE_ERROR.send(sender);
} }
});
user.getRefreshBuffer().request().getUnchecked();
} }
public static void save(Group group, Sender sender, LuckPermsPlugin plugin) { public static void save(Group group, Sender sender, LuckPermsPlugin plugin) {
if (plugin.getDatastore().saveGroup(group).getUnchecked()) { plugin.doAsync(() -> {
boolean success = plugin.getDatastore().saveGroup(group).getUnchecked();
plugin.getUpdateTaskBuffer().request().getUnchecked();
if (success) {
Message.GROUP_SAVE_SUCCESS.send(sender); Message.GROUP_SAVE_SUCCESS.send(sender);
} else { } else {
Message.GROUP_SAVE_ERROR.send(sender); Message.GROUP_SAVE_ERROR.send(sender);
} }
});
plugin.getUpdateTaskBuffer().request();
} }
public static void save(Track track, Sender sender, LuckPermsPlugin plugin) { public static void save(Track track, Sender sender, LuckPermsPlugin plugin) {
if (plugin.getDatastore().saveTrack(track).getUnchecked()) { plugin.doAsync(() -> {
boolean success = plugin.getDatastore().saveTrack(track).getUnchecked();
plugin.getUpdateTaskBuffer().request().getUnchecked();
if (success) {
Message.TRACK_SAVE_SUCCESS.send(sender); Message.TRACK_SAVE_SUCCESS.send(sender);
} else { } else {
Message.TRACK_SAVE_ERROR.send(sender); Message.TRACK_SAVE_ERROR.send(sender);
} }
});
plugin.getUpdateTaskBuffer().request();
} }
} }

View File

@ -174,8 +174,10 @@ public class Importer {
} }
private void logMessage(String msg) { private void logMessage(String msg) {
if (executing != -1) {
getResult(executing, "").getOutput().add(Util.stripColor(msg)); getResult(executing, "").getOutput().add(Util.stripColor(msg));
} }
}
private static class FakeSender implements Sender { private static class FakeSender implements Sender {
private final Importer instance; private final Importer instance;

View File

@ -87,6 +87,11 @@ public class AbstractDatastore implements Datastore {
backing.doSync(r); backing.doSync(r);
} }
@Override
public Datastore force() {
return this;
}
@Override @Override
public void init() { public void init() {
backing.init(); backing.init();

View File

@ -52,9 +52,7 @@ public interface Datastore {
*/ */
void doSync(Runnable r); void doSync(Runnable r);
default Datastore force() { Datastore force();
return this;
}
void init(); void init();
void shutdown(); void shutdown();

View File

@ -74,6 +74,11 @@ public class TolerantDatastore implements Datastore {
backing.doSync(r); backing.doSync(r);
} }
@Override
public Datastore force() {
return this;
}
@Override @Override
public void init() { public void init() {
backing.init(); backing.init();