public BootstrapSessionFactoryInvocationHandler(AsyncTaskExecutor bootstrapExecutor) { this.sessionFactoryFuture = bootstrapExecutor.submit( (Callable<SessionFactory>) LocalSessionFactoryBuilder.this::buildSessionFactory); }
public final void execute(Runnable task, long startTimeout) { task = wrap(task); getDelegate().execute(task, startTimeout); }
public BootstrapSessionFactoryInvocationHandler(AsyncTaskExecutor bootstrapExecutor) { this.sessionFactoryFuture = bootstrapExecutor.submit( (Callable<SessionFactory>) LocalSessionFactoryBuilder.this::buildSessionFactory); }
public final void execute(Runnable task, long startTimeout) { task = wrap(task); getDelegate().execute(task, startTimeout); }
/** * 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; } }
@Test public void executeStartTimeout() { executor.execute(runnable, 1); verify(getExecutor()).execute(wrappedRunnable, 1); }
public final Future<?> submit(Runnable task) { task = wrap(task); return getDelegate().submit(task); }
try { if (isAsync) { ((AsyncTaskExecutor) taskExecutor).execute(workHandle, startTimeout);
public final <T> Future<T> submit(Callable<T> task) { task = wrap(task); return getDelegate().submit(task); }
try { if (isAsync) { ((AsyncTaskExecutor) taskExecutor).execute(workHandle, startTimeout);
public final Future<?> submit(Runnable task) { task = wrap(task); return getDelegate().submit(task); }
final CountDownLatch latch3 = new CountDownLatch(1); lock1.lockInterruptibly(); this.taskExecutor.execute(() -> { Lock lock2 = JdbcLockRegistryTests.this.registry.obtain("foo"); try {
public final <T> Future<T> submit(Callable<T> task) { task = wrap(task); return getDelegate().submit(task); }
final CountDownLatch latch3 = new CountDownLatch(1); lock1.lockInterruptibly(); this.taskExecutor.execute(() -> { Lock lock2 = registry2.obtain("foo"); try {
/** * @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); }
@Test public void testByteArrayBlocksForZeroRead() throws Exception { SocketChannel socketChannel = mock(SocketChannel.class); Socket socket = mock(Socket.class); when(socketChannel.socket()).thenReturn(socket); TcpNioConnection connection = new TcpNioConnection(socketChannel, false, false, null, null); final TcpNioConnection.ChannelInputStream stream = (ChannelInputStream) new DirectFieldAccessor(connection) .getPropertyValue("channelInputStream"); final CountDownLatch latch = new CountDownLatch(1); final byte[] out = new byte[4]; this.executor.execute(() -> { try { stream.read(out); } catch (IOException e) { e.printStackTrace(); } latch.countDown(); }); Thread.sleep(1000); assertEquals(0x00, out[0]); stream.write(ByteBuffer.wrap("foo".getBytes())); assertTrue(latch.await(10, TimeUnit.SECONDS)); assertEquals("foo\u0000", new String(out)); }
/** * 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); }
final CountDownLatch done = new CountDownLatch(1); final AtomicReference<ServerSocket> serverSocket = new AtomicReference<>(); this.executor.execute(() -> { try { ServerSocket server = ServerSocketFactory.getDefault().createServerSocket(0);
this.nativeEntityManagerFactoryFuture = bootstrapExecutor.submit(this::buildNativeEntityManagerFactory);
final CountDownLatch latch = new CountDownLatch(1); final AtomicBoolean done = new AtomicBoolean(); this.executor.execute(() -> { try { ServerSocket server = ServerSocketFactory.getDefault().createServerSocket(0);