/** * Serializes the work context. * * @param workContext the work context * @return the serialized work context * @throws IOException if a serialization error is encountered */ private byte[] serialize(WorkContext workContext) throws IOException { List<CallbackReference> stack = workContext.getCallbackReferences(); if (stack == null || stack.isEmpty()) { return null; } return CallbackReferenceSerializer.serializeToBytes(stack); }
/** * Serializes the work context. * * @param workContext the work context * @return the serialized work context * @throws IOException if a serialization error is encountered */ private byte[] serialize(WorkContext workContext) throws IOException { List<CallbackReference> stack = workContext.getCallbackReferences(); if (stack == null || stack.isEmpty()) { return null; } return CallbackReferenceSerializer.serializeToBytes(stack); }
private PropagatingRunnable createRunnable(Runnable runnable) { WorkContext context = WorkContextCache.getThreadWorkContext(); List<CallbackReference> stack = context.getCallbackReferences(); if (stack != null && !stack.isEmpty()) { // clone the callstack to avoid multiple threads seeing changes stack = new ArrayList<CallbackReference>(stack); } Map<String, Object> headers = context.getHeaders(); if (headers != null && !headers.isEmpty()) { // clone the headers to avoid multiple threads seeing changes headers = new HashMap<String, Object>(headers); } SecuritySubject subject = context.getSubject(); return new PropagatingRunnable(runnable, stack, headers, subject); }
private <T> PropagatingCallable<T> createCallable(Callable<T> callable) { WorkContext context = WorkContextCache.getThreadWorkContext(); List<CallbackReference> stack = context.getCallbackReferences(); if (stack != null && !stack.isEmpty()) { // clone the callstack to avoid multiple threads seeing changes stack = new ArrayList<CallbackReference>(stack); } Map<String, Object> headers = context.getHeaders(); if (headers != null && !headers.isEmpty()) { // clone the headers to avoid multiple threads seeing changes headers = new HashMap<String, Object>(headers); } SecuritySubject subject = context.getSubject(); return new PropagatingCallable<T>(callable, stack, headers, subject); }
public Message invoke(final Message msg) { WorkContext workContext = msg.getWorkContext(); List<CallbackReference> newStack = null; List<CallbackReference> stack = workContext.getCallbackReferences(); if (stack != null && !stack.isEmpty()) { // clone the callstack to avoid multiple threads seeing changes newStack = new ArrayList<CallbackReference>(stack); } Map<String, Object> newHeaders = null; Map<String, Object> headers = workContext.getHeaders(); if (headers != null && !headers.isEmpty()) { // clone the headers to avoid multiple threads seeing changes newHeaders = new HashMap<String, Object>(headers); } SecuritySubject subject = workContext.getSubject(); Object payload = msg.getBody(); AsyncRequest request = new AsyncRequest(next, payload, subject, newStack, newHeaders, monitor); executorService.execute(request); return RESPONSE; }