302
303 Fiber(Engine engine) {
304 this.owner = engine;
305 id = iotaGen.incrementAndGet();
306 if (isTraceEnabled()) {
307 LOGGER.log(Level.FINE, "{0} created", getName());
308 }
309
310 // if this is run from another fiber, then we naturally inherit its context classloader,
311 // so this code works for fiber->fiber inheritance just fine.
312 contextClassLoader = Thread.currentThread().getContextClassLoader();
313 }
314
315 /**
316 * Starts the execution of this fiber asynchronously.
317 * <p/>
318 * <p/>
319 * This method works like {@link Thread#start()}.
320 *
321 * @param tubeline The first tube of the tubeline that will act on the packet.
322 * @param request The request packet to be passed to <tt>startPoint.processRequest()</tt>.
323 * @param completionCallback The callback to be invoked when the processing is finished and the
324 * final response packet is available.
325 * @see #runSync(Tube, Packet)
326 */
327 public void start(@NotNull Tube tubeline, @NotNull Packet request, @Nullable CompletionCallback completionCallback) {
328 start(tubeline, request, completionCallback, false);
329 }
330
331 private void dumpFiberContext(String desc) {
332 if(isTraceEnabled()) {
333 String action = null;
334 String msgId = null;
335 if (packet != null) {
336 for (SOAPVersion sv: SOAPVersion.values()) {
337 for (AddressingVersion av: AddressingVersion.values()) {
338 action = packet.getMessage() != null ? AddressingUtils.getAction(packet.getMessage().getHeaders(), av, sv) : null;
339 msgId = packet.getMessage() != null ? AddressingUtils.getMessageID(packet.getMessage().getHeaders(), av, sv) : null;
340 if (action != null || msgId != null) {
341 break;
342 }
368 * Starts the execution of this fiber.
369 *
370 * If forceSync is true, then the fiber is started for an ostensibly async invocation,
371 * but allows for some portion of the tubeline to run sync with the calling
372 * client instance (Port/Dispatch instance). This allows tubes that enforce
373 * ordering to see requests in the order they were sent at the point the
374 * client invoked them.
375 * <p>
376 * The forceSync parameter will be true only when the caller (e.g. AsyncInvoker or
377 * SEIStub) knows one or more tubes need to enforce ordering and thus need
378 * to run sync with the client. Such tubes can return
379 * NextAction.INVOKE_ASYNC to indicate that the next tube in the tubeline
380 * should be invoked async to the current thread.
381 *
382 * <p>
383 * This method works like {@link Thread#start()}.
384 *
385 * @param tubeline
386 * The first tube of the tubeline that will act on the packet.
387 * @param request
388 * The request packet to be passed to <tt>startPoint.processRequest()</tt>.
389 * @param completionCallback
390 * The callback to be invoked when the processing is finished and the
391 * final response packet is available.
392 *
393 * @see #start(Tube,Packet,CompletionCallback)
394 * @see #runSync(Tube,Packet)
395 * @since 2.2.6
396 */
397 public void start(@NotNull Tube tubeline, @NotNull Packet request, @Nullable CompletionCallback completionCallback, boolean forceSync) {
398 next = tubeline;
399 this.packet = request;
400 this.completionCallback = completionCallback;
401
402 if (forceSync) {
403 this.startedSync = true;
404 dumpFiberContext("starting (sync)");
405 run();
406 } else {
407 this.started = true;
408 dumpFiberContext("starting (async)");
818 * <p/>
819 * <p/>
820 * This method blocks and returns only when all the successive {@link Tube}s
821 * complete their request/response processing. This method can be used
822 * if a {@link Tube} needs to fallback to synchronous processing.
823 * <p/>
824 * <h3>Example:</h3>
825 * <pre>
826 * class FooTube extends {@link AbstractFilterTubeImpl} {
827 * NextAction processRequest(Packet request) {
828 * // run everything synchronously and return with the response packet
829 * return doReturnWith(Fiber.current().runSync(next,request));
830 * }
831 * NextAction processResponse(Packet response) {
832 * // never be invoked
833 * }
834 * }
835 * </pre>
836 *
837 * @param tubeline The first tube of the tubeline that will act on the packet.
838 * @param request The request packet to be passed to <tt>startPoint.processRequest()</tt>.
839 * @return The response packet to the <tt>request</tt>.
840 * @see #start(Tube, Packet, CompletionCallback)
841 */
842 public
843 @NotNull
844 Packet runSync(@NotNull Tube tubeline, @NotNull Packet request) {
845 lock.lock();
846 try {
847 // save the current continuation, so that we return runSync() without executing them.
848 final Tube[] oldCont = conts;
849 final int oldContSize = contsSize;
850 final boolean oldSynchronous = synchronous;
851 final Tube oldNext = next;
852
853 if (oldContSize > 0) {
854 conts = new Tube[16];
855 contsSize = 0;
856 }
857
858 try {
859 synchronous = true;
|
302
303 Fiber(Engine engine) {
304 this.owner = engine;
305 id = iotaGen.incrementAndGet();
306 if (isTraceEnabled()) {
307 LOGGER.log(Level.FINE, "{0} created", getName());
308 }
309
310 // if this is run from another fiber, then we naturally inherit its context classloader,
311 // so this code works for fiber->fiber inheritance just fine.
312 contextClassLoader = Thread.currentThread().getContextClassLoader();
313 }
314
315 /**
316 * Starts the execution of this fiber asynchronously.
317 * <p/>
318 * <p/>
319 * This method works like {@link Thread#start()}.
320 *
321 * @param tubeline The first tube of the tubeline that will act on the packet.
322 * @param request The request packet to be passed to {@code startPoint.processRequest()}.
323 * @param completionCallback The callback to be invoked when the processing is finished and the
324 * final response packet is available.
325 * @see #runSync(Tube, Packet)
326 */
327 public void start(@NotNull Tube tubeline, @NotNull Packet request, @Nullable CompletionCallback completionCallback) {
328 start(tubeline, request, completionCallback, false);
329 }
330
331 private void dumpFiberContext(String desc) {
332 if(isTraceEnabled()) {
333 String action = null;
334 String msgId = null;
335 if (packet != null) {
336 for (SOAPVersion sv: SOAPVersion.values()) {
337 for (AddressingVersion av: AddressingVersion.values()) {
338 action = packet.getMessage() != null ? AddressingUtils.getAction(packet.getMessage().getHeaders(), av, sv) : null;
339 msgId = packet.getMessage() != null ? AddressingUtils.getMessageID(packet.getMessage().getHeaders(), av, sv) : null;
340 if (action != null || msgId != null) {
341 break;
342 }
368 * Starts the execution of this fiber.
369 *
370 * If forceSync is true, then the fiber is started for an ostensibly async invocation,
371 * but allows for some portion of the tubeline to run sync with the calling
372 * client instance (Port/Dispatch instance). This allows tubes that enforce
373 * ordering to see requests in the order they were sent at the point the
374 * client invoked them.
375 * <p>
376 * The forceSync parameter will be true only when the caller (e.g. AsyncInvoker or
377 * SEIStub) knows one or more tubes need to enforce ordering and thus need
378 * to run sync with the client. Such tubes can return
379 * NextAction.INVOKE_ASYNC to indicate that the next tube in the tubeline
380 * should be invoked async to the current thread.
381 *
382 * <p>
383 * This method works like {@link Thread#start()}.
384 *
385 * @param tubeline
386 * The first tube of the tubeline that will act on the packet.
387 * @param request
388 * The request packet to be passed to {@code startPoint.processRequest()}.
389 * @param completionCallback
390 * The callback to be invoked when the processing is finished and the
391 * final response packet is available.
392 *
393 * @see #start(Tube,Packet,CompletionCallback)
394 * @see #runSync(Tube,Packet)
395 * @since 2.2.6
396 */
397 public void start(@NotNull Tube tubeline, @NotNull Packet request, @Nullable CompletionCallback completionCallback, boolean forceSync) {
398 next = tubeline;
399 this.packet = request;
400 this.completionCallback = completionCallback;
401
402 if (forceSync) {
403 this.startedSync = true;
404 dumpFiberContext("starting (sync)");
405 run();
406 } else {
407 this.started = true;
408 dumpFiberContext("starting (async)");
818 * <p/>
819 * <p/>
820 * This method blocks and returns only when all the successive {@link Tube}s
821 * complete their request/response processing. This method can be used
822 * if a {@link Tube} needs to fallback to synchronous processing.
823 * <p/>
824 * <h3>Example:</h3>
825 * <pre>
826 * class FooTube extends {@link AbstractFilterTubeImpl} {
827 * NextAction processRequest(Packet request) {
828 * // run everything synchronously and return with the response packet
829 * return doReturnWith(Fiber.current().runSync(next,request));
830 * }
831 * NextAction processResponse(Packet response) {
832 * // never be invoked
833 * }
834 * }
835 * </pre>
836 *
837 * @param tubeline The first tube of the tubeline that will act on the packet.
838 * @param request The request packet to be passed to {@code startPoint.processRequest()}.
839 * @return The response packet to the {@code request}.
840 * @see #start(Tube, Packet, CompletionCallback)
841 */
842 public
843 @NotNull
844 Packet runSync(@NotNull Tube tubeline, @NotNull Packet request) {
845 lock.lock();
846 try {
847 // save the current continuation, so that we return runSync() without executing them.
848 final Tube[] oldCont = conts;
849 final int oldContSize = contsSize;
850 final boolean oldSynchronous = synchronous;
851 final Tube oldNext = next;
852
853 if (oldContSize > 0) {
854 conts = new Tube[16];
855 contsSize = 0;
856 }
857
858 try {
859 synchronous = true;
|