public BootstrapSessionFactoryInvocationHandler(AsyncTaskExecutor bootstrapExecutor) { this.sessionFactoryFuture = bootstrapExecutor.submit( (Callable<SessionFactory>) LocalSessionFactoryBuilder.this::buildSessionFactory); }
public BootstrapSessionFactoryInvocationHandler(AsyncTaskExecutor bootstrapExecutor) { this.sessionFactoryFuture = bootstrapExecutor.submit( (Callable<SessionFactory>) LocalSessionFactoryBuilder.this::buildSessionFactory); }
/** * Delegate for actually executing the given task with the chosen executor. * @param task the task to execute * @param executor the chosen executor * @param returnType the declared return type (potentially a {@link Future} variant) * @return the execution result (potentially a corresponding {@link Future} handle) */ @Nullable protected Object doSubmit(Callable<Object> task, AsyncTaskExecutor executor, Class<?> returnType) { if (CompletableFuture.class.isAssignableFrom(returnType)) { return CompletableFuture.supplyAsync(() -> { try { return task.call(); } catch (Throwable ex) { throw new CompletionException(ex); } }, executor); } else if (ListenableFuture.class.isAssignableFrom(returnType)) { return ((AsyncListenableTaskExecutor) executor).submitListenable(task); } else if (Future.class.isAssignableFrom(returnType)) { return executor.submit(task); } else { executor.submit(task); return null; } }
public final Future<?> submit(Runnable task) { task = wrap(task); return getDelegate().submit(task); }
public final <T> Future<T> submit(Callable<T> task) { task = wrap(task); return getDelegate().submit(task); }
public final Future<?> submit(Runnable task) { task = wrap(task); return getDelegate().submit(task); }
public final <T> Future<T> submit(Callable<T> task) { task = wrap(task); return getDelegate().submit(task); }
/** * @param callback must not be {@literal null}. * @param nodes must not be {@literal null}. * @return never {@literal null}. * @throws ClusterCommandExecutionFailureException * @throws IllegalArgumentException in case the node could not be resolved to a topology-known node */ public <S, T> MultiNodeResult<T> executeCommandAsyncOnNodes(ClusterCommandCallback<S, T> callback, Iterable<RedisClusterNode> nodes) { Assert.notNull(callback, "Callback must not be null!"); Assert.notNull(nodes, "Nodes must not be null!"); List<RedisClusterNode> resolvedRedisClusterNodes = new ArrayList<>(); ClusterTopology topology = topologyProvider.getTopology(); for (RedisClusterNode node : nodes) { try { resolvedRedisClusterNodes.add(topology.lookup(node)); } catch (ClusterStateFailureException e) { throw new IllegalArgumentException(String.format("Node %s is unknown to cluster", node), e); } } Map<NodeExecution, Future<NodeResult<T>>> futures = new LinkedHashMap<>(); for (RedisClusterNode node : resolvedRedisClusterNodes) { futures.put(new NodeExecution(node), executor.submit(() -> executeCommandOnSingleNode(callback, node))); } return collectResults(futures); }
/** * Run {@link MultiKeyClusterCommandCallback} with on a curated set of nodes serving one or more keys. * * @param cmd must not be {@literal null}. * @return never {@literal null}. * @throws ClusterCommandExecutionFailureException */ public <S, T> MultiNodeResult<T> executeMultiKeyCommand(MultiKeyClusterCommandCallback<S, T> cmd, Iterable<byte[]> keys) { Map<RedisClusterNode, PositionalKeys> nodeKeyMap = new HashMap<>(); int index = 0; for (byte[] key : keys) { for (RedisClusterNode node : getClusterTopology().getKeyServingNodes(key)) { nodeKeyMap.computeIfAbsent(node, val -> PositionalKeys.empty()).append(PositionalKey.of(key, index++)); } } Map<NodeExecution, Future<NodeResult<T>>> futures = new LinkedHashMap<>(); for (Entry<RedisClusterNode, PositionalKeys> entry : nodeKeyMap.entrySet()) { if (entry.getKey().isMaster()) { for (PositionalKey key : entry.getValue()) { futures.put(new NodeExecution(entry.getKey(), key), executor.submit(() -> executeMultiKeyCommandOnSingleNode(cmd, entry.getKey(), key.getBytes()))); } } } return collectResults(futures); }
this.nativeEntityManagerFactoryFuture = bootstrapExecutor.submit(this::buildNativeEntityManagerFactory);
@SuppressWarnings("unchecked") @Test public void startCallableProcessingTimeoutAndCheckThreadInterrupted() throws Exception { StubCallable callable = new StubCallable(); Future future = mock(Future.class); AsyncTaskExecutor executor = mock(AsyncTaskExecutor.class); when(executor.submit(any(Runnable.class))).thenReturn(future); this.asyncManager.setTaskExecutor(executor); this.asyncManager.startCallableProcessing(callable); this.asyncWebRequest.onTimeout(ASYNC_EVENT); assertTrue(this.asyncManager.hasConcurrentResult()); verify(future).cancel(true); verifyNoMoreInteractions(future); }
@Test public void submitCallable() { executor.submit(callable); verify(getExecutor()).submit(wrappedCallable); }
@Test public void submit() { executor.submit(runnable); verify(getExecutor()).submit(wrappedRunnable); }
startAsyncProcessing(processingContext); try { Future<?> future = this.taskExecutor.submit(() -> { Object result = null; try {
@Test public void getObjectMultiThread() throws Exception { List<Future<StepContext>> stepContexts = new ArrayList<>(); AsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(); for(int i = 0; i < 4; i++) { final long count = i; stepContexts.add(executor.submit(new Callable<StepContext>() { @Override public StepContext call() throws Exception { try { StepSynchronizationManager.register(new StepExecution("step" + count, new JobExecution(count))); StepContext context = factory.getObject(); Thread.sleep(1000L); return context; } catch (Throwable ignore) { return null; }finally { StepSynchronizationManager.close(); } } })); } Set<StepContext> contexts = new HashSet<>(); for (Future<StepContext> future : stepContexts) { contexts.add(future.get()); } assertEquals(4, contexts.size()); }
jobContexts.add(executor.submit(new Callable<JobContext>() {
startAsyncProcessing(processingContext); try { Future<?> future = this.taskExecutor.submit(() -> { Object result = null; try {
this.nativeEntityManagerFactoryFuture = bootstrapExecutor.submit(this::buildNativeEntityManagerFactory);
stepContexts.add(executor.submit(new Callable<StepContext>() {
@SuppressWarnings("unchecked") @Test public void startCallableProcessingWithAsyncTask() throws Exception { AsyncTaskExecutor executor = mock(AsyncTaskExecutor.class); given(this.asyncWebRequest.getNativeRequest(HttpServletRequest.class)).willReturn(this.servletRequest); WebAsyncTask<Object> asyncTask = new WebAsyncTask<>(1000L, executor, mock(Callable.class)); this.asyncManager.startCallableProcessing(asyncTask); verify(executor).submit((Runnable) notNull()); verify(this.asyncWebRequest).setTimeout(1000L); verify(this.asyncWebRequest).addTimeoutHandler(any(Runnable.class)); verify(this.asyncWebRequest).addErrorHandler(any(Consumer.class)); verify(this.asyncWebRequest).addCompletionHandler(any(Runnable.class)); verify(this.asyncWebRequest).startAsync(); }