当前位置: 首页>>代码示例>>Java>>正文


Java WebAsyncTask类代码示例

本文整理汇总了Java中org.springframework.web.context.request.async.WebAsyncTask的典型用法代码示例。如果您正苦于以下问题:Java WebAsyncTask类的具体用法?Java WebAsyncTask怎么用?Java WebAsyncTask使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


WebAsyncTask类属于org.springframework.web.context.request.async包,在下文中一共展示了WebAsyncTask类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: longTimeTask

import org.springframework.web.context.request.async.WebAsyncTask; //导入依赖的package包/类
@RequestMapping(value="/web/webasync.html")
@ResponseBody
public WebAsyncTask<String> longTimeTask(){
   
    Callable<String> callable = new Callable<String>() {
        public String call() throws Exception {
            Thread.sleep(3000); 
         
            System.out.println("controller#webasync task started. Thread: " +
                       Thread.currentThread()
                             .getName());
            return "Trial";
        }
    };
    return new WebAsyncTask<String>(callable);
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:17,代码来源:DataController.java

示例2: websyncDeptList

import org.springframework.web.context.request.async.WebAsyncTask; //导入依赖的package包/类
@GetMapping(value="/webSyncDept/{id}.json", produces ="application/json", headers = {"Accept=text/xml, application/json"})
public WebAsyncTask<Department> websyncDeptList(@PathVariable("id") Integer id){
   
    Callable<Department> callable = new Callable<Department>() {
    	public Department call() throws Exception {
    		
    		 ListenableFuture<Department> listenFuture = departmentServiceImpl.findAllFirstById(id);
    		 listenFuture.addCallback(new ListenableFutureCallback<Department>(){

				@Override
				public void onSuccess(Department dept) {
					result = dept;
				}

				@Override
				public void onFailure(Throwable arg0) {
					result = new Department();
				}
    			 
    		 });
    		 return result;
          }
    };
    return new WebAsyncTask<Department>(500, callable);
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:26,代码来源:DeptAsyncController.java

示例3: wrapWebAsyncTaskWithCorrelationId

import org.springframework.web.context.request.async.WebAsyncTask; //导入依赖的package包/类
@Around("anyControllerOrRestControllerWithPublicWebAsyncTaskMethod()")
public Object wrapWebAsyncTaskWithCorrelationId(ProceedingJoinPoint pjp) throws Throwable {
	final WebAsyncTask<?> webAsyncTask = (WebAsyncTask<?>) pjp.proceed();
	if (this.tracer.isTracing()) {
		try {
			log.debug("Wrapping callable with span ["
					+ this.tracer.getCurrentSpan() + "]");
			Field callableField = WebAsyncTask.class.getDeclaredField("callable");
			callableField.setAccessible(true);
			callableField.set(webAsyncTask, new TraceContinuingCallable<>(this.tracer,
					this.spanNamer, webAsyncTask.getCallable()));
		} catch (NoSuchFieldException ex) {
			log.warn("Cannot wrap webAsyncTask's callable with TraceCallable", ex);
		}
	}
	return webAsyncTask;
}
 
开发者ID:reshmik,项目名称:Zipkin,代码行数:18,代码来源:TraceWebAspect.java

示例4: wrapWebAsyncTaskWithCorrelationId

import org.springframework.web.context.request.async.WebAsyncTask; //导入依赖的package包/类
@Around("anyControllerOrRestControllerWithPublicWebAsyncTaskMethod()")
public Object wrapWebAsyncTaskWithCorrelationId(ProceedingJoinPoint pjp) throws Throwable {
	final WebAsyncTask<?> webAsyncTask = (WebAsyncTask<?>) pjp.proceed();
	if (this.tracer.isTracing()) {
		try {
			if (log.isDebugEnabled()) {
				log.debug("Wrapping callable with span [" + this.tracer.getCurrentSpan()
						+ "]");
			}
			Field callableField = WebAsyncTask.class.getDeclaredField("callable");
			callableField.setAccessible(true);
			callableField.set(webAsyncTask, new SpanContinuingTraceCallable<>(this.tracer,
					this.traceKeys, this.spanNamer, webAsyncTask.getCallable()));
		} catch (NoSuchFieldException ex) {
			log.warn("Cannot wrap webAsyncTask's callable with TraceCallable", ex);
		}
	}
	return webAsyncTask;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-sleuth,代码行数:20,代码来源:TraceWebAspect.java

示例5: longTimeTask

import org.springframework.web.context.request.async.WebAsyncTask; //导入依赖的package包/类
@RequestMapping(value="/web/webasync.html")
public WebAsyncTask<String> longTimeTask(){
   
    Callable<String> callable = new Callable<String>() {
        public String call() throws Exception {
            Thread.sleep(3000); 
            logger.info("controller#longTimeTask task started.");
            System.out.println("controller#webasync task started. Thread: " +
                       Thread.currentThread()
                             .getName());
            return "Tral";
        }
    };
    return new WebAsyncTask<String>(callable);
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:16,代码来源:DataController.java

示例6: jsonEmpList

import org.springframework.web.context.request.async.WebAsyncTask; //导入依赖的package包/类
@RequestMapping(value="/web/employeeList.json", produces ="application/json", method = RequestMethod.GET, headers = {"Accept=text/xml, application/json"})
@ResponseBody
public WebAsyncTask<List<Employee>> jsonEmpList(){
   
    Callable<List<Employee>> callable = new Callable<List<Employee>>() {
        public List<Employee> call() throws Exception {
            Thread.sleep(3000); 
            logger.info("ServiceController#jsonEmpList task started.");
            System.out.println("jsonEmpList task executor: " + Thread.currentThread().getName());
            return employeeServiceImpl.readEmployees().get(50000, TimeUnit.MILLISECONDS);
        }
    };
    return new WebAsyncTask<List<Employee>>(5000, callable);
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:15,代码来源:ServiceController.java

示例7: jsonEmpList

import org.springframework.web.context.request.async.WebAsyncTask; //导入依赖的package包/类
@RequestMapping(value="/web/employeeList.json", produces ="application/json", method = RequestMethod.GET, headers = {"Accept=text/xml, application/json"})
@ResponseBody
public WebAsyncTask<List<Employee>> jsonEmpList(){
   
    Callable<List<Employee>> callable = new Callable<List<Employee>>() {
        public List<Employee> call() throws Exception {
            Thread.sleep(3000); 
         
            System.out.println("jsonEmpList task executor: " + Thread.currentThread().getName());
            return employeeServiceImpl.readEmployees().get(5000, TimeUnit.MILLISECONDS);
        }
    };
    return new WebAsyncTask<List<Employee>>(5000, callable);
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:15,代码来源:ServiceController.java

示例8: websyncDeptList

import org.springframework.web.context.request.async.WebAsyncTask; //导入依赖的package包/类
@GetMapping(value="/webSyncDeptList.json", produces ="application/json", headers = {"Accept=text/xml, application/json"})
public WebAsyncTask<List<Department>> websyncDeptList(){
   
    Callable<List<Department>> callable = new Callable<List<Department>>() {
        public List<Department> call() throws Exception {
             return departmentServiceImpl.readDepartments().get(500, TimeUnit.MILLISECONDS);
        }
    };
    return new WebAsyncTask<List<Department>>(500, callable);
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:11,代码来源:DeptAsyncController.java

示例9: websyncEmpList

import org.springframework.web.context.request.async.WebAsyncTask; //导入依赖的package包/类
@GetMapping(value="/webSyncEmpList.json", produces ="application/json", headers = {"Accept=text/xml, application/json"})
public WebAsyncTask<List<Employee>> websyncEmpList(){
   
    Callable<List<Employee>> callable = new Callable<List<Employee>>() {
        public List<Employee> call() throws Exception {
             return employeeServiceImpl.readEmployees().get(500, TimeUnit.MILLISECONDS);
        }
    };
    return new WebAsyncTask<List<Employee>>(500, callable);
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:11,代码来源:EmpAsyncController.java

示例10: handleRequestInternal

import org.springframework.web.context.request.async.WebAsyncTask; //导入依赖的package包/类
/**
 * Handle request.
 *
 * @param request the request
 * @param response the response
 * @return the model and view
 * @throws Exception the exception
 */
@RequestMapping(method = RequestMethod.GET)
@ResponseBody
protected WebAsyncTask<HealthStatus> handleRequestInternal(
        final HttpServletRequest request, final HttpServletResponse response)
        throws Exception {

    final Callable<HealthStatus> asyncTask = new Callable<HealthStatus>() {
        @Override
        public HealthStatus call() throws Exception {
            final HealthStatus healthStatus = healthCheckMonitor.observe();
            final StringBuilder sb = new StringBuilder();
            sb.append("Health: ").append(healthStatus.getCode());
            String name;
            Status status;
            int i = 0;
            for (final Map.Entry<String, Status> entry : healthStatus.getDetails().entrySet()) {
                name = entry.getKey();
                status = entry.getValue();
                response.addHeader("X-CAS-" + name, String.format("%s;%s", status.getCode(), status.getDescription()));

                sb.append("\n\n\t").append(++i).append('.').append(name).append(": ");
                sb.append(status.getCode());
                if (status.getDescription() != null) {
                    sb.append(" - ").append(status.getDescription());
                }
            }
            response.setStatus(healthStatus.getCode().value());
            response.setContentType("text/plain");
            response.getOutputStream().write(sb.toString().getBytes(response.getCharacterEncoding()));
            return null;
        }
    };
    
    return new WebAsyncTask<>(this.timeout, asyncTask);
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:44,代码来源:HealthCheckController.java

示例11: tracePublicWebAsyncTaskMethods

import org.springframework.web.context.request.async.WebAsyncTask; //导入依赖的package包/类
@Around("anyControllerOrRestControllerWithPublicWebAsyncTaskMethod()")
public Object tracePublicWebAsyncTaskMethods(ProceedingJoinPoint proceedingJoinPoint)
    throws Throwable {
  final WebAsyncTask<?> webAsyncTask = (WebAsyncTask<?>) proceedingJoinPoint.proceed();
  Field callableField = WebAsyncTask.class.getDeclaredField("callable");
  callableField.setAccessible(true);
  // do not create span (there is always server span) just pass it to new thread.
  callableField
      .set(webAsyncTask, new TracedCallable<>(webAsyncTask.getCallable(), tracer.activeSpan()));
  return webAsyncTask;
}
 
开发者ID:opentracing-contrib,项目名称:java-spring-cloud,代码行数:12,代码来源:TracedAsyncWebAspect.java

示例12: webAsyncTask

import org.springframework.web.context.request.async.WebAsyncTask; //导入依赖的package包/类
@RequestMapping("/webAsyncTask")
public WebAsyncTask<String> webAsyncTask() {
  return new WebAsyncTask<>(() -> {
    mockTracer.buildSpan("foo").startManual().finish();
    return "webAsyncTask";
  });
}
 
开发者ID:opentracing-contrib,项目名称:java-spring-cloud,代码行数:8,代码来源:WebAsyncTaskTest.java

示例13: handleReturnValue

import org.springframework.web.context.request.async.WebAsyncTask; //导入依赖的package包/类
@Override
public void handleReturnValue(Object returnValue, MethodParameter returnType,
		ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {

	if (returnValue == null) {
		mavContainer.setRequestHandled(true);
		return;
	}

	WebAsyncTask<?> webAsyncTask = (WebAsyncTask<?>) returnValue;
	webAsyncTask.setBeanFactory(this.beanFactory);
	WebAsyncUtils.getAsyncManager(webRequest).startCallableProcessing(webAsyncTask, mavContainer);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:AsyncTaskMethodReturnValueHandler.java

示例14: webAsyncTaskPing

import org.springframework.web.context.request.async.WebAsyncTask; //导入依赖的package包/类
@RequestMapping(value = "/webAsyncTaskPing", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
public WebAsyncTask<String> webAsyncTaskPing() {
	return new WebAsyncTask<>(new Callable<String>() {
		@Override
		public String call() throws Exception {
			return callAndReturnOk();
		}
	});
}
 
开发者ID:reshmik,项目名称:Zipkin,代码行数:10,代码来源:RestTemplateTraceAspectIntegrationTests.java

示例15: addMovie

import org.springframework.web.context.request.async.WebAsyncTask; //导入依赖的package包/类
@RequestMapping(value = "/media/music/add", method = RequestMethod.POST)
public WebAsyncTask<Void> addMovie(Model model, MultipartFile musicFile,
		MusicDto musicDto) {

	log.info("用户[" + UserUtils.getCurrentUserId() + "]正在上传音乐"
			+ ToStringBuilder.reflectionToString(musicDto));

	return new WebAsyncTask<>(fileUploadTime, new MusicAsyncCallable(model,
			musicFile, musicDto, filePath, musicService));
}
 
开发者ID:wu560130911,项目名称:MultimediaDesktop,代码行数:11,代码来源:MusicController.java


注:本文中的org.springframework.web.context.request.async.WebAsyncTask类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。