improve logging of happy eyeball
This commit is contained in:
parent
0e32326d22
commit
8f8e8a6acf
|
@ -136,14 +136,12 @@ public class Resolver {
|
||||||
threads[2].interrupt();
|
threads[2].interrupt();
|
||||||
synchronized (results) {
|
synchronized (results) {
|
||||||
Collections.sort(results);
|
Collections.sort(results);
|
||||||
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": " + results.toString());
|
|
||||||
return happyEyeball(results);
|
return happyEyeball(results);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
threads[2].join();
|
threads[2].join();
|
||||||
synchronized (fallbackResults) {
|
synchronized (fallbackResults) {
|
||||||
Collections.sort(fallbackResults);
|
Collections.sort(fallbackResults);
|
||||||
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": " + fallbackResults.toString());
|
|
||||||
return happyEyeball(fallbackResults);
|
return happyEyeball(fallbackResults);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -262,15 +260,22 @@ public class Resolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Result happyEyeball(List<Result> r) {
|
private static Result happyEyeball(List<Result> r) {
|
||||||
|
String logID = Long.toHexString(Double.doubleToLongBits(Math.random()));
|
||||||
|
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": happy eyeball (" + logID + ") with " + r.toString());
|
||||||
if (r.size() == 0) return null;
|
if (r.size() == 0) return null;
|
||||||
|
|
||||||
Result result;
|
Result result;
|
||||||
if (r.size() == 1) {
|
if (r.size() == 1) {
|
||||||
result = r.get(0);
|
result = r.get(0);
|
||||||
|
result.setLogID(logID);
|
||||||
result.connect();
|
result.connect();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (Result result in r) {
|
||||||
|
result.setLogID(logID);
|
||||||
|
}
|
||||||
|
|
||||||
ExecutorService executor = (ExecutorService) Executors.newFixedThreadPool(4);
|
ExecutorService executor = (ExecutorService) Executors.newFixedThreadPool(4);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -280,22 +285,22 @@ public class Resolver {
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
if (executor.awaitTermination(5, TimeUnit.SECONDS)) break;
|
if (executor.awaitTermination(5, TimeUnit.SECONDS)) break;
|
||||||
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": happy eyeball wait for cleanup ...");
|
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": happy eyeball (" + logID + ") wait for cleanup ...");
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
}
|
}
|
||||||
Log.i(Config.LOGTAG, Resolver.class.getSimpleName() + ": happy eyeball cleanup");
|
Log.i(Config.LOGTAG, Resolver.class.getSimpleName() + ": happy eyeball (" + logID + ") cleanup");
|
||||||
for (Result re : r) {
|
for (Result re : r) {
|
||||||
if(!re.equals(result)) re.disconnect();
|
if(!re.equals(result)) re.disconnect();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
disconnector.start();
|
disconnector.start();
|
||||||
Log.i(Config.LOGTAG, Resolver.class.getSimpleName() + ": happy eyeball used: " + result.toString());
|
Log.i(Config.LOGTAG, Resolver.class.getSimpleName() + ": happy eyeball (" + logID + ") used: " + result.toString());
|
||||||
return result;
|
return result;
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Log.e(Config.LOGTAG, Resolver.class.getSimpleName() + ": happy eyeball failed: ", e);
|
Log.e(Config.LOGTAG, Resolver.class.getSimpleName() + ": happy eyeball (" + logID + ") failed: ", e);
|
||||||
return null;
|
return null;
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
Log.i(Config.LOGTAG, Resolver.class.getSimpleName() + ": happy eyeball unable to connect to one address");
|
Log.i(Config.LOGTAG, Resolver.class.getSimpleName() + ": happy eyeball (" + logID + ") unable to connect to one address");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -320,6 +325,8 @@ public class Resolver {
|
||||||
private int priority;
|
private int priority;
|
||||||
private Socket socket;
|
private Socket socket;
|
||||||
|
|
||||||
|
private String logID;
|
||||||
|
|
||||||
static Result fromRecord(SRV srv, boolean directTls) {
|
static Result fromRecord(SRV srv, boolean directTls) {
|
||||||
Result result = new Result();
|
Result result = new Result();
|
||||||
result.port = srv.port;
|
result.port = srv.port;
|
||||||
|
@ -401,7 +408,11 @@ public class Resolver {
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
this.socket.connect(addr, Config.SOCKET_TIMEOUT * 1000);
|
this.socket.connect(addr, Config.SOCKET_TIMEOUT * 1000);
|
||||||
time = System.currentTimeMillis() - time;
|
time = System.currentTimeMillis() - time;
|
||||||
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": Result connect: " + toString() + " after: " + time + " ms");
|
if (!this.logID.isEmpty()) {
|
||||||
|
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": Result (" + this.logID + ") connect: " + toString() + " after: " + time + " ms");
|
||||||
|
} else {
|
||||||
|
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": Result connect: " + toString() + " after: " + time + " ms");
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
this.disconnect();
|
this.disconnect();
|
||||||
}
|
}
|
||||||
|
@ -411,7 +422,11 @@ public class Resolver {
|
||||||
if (this.socket != null ) {
|
if (this.socket != null ) {
|
||||||
FileBackend.close(this.socket);
|
FileBackend.close(this.socket);
|
||||||
this.socket = null;
|
this.socket = null;
|
||||||
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": Result disconnect: " + toString());
|
if (!this.logID.isEmpty()) {
|
||||||
|
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": Result (" + this.logID + ") disconnect: " + toString());
|
||||||
|
} else {
|
||||||
|
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": Result disconnect: " + toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,6 +451,10 @@ public class Resolver {
|
||||||
throw new Exception("Resolver.Result was not possible to connect - should be catched by executor");
|
throw new Exception("Resolver.Result was not possible to connect - should be catched by executor");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLogID(String logID) {
|
||||||
|
this.logID = logID;
|
||||||
|
}
|
||||||
|
|
||||||
public ContentValues toContentValues() {
|
public ContentValues toContentValues() {
|
||||||
final ContentValues contentValues = new ContentValues();
|
final ContentValues contentValues = new ContentValues();
|
||||||
contentValues.put(IP, ip == null ? null : ip.getAddress());
|
contentValues.put(IP, ip == null ? null : ip.getAddress());
|
||||||
|
|
Loading…
Reference in New Issue