private void processAsync(final Packet request, final CompletionCallback callback, FiberContextSwitchInterceptor interceptor, boolean schedule) {
request.endpoint = WSEndpointImpl.this;
if (wsdlProperties != null) {
request.addSatellite(wsdlProperties);
}
Fiber fiber = engine.createFiber();
if (interceptor != null) {
fiber.addInterceptor(interceptor);
}
final Tube tube = tubePool.take();
Fiber.CompletionCallback cbak = new Fiber.CompletionCallback() {
public void onCompletion(@NotNull Packet response) {
tubePool.recycle(tube);
if (callback!=null) {
callback.onCompletion(response);
}
}
public void onCompletion(@NotNull Throwable error) {
// let's not reuse tubes as they might be in a wrong state, so not
// calling tubePool.recycle()
error.printStackTrace();
// Convert all runtime exceptions to Packet so that transport doesn't
// have to worry about converting to wire message
// TODO XML/HTTP binding
Message faultMsg = SOAPFaultBuilder.createSOAPFaultMessage(
soapVersion, null, error);
Packet response = request.createServerResponse(faultMsg, request.endpoint.getPort(), null,
request.endpoint.getBinding());
if (callback!=null) {
callback.onCompletion(response);
}
}
};
if (schedule) {
fiber.start(tube, request, cbak);
} else {
fiber.runAsync(tube, request, cbak);
}
}