private void testCleanup() { transfer.cleanup(); // check all thread locals have been cleaned up from the current // thread assertNull(Dispatcher.REQUEST.get()); assertNull(AdminRequest.get()); assertNull(LocalPublished.get()); assertNull(LocalWorkspace.get()); assertNull(SecurityContextHolder.getContext().getAuthentication()); } });
@Override public Future<?> submit(Runnable task) { ThreadLocalsTransfer threadLocalTransfer = new ThreadLocalsTransfer(); return super.submit( () -> { threadLocalTransfer.apply(); try { task.run(); } finally { threadLocalTransfer.cleanup(); } }); }
@Override public <T> Future<T> submit(Callable<T> task) { ThreadLocalsTransfer threadLocalTransfer = new ThreadLocalsTransfer(); return super.submit( () -> { threadLocalTransfer.apply(); try { return task.call(); } finally { threadLocalTransfer.cleanup(); } }); }
@Override public <T> Future<T> submit(Runnable task, T result) { ThreadLocalsTransfer threadLocalTransfer = new ThreadLocalsTransfer(); return super.submit( () -> { threadLocalTransfer.apply(); try { task.run(); return result; } finally { threadLocalTransfer.cleanup(); } }); } }
@Override public ExecuteResponseType call() { if (transfer != null) { try { transfer.apply(); localProcesses.put(status.getExecutionId(), notifier); return execute(); } finally { localProcesses.remove(status.getExecutionId()); try { transfer.cleanup(); } finally { resourceManager.finished(status.getExecutionId()); } } } else { return execute(); } }
@Override public Map<String, Object> call() throws Exception { try { // transfer the thread locals to this execution context threadLocalTransfer.apply(); ProcessFactory pf = GeoServerProcessors.createProcessFactory(processName, true); if (pf == null) { throw new WPSException("No such process: " + processName); } // execute the process Map<String, Object> result = null; Process p = pf.create(processName); result = p.execute(inputs, listener); return result; } finally { // clean up the thread locals threadLocalTransfer.cleanup(); } } }