Cached ping executor
This commit is contained in:
@@ -34,7 +34,7 @@ public class Net{
|
||||
private final ObjectMap<Class<?>, Cons> clientListeners = new ObjectMap<>();
|
||||
private final ObjectMap<Class<?>, Cons2<NetConnection, Object>> serverListeners = new ObjectMap<>();
|
||||
private final IntMap<StreamBuilder> streams = new IntMap<>();
|
||||
private final ExecutorService pingExecutor = Threads.executor(Math.max(Runtime.getRuntime().availableProcessors(), 6));
|
||||
private final ExecutorService pingExecutor = Threads.cachedExecutor();
|
||||
|
||||
private final NetProvider provider;
|
||||
|
||||
@@ -326,13 +326,6 @@ public class Net{
|
||||
pingExecutor.submit(() -> provider.pingHost(address, port, valid, failed));
|
||||
}
|
||||
|
||||
/**
|
||||
* Pings a host in an new thread. If an error occurred, failed() should be called with the exception.
|
||||
*/
|
||||
public void pingHostThread(String address, int port, Cons<Host> valid, Cons<Exception> failed){
|
||||
Threads.daemon(() -> provider.pingHost(address, port, valid, failed));
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the net is active, e.g. whether this is a multiplayer game.
|
||||
*/
|
||||
|
||||
@@ -375,7 +375,7 @@ public class JoinDialog extends BaseDialog{
|
||||
for(String address : group.addresses){
|
||||
String resaddress = address.contains(":") ? address.split(":")[0] : address;
|
||||
int resport = address.contains(":") ? Strings.parseInt(address.split(":")[1]) : port;
|
||||
net.pingHostThread(resaddress, resport, res -> {
|
||||
net.pingHost(resaddress, resport, res -> {
|
||||
if(refreshes != cur) return;
|
||||
res.port = resport;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user