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) {
if (plugin.getDatastore().saveUser(user).getUnchecked()) {
Message.USER_SAVE_SUCCESS.send(sender);
} else {
Message.USER_SAVE_ERROR.send(sender);
}
plugin.doAsync(() -> {
boolean success = plugin.getDatastore().saveUser(user).getUnchecked();
user.getRefreshBuffer().request().getUnchecked();
if (success) {
Message.USER_SAVE_SUCCESS.send(sender);
} else {
Message.USER_SAVE_ERROR.send(sender);
}
});
user.getRefreshBuffer().request().getUnchecked();
}
public static void save(Group group, Sender sender, LuckPermsPlugin plugin) {
if (plugin.getDatastore().saveGroup(group).getUnchecked()) {
Message.GROUP_SAVE_SUCCESS.send(sender);
} else {
Message.GROUP_SAVE_ERROR.send(sender);
}
plugin.doAsync(() -> {
boolean success = plugin.getDatastore().saveGroup(group).getUnchecked();
plugin.getUpdateTaskBuffer().request().getUnchecked();
if (success) {
Message.GROUP_SAVE_SUCCESS.send(sender);
} else {
Message.GROUP_SAVE_ERROR.send(sender);
}
});
plugin.getUpdateTaskBuffer().request();
}
public static void save(Track track, Sender sender, LuckPermsPlugin plugin) {
if (plugin.getDatastore().saveTrack(track).getUnchecked()) {
Message.TRACK_SAVE_SUCCESS.send(sender);
} else {
Message.TRACK_SAVE_ERROR.send(sender);
}
plugin.doAsync(() -> {
boolean success = plugin.getDatastore().saveTrack(track).getUnchecked();
plugin.getUpdateTaskBuffer().request().getUnchecked();
if (success) {
Message.TRACK_SAVE_SUCCESS.send(sender);
} else {
Message.TRACK_SAVE_ERROR.send(sender);
}
});
plugin.getUpdateTaskBuffer().request();
}
}

View File

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

View File

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

View File

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

View File

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