public void triggerAfterTimeout(NativeWebRequest request, DeferredResult<?> deferredResult) throws Exception { for (DeferredResultProcessingInterceptor interceptor : this.interceptors) { if (deferredResult.isSetOrExpired()) { return; } if (!interceptor.handleTimeout(request, deferredResult)){ break; } } }
private boolean setResultInternal(Object result) { // Immediate expiration check outside of the result lock if (isSetOrExpired()) { return false; } DeferredResultHandler resultHandlerToUse; synchronized (this) { // Got the lock in the meantime: double-check expiration status if (isSetOrExpired()) { return false; } // At this point, we got a new result to process this.result = result; resultHandlerToUse = this.resultHandler; if (resultHandlerToUse == null) { // No result handler set yet -> let the setResultHandler implementation // pick up the result object and invoke the result handler for it. return true; } // Result handler available -> let's clear the stored reference since // we don't need it anymore. this.resultHandler = null; } // If we get here, we need to process an existing result object immediately. // The decision is made within the result lock; just the handle call outside // of it, avoiding any deadlock potential with Servlet container locks. resultHandlerToUse.handleResult(result); return true; }
/** * Determine if further error handling should be bypassed. * @return {@code true} to continue error handling, or false to bypass any further * error handling */ public boolean triggerAfterError(NativeWebRequest request, DeferredResult<?> deferredResult, Throwable ex) throws Exception { for (DeferredResultProcessingInterceptor interceptor : this.interceptors) { if (deferredResult.isSetOrExpired()) { return false; } if (!interceptor.handleError(request, deferredResult, ex)){ return false; } } return true; }
public void triggerAfterTimeout(NativeWebRequest request, DeferredResult<?> deferredResult) throws Exception { for (DeferredResultProcessingInterceptor interceptor : this.interceptors) { if (deferredResult.isSetOrExpired()) { return; } if (!interceptor.handleTimeout(request, deferredResult)){ break; } } }
private boolean setResultInternal(Object result) { // Immediate expiration check outside of the result lock if (isSetOrExpired()) { return false; } DeferredResultHandler resultHandlerToUse; synchronized (this) { // Got the lock in the meantime: double-check expiration status if (isSetOrExpired()) { return false; } // At this point, we got a new result to process this.result = result; resultHandlerToUse = this.resultHandler; if (resultHandlerToUse == null) { // No result handler set yet -> let the setResultHandler implementation // pick up the result object and invoke the result handler for it. return true; } // Result handler available -> let's clear the stored reference since // we don't need it anymore. this.resultHandler = null; } // If we get here, we need to process an existing result object immediately. // The decision is made within the result lock; just the handle call outside // of it, avoiding any deadlock potential with Servlet container locks. resultHandlerToUse.handleResult(result); return true; }
/** * Determine if further error handling should be bypassed. * @return {@code true} to continue error handling, or false to bypass any further * error handling */ public boolean triggerAfterError(NativeWebRequest request, DeferredResult<?> deferredResult, Throwable ex) throws Exception { for (DeferredResultProcessingInterceptor interceptor : this.interceptors) { if (deferredResult.isSetOrExpired()) { return false; } if (!interceptor.handleError(request, deferredResult, ex)){ return false; } } return true; }
@Test public void isSetOrExpired() { DeferredResultHandler handler = mock(DeferredResultHandler.class); DeferredResult<String> result = new DeferredResult<>(); result.setResultHandler(handler); assertFalse(result.isSetOrExpired()); result.setResult("hello"); assertTrue(result.isSetOrExpired()); verify(handler).handleResult("hello"); }
@Test public void onCompletion() throws Exception { final StringBuilder sb = new StringBuilder(); DeferredResult<String> result = new DeferredResult<>(); result.onCompletion(new Runnable() { @Override public void run() { sb.append("completion event"); } }); result.getInterceptor().afterCompletion(null, null); assertTrue(result.isSetOrExpired()); assertEquals("completion event", sb.toString()); }
private boolean setResultInternal(Object result) { // Immediate expiration check outside of the result lock if (isSetOrExpired()) { return false; } DeferredResultHandler resultHandlerToUse; synchronized (this) { // Got the lock in the meantime: double-check expiration status if (isSetOrExpired()) { return false; } // At this point, we got a new result to process this.result = result; resultHandlerToUse = this.resultHandler; if (resultHandlerToUse == null) { // No result handler set yet -> let the setResultHandler implementation // pick up the result object and invoke the result handler for it. return true; } // Result handler available -> let's clear the stored reference since // we don't need it anymore. this.resultHandler = null; } // If we get here, we need to process an existing result object immediately. // The decision is made within the result lock; just the handle call outside // of it, avoiding any deadlock potential with Servlet container locks. resultHandlerToUse.handleResult(result); return true; }
public void triggerAfterTimeout(NativeWebRequest request, DeferredResult<?> deferredResult) throws Exception { for (DeferredResultProcessingInterceptor interceptor : this.interceptors) { if (deferredResult.isSetOrExpired()) { return; } if (!interceptor.handleTimeout(request, deferredResult)){ break; } } }
@Override protected void doApply(C input) { if (deferredResult.isSetOrExpired()) { LOG.warn("Deferred result is already set or expired, could not deliver value {} for result {}.", value, input); } else { deferredResult.setResult(value); } } }
public void triggerAfterTimeout(NativeWebRequest request, DeferredResult<?> deferredResult) throws Exception { for (DeferredResultProcessingInterceptor interceptor : this.interceptors) { if (deferredResult.isSetOrExpired()) { return; } if (!interceptor.handleTimeout(request, deferredResult)){ break; } } }
@Override protected void doApply(T input) { if (deferredResult.isSetOrExpired()) { LOG.warn("Deferred result is already set or expired, could not deliver result {}.", input); } else { deferredResult.setResult(input); } } }
@Override protected void doApply(Throwable err) { if (deferredResult.isSetOrExpired()) { LOG.warn("Deferred result is already set or expired, could not deliver Throwable.", err); } else { deferredResult.setErrorResult(err); } } }
private boolean setResultInternal(Object result) { // Immediate expiration check outside of the result lock if (isSetOrExpired()) { return false; } DeferredResultHandler resultHandlerToUse; synchronized (this) { // Got the lock in the meantime: double-check expiration status if (isSetOrExpired()) { return false; } // At this point, we got a new result to process this.result = result; resultHandlerToUse = this.resultHandler; if (resultHandlerToUse == null) { // No result handler set yet -> let the setResultHandler implementation // pick up the result object and invoke the result handler for it. return true; } // Result handler available -> let's clear the stored reference since // we don't need it anymore. this.resultHandler = null; } // If we get here, we need to process an existing result object immediately. // The decision is made within the result lock; just the handle call outside // of it, avoiding any deadlock potential with Servlet container locks. resultHandlerToUse.handleResult(result); return true; }
/** * @return true to continue error handling, or false to bypass any further * error handling */ public boolean triggerAfterError(NativeWebRequest request, DeferredResult<?> deferredResult, Throwable ex) throws Exception { for (DeferredResultProcessingInterceptor interceptor : this.interceptors) { if (deferredResult.isSetOrExpired()) { return false; } if (!interceptor.handleError(request, deferredResult, ex)){ return false; } } return true; }
/** * Determine if further error handling should be bypassed. * @return {@code true} to continue error handling, or false to bypass any further * error handling */ public boolean triggerAfterError(NativeWebRequest request, DeferredResult<?> deferredResult, Throwable ex) throws Exception { for (DeferredResultProcessingInterceptor interceptor : this.interceptors) { if (deferredResult.isSetOrExpired()) { return false; } if (!interceptor.handleError(request, deferredResult, ex)){ return false; } } return true; }