本文整理汇总了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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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";
});
}
示例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);
}
示例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();
}
});
}
示例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));
}