Package org.springframework.core.task

Examples of org.springframework.core.task.AsyncTaskExecutor


    Long timeout = webAsyncTask.getTimeout();
    if (timeout != null) {
      this.asyncWebRequest.setTimeout(timeout);
    }

    AsyncTaskExecutor executor = webAsyncTask.getExecutor();
    if (executor != null) {
      this.taskExecutor = executor;
    }

    List<CallableProcessingInterceptor> interceptors = new ArrayList<CallableProcessingInterceptor>();
View Full Code Here


        super();
    }

    @Test
    public void testExecutionMethod() throws InterruptedException {
        AsyncTaskExecutor executor = new SimpleAsyncTaskExecutor("tTestExecutionMethod");
        SignallingRunnable runner = new SignallingRunnable("testExecutionMethod");
        executor.execute(runner, 125L);

        assertLastExecutionOperation(runner);
        assertCurrentThreadExecution();
    }
View Full Code Here

        assertCurrentThreadExecution();
    }

    @Test
    public void testSubmissionMethod() throws InterruptedException, ExecutionException, TimeoutException {
        AsyncTaskExecutor executor = new SimpleAsyncTaskExecutor("testSubmissionMethod");
        SignallingRunnable runner = new SignallingRunnable("testSubmissionMethod");
        Future<?> future = executor.submit(runner);
        Object result = future.get(5L, TimeUnit.SECONDS);

        assertLastExecutionOperation(runner);
        assertCurrentThreadExecution();
View Full Code Here

    Long timeout = webAsyncTask.getTimeout();
    if (timeout != null) {
      this.asyncWebRequest.setTimeout(timeout);
    }

    AsyncTaskExecutor executor = webAsyncTask.getExecutor();
    if (executor != null) {
      this.taskExecutor = executor;
    }

    List<CallableProcessingInterceptor> interceptors = new ArrayList<CallableProcessingInterceptor>();
View Full Code Here

  }

  @Test
  public void startCallableProcessingWithAsyncTask() throws Exception {

    AsyncTaskExecutor executor = mock(AsyncTaskExecutor.class);
    given(this.asyncWebRequest.getNativeRequest(HttpServletRequest.class)).willReturn(this.servletRequest);

    @SuppressWarnings("unchecked")
    WebAsyncTask<Object> asyncTask = new WebAsyncTask<Object>(1000L, executor, mock(Callable.class));
    this.asyncManager.startCallableProcessing(asyncTask);
View Full Code Here

    this.servletRequest = new MockHttpServletRequest("GET", "/test");
    this.servletRequest.setAsyncSupported(true);
    this.servletResponse = new MockHttpServletResponse();
    this.asyncWebRequest = new StandardServletAsyncWebRequest(servletRequest, servletResponse);

    AsyncTaskExecutor executor = mock(AsyncTaskExecutor.class);

    this.asyncManager = WebAsyncUtils.getAsyncManager(servletRequest);
    this.asyncManager.setTaskExecutor(executor);
    this.asyncManager.setAsyncWebRequest(this.asyncWebRequest);
  }
View Full Code Here

  public Object invoke(final MethodInvocation invocation) throws Throwable {
    Class<?> targetClass = (invocation.getThis() != null ? AopUtils.getTargetClass(invocation.getThis()) : null);
    Method specificMethod = ClassUtils.getMostSpecificMethod(invocation.getMethod(), targetClass);
    final Method userDeclaredMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);

    AsyncTaskExecutor executor = determineAsyncExecutor(userDeclaredMethod);
    if (executor == null) {
      throw new IllegalStateException(
          "No executor specified and no default executor set on AsyncExecutionInterceptor either");
    }

    Callable<Object> task = new Callable<Object>() {
      @Override
      public Object call() throws Exception {
        try {
          Object result = invocation.proceed();
          if (result instanceof Future) {
            return ((Future<?>) result).get();
          }
        }
        catch (Throwable ex) {
          handleError(ex, userDeclaredMethod, invocation.getArguments());
        }
        return null;
      }
    };

    Class<?> returnType = invocation.getMethod().getReturnType();
    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;
    }
  }
View Full Code Here

   * Determine the specific executor to use when executing the given method.
   * Should preferably return an {@link AsyncListenableTaskExecutor} implementation.
   * @return the executor to use (or {@code null}, but just if no default executor has been set)
   */
  protected AsyncTaskExecutor determineAsyncExecutor(Method method) {
    AsyncTaskExecutor executor = this.executors.get(method);
    if (executor == null) {
      Executor executorToUse = this.defaultExecutor;
      String qualifier = getExecutorQualifier(method);
      if (StringUtils.hasLength(qualifier)) {
        Assert.notNull(this.beanFactory, "BeanFactory must be set on " + getClass().getSimpleName() +
View Full Code Here

  @Test
  public void testOneJobContextPerThread() throws Exception {
    List<Future<JobContext>> jobContexts = new ArrayList<Future<JobContext>>();

    AsyncTaskExecutor executor = new SimpleAsyncTaskExecutor();

    for(int i = 0; i < 4; i++) {
      final long count = i;
      jobContexts.add(executor.submit(new Callable<JobContext>() {

        @Override
        public JobContext call() throws Exception {
          try {
            StepSynchronizationManager.register(new StepExecution("step" + count, new JobExecution(count)));
View Full Code Here

  @Test
  public void getObjectMultiThread() throws Exception {
    List<Future<StepContext>> stepContexts = new ArrayList<Future<StepContext>>();

    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)));
View Full Code Here

TOP

Related Classes of org.springframework.core.task.AsyncTaskExecutor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.