@Override public void execute(Runnable task) { this.taskExecutor.execute(task); }
@Override public void execute(Runnable command) { this.taskExecutor.execute(command); }
@Override public void execute(Runnable task) { this.taskExecutor.execute(task); }
@Override public void execute(Runnable command) { this.taskExecutor.execute(command); }
private void schedule() { try { this.taskExecutor.execute(this); } catch (Throwable ex) { try { terminate(); } finally { this.executing.decrementAndGet(); this.elementRef.lazySet(null); } } }
@Override protected void openConnection() { this.taskExecutor.execute(() -> { try { if (logger.isInfoEnabled()) { logger.info("Connecting to WebSocket at " + getUri()); } Object endpointToUse = this.endpoint; if (endpointToUse == null) { Assert.state(this.endpointProvider != null, "No endpoint set"); endpointToUse = this.endpointProvider.getHandler(); } this.session = this.webSocketContainer.connectToServer(endpointToUse, getUri()); logger.info("Successfully connected to WebSocket"); } catch (Throwable ex) { logger.error("Failed to connect to WebSocket", ex); } }); }
@Override public boolean executeAsyncJob(Job job) { try { taskExecutor.execute(new ExecuteAsyncRunnable((JobEntity) job, processEngineConfiguration)); return true; } catch (RejectedExecutionException e) { rejectedJobsHandler.jobRejected(this, job); return false; } }
@Override protected void openConnection() { this.taskExecutor.execute(() -> { try { if (logger.isInfoEnabled()) { logger.info("Connecting to WebSocket at " + getUri()); } Endpoint endpointToUse = this.endpoint; if (endpointToUse == null) { Assert.state(this.endpointProvider != null, "No endpoint set"); endpointToUse = this.endpointProvider.getHandler(); } ClientEndpointConfig endpointConfig = this.configBuilder.build(); this.session = getWebSocketContainer().connectToServer(endpointToUse, endpointConfig, getUri()); logger.info("Successfully connected to WebSocket"); } catch (Throwable ex) { logger.error("Failed to connect to WebSocket", ex); } }); }
private void schedule() { try { this.taskExecutor.execute(this); } catch (Throwable ex) { try { terminate(); } finally { this.executing.decrementAndGet(); this.elementRef.lazySet(null); } } }
public void copyActivityFeed( final EntityRef connectingEntity, final EntityRef connectedEntityRef ) throws Exception { if (logger.isTraceEnabled()) { logger.trace("Copying activities to feed..."); } TaskExecutor taskExecutor = ( TaskExecutor ) getApplicationContext().getBean( "taskExecutor" ); taskExecutor.execute( new Runnable() { @Override public void run() { try { em.copyRelationships( connectedEntityRef, "activities", connectingEntity, "feed" ); } catch ( Exception e ) { logger.error( "Error while copying activities into feed", e ); } } } ); } }
/** * Transform the input by delegating to the provided item processor. The * return value is wrapped in a {@link Future} so that clients can unpack it * later. * * @see ItemProcessor#process(Object) */ public Future<O> process(final I item) throws Exception { final StepExecution stepExecution = getStepExecution(); FutureTask<O> task = new FutureTask<>(new Callable<O>() { public O call() throws Exception { if (stepExecution != null) { StepSynchronizationManager.register(stepExecution); } try { return delegate.process(item); } finally { if (stepExecution != null) { StepSynchronizationManager.close(); } } } }); taskExecutor.execute(task); return task; }
@Override protected Set<StepExecution> doHandle(StepExecution masterStepExecution, Set<StepExecution> partitionStepExecutions) throws Exception { Assert.notNull(step, "A Step must be provided."); final Set<Future<StepExecution>> tasks = new HashSet<>(getGridSize()); final Set<StepExecution> result = new HashSet<>(); for (final StepExecution stepExecution : partitionStepExecutions) { final FutureTask<StepExecution> task = createTask(step, stepExecution); try { taskExecutor.execute(task); tasks.add(task); } catch (TaskRejectedException e) { // couldn't execute one of the tasks ExitStatus exitStatus = ExitStatus.FAILED .addExitDescription("TaskExecutor rejected the task for this step."); /* * Set the status in case the caller is tracking it through the * JobExecution. */ stepExecution.setStatus(BatchStatus.FAILED); stepExecution.setExitStatus(exitStatus); result.add(stepExecution); } } for (Future<StepExecution> task : tasks) { result.add(task.get()); } return result; }
taskExecutor.execute(workHandle);
final SettableListenableFuture<WebSocketSession> connectFuture) { getTaskExecutor().execute(() -> { HttpHeaders httpHeaders = transportRequest.getHttpRequestHeaders(); XhrRequestCallback requestCallback = new XhrRequestCallback(handshakeHeaders);
@Test public void testGetMultipleInMultipleThreads() throws Exception { List<FutureTask<String>> tasks = new ArrayList<>(); for (int i = 0; i < 12; i++) { final String value = "foo" + i; final Long id = 123L + i; FutureTask<String> task = new FutureTask<>(new Callable<String>() { @Override public String call() throws Exception { StepExecution stepExecution = new StepExecution(value, new JobExecution(0L), id); ExecutionContext executionContext = stepExecution.getExecutionContext(); executionContext.put("foo", value); StepContext context = StepSynchronizationManager.register(stepExecution); logger.debug("Registered: " + context.getStepExecutionContext()); try { return simple.getName(); } finally { StepSynchronizationManager.close(); } } }); tasks.add(task); taskExecutor.execute(task); } int i = 0; for (FutureTask<String> task : tasks) { assertEquals("foo" + i, task.get()); i++; } }
@Test public void testMultiPlex() throws Exception { TaskExecutor executor = new SimpleAsyncTaskExecutor(); final CountDownLatch latch = new CountDownLatch(100); final BlockingQueue<Integer> results = new LinkedBlockingQueue<>(); for (int i = 100; i < 200; i++) { results.add(i); final int j = i; executor.execute(() -> { String result = gw.send(j + "Hello world!"); // first 3 bytes is correlationid assertEquals(j + "Hello world!:echo", result); results.remove(j); latch.countDown(); }); } assertTrue(latch.await(60, TimeUnit.SECONDS)); assertEquals(0, results.size()); }
@Test public void testFilteredItem() throws Exception { writer.setDelegate(new ListItemWriter(writtenItems)); List<FutureTask<String>> processedItems = new ArrayList<>(); processedItems.add(new FutureTask<>(new Callable<String>() { @Override public String call() throws Exception { return "foo"; } })); processedItems.add(new FutureTask<>(new Callable<String>() { @Override public String call() throws Exception { return null; } })); for (FutureTask<String> processedItem : processedItems) { taskExecutor.execute(processedItem); } writer.write(processedItems); assertEquals(1, writtenItems.size()); assertTrue(writtenItems.contains("foo")); }
@Test public void testRoseyScenario() throws Exception { writer.setDelegate(new ListItemWriter(writtenItems)); List<FutureTask<String>> processedItems = new ArrayList<>(); processedItems.add(new FutureTask<>(new Callable<String>() { @Override public String call() throws Exception { return "foo"; } })); processedItems.add(new FutureTask<>(new Callable<String>() { @Override public String call() throws Exception { return "bar"; } })); for (FutureTask<String> processedItem : processedItems) { taskExecutor.execute(processedItem); } writer.write(processedItems); assertEquals(2, writtenItems.size()); assertTrue(writtenItems.contains("foo")); assertTrue(writtenItems.contains("bar")); }
@Test public void testException() throws Exception { writer.setDelegate(new ListItemWriter(writtenItems)); List<FutureTask<String>> processedItems = new ArrayList<>(); processedItems.add(new FutureTask<>(new Callable<String>() { @Override public String call() throws Exception { return "foo"; } })); processedItems.add(new FutureTask<>(new Callable<String>() { @Override public String call() throws Exception { throw new RuntimeException("This was expected"); } })); for (FutureTask<String> processedItem : processedItems) { taskExecutor.execute(processedItem); } try { writer.write(processedItems); } catch (Exception e) { assertTrue(e instanceof RuntimeException); assertEquals("This was expected", e.getMessage()); } }
@Test public void sendWithExecutor() { BeforeHandleInterceptor interceptor = new BeforeHandleInterceptor(); TaskExecutor executor = mock(TaskExecutor.class); ExecutorSubscribableChannel testChannel = new ExecutorSubscribableChannel(executor); testChannel.addInterceptor(interceptor); testChannel.subscribe(this.handler); testChannel.send(this.message); verify(executor).execute(this.runnableCaptor.capture()); verify(this.handler, never()).handleMessage(this.message); this.runnableCaptor.getValue().run(); verify(this.handler).handleMessage(this.message); assertEquals(1, interceptor.getCounter().get()); assertTrue(interceptor.wasAfterHandledInvoked()); }