org.frameworkset.web.request.async.DeferredResultInterceptorChain Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bboss-mvc Show documentation
Show all versions of bboss-mvc Show documentation
bboss is a j2ee framework include aop/ioc,mvc,persistent,taglib,rpc,event ,bean-xml serializable and so on.http://www.bbossgroups.com
package org.frameworkset.web.request.async;
import java.util.List;
import org.frameworkset.web.servlet.mvc.NativeWebRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Assists with the invocation of {@link DeferredResultProcessingInterceptor}'s.
*
* @author Rossen Stoyanchev
* @since 3.2
*/
class DeferredResultInterceptorChain {
private static final Logger logger = LoggerFactory.getLogger(DeferredResultInterceptorChain.class);
private final List interceptors;
private int preProcessingIndex = -1;
public DeferredResultInterceptorChain(List interceptors) {
this.interceptors = interceptors;
}
public void applyBeforeConcurrentHandling(NativeWebRequest request, DeferredResult> deferredResult) throws Exception {
for (DeferredResultProcessingInterceptor interceptor : this.interceptors) {
interceptor.beforeConcurrentHandling(request, deferredResult);
}
}
public void applyPreProcess(NativeWebRequest request, DeferredResult> deferredResult) throws Exception {
for (DeferredResultProcessingInterceptor interceptor : this.interceptors) {
interceptor.preProcess(request, deferredResult);
this.preProcessingIndex++;
}
}
public Object applyPostProcess(NativeWebRequest request, DeferredResult> deferredResult, Object concurrentResult) {
try {
for (int i = this.preProcessingIndex; i >= 0; i--) {
this.interceptors.get(i).postProcess(request, deferredResult, concurrentResult);
}
}
catch (Throwable t) {
return t;
}
return concurrentResult;
}
public void triggerAfterTimeout(NativeWebRequest request, DeferredResult> deferredResult) throws Exception {
for (DeferredResultProcessingInterceptor interceptor : this.interceptors) {
if (deferredResult.isSetOrExpired()) {
return;
}
if (!interceptor.handleTimeout(request, deferredResult)){
break;
}
}
}
public void triggerAfterCompletion(NativeWebRequest request, DeferredResult> deferredResult) {
for (int i = this.preProcessingIndex; i >= 0; i--) {
try {
this.interceptors.get(i).afterCompletion(request, deferredResult);
}
catch (Throwable t) {
logger.error("afterCompletion error", t);
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy