public async ValueTask<OutgoingResponseFrame> DispatchAsync(IncomingRequestFrame requestFrame, Current current) { var request = new Request(this, requestFrame.Payload, current); Invoke(null, request); IncomingResponseFrame incomingResponseFrame = await request.Task.ConfigureAwait(false); return new OutgoingResponseFrame(current.Encoding, incomingResponseFrame.Payload); }
ValueTask <OutgoingResponseFrame> IObject.DispatchAsync( IncomingRequestFrame request, Current current, CancellationToken cancel) { if (current.Operation == "op" || current.Operation == "opVoid") { TestHelper.Assert(request.Context.Count == 1); TestHelper.Assert(request.Context["MyCtx"] == "hello"); if (current.Operation == "opVoid") { request.Context.Clear(); } } else { TestHelper.Assert(request.Context.Count == 0); } if (current.Operation != "opVoid" && current.Operation != "shutdown") { request.Context["Intercepted"] = "1"; } return(_target.ForwardAsync(request, current.IsOneway, cancel: cancel)); }
public ValueTask <OutgoingResponseFrame> DispatchAsync(IncomingRequestFrame request, Current current) { var ae = new AlsoEmpty(); var responseFrame = OutgoingResponseFrame.WithReturnValue(current, compress: false, format: default,
public async ValueTask<OutgoingResponseFrame> DispatchAsync( IncomingRequestFrame incomingRequest, Current current) { ILocatorPrx? locator = null; Exception? exception = null; while (true) { // Get the locator to send the request to (this will return the void locator if no locator is found) ILocatorPrx newLocator = await GetLocatorAsync().ConfigureAwait(false); if (locator != newLocator) { var outgoingRequest = new OutgoingRequestFrame( newLocator, current.Operation, current.IsIdempotent, current.Context, incomingRequest.Payload); try { IncomingResponseFrame incomingResponse = await newLocator.InvokeAsync(outgoingRequest).ConfigureAwait(false); return new OutgoingResponseFrame(current.Protocol, current.Encoding, incomingResponse.Payload); } catch (DispatchException) { throw; } catch (NoEndpointException) { throw new ObjectNotExistException(current); } catch (ObjectAdapterDeactivatedException) { throw new ObjectNotExistException(current); } catch (CommunicatorDestroyedException) { throw new ObjectNotExistException(current); } catch (Exception ex) { lock (_mutex) { locator = newLocator; // If the current locator is equal to the one we use to send the request, // clear it and retry, this will trigger the lookup of a new locator. if (_locator == newLocator) { _locator = null; } } exception = ex; } } else { // We got the same locator after a previous failure, throw the saved exception now. Debug.Assert(exception != null); throw exception; } } }
public async ValueTask <OutgoingResponseFrame> DispatchAsync( IncomingRequestFrame request, Current current, CancellationToken cancel) { if (current.Operation == "opCompressArgs" || current.Operation == "opCompressArgsAndReturn") { if (request.PayloadEncoding == Encoding.V20) { TestHelper.Assert(request.HasCompressedPayload == _compressed); if (!_compressed) { // Ensure payload count is less than Ice.CompressionMinSize TestHelper.Assert(request.PayloadSize < 1024); } } } OutgoingResponseFrame response = await _servant.DispatchAsync(request, current, cancel); if (current.Operation == "opCompressReturn" || current.Operation == "opCompressArgsAndReturn") { if (response.PayloadEncoding == Encoding.V20) { if (_compressed) { try { response.CompressPayload(); TestHelper.Assert(false); } catch (InvalidOperationException) { // Expected if the request is already compressed } } else { // Ensure size is less than Ice.CompressionMinSize TestHelper.Assert(response.PayloadSize < 1024); } } } if (response.PayloadEncoding == Encoding.V20 && current.Operation == "opWithUserException") { try { response.CompressPayload((CompressionFormat)2); TestHelper.Assert(false); } catch (NotSupportedException) { // expected. } response.CompressPayload(); } return(response); }
public ValueTask <OutgoingResponseFrame> DispatchAsync(IncomingRequestFrame request, Current current) { var ae = new Test.AlsoEmpty(); var responseFrame = OutgoingResponseFrame.WithReturnValue(current, format: null, ae, (OutputStream ostr, Test.AlsoEmpty ae) => ostr.WriteClass(ae)); return(new ValueTask <OutgoingResponseFrame>(responseFrame)); }
public ValueTask <OutgoingResponseFrame> DispatchAsync(IncomingRequestFrame request, Current current) { TestHelper.Assert(current.Connection != null); IObjectPrx proxy = current.Connection.CreateProxy(current.Identity, IObjectPrx.Factory).Clone(current.Facet, IObjectPrx.Factory, oneway: current.IsOneway); return(proxy.ForwardAsync(current.IsOneway, request)); }
public ValueTask <OutgoingResponseFrame> DispatchAsync(InputStream inputStream, Current current) { var request = new IncomingRequestFrame(inputStream, current); // Temporary Debug.Assert(current.Connection != null); var proxy = current.Connection.CreateProxy(current.Id, IObjectPrx.Factory).Clone(facet: current.Facet, oneway: current.IsOneway); return(proxy.ForwardAsync(request)); }
public ValueTask <OutgoingResponseFrame> DispatchAsync( IncomingRequestFrame request, Current current, CancellationToken cancel) { TestHelper.Assert(current.Connection != null); IObjectPrx proxy = current.Connection.CreateProxy(current.Identity, current.Facet, IObjectPrx.Factory); return(proxy.ForwardAsync(request, current.IsOneway, cancel: cancel)); }
public async ValueTask <OutgoingResponseFrame> DispatchAsync(InputStream inputStream, Current current) { var requestFrame = new IncomingRequestFrame(inputStream, current); var request = new Request(this, current.Operation, current.IsIdempotent, requestFrame.TakePayload(), current.Context); Invoke(null, request); IncomingResponseFrame incomingResponseFrame = await request.Task.ConfigureAwait(false); return(new OutgoingResponseFrame(current.Encoding, incomingResponseFrame.TakePayload())); }
public async ValueTask <OutgoingResponseFrame> DispatchAsync( IncomingRequestFrame incomingRequest, Current current) { ILocatorPrx?locator = null; Exception? exception = null; while (true) { // Get the locator to send the request to (this will return the void locator if no locator is found) ILocatorPrx newLocator = await GetLocatorAsync().ConfigureAwait(false); if (!newLocator.Equals(locator)) { try { return(await newLocator.ForwardAsync(false, incomingRequest).ConfigureAwait(false)); } catch (ObjectNotExistException) { throw; } catch (NoEndpointException) { throw new ObjectNotExistException(current); } catch (ObjectDisposedException) { throw new ObjectNotExistException(current); } catch (Exception ex) { lock (_mutex) { locator = newLocator; // If the current locator is equal to the one we use to send the request, // clear it and retry, this will trigger the lookup of a new locator. if (_locator == newLocator) { _locator = null; } } exception = ex; } } else { // We got the same locator after a previous failure, throw the saved exception now. Debug.Assert(exception != null); throw exception; } } }
public ValueTask <OutgoingResponseFrame> DispatchAsync(IncomingRequestFrame request, Current current) { IObject?servant; if (current.Identity.Name.Equals("router")) { servant = _router; } else { TestHelper.Assert(current.Identity.Category.Length == 0); TestHelper.Assert(current.Identity.Name.Equals("test")); servant = new TestIntf(); } return(servant.DispatchAsync(request, current)); }
public ValueTask <OutgoingResponseFrame> DispatchAsync(IncomingRequestFrame request, Current current) { if (current.Operation.Equals("opOneway")) { if (!current.IsOneway) { // If called two-way, return exception to caller. throw new MyException(); } return(new ValueTask <OutgoingResponseFrame>(OutgoingResponseFrame.WithVoidReturnValue(current))); } else if (current.Operation.Equals("opString")) { string s = request.ReadArgs(current.Communicator, InputStream.IceReaderIntoString); var responseFrame = OutgoingResponseFrame.WithReturnValue(current, compress: false, format: default,
public async ValueTask <OutgoingResponseFrame> DispatchAsync(IncomingRequestFrame request, Current current) { if (current.Operation == "opCompressParams" || current.Operation == "opCompressParamsAndReturn") { if (request.Encoding == Encoding.V2_0) { TestHelper.Assert(request.HasCompressedPayload == _compressed); if (!_compressed) { // Ensure size is less than Ice.CompressionMinSize TestHelper.Assert(request.Size < 1024); } } } OutgoingResponseFrame response = await _servant.DispatchAsync(request, current); if (current.Operation == "opCompressReturn" || current.Operation == "opCompressParamsAndReturn") { if (response.Encoding == Encoding.V2_0) { if (_compressed) { try { response.CompressPayload(); TestHelper.Assert(false); } catch (InvalidOperationException) { // Expected if the request is already compressed } } else { // Ensure size is less than Ice.CompressionMinSize TestHelper.Assert(response.Size < 1024); } } } if (response.Encoding == Encoding.V2_0 && current.Operation == "opWithUserException") { response.CompressPayload(); } return(response); }
public ValueTask <OutgoingResponseFrame> DispatchAsync(IncomingRequestFrame request, Current current) { if (current.Operation.Equals("opOneway")) { if (!current.IsOneway) { // If called two-way, return exception to caller. throw new MyException(); } return(new ValueTask <OutgoingResponseFrame>(OutgoingResponseFrame.WithVoidReturnValue(current))); } else if (current.Operation.Equals("opString")) { string s = request.ReadParamList(current.Communicator, InputStream.IceReaderIntoString); var responseFrame = OutgoingResponseFrame.WithReturnValue(current, format: null, (s, s), (OutputStream ostr, (string ReturnValue, string s2)value) => { ostr.WriteString(value.ReturnValue); ostr.WriteString(value.s2); });
ValueTask <OutgoingResponseFrame> IObject.DispatchAsync( IncomingRequestFrame request, Current current, CancellationToken cancel) => _target.ForwardAsync(request, current.IsOneway, cancel: cancel);
public ValueTask <OutgoingResponseFrame> DispatchAsync( IncomingRequestFrame request, Current current, CancellationToken cancel) { OutgoingResponseFrame?response = null; if (current.Operation == "printString") { string message = request.ReadArgs(current.Connection, istr => istr.ReadString()); Console.WriteLine($"Printing string `{message}'"); } else if (current.Operation == "printStringSequence") { string[] messages = request.ReadArgs(current.Connection, istr => istr.ReadArray(1, istr => istr.ReadString())); Console.Write("Printing string sequence {"); Console.Write(string.Join(", ", messages)); Console.WriteLine("}"); } else if (current.Operation == "printDictionary") { Dictionary <string, string> dict = request.ReadArgs(current.Connection, istr => istr.ReadDictionary(1, 1, istr => istr.ReadString(), istr => istr.ReadString())); Console.Write("Printing dictionary {"); bool first = true; foreach ((string key, string value) in dict) { if (!first) { Console.Write(", "); } first = false; Console.Write($"{key} = {value}"); } Console.WriteLine("}"); } else if (current.Operation == "printEnum") { Color color = request.ReadArgs(current.Connection, ColorHelper.IceReader); Console.WriteLine($"Printing enum {color}"); } else if (current.Operation == "printStruct") { Structure s = request.ReadArgs(current.Connection, Structure.IceReader); Console.WriteLine($"Printing struct: name={s.Name}, value={s.Value}"); } else if (current.Operation == "printStructSequence") { Structure[] seq = request.ReadArgs( current.Connection, istr => istr.ReadArray(minElementSize: 2, Structure.IceReader)); Console.Write("Printing struct sequence: {"); bool first = true; foreach (Structure s in seq) { if (!first) { Console.Write(", "); } first = false; Console.Write($"{s.Name} = {s.Value}"); } Console.WriteLine("}"); } else if (current.Operation == "printClass") { C c = request.ReadArgs(current.Connection, istr => istr.ReadClass <C>(C.IceTypeId)); Console.WriteLine($"Printing class: s.name={c.S.Name}, s.value={c.S.Value}"); } else if (current.Operation == "getValues") { var c = new C(new Structure("green", Color.green)); response = OutgoingResponseFrame.WithReturnValue <(string, C)>( current, false, FormatType.Compact, ("hello", c), (OutputStream ostr, (string s, C c)value) => { ostr.WriteString(value.s); ostr.WriteClass(value.c, C.IceTypeId); });
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); } } }
/// <summary>The <see cref="RequestReader{T}"/> for the parameter of operation ice_isA.</summary> /// <summary>Decodes the ice_id operation parameters from an <see cref="IncomingRequestFrame"/>.</summary> /// <param name="connection">The used to receive the frame.</param> /// <param name="request">The request frame.</param> /// <returns>The return value decoded from the frame.</returns> public static string IceIsA(Connection connection, IncomingRequestFrame request) => request.ReadArgs(connection, InputStream.IceReaderIntoString);