List of usage examples for java.util.concurrent Callable getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:org.glowroot.agent.plugin.executor.ExecutorAspect.java
private static <T> void onBeforeWithCallableHolder(ThreadContext context, ParameterHolder<Callable<T>> callableHolder) { Callable<T> callable = callableHolder.get(); if (callable instanceof RunnableEtcMixin) { onBeforeCommon(context, (RunnableEtcMixin) callable); } else if (callable != null && callable.getClass().getName().contains("$$Lambda$")) { wrapCallable(callableHolder, context); }/* w w w.j a v a 2 s . c o m*/ }
From source file:ch.sourcepond.utils.mdcwrapper.impl.DefaultMdcWrapper.java
@Override public <V> Callable<V> wrap(final Callable<V> pCallable) { notNull(pCallable, "Callable to be wrapped is null!"); // If the object is already a MDC-aware wrapper simply return it. if (MdcAwareCallable.class.equals(pCallable.getClass())) { return pCallable; }// ww w .ja v a2s . c om return new MdcAwareCallable<>(pCallable); }
From source file:com.linkedin.helix.TestHelper.java
public static <T> Map<String, T> startThreadsConcurrently(final List<Callable<T>> methods, final long timeout) { final int nrThreads = methods.size(); final CountDownLatch startLatch = new CountDownLatch(1); final CountDownLatch finishCounter = new CountDownLatch(nrThreads); final Map<String, T> resultsMap = new ConcurrentHashMap<String, T>(); final List<Thread> threadList = new ArrayList<Thread>(); for (int i = 0; i < nrThreads; i++) { final Callable<T> method = methods.get(i); Thread thread = new Thread() { @Override/*from w w w . jav a 2 s. co m*/ public void run() { try { boolean isTimeout = !startLatch.await(timeout, TimeUnit.SECONDS); if (isTimeout) { LOG.error("Timeout while waiting for start latch"); } } catch (InterruptedException ex) { LOG.error("Interrupted while waiting for start latch"); } try { T result = method.call(); if (result != null) { resultsMap.put("thread_" + this.getId(), result); } LOG.debug("result=" + result); } catch (Exception e) { LOG.error("Exeption in executing " + method.getClass().getName(), e); } finishCounter.countDown(); } }; threadList.add(thread); thread.start(); } startLatch.countDown(); // wait for all thread to complete try { boolean isTimeout = !finishCounter.await(timeout, TimeUnit.SECONDS); if (isTimeout) { LOG.error("Timeout while waiting for finish latch. Interrupt all threads"); for (Thread thread : threadList) { thread.interrupt(); } } } catch (InterruptedException e) { LOG.error("Interrupted while waiting for finish latch", e); } return resultsMap; }
From source file:com.linkedin.helix.TestHelper.java
public static <T> Map<String, T> startThreadsConcurrently(final int nrThreads, final Callable<T> method, final long timeout) { final CountDownLatch startLatch = new CountDownLatch(1); final CountDownLatch finishCounter = new CountDownLatch(nrThreads); final Map<String, T> resultsMap = new ConcurrentHashMap<String, T>(); final List<Thread> threadList = new ArrayList<Thread>(); for (int i = 0; i < nrThreads; i++) { Thread thread = new Thread() { @Override/*from w ww. j a v a2s.c o m*/ public void run() { try { boolean isTimeout = !startLatch.await(timeout, TimeUnit.SECONDS); if (isTimeout) { LOG.error("Timeout while waiting for start latch"); } } catch (InterruptedException ex) { LOG.error("Interrupted while waiting for start latch"); } try { T result = method.call(); if (result != null) { resultsMap.put("thread_" + this.getId(), result); } LOG.debug("result=" + result); } catch (Exception e) { LOG.error("Exeption in executing " + method.getClass().getName(), e); } finishCounter.countDown(); } }; threadList.add(thread); thread.start(); } startLatch.countDown(); // wait for all thread to complete try { boolean isTimeout = !finishCounter.await(timeout, TimeUnit.SECONDS); if (isTimeout) { LOG.error("Timeout while waiting for finish latch. Interrupt all threads"); for (Thread thread : threadList) { thread.interrupt(); } } } catch (InterruptedException e) { LOG.error("Interrupted while waiting for finish latch", e); } return resultsMap; }
From source file:org.geowebcache.diskquota.bdb.BDBQuotaStore.java
/** * Synchronously issues the given {@code command} to the working transactional thread * /*from www . j a va 2s. c o m*/ * @throws InterruptedException * in case the calling thread was interrupted while waiting for the command to * complete */ private <E> E issueSync(final Callable<E> command) throws InterruptedException { Future<E> result = issue(command); try { return result.get(); } catch (RuntimeException e) { throw e; } catch (InterruptedException e) { log.debug( "Caught InterruptedException while waiting for command " + command.getClass().getSimpleName()); throw e; } catch (ExecutionException e) { log.warn(e); Throwable cause = e.getCause(); if (cause instanceof RuntimeException) { throw (RuntimeException) cause; } throw new RuntimeException(cause); } }
From source file:org.diorite.impl.scheduler.DioriteFuture.java
DioriteFuture(final Callable<T> callable, final DioritePlugin dioritePlugin, final Synchronizable sync, final int id) { super(callable.getClass().getName() + "@" + System.identityHashCode(callable), dioritePlugin, null, sync, false, id, STATE_SINGLE);/*from w w w. ja v a 2s.c o m*/ this.callable = callable; }
From source file:org.force66.circuit.Circuit.java
public T invoke(Callable<T> operation) { Validate.notNull(operation, "Null operation not allowed."); if (!circuitBreakerAlgorithm.isExecutionAllowed()) { throw new CircuitException("Operation not available.") .addContextValue("callable class", operation.getClass().getName()) .addContextValue("callable", operation.toString()); }/*from w w w .ja va2s . c o m*/ try { T output = operation.call(); circuitBreakerAlgorithm.reportExecutionSuccess(); return output; } catch (Exception e) { circuitBreakerAlgorithm.reportExecutionFailure(e); throw new CircuitException(e).addContextValue("callable class", operation.getClass().getName()) .addContextValue("callable", operation.toString()); } }
From source file:org.force66.insanity.RetryManager.java
public T invoke(Callable<T> operation) { Validate.notNull(operation, "Null operation not allowed."); int nbrTries = 0; Exception lastFailure = null; retryAlgorithm.reset();// w w w .java 2s. co m while (retryAlgorithm.isExecutionAllowed()) { nbrTries++; try { T output = operation.call(); return output; } catch (Exception e) { lastFailure = e; retryAlgorithm.reportExecutionFailure(e); } } throw new RetryException("invocation not successful.", lastFailure) .addContextValue("callable class", operation.getClass().getName()) .addContextValue("callable", operation.toString()).addContextValue("nbrTries", nbrTries); }