public IncomingAsync(Incoming inc) : base(inc) { _retriable = inc.isRetriable(); if(_retriable) { inc.setActive(this); _active = true; } }
public IncomingAsync(Incoming inc) : base(inc) { _retriable = inc.isRetriable(); if (_retriable) { inc.setActive(this); _active = true; } }
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(); }
internal void deactivate__(Incoming inc) { Debug.Assert(_retriable); lock(this) { if(!_active) { // // Since __deactivate can only be called on an active object, // this means the response has already been sent (see validateXXX below) // throw new Ice.ResponseSentException(); } _active = false; } inc.adopt(this); }
internal void deactivate__(Incoming inc) { Debug.Assert(_retriable); lock (this) { if (!_active) { // // Since __deactivate can only be called on an active object, // this means the response has already been sent (see validateXXX below) // throw new Ice.ResponseSentException(); } _active = false; } inc.adopt(this); }
private async ValueTask InvokeAllAsync(OutgoingRequestFrame outgoingRequest, int requestId) { // The object adapter DirectCount was incremented by the caller and we are responsible to decrement it // upon completion. Ice.Instrumentation.IDispatchObserver?dispatchObserver = null; try { if (_traceLevels.Protocol >= 1) { // TODO we need a better API for tracing List <System.ArraySegment <byte> > requestData = Ice1Definitions.GetRequestData(outgoingRequest, requestId); TraceUtil.TraceSend(_adapter.Communicator, VectoredBufferExtensions.ToArray(requestData), _logger, _traceLevels); } var incomingRequest = new IncomingRequestFrame(_adapter.Communicator, outgoingRequest); var current = new Current(_adapter, incomingRequest, requestId); // Then notify and set dispatch observer, if any. Ice.Instrumentation.ICommunicatorObserver?communicatorObserver = _adapter.Communicator.Observer; if (communicatorObserver != null) { dispatchObserver = communicatorObserver.GetDispatchObserver(current, incomingRequest.Size); dispatchObserver?.Attach(); } bool amd = true; try { IObject?servant = current.Adapter.Find(current.Identity, current.Facet); if (servant == null) { amd = false; throw new ObjectNotExistException(current.Identity, current.Facet, current.Operation); } ValueTask <OutgoingResponseFrame> vt = servant.DispatchAsync(incomingRequest, current); amd = !vt.IsCompleted; if (requestId != 0) { OutgoingResponseFrame response = await vt.ConfigureAwait(false); dispatchObserver?.Reply(response.Size); SendResponse(requestId, response, amd); } } catch (System.Exception ex) { if (requestId != 0) { RemoteException actualEx; if (ex is RemoteException remoteEx && !remoteEx.ConvertToUnhandled) { actualEx = remoteEx; } else { actualEx = new UnhandledException(current.Identity, current.Facet, current.Operation, ex); } Incoming.ReportException(actualEx, dispatchObserver, current); var response = new OutgoingResponseFrame(current, actualEx); dispatchObserver?.Reply(response.Size); SendResponse(requestId, response, amd); } } }
private void invokeAll(Ice.OutputStream os, int requestId, int batchRequestNum) { if(_traceLevels.protocol >= 1) { fillInValue(os, 10, os.size()); if(requestId > 0) { fillInValue(os, Protocol.headerSize, requestId); } else if(batchRequestNum > 0) { fillInValue(os, Protocol.headerSize, batchRequestNum); } TraceUtil.traceSend(os, _logger, _traceLevels); } Ice.InputStream iss = new Ice.InputStream(os.instance(), os.getEncoding(), os.getBuffer(), false); if(batchRequestNum > 0) { iss.pos(Protocol.requestBatchHdr.Length); } else { iss.pos(Protocol.requestHdr.Length); } int invokeNum = batchRequestNum > 0 ? batchRequestNum : 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 @in = new Incoming(_reference.getInstance(), this, null, _adapter, _response, (byte)0, requestId); @in.invoke(servantManager, iss); --invokeNum; } } catch(Ice.LocalException ex) { invokeException(requestId, ex, invokeNum, false); // Fatal invocation exception } _adapter.decDirectCount(); }
private IceInternal.Incoming getIncoming(ObjectAdapter adapter, bool response, byte compress, int requestId) { IceInternal.Incoming inc = null; if(_cacheBuffers) { lock(_incomingCacheMutex) { if(_incomingCache == null) { inc = new IceInternal.Incoming(_instance, this, this, adapter, response, compress, requestId); } else { inc = _incomingCache; _incomingCache = _incomingCache.next; inc.reset(_instance, this, this, adapter, response, compress, requestId); inc.next = null; } } } else { inc = new IceInternal.Incoming(_instance, this, this, adapter, response, compress, requestId); } return inc; }
private void finish() { if(!_initialized) { if(_instance.traceLevels().network >= 2) { StringBuilder s = new StringBuilder("failed to "); s.Append(_connector != null ? "establish" : "accept"); s.Append(" "); s.Append(_endpoint.protocol()); s.Append(" connection\n"); s.Append(ToString()); s.Append("\n"); s.Append(_exception); _instance.initializationData().logger.trace(_instance.traceLevels().networkCat, s.ToString()); } } else { if(_instance.traceLevels().network >= 1) { StringBuilder s = new StringBuilder("closed "); s.Append(_endpoint.protocol()); s.Append(" connection\n"); s.Append(ToString()); // // Trace the cause of unexpected connection closures // if(!(_exception is CloseConnectionException || _exception is ForcedCloseConnectionException || _exception is ConnectionTimeoutException || _exception is CommunicatorDestroyedException || _exception is ObjectAdapterDeactivatedException)) { s.Append("\n"); s.Append(_exception); } _instance.initializationData().logger.trace(_instance.traceLevels().networkCat, s.ToString()); } } if(_startCallback != null) { _startCallback.connectionStartFailed(this, _exception); _startCallback = null; } if(_sendStreams.Count > 0) { if(!_writeStream.isEmpty()) { // // Return the stream to the outgoing call. This is important for // retriable AMI calls which are not marshalled again. // OutgoingMessage message = _sendStreams.First.Value; _writeStream.swap(message.stream); // // The current message might be sent but not yet removed from _sendStreams. If // the response has been received in the meantime, we remove the message from // _sendStreams to not call finished on a message which is already done. // if(message.isSent || message.receivedReply) { if(message.sent() && message.invokeSent) { message.outAsync.invokeSent(); } if(message.receivedReply) { IceInternal.OutgoingAsync outAsync = (IceInternal.OutgoingAsync)message.outAsync; if(outAsync.response()) { outAsync.invokeResponse(); } } _sendStreams.RemoveFirst(); } } foreach (OutgoingMessage o in _sendStreams) { o.completed(_exception); if(o.requestId > 0) // Make sure finished isn't called twice. { _asyncRequests.Remove(o.requestId); } } _sendStreams.Clear(); // Must be cleared before _requests because of Outgoing* references in OutgoingMessage } foreach(IceInternal.OutgoingAsyncBase o in _asyncRequests.Values) { if(o.exception(_exception)) { o.invokeException(); } } _asyncRequests.Clear(); // // Don't wait to be reaped to reclaim memory allocated by read/write streams. // _writeStream.clear(); _writeStream.getBuffer().clear(); _readStream.clear(); _readStream.getBuffer().clear(); _incomingCache = null; if(_closeCallback != null) { try { _closeCallback(this); } catch(System.Exception ex) { _logger.error("connection callback exception:\n" + ex + '\n' + _desc); } _closeCallback = null; } _heartbeatCallback = null; // // This must be done last as this will cause waitUntilFinished() to return (and communicator // objects such as the timer might be destroyed too). // lock(this) { setState(StateFinished); if(_dispatchCount == 0) { reap(); } } }
internal void reclaimIncoming(IceInternal.Incoming inc) { if(_cacheBuffers && inc.reclaim()) { lock(_incomingCacheMutex) { inc.next = _incomingCache; _incomingCache = inc; } } }
private void invokeAll(BasicStream os, int requestId, int invokeNum, bool batch) { if(batch) { os.pos(Protocol.requestBatchHdr.Length); } else { os.pos(Protocol.requestHdr.Length); } if(_traceLevels.protocol >= 1) { fillInValue(os, 10, os.size()); if(requestId > 0) { fillInValue(os, Protocol.headerSize, requestId); } else if(batch) { fillInValue(os, Protocol.headerSize, invokeNum); } TraceUtil.traceSend(os, _logger, _traceLevels); } ServantManager servantManager = _adapter.getServantManager(); try { while(invokeNum > 0) { try { _adapter.incDirectCount(); } catch(Ice.ObjectAdapterDeactivatedException ex) { handleException(requestId, ex, false); return; } Incoming @in = new Incoming(_reference.getInstance(), this, null, _adapter, _response, (byte)0, requestId); @in.invoke(servantManager, os); --invokeNum; } } catch(Ice.LocalException ex) { invokeException(requestId, ex, invokeNum, false); // Fatal invocation exception } }
private void reclaimIncoming(IceInternal.Incoming inc) { if(_cacheBuffers) { lock(_incomingCacheMutex) { inc.next = _incomingCache; _incomingCache = inc; // // Clear references to Ice objects as soon as possible. // _incomingCache.reclaim(); } } }
private async ValueTask InvokeAllAsync(Ice.OutputStream os, int requestId) { // The object adapter DirectCount was incremented by the caller and we are responsible to decrement it // upon completion. Ice.Instrumentation.IDispatchObserver?dispatchObserver = null; try { if (_traceLevels.Protocol >= 1) { FillInValue(os, 10, os.Size); if (requestId > 0) { FillInValue(os, Protocol.headerSize, requestId); } TraceUtil.TraceSend(os, _logger, _traceLevels); } var requestFrame = new Ice.InputStream(os.Communicator, os.Encoding, os.GetBuffer(), false); requestFrame.Pos = Protocol.requestHdr.Length; int start = requestFrame.Pos; var current = Protocol.CreateCurrent(requestId, requestFrame, _adapter); // Then notify and set dispatch observer, if any. Ice.Instrumentation.ICommunicatorObserver?communicatorObserver = _adapter.Communicator.Observer; if (communicatorObserver != null) { int encapsSize = requestFrame.GetEncapsulationSize(); dispatchObserver = communicatorObserver.GetDispatchObserver(current, requestFrame.Pos - start + encapsSize); dispatchObserver?.Attach(); } bool amd = true; try { Ice.IObject?servant = current.Adapter.Find(current.Id, current.Facet); if (servant == null) { amd = false; throw new Ice.ObjectNotExistException(current.Id, current.Facet, current.Operation); } ValueTask <Ice.OutputStream> vt = servant.DispatchAsync(requestFrame, current); amd = !vt.IsCompleted; if (requestId != 0) { var responseFrame = await vt.ConfigureAwait(false); dispatchObserver?.Reply(responseFrame.Size - Protocol.headerSize - 4); SendResponse(requestId, responseFrame, amd); } } catch (Ice.SystemException ex) { Incoming.ReportException(ex, dispatchObserver, current); // Forward the exception to the caller without marshaling HandleException(requestId, ex, amd); } catch (System.Exception ex) { Incoming.ReportException(ex, dispatchObserver, current); if (requestId != 0) { // For now, marshal it // TODO: revisit during exception refactoring. var responseFrame = Protocol.CreateFailureResponseFrame(ex, current); dispatchObserver?.Reply(responseFrame.Size - Protocol.headerSize - 4); SendResponse(requestId, responseFrame, amd); } } } catch (Ice.LocalException ex) { HandleException(requestId, ex, false); } finally { dispatchObserver?.Detach(); _adapter.DecDirectCount(); } }
private async ValueTask InvokeAllAsync(Ice.OutputStream os, int requestId) { // The object adapter DirectCount was incremented by the caller and we are responsible to decrement it // upon completion. Ice.Instrumentation.IDispatchObserver?dispatchObserver = null; try { if (_traceLevels.Protocol >= 1) { FillInValue(os, new Ice.OutputStream.Position(0, 10), os.Size); if (requestId > 0) { FillInValue(os, new Ice.OutputStream.Position(0, Ice1Definitions.HeaderSize), requestId); } TraceUtil.TraceSend(os, _logger, _traceLevels); } // TODO Avoid copy OutputStream buffer var requestFrame = new Ice.InputStream(os.Communicator, os.Encoding, os.ToArray()); requestFrame.Pos = Ice1Definitions.RequestHeader.Length; int start = requestFrame.Pos; var current = new Ice.Current(requestId, requestFrame, _adapter); // Then notify and set dispatch observer, if any. Ice.Instrumentation.ICommunicatorObserver?communicatorObserver = _adapter.Communicator.Observer; if (communicatorObserver != null) { int encapsSize = requestFrame.GetEncapsulationSize(); dispatchObserver = communicatorObserver.GetDispatchObserver(current, requestFrame.Pos - start + encapsSize); dispatchObserver?.Attach(); } bool amd = true; try { Ice.IObject?servant = current.Adapter.Find(current.Id, current.Facet); if (servant == null) { amd = false; throw new Ice.ObjectNotExistException(current.Id, current.Facet, current.Operation); } ValueTask <Ice.OutputStream> vt = servant.DispatchAsync(requestFrame, current); amd = !vt.IsCompleted; if (requestId != 0) { Ice.OutputStream responseFrame = await vt.ConfigureAwait(false); dispatchObserver?.Reply(responseFrame.Size - Ice1Definitions.HeaderSize - 4); SendResponse(requestId, responseFrame, amd); } } catch (System.Exception ex) { if (requestId != 0) { Ice.RemoteException actualEx; if (ex is Ice.RemoteException remoteEx && !remoteEx.ConvertToUnhandled) { actualEx = remoteEx; } else { actualEx = new UnhandledException(current.Id, current.Facet, current.Operation, ex); } Incoming.ReportException(actualEx, dispatchObserver, current); var responseFrame = new Ice.OutgoingResponseFrame(current, actualEx); dispatchObserver?.Reply(responseFrame.Size - Ice1Definitions.HeaderSize - 4); SendResponse(requestId, responseFrame, amd); } } }
private void invokeAll(BasicStream os, int requestId, int batchRequestNum) { if (batchRequestNum > 0) { os.pos(Protocol.requestBatchHdr.Length); } else { os.pos(Protocol.requestHdr.Length); } if (_traceLevels.protocol >= 1) { fillInValue(os, 10, os.size()); if (requestId > 0) { fillInValue(os, Protocol.headerSize, requestId); } else if (batchRequestNum > 0) { fillInValue(os, Protocol.headerSize, batchRequestNum); } TraceUtil.traceSend(os, _logger, _traceLevels); } int invokeNum = batchRequestNum > 0 ? batchRequestNum : 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 @in = new Incoming(_reference.getInstance(), this, null, _adapter, _response, (byte)0, requestId); @in.invoke(servantManager, os); --invokeNum; } } catch (Ice.LocalException ex) { invokeException(requestId, ex, invokeNum, false); // Fatal invocation exception } _adapter.decDirectCount(); }