final Authentication auth = new UsernamePasswordAuthenticationToken("user", "password"); SecurityContextHolder.getContext().setAuthentication(auth); final ThreadLocalsTransfer transfer = new ThreadLocalsTransfer(); Future<Void> future = executor.submit(
private void testApply() { transfer.apply(); // check all thread locals have been applied to the current thread assertSame(request, Dispatcher.REQUEST.get()); assertSame(myState, AdminRequest.get()); assertSame(layer, LocalPublished.get()); assertSame(ws, LocalWorkspace.get()); assertSame( auth, SecurityContextHolder.getContext().getAuthentication()); }
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 <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 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(); } } }
@Override public Future<?> submit(Runnable task) { ThreadLocalsTransfer threadLocalTransfer = new ThreadLocalsTransfer(); return super.submit( () -> { threadLocalTransfer.apply(); try { task.run(); } 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 <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(); } }); } }
public ProcessCallable( Name processName, Map<String, Object> inputs, ProgressListener listener) { this.processName = processName; this.inputs = inputs; this.listener = listener; this.threadLocalTransfer = new ThreadLocalsTransfer(); }
this.transfer = new ThreadLocalsTransfer();