• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java WebAsyncTask类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: addMovie

import org.springframework.web.context.request.async.WebAsyncTask; //导入依赖的package包/类
/**
 * 异步处理文件上传,Servlet3规范新特性,不会消耗更多的资源
 * 
 * @param model
 * @param movieFile
 * @param movieDto
 * @param madeDate
 * @param request
 * @return
 */
@RequestMapping(value = "/media/movie/add", method = RequestMethod.POST)
public WebAsyncTask<Void> addMovie(Model model, MultipartFile movieFile,
		MovieDto movieDto,
		@DateTimeFormat(pattern = "yyyy-MM-dd") Date madeDate,
		HttpServletRequest request) {

	log.info("用户[" + UserUtils.getCurrentUserId() + "]正在上传视频[标题:"+movieDto.getTitle()+"]");

	return new WebAsyncTask<Void>(fileUploadTime, new MovieAsyncCallable(model,
			movieFile, movieDto, madeDate, movieService, filePath));
}
 
开发者ID:wu560130911,项目名称:MultimediaDesktop,代码行数:22,代码来源:MovieController.java


示例17: ingredients

import org.springframework.web.context.request.async.WebAsyncTask; //导入依赖的package包/类
/**
 * [SLEUTH] WebAsyncTask
 */
@RequestMapping(value = "/{ingredient}", method = RequestMethod.POST)
public WebAsyncTask<Ingredient> ingredients(@PathVariable("ingredient") IngredientType ingredientType,
											@RequestHeader("PROCESS-ID") String processId,
											@RequestHeader(TestConfigurationHolder.TEST_COMMUNICATION_TYPE_HEADER_NAME) String testCommunicationType) {
	log.info("Received a request to [/{}] with process id [{}] and communication type [{}]", ingredientType,
			processId, testCommunicationType);
	return new WebAsyncTask<>(() -> {
		Span span = tracer.createSpan("inside_ingredients");
		Ingredient ingredient = new Ingredient(ingredientType, stubbedIngredientsProperties.getReturnedIngredientsQuantity());
		log.info("Returning [{}] as fetched ingredient from an external service", ingredient);
		tracer.close(span);
		return ingredient;
	});
}
 
开发者ID:spring-cloud-samples,项目名称:brewery,代码行数:18,代码来源:IngredientsFetchController.java


示例18: handleReturnValue

import org.springframework.web.context.request.async.WebAsyncTask; //导入依赖的package包/类
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:deathspeeder,项目名称:class-guard,代码行数:14,代码来源:AsyncTaskMethodReturnValueHandler.java


示例19: allAsyncDepts

import org.springframework.web.context.request.async.WebAsyncTask; //导入依赖的package包/类
@RequestMapping(value = "/feignAsyncList", method = RequestMethod.GET, produces = "application/json")
  public WebAsyncTask<List<Department>> allAsyncDepts()			    {
WebAsyncTask<List<Department>> depts = deptListClient.getAsyncListDepts();
return depts;
    }
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:6,代码来源:DeptFeignController.java


示例20: getAsyncListDepts

import org.springframework.web.context.request.async.WebAsyncTask; //导入依赖的package包/类
@RequestMapping(method = RequestMethod.GET, value = "/webSyncDeptList.json" )
public WebAsyncTask<List<Department>> getAsyncListDepts();
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:3,代码来源:DeptListClient.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Hits类代码示例发布时间:2022-05-22
下一篇:
Java GzipUtils类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap