public bool invokeAsyncRequest(OutgoingAsyncBase outAsync, int batchRequestNum, bool synchronous, out Ice.AsyncCallback sentCallback) { // // Increase the direct count to prevent the thread pool from being destroyed before // invokeAll is called. This will also throw if the object adapter has been deactivated. // _adapter.incDirectCount(); int requestId = 0; try { lock (this) { outAsync.cancelable(this); // This will throw if the request is canceled if (_response) { requestId = ++_requestId; _asyncRequests.Add(requestId, outAsync); } _sendAsyncRequests.Add(outAsync, requestId); } } catch (System.Exception ex) { _adapter.decDirectCount(); throw ex; } outAsync.attachCollocatedObserver(_adapter, requestId); if (synchronous) { // // Treat this collocated call as if it is a synchronous invocation. // if (_reference.getInvocationTimeout() > 0 || !_response) { // Don't invoke from the user thread, invocation timeouts wouldn't work otherwise. _adapter.getThreadPool().dispatch(() => { if (sentAsync(outAsync)) { invokeAll(outAsync.getOs(), requestId, batchRequestNum); } }, null); } else if (_dispatcher) { _adapter.getThreadPool().dispatchFromThisThread(() => { if (sentAsync(outAsync)) { invokeAll(outAsync.getOs(), requestId, batchRequestNum); } }, null); } else // Optimization: directly call invokeAll if there's no dispatcher. { if (sentAsync(outAsync)) { invokeAll(outAsync.getOs(), requestId, batchRequestNum); } } sentCallback = null; } else { _adapter.getThreadPool().dispatch(() => { if (sentAsync(outAsync)) { invokeAll(outAsync.getOs(), requestId, batchRequestNum); } }, null); sentCallback = null; } return(false); }
public int invokeAsyncRequest(OutgoingAsyncBase outAsync, bool synchronous) { // // Increase the direct count to prevent the thread pool from being destroyed before // invokeAll is called. This will also throw if the object adapter has been deactivated. // _adapter.incDirectCount(); int requestId = 0; try { lock (this) { outAsync.cancelable(this); // This will throw if the request is canceled if (_response) { requestId = ++_requestId; _asyncRequests.Add(requestId, outAsync); } _sendAsyncRequests.Add(outAsync, requestId); } } catch (Exception) { _adapter.decDirectCount(); throw; } outAsync.attachCollocatedObserver(_adapter, requestId); if (!synchronous || !_response || _reference.getInvocationTimeout() > 0) { // Don't invoke from the user thread if async or invocation timeout is set _adapter.getThreadPool().dispatch( () => { if (sentAsync(outAsync)) { invokeAll(outAsync.getOs(), requestId); } }, null); } else if (_dispatcher) { _adapter.getThreadPool().dispatchFromThisThread( () => { if (sentAsync(outAsync)) { invokeAll(outAsync.getOs(), requestId); } }, null); } else // Optimization: directly call invokeAll if there's no dispatcher. { if (sentAsync(outAsync)) { invokeAll(outAsync.getOs(), requestId); } } return(OutgoingAsyncBase.AsyncStatusQueued); }