Print proper name for TrustedListenableFutureTask in show-queue command
Since guava 19.0-rc0, MoreExecutors.listeningDecorator is wrapping tasks with TrustedListenableFutureTask instead of ListenableFutureTask. Adapt change done in I551a89e88 to work with new decorator class. Change-Id: I55488ddd8e1f7d13709744741767567496641028
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
package com.google.gerrit.server.git;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.util.concurrent.ListenableFutureTask;
|
||||
import com.google.gerrit.extensions.events.LifecycleListener;
|
||||
import com.google.gerrit.lifecycle.LifecycleModule;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
@@ -388,24 +387,29 @@ public class WorkQueue {
|
||||
@Override
|
||||
public String toString() {
|
||||
//This is a workaround to be able to print a proper name when the task
|
||||
//is wrapped into a ListenableFutureTask.
|
||||
if (runnable instanceof ListenableFutureTask<?>) {
|
||||
String errorMessage;
|
||||
try {
|
||||
for (Field field : ListenableFutureTask.class.getSuperclass()
|
||||
.getDeclaredFields()) {
|
||||
if (field.getType().isAssignableFrom(Callable.class)) {
|
||||
//is wrapped into a TrustedListenableFutureTask.
|
||||
try {
|
||||
if (runnable.getClass().isAssignableFrom(Class.forName(
|
||||
"com.google.common.util.concurrent.TrustedListenableFutureTask"))) {
|
||||
Class<?> trustedFutureInterruptibleTask = Class.forName(
|
||||
"com.google.common.util.concurrent.TrustedListenableFutureTask$TrustedFutureInterruptibleTask");
|
||||
for (Field field : runnable.getClass().getDeclaredFields()) {
|
||||
if (field.getType().isAssignableFrom(trustedFutureInterruptibleTask)) {
|
||||
field.setAccessible(true);
|
||||
return ((Callable<?>) field.get(runnable)).toString();
|
||||
Object innerObj = field.get(runnable);
|
||||
for (Field innerField : innerObj.getClass().getDeclaredFields()) {
|
||||
if (innerField.getType().isAssignableFrom(Callable.class)) {
|
||||
innerField.setAccessible(true);
|
||||
return ((Callable<?>) innerField.get(innerObj)).toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
errorMessage = "Cannot find wrapped Callable field";
|
||||
} catch (SecurityException | IllegalArgumentException
|
||||
| IllegalAccessException e) {
|
||||
errorMessage = "Cannot call toString on Callable field";
|
||||
}
|
||||
log.debug("Cannot get a proper name for ListenableFutureTask: {}",
|
||||
errorMessage);
|
||||
} catch (ClassNotFoundException | IllegalArgumentException
|
||||
| IllegalAccessException e) {
|
||||
log.debug("Cannot get a proper name for TrustedListenableFutureTask: {}",
|
||||
e.getMessage());
|
||||
}
|
||||
return runnable.toString();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user