/** convenience for setting "blocking details" on any task where the current thread is running; * typically invoked prior to a wait, for transparency to a user; * then invoked with 'null' just after the wait */ public static String setBlockingDetails(String description) { Task<?> current = current(); if (current instanceof TaskInternal) return ((TaskInternal<?>)current).setBlockingDetails(description); return null; } public static void resetBlockingDetails() {
/** convenience for setting "blocking details" on any task where the current thread is running, * while the passed code is executed; often used from groovy as * <pre>{@code withBlockingDetails("sleeping 5s") { Thread.sleep(5000); } }</pre> * If code block is null, the description is set until further notice (not cleareed). */ @SuppressWarnings("rawtypes") public static <T> T withBlockingDetails(String description, Callable<T> code) throws Exception { Task current = current(); if (code==null) { log.warn("legacy invocation of withBlockingDetails with null code block, ignoring"); return null; } String prevBlockingDetails = null; if (current instanceof TaskInternal) { prevBlockingDetails = ((TaskInternal)current).setBlockingDetails(description); } try { return code.call(); } finally { if (current instanceof TaskInternal) ((TaskInternal)current).setBlockingDetails(prevBlockingDetails); } }
@Override public String setBlockingDetails(String blockingDetails) { return delegate().setBlockingDetails(blockingDetails); }
String prevBlockingDetails = current.setBlockingDetails(blockingDetails); try { if (semaphore.tryAcquire(nextPeriod.toMilliseconds(), TimeUnit.MILLISECONDS)) { current.setBlockingDetails(prevBlockingDetails);