Add ViaRift name on thread, print exceptions

This commit is contained in:
creeper123123321 2018-08-26 16:59:13 -03:00
parent dec421ff61
commit 5ed38fbd5b
2 changed files with 23 additions and 5 deletions

View File

@ -30,6 +30,7 @@ import com.github.creeper123123321.viarift.platform.VRPlatform;
import com.github.creeper123123321.viarift.util.JLoggerToLog4j; import com.github.creeper123123321.viarift.util.JLoggerToLog4j;
import io.netty.channel.DefaultEventLoop; import io.netty.channel.DefaultEventLoop;
import io.netty.channel.EventLoop; import io.netty.channel.EventLoop;
import net.minecraft.util.NamedThreadFactory;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.dimdev.riftloader.listener.InitializationListener; import org.dimdev.riftloader.listener.InitializationListener;
@ -38,11 +39,16 @@ import org.spongepowered.asm.mixin.Mixins;
import us.myles.ViaVersion.ViaManager; import us.myles.ViaVersion.ViaManager;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
public class ViaRift implements InitializationListener { public class ViaRift implements InitializationListener {
public static int fakeServerVersion = -1; public static int fakeServerVersion = -1;
public static final Logger LOGGER = LogManager.getLogger(); public static final Logger LOGGER = LogManager.getLogger();
public static final java.util.logging.Logger JLOGGER = new JLoggerToLog4j(LOGGER); public static final java.util.logging.Logger JLOGGER = new JLoggerToLog4j(LOGGER);
public static final EventLoop EVENT_LOOP = new DefaultEventLoop(); public static final ThreadFactory THREAD_FACTORY = new NamedThreadFactory("ViaRift");
public static final EventLoop EVENT_LOOP = new DefaultEventLoop(THREAD_FACTORY);
@Override @Override
public void onInitialization() { public void onInitialization() {
MixinBootstrap.init(); MixinBootstrap.init();

View File

@ -68,24 +68,36 @@ public class VRPlatform implements ViaPlatform {
@Override @Override
public TaskId runAsync(Runnable runnable) { public TaskId runAsync(Runnable runnable) {
Thread t = new Thread(runnable, "ViaRift Async Task"); Thread t = ViaRift.THREAD_FACTORY.newThread(runnable);
t.start(); t.start();
return new ThreadTaskId(t); return new ThreadTaskId(t);
} }
@Override @Override
public TaskId runSync(Runnable runnable) { public TaskId runSync(Runnable runnable) {
return new FutureTaskId(ViaRift.EVENT_LOOP.submit(runnable)); return new FutureTaskId(ViaRift.EVENT_LOOP.submit(runnable).addListener(future -> {
if (!future.isSuccess()) {
future.cause().printStackTrace();
}
}));
} }
@Override @Override
public TaskId runSync(Runnable runnable, Long ticks) { public TaskId runSync(Runnable runnable, Long ticks) {
return new FutureTaskId(ViaRift.EVENT_LOOP.schedule(runnable, ticks * 50, TimeUnit.SECONDS)); return new FutureTaskId(ViaRift.EVENT_LOOP.schedule(runnable, ticks * 50, TimeUnit.SECONDS).addListener(future -> {
if (!future.isSuccess()) {
future.cause().printStackTrace();
}
}));
} }
@Override @Override
public TaskId runRepeatingSync(Runnable runnable, Long ticks) { public TaskId runRepeatingSync(Runnable runnable, Long ticks) {
return new FutureTaskId(ViaRift.EVENT_LOOP.scheduleAtFixedRate(runnable, 0, ticks * 50, TimeUnit.SECONDS)); return new FutureTaskId(ViaRift.EVENT_LOOP.scheduleAtFixedRate(runnable, 0, ticks * 50, TimeUnit.SECONDS).addListener(future -> {
if (!future.isSuccess()) {
future.cause().printStackTrace();
}
}));
} }
@Override @Override