@Test public void rendererAsyncNotCachedContextEnabled() throws JobException, RenderingException { when(this.asyncContext.isEnabled()).thenReturn(true); when(this.renderer.getId()).thenReturn(Arrays.asList("1", "2")); when(this.renderer.isAsyncAllowed()).thenReturn(true); when(this.renderer.isCacheAllowed()).thenReturn(false); AsyncRendererExecutorResponse response = this.executor.render(this.renderer, this.configuration); assertNotNull(response.getAsyncClientId()); assertEquals(Arrays.asList("1", "2", "celement1", "value1%5c", "celement2", "value2%2f", String.valueOf(response.getAsyncClientId())), response.getStatus().getRequest().getId()); assertEquals("1/2/celement1/value1%255c/celement2/value2%252f/" + response.getAsyncClientId(), response.getJobIdHTTPPath()); assertEquals("true false", response.getStatus().getResult().getResult()); assertEquals(this.jobGroupPath, response.getStatus().getRequest().getJobGroupPath()); }
@Override public AsyncRendererExecutorResponse render(AsyncRenderer renderer, AsyncRendererConfiguration configuration) throws JobException, RenderingException { boolean asyncAllowed = configuration.isPlaceHolderForced() || (renderer.isAsyncAllowed() && this.asyncContext.isEnabled()); boolean cacheAllowed = renderer.isCacheAllowed(); Map<String, Serializable> context = getContext(asyncAllowed, cacheAllowed, configuration); List<String> jobId = getJobId(renderer, context); if (cacheAllowed) { this.cache.getLock().readLock().lock(); try { AsyncRendererJobStatus status = getCurrent(jobId); if (status != null && (status.getEndDate() == null || this.cacheControl.isCacheReadAllowed(status.getEndDate()))) { if (status.getResult() != null && !configuration.isPlaceHolderForced()) { injectUses(status); return new AsyncRendererExecutorResponse(status); } else if (asyncAllowed) { return new AsyncRendererExecutorResponse(status, newClientId()); } } } finally { this.cache.getLock().readLock().unlock(); } } AsyncRendererExecutorResponse response; AsyncRendererJobRequest request = new AsyncRendererJobRequest(); request.setRenderer(renderer); request.setJobGroupPath(renderer.getJobGroupPath()); if (asyncAllowed) { this.cache.getLock().writeLock().lock(); try { if (context != null) { request.setContext(context); } String asyncClientId = newClientId(); if (!renderer.isCacheAllowed()) { jobId.add(asyncClientId); } request.setId(jobId); Job job = this.executor.execute(AsyncRendererJobStatus.JOBTYPE, request); AsyncRendererJobStatus status = (AsyncRendererJobStatus) job.getStatus(); response = new AsyncRendererExecutorResponse(status, asyncClientId); } finally { this.cache.getLock().writeLock().unlock(); } } else { AsyncRendererJobStatus status; if (renderer.isCacheAllowed()) { if (this.asyncContext instanceof DefaultAsyncContext) { ((DefaultAsyncContext) this.asyncContext).pushContextUse(); } AsyncRendererResult result = syncRender(renderer, true, configuration); if (this.asyncContext instanceof DefaultAsyncContext) { ContextUse contextUse = ((DefaultAsyncContext) this.asyncContext).popContextUse(); status = new AsyncRendererJobStatus(request, result, contextUse.getReferences(), contextUse.getRoleTypes(), contextUse.getRoles(), contextUse.getRights(), contextUse.getUses()); } else { status = new AsyncRendererJobStatus(request, result, null, null, null, null, null); } request.setId(jobId); this.cache.put(status); } else { AsyncRendererResult result = syncRender(renderer, false, configuration); status = new AsyncRendererJobStatus(request, result); } response = new AsyncRendererExecutorResponse(status); } return response; }
DefaultAsyncRendererExecutor implements AsyncRendererExecutor { @Override public AsyncRendererExecutorResponse render(AsyncRenderer renderer, AsyncRendererConfiguration configuration) throws JobException, RenderingException { boolean asyncAllowed = configuration.isPlaceHolderForced() || (renderer.isAsyncAllowed() && this.asyncContext.isEnabled()); boolean cacheAllowed = renderer.isCacheAllowed(); Map<String, Serializable> context = getContext(asyncAllowed, cacheAllowed, configuration); List<String> jobId = getJobId(renderer, context); if (cacheAllowed) { this.cache.getLock().readLock().lock(); try { AsyncRendererJobStatus status = getCurrent(jobId); if (status != null && (status.getEndDate() == null || this.cacheControl.isCacheReadAllowed(status.getEndDate()))) { if (status.getResult() != null && !configuration.isPlaceHolderForced()) { injectUses(status); return new AsyncRendererExecutorResponse(status); } else if (asyncAllowed) { return new AsyncRendererExecutorResponse(status, newClientId()); } } } finally { this.cache.getLock().readLock().unlock(); } } AsyncRendererExecutorResponse response; AsyncRendererJobRequest request = new AsyncRendererJobRequest(); request.setRenderer(renderer); request.setJobGroupPath(renderer.getJobGroupPath()); if (asyncAllowed) { this.cache.getLock().writeLock().lock(); try { if (context != null) { request.setContext(context); } String asyncClientId = newClientId(); if (!renderer.isCacheAllowed()) { jobId.add(asyncClientId); } request.setId(jobId); Job job = this.executor.execute(AsyncRendererJobStatus.JOBTYPE, request); AsyncRendererJobStatus status = (AsyncRendererJobStatus) job.getStatus(); response = new AsyncRendererExecutorResponse(status, asyncClientId); } finally { this.cache.getLock().writeLock().unlock(); } } else { AsyncRendererJobStatus status; if (renderer.isCacheAllowed()) { if (this.asyncContext instanceof DefaultAsyncContext) { ((DefaultAsyncContext) this.asyncContext).pushContextUse(); } AsyncRendererResult result = syncRender(renderer, true, configuration); if (this.asyncContext instanceof DefaultAsyncContext) { ContextUse contextUse = ((DefaultAsyncContext) this.asyncContext).popContextUse(); status = new AsyncRendererJobStatus(request, result, contextUse.getReferences(), contextUse.getRoleTypes(), contextUse.getRoles(), contextUse.getRights(), contextUse.getUses()); } else { status = new AsyncRendererJobStatus(request, result, null, null, null, null, null); } request.setId(jobId); this.cache.put(status); } else { AsyncRendererResult result = syncRender(renderer, false, configuration); status = new AsyncRendererJobStatus(request, result); } response = new AsyncRendererExecutorResponse(status); } return response; } }
DefaultAsyncRendererExecutor implements AsyncRendererExecutor { @Override public AsyncRendererExecutorResponse render(AsyncRenderer renderer, AsyncRendererConfiguration configuration) throws JobException, RenderingException { boolean asyncAllowed = configuration.isPlaceHolderForced() || (renderer.isAsyncAllowed() && this.asyncContext.isEnabled()); boolean cacheAllowed = renderer.isCacheAllowed(); Map<String, Serializable> context = getContext(asyncAllowed, cacheAllowed, configuration); List<String> jobId = getJobId(renderer, context); if (cacheAllowed) { this.cache.getLock().readLock().lock(); try { AsyncRendererJobStatus status = getCurrent(jobId); if (status != null && (status.getEndDate() == null || this.cacheControl.isCacheReadAllowed(status.getEndDate()))) { if (status.getResult() != null && !configuration.isPlaceHolderForced()) { injectUses(status); return new AsyncRendererExecutorResponse(status); } else if (asyncAllowed) { return new AsyncRendererExecutorResponse(status, newClientId()); } } } finally { this.cache.getLock().readLock().unlock(); } } AsyncRendererExecutorResponse response; AsyncRendererJobRequest request = new AsyncRendererJobRequest(); request.setRenderer(renderer); request.setJobGroupPath(renderer.getJobGroupPath()); if (asyncAllowed) { this.cache.getLock().writeLock().lock(); try { if (context != null) { request.setContext(context); } String asyncClientId = newClientId(); if (!renderer.isCacheAllowed()) { jobId.add(asyncClientId); } request.setId(jobId); Job job = this.executor.execute(AsyncRendererJobStatus.JOBTYPE, request); AsyncRendererJobStatus status = (AsyncRendererJobStatus) job.getStatus(); response = new AsyncRendererExecutorResponse(status, asyncClientId); } finally { this.cache.getLock().writeLock().unlock(); } } else { AsyncRendererJobStatus status; if (renderer.isCacheAllowed()) { if (this.asyncContext instanceof DefaultAsyncContext) { ((DefaultAsyncContext) this.asyncContext).pushContextUse(); } AsyncRendererResult result = syncRender(renderer, true, configuration); if (this.asyncContext instanceof DefaultAsyncContext) { ContextUse contextUse = ((DefaultAsyncContext) this.asyncContext).popContextUse(); status = new AsyncRendererJobStatus(request, result, contextUse.getReferences(), contextUse.getRoleTypes(), contextUse.getRoles(), contextUse.getRights(), contextUse.getUses()); } else { status = new AsyncRendererJobStatus(request, result, null, null, null, null, null); } request.setId(jobId); this.cache.put(status); } else { AsyncRendererResult result = syncRender(renderer, false, configuration); status = new AsyncRendererJobStatus(request, result); } response = new AsyncRendererExecutorResponse(status); } return response; }  }
DefaultAsyncRendererExecutor implements AsyncRendererExecutor { @Override public AsyncRendererExecutorResponse render(AsyncRenderer renderer, AsyncRendererConfiguration configuration) throws JobException, RenderingException { boolean asyncAllowed = configuration.isPlaceHolderForced() || (renderer.isAsyncAllowed() && this.asyncContext.isEnabled()); boolean cacheAllowed = renderer.isCacheAllowed(); Map<String, Serializable> context = getContext(asyncAllowed, cacheAllowed, configuration); List<String> jobId = getJobId(renderer, context); if (cacheAllowed) { this.cache.getLock().readLock().lock(); try { AsyncRendererJobStatus status = getCurrent(jobId); if (status != null && (status.getEndDate() == null || this.cacheControl.isCacheReadAllowed(status.getEndDate()))) { if (status.getResult() != null && !configuration.isPlaceHolderForced()) { injectUses(status); return new AsyncRendererExecutorResponse(status); } else if (asyncAllowed) { return new AsyncRendererExecutorResponse(status, newClientId()); } } } finally { this.cache.getLock().readLock().unlock(); } } AsyncRendererExecutorResponse response; AsyncRendererJobRequest request = new AsyncRendererJobRequest(); request.setRenderer(renderer); request.setJobGroupPath(renderer.getJobGroupPath()); if (asyncAllowed) { this.cache.getLock().writeLock().lock(); try { if (context != null) { request.setContext(context); } String asyncClientId = newClientId(); if (!renderer.isCacheAllowed()) { jobId.add(asyncClientId); } request.setId(jobId); Job job = this.executor.execute(AsyncRendererJobStatus.JOBTYPE, request); AsyncRendererJobStatus status = (AsyncRendererJobStatus) job.getStatus(); response = new AsyncRendererExecutorResponse(status, asyncClientId); } finally { this.cache.getLock().writeLock().unlock(); } } else { AsyncRendererJobStatus status; if (renderer.isCacheAllowed()) { if (this.asyncContext instanceof DefaultAsyncContext) { ((DefaultAsyncContext) this.asyncContext).pushContextUse(); } AsyncRendererResult result = syncRender(renderer, true, configuration); if (this.asyncContext instanceof DefaultAsyncContext) { ContextUse contextUse = ((DefaultAsyncContext) this.asyncContext).popContextUse(); status = new AsyncRendererJobStatus(request, result, contextUse.getReferences(), contextUse.getRoleTypes(), contextUse.getRoles(), contextUse.getRights(), contextUse.getUses()); } else { status = new AsyncRendererJobStatus(request, result, null, null, null, null, null); } request.setId(jobId); this.cache.put(status); } else { AsyncRendererResult result = syncRender(renderer, false, configuration); status = new AsyncRendererJobStatus(request, result); } response = new AsyncRendererExecutorResponse(status); } return response; }  @Override AsyncRendererJobStatus getAsyncStatus(List<String> id, String clientId); @Override AsyncRendererJobStatus getAsyncStatus(List<String> id, String clientId, long time, TimeUnit unit); @Override AsyncRendererExecutorResponse render(AsyncRenderer renderer, AsyncRendererConfiguration configuration); }
DefaultAsyncRendererExecutor implements AsyncRendererExecutor { @Override public AsyncRendererExecutorResponse render(AsyncRenderer renderer, AsyncRendererConfiguration configuration) throws JobException, RenderingException { boolean asyncAllowed = configuration.isPlaceHolderForced() || (renderer.isAsyncAllowed() && this.asyncContext.isEnabled()); boolean cacheAllowed = renderer.isCacheAllowed(); Map<String, Serializable> context = getContext(asyncAllowed, cacheAllowed, configuration); List<String> jobId = getJobId(renderer, context); if (cacheAllowed) { this.cache.getLock().readLock().lock(); try { AsyncRendererJobStatus status = getCurrent(jobId); if (status != null && (status.getEndDate() == null || this.cacheControl.isCacheReadAllowed(status.getEndDate()))) { if (status.getResult() != null && !configuration.isPlaceHolderForced()) { injectUses(status); return new AsyncRendererExecutorResponse(status); } else if (asyncAllowed) { return new AsyncRendererExecutorResponse(status, newClientId()); } } } finally { this.cache.getLock().readLock().unlock(); } } AsyncRendererExecutorResponse response; AsyncRendererJobRequest request = new AsyncRendererJobRequest(); request.setRenderer(renderer); request.setJobGroupPath(renderer.getJobGroupPath()); if (asyncAllowed) { this.cache.getLock().writeLock().lock(); try { if (context != null) { request.setContext(context); } String asyncClientId = newClientId(); if (!renderer.isCacheAllowed()) { jobId.add(asyncClientId); } request.setId(jobId); Job job = this.executor.execute(AsyncRendererJobStatus.JOBTYPE, request); AsyncRendererJobStatus status = (AsyncRendererJobStatus) job.getStatus(); response = new AsyncRendererExecutorResponse(status, asyncClientId); } finally { this.cache.getLock().writeLock().unlock(); } } else { AsyncRendererJobStatus status; if (renderer.isCacheAllowed()) { if (this.asyncContext instanceof DefaultAsyncContext) { ((DefaultAsyncContext) this.asyncContext).pushContextUse(); } AsyncRendererResult result = syncRender(renderer, true, configuration); if (this.asyncContext instanceof DefaultAsyncContext) { ContextUse contextUse = ((DefaultAsyncContext) this.asyncContext).popContextUse(); status = new AsyncRendererJobStatus(request, result, contextUse.getReferences(), contextUse.getRoleTypes(), contextUse.getRoles(), contextUse.getRights(), contextUse.getUses()); } else { status = new AsyncRendererJobStatus(request, result, null, null, null, null, null); } request.setId(jobId); this.cache.put(status); } else { AsyncRendererResult result = syncRender(renderer, false, configuration); status = new AsyncRendererJobStatus(request, result); } response = new AsyncRendererExecutorResponse(status); } return response; }  @Override AsyncRendererJobStatus getAsyncStatus(List<String> id, String clientId); @Override AsyncRendererJobStatus getAsyncStatus(List<String> id, String clientId, long time, TimeUnit unit); @Override AsyncRendererExecutorResponse render(AsyncRenderer renderer, AsyncRendererConfiguration configuration);  }