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<?>, Cons> clientListeners = new ObjectMap<>();
|
||||||
private final ObjectMap<Class<?>, Cons2<NetConnection, Object>> serverListeners = new ObjectMap<>();
|
private final ObjectMap<Class<?>, Cons2<NetConnection, Object>> serverListeners = new ObjectMap<>();
|
||||||
private final IntMap<StreamBuilder> streams = new IntMap<>();
|
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;
|
private final NetProvider provider;
|
||||||
|
|
||||||
@@ -326,13 +326,6 @@ public class Net{
|
|||||||
pingExecutor.submit(() -> provider.pingHost(address, port, valid, failed));
|
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.
|
* 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){
|
for(String address : group.addresses){
|
||||||
String resaddress = address.contains(":") ? address.split(":")[0] : address;
|
String resaddress = address.contains(":") ? address.split(":")[0] : address;
|
||||||
int resport = address.contains(":") ? Strings.parseInt(address.split(":")[1]) : port;
|
int resport = address.contains(":") ? Strings.parseInt(address.split(":")[1]) : port;
|
||||||
net.pingHostThread(resaddress, resport, res -> {
|
net.pingHost(resaddress, resport, res -> {
|
||||||
if(refreshes != cur) return;
|
if(refreshes != cur) return;
|
||||||
res.port = resport;
|
res.port = resport;
|
||||||
|
|
||||||
|
|||||||
@@ -10,4 +10,4 @@ kapt.include.compile.classpath=false
|
|||||||
kotlin.stdlib.default.dependency=false
|
kotlin.stdlib.default.dependency=false
|
||||||
#needed for android compilation
|
#needed for android compilation
|
||||||
android.useAndroidX=true
|
android.useAndroidX=true
|
||||||
archash=41de08d2d3c2f415e1965b66cf9aab3c9950477d
|
archash=b5d3986d159cc42f2b38da24682ad0cc19c6c656
|
||||||
|
|||||||
Reference in New Issue
Block a user