/* * Decompiled with CFR 0.152. */ package com.google.common.util.concurrent; import com.google.common.base.Preconditions; import com.google.common.base.Supplier; import java.util.concurrent.Callable; import javax.annotation.Nullable; public final class Callables { private Callables() { } public static Callable returning(final @Nullable T value) { return new Callable(){ @Override public T call() { return value; } }; } static Callable threadRenaming(final Callable callable, final Supplier nameSupplier) { Preconditions.checkNotNull(nameSupplier); Preconditions.checkNotNull(callable); return new Callable(){ /* * WARNING - Removed try catching itself - possible behaviour change. */ @Override public T call() throws Exception { Thread currentThread = Thread.currentThread(); String oldName = currentThread.getName(); boolean restoreName = Callables.trySetName((String)nameSupplier.get(), currentThread); try { Object v = callable.call(); return v; } finally { if (restoreName) { Callables.trySetName(oldName, currentThread); } } } }; } static Runnable threadRenaming(final Runnable task, final Supplier nameSupplier) { Preconditions.checkNotNull(nameSupplier); Preconditions.checkNotNull(task); return new Runnable(){ /* * WARNING - Removed try catching itself - possible behaviour change. */ @Override public void run() { Thread currentThread = Thread.currentThread(); String oldName = currentThread.getName(); boolean restoreName = Callables.trySetName((String)nameSupplier.get(), currentThread); try { task.run(); } finally { if (restoreName) { Callables.trySetName(oldName, currentThread); } } } }; } private static boolean trySetName(String threadName, Thread currentThread) { try { currentThread.setName(threadName); return true; } catch (SecurityException e) { return false; } } }