private void invokeAll(Ice.OutputStream os, int requestId) { if (_traceLevels.protocol >= 1) { fillInValue(os, 10, os.size()); if (requestId > 0) { fillInValue(os, Protocol.headerSize, requestId); } TraceUtil.traceSend(os, _logger, _traceLevels); } Ice.InputStream iss = new Ice.InputStream(os.communicator(), os.GetEncoding(), os.GetBuffer(), false); iss.pos(Protocol.requestHdr.Length); int invokeNum = 1; ServantManager servantManager = _adapter.getServantManager(); try { while (invokeNum > 0) { // // Increase the direct count for the dispatch. We increase it again here for // each dispatch. It's important for the direct count to be > 0 until the last // collocated request response is sent to make sure the thread pool isn't // destroyed before. // try { _adapter.incDirectCount(); } catch (Ice.ObjectAdapterDeactivatedException ex) { handleException(requestId, ex, false); break; } Incoming inS = new Incoming(_reference.getCommunicator(), this, null, _adapter, _response, 0, requestId); inS.invoke(servantManager, iss); --invokeNum; } } catch (Ice.LocalException ex) { invokeException(requestId, ex, invokeNum, false); // Fatal invocation exception } _adapter.decDirectCount(); }
public void sendResponse(int requestId, Ice.OutputStream os, byte status, bool amd) { OutgoingAsyncBase outAsync; lock (this) { Debug.Assert(_response); if (_traceLevels.protocol >= 1) { fillInValue(os, 10, os.size()); } // Adopt the OutputStream's buffer. Ice.InputStream iss = new Ice.InputStream(os.instance(), os.getEncoding(), os.getBuffer(), true); iss.pos(Protocol.replyHdr.Length + 4); if (_traceLevels.protocol >= 1) { TraceUtil.traceRecv(iss, _logger, _traceLevels); } if (_asyncRequests.TryGetValue(requestId, out outAsync)) { outAsync.getIs().swap(iss); if (!outAsync.response()) { outAsync = null; } _asyncRequests.Remove(requestId); } } if (outAsync != null) { if (amd) { outAsync.invokeResponseAsync(); } else { outAsync.invokeResponse(); } } _adapter.decDirectCount(); }
public BatchRequestQueue(Instance instance, bool datagram) { Ice.InitializationData initData = instance.initializationData(); _interceptor = initData.batchRequestInterceptor; _batchStreamInUse = false; _batchRequestNum = 0; _batchStream = new Ice.OutputStream(instance, Ice.Util.currentProtocolEncoding); _batchStream.writeBlob(Protocol.requestBatchHdr); _batchMarker = _batchStream.size(); _request = new BatchRequestI(this); _maxSize = instance.batchAutoFlushSize(); if (_maxSize > 0 && datagram) { int udpSndSize = initData.properties.getPropertyAsIntWithDefault("Ice.UDP.SndSize", 65535 - _udpOverhead); if (udpSndSize < _maxSize) { _maxSize = udpSndSize; } } }
private void handleException(Exception exc, bool amd) { Debug.Assert(_responseHandler != null); if (exc is Ice.SystemException) { if (_responseHandler.systemException(_current.requestId, (Ice.SystemException)exc, amd)) { return; } } try { throw exc; } catch (Ice.RequestFailedException ex) { if (ex.id == null || ex.id.name == null || ex.id.name.Length == 0) { ex.id = _current.id; } if (ex.facet == null || ex.facet.Length == 0) { ex.facet = _current.facet; } if (ex.operation == null || ex.operation.Length == 0) { ex.operation = _current.operation; } if (_instance.initializationData().properties.getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 1) { warning(ex); } if (_observer != null) { _observer.failed(ex.ice_id()); } if (_response) { _os = new Ice.OutputStream(_instance, Ice.Util.currentProtocolEncoding); _os.writeBlob(Protocol.replyHdr); _os.writeInt(_current.requestId); if (ex is Ice.ObjectNotExistException) { _os.writeByte(ReplyStatus.replyObjectNotExist); } else if (ex is Ice.FacetNotExistException) { _os.writeByte(ReplyStatus.replyFacetNotExist); } else if (ex is Ice.OperationNotExistException) { _os.writeByte(ReplyStatus.replyOperationNotExist); } else { Debug.Assert(false); } ex.id.ice_writeMembers(_os); // // For compatibility with the old FacetPath. // if (ex.facet == null || ex.facet.Length == 0) { _os.writeStringSeq(null); } else { string[] facetPath2 = { ex.facet }; _os.writeStringSeq(facetPath2); } _os.writeString(ex.operation); if (_observer != null) { _observer.reply(_os.size() - Protocol.headerSize - 4); } _responseHandler.sendResponse(_current.requestId, _os, _compress, amd); } else { _responseHandler.sendNoResponse(); } } catch (Ice.UnknownLocalException ex) { if (_instance.initializationData().properties.getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) { warning(ex); } if (_observer != null) { _observer.failed(ex.ice_id()); } if (_response) { _os = new Ice.OutputStream(_instance, Ice.Util.currentProtocolEncoding); _os.writeBlob(Protocol.replyHdr); _os.writeInt(_current.requestId); _os.writeByte(ReplyStatus.replyUnknownLocalException); _os.writeString(ex.unknown); if (_observer != null) { _observer.reply(_os.size() - Protocol.headerSize - 4); } _responseHandler.sendResponse(_current.requestId, _os, _compress, amd); } else { _responseHandler.sendNoResponse(); } } catch (Ice.UnknownUserException ex) { if (_instance.initializationData().properties.getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) { warning(ex); } if (_observer != null) { _observer.failed(ex.ice_id()); } if (_response) { _os = new Ice.OutputStream(_instance, Ice.Util.currentProtocolEncoding); _os.writeBlob(Protocol.replyHdr); _os.writeInt(_current.requestId); _os.writeByte(ReplyStatus.replyUnknownUserException); _os.writeString(ex.unknown); if (_observer != null) { _observer.reply(_os.size() - Protocol.headerSize - 4); } Debug.Assert(_responseHandler != null && _current != null); _responseHandler.sendResponse(_current.requestId, _os, _compress, amd); } else { _responseHandler.sendNoResponse(); } } catch (Ice.UnknownException ex) { if (_instance.initializationData().properties.getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) { warning(ex); } if (_observer != null) { _observer.failed(ex.ice_id()); } if (_response) { _os = new Ice.OutputStream(_instance, Ice.Util.currentProtocolEncoding); _os.writeBlob(Protocol.replyHdr); _os.writeInt(_current.requestId); _os.writeByte(ReplyStatus.replyUnknownException); _os.writeString(ex.unknown); if (_observer != null) { _observer.reply(_os.size() - Protocol.headerSize - 4); } _responseHandler.sendResponse(_current.requestId, _os, _compress, amd); } else { _responseHandler.sendNoResponse(); } } catch (Ice.UserException ex) { if (_observer != null) { _observer.userException(); } if (_response) { _os = new Ice.OutputStream(_instance, Ice.Util.currentProtocolEncoding); _os.writeBlob(Protocol.replyHdr); _os.writeInt(_current.requestId); _os.writeByte(ReplyStatus.replyUserException); _os.startEncapsulation(_current.encoding, _format); _os.writeException(ex); _os.endEncapsulation(); if (_observer != null) { _observer.reply(_os.size() - Protocol.headerSize - 4); } _responseHandler.sendResponse(_current.requestId, _os, _compress, false); } else { _responseHandler.sendNoResponse(); } } catch (Ice.Exception ex) { if (_instance.initializationData().properties.getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) { warning(ex); } if (_observer != null) { _observer.failed(ex.ice_id()); } if (_response) { _os = new Ice.OutputStream(_instance, Ice.Util.currentProtocolEncoding); _os.writeBlob(Protocol.replyHdr); _os.writeInt(_current.requestId); _os.writeByte(ReplyStatus.replyUnknownLocalException); _os.writeString(ex.ice_id() + "\n" + ex.StackTrace); if (_observer != null) { _observer.reply(_os.size() - Protocol.headerSize - 4); } _responseHandler.sendResponse(_current.requestId, _os, _compress, amd); } else { _responseHandler.sendNoResponse(); } } catch (Exception ex) { if (_instance.initializationData().properties.getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) { warning(ex); } if (_observer != null) { _observer.failed(ex.GetType().FullName); } if (_response) { _os = new Ice.OutputStream(_instance, Ice.Util.currentProtocolEncoding); _os.writeBlob(Protocol.replyHdr); _os.writeInt(_current.requestId); _os.writeByte(ReplyStatus.replyUnknownException); _os.writeString(ex.ToString()); if (_observer != null) { _observer.reply(_os.size() - Protocol.headerSize - 4); } _responseHandler.sendResponse(_current.requestId, _os, _compress, amd); } else { _responseHandler.sendNoResponse(); } } if (_observer != null) { _observer.detach(); _observer = null; } _responseHandler = null; }