public override Task <IServiceRemotingResponseMessageBody> HandleRequestResponseAsync( ServiceRemotingDispatchHeaders requestMessageDispatchHeaders, IServiceRemotingRequestMessageBody requestMessageBody, CancellationToken cancellationToken) { return(base.HandleRequestResponseAsync(requestMessageDispatchHeaders, requestMessageBody, cancellationToken)); }
public Task <IServiceRemotingResponseMessageBody> InvokeAsync(ActorId actorId, int interfaceId, int methodId, string callContext, IServiceRemotingRequestMessageBody requestMsgBody, IServiceRemotingMessageBodyFactory remotingMessageBodyFactory, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); this.ThrowIfClosed(); var methodDispatcher = this.actorService.MethodDispatcherMapV2.GetDispatcher(interfaceId, methodId); var actorMethodName = methodDispatcher.GetMethodName(methodId); var actorMethodContext = ActorMethodContext.CreateForActor(actorMethodName); return(this.DispatchToActorAsync <IServiceRemotingResponseMessageBody>( actorId: actorId, actorMethodContext: actorMethodContext, createIfRequired: true, actorFunc: (actor, innerCancellationToken) => this.ActorMethodDispatch(methodDispatcher, actor, interfaceId, methodId, requestMsgBody, remotingMessageBodyFactory, innerCancellationToken), callContext: callContext, timerCall: false, cancellationToken: cancellationToken)); }
private Task <IServiceRemotingResponseMessage> OnDispatch( IServiceRemotingRequestMessageHeader requestMessageHeaders, IServiceRemotingRequestMessageBody requestBody, CancellationToken cancellationToken) { MethodDispatcherBase methodDispatcher; if (!this.methodDispatcherMap.TryGetValue(requestMessageHeaders.InterfaceId, out methodDispatcher)) { throw new NotImplementedException(string.Format(CultureInfo.CurrentCulture, SR.ErrorInterfaceNotImplemented, requestMessageHeaders.InterfaceId, this.serviceImplementation)); } Task <IServiceRemotingResponseMessageBody> dispatchTask = null; var stopwatch = Stopwatch.StartNew(); try { dispatchTask = methodDispatcher.DispatchAsync(this.serviceImplementation, requestMessageHeaders.MethodId, requestBody, this.GetRemotingMessageBodyFactory(), cancellationToken); } catch (Exception e) { var info = ExceptionDispatchInfo.Capture(e); this.servicePerformanceCounterProvider.OnServiceMethodFinish (requestMessageHeaders.InterfaceId, requestMessageHeaders.MethodId, stopwatch.Elapsed, e); info.Throw(); } return(dispatchTask.ContinueWith( t => { object responseBody = null; try { responseBody = t.GetAwaiter().GetResult(); } catch (Exception e) { var info = ExceptionDispatchInfo.Capture(e); this.servicePerformanceCounterProvider.OnServiceMethodFinish (requestMessageHeaders.InterfaceId, requestMessageHeaders.MethodId, stopwatch.Elapsed, e); info.Throw(); } this.servicePerformanceCounterProvider.OnServiceMethodFinish( requestMessageHeaders.InterfaceId, requestMessageHeaders.MethodId, stopwatch.Elapsed); return (IServiceRemotingResponseMessage) new ServiceRemotingResponseMessage(null, (IServiceRemotingResponseMessageBody)responseBody); }, TaskContinuationOptions.ExecuteSynchronously)); }
internal override void InvokeImplV2( int interfaceId, int methodId, IServiceRemotingRequestMessageBody requestMsgBodyValue) { this.SendToSubscribers(interfaceId, methodId, requestMsgBodyValue); }
private async Task <IServiceRemotingResponseMessage> HandleActorMethodDispatchAsync( IActorRemotingMessageHeaders messageHeaders, IServiceRemotingRequestMessageBody msgBody) { var startTime = DateTime.UtcNow; if (this.IsCancellationRequest(messageHeaders)) { await this.cancellationHelper.CancelRequestAsync( messageHeaders.InterfaceId, messageHeaders.MethodId, messageHeaders.InvocationId); return(null); } else { IServiceRemotingResponseMessageBody retVal; this.actorService.ActorManager.DiagnosticsEventManager.ActorRequestProcessingStart(); try { retVal = await this.cancellationHelper.DispatchRequest( messageHeaders.InterfaceId, messageHeaders.MethodId, messageHeaders.InvocationId, cancellationToken => this.OnDispatch(messageHeaders, msgBody, cancellationToken)); } finally { this.actorService.ActorManager.DiagnosticsEventManager.ActorRequestProcessingFinish(startTime); } return(new ServiceRemotingResponseMessage(null, retVal)); } }
internal override void InvokeImplV2( int interfaceId, int methodId, IServiceRemotingRequestMessageBody requestMsgBodyValue) { // no - op as events/one way messages are not supported for services }
public OutgoingMessageBody Serialize(IServiceRemotingRequestMessageBody serviceRemotingRequestMessageBody) { if (serviceRemotingRequestMessageBody == null) { return(null); } var writeStream = new MemoryStream(); var jsonWriter = new JsonTextWriter(new StreamWriter(writeStream)); var serializer = JsonSerializer.Create(new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All }); serializer.Serialize(jsonWriter, serviceRemotingRequestMessageBody); jsonWriter.Flush(); var segment = new ArraySegment <byte>(writeStream.ToArray()); var segments = new List <ArraySegment <byte> > { segment }; return(new OutgoingMessageBody(segments)); }
/// <summary> /// Handles a message from the client that requires a response from the service. This Api can be used for the short-circuiting where client is in same process as service. /// Client can now directly dispatch request to service instead of using ServiceProxy. /// </summary> /// <param name="requestMessageDispatchHeaders">Request message headers</param> /// <param name="requestMessageBody">Request message body</param> /// <param name="cancellationToken">Cancellation token. It can be used to cancel the request</param> public virtual Task <IServiceRemotingResponseMessageBody> HandleRequestResponseAsync( ServiceRemotingDispatchHeaders requestMessageDispatchHeaders, IServiceRemotingRequestMessageBody requestMessageBody, CancellationToken cancellationToken) { var header = this.CreateServiceRemotingRequestMessageHeader(requestMessageDispatchHeaders); return(this.HandleRequestResponseAsync(header, requestMessageBody, cancellationToken)); }
//V2 Stack Api internal override Task <IServiceRemotingResponseMessage> InvokeAsyncImplV2( int interfaceId, int methodId, IServiceRemotingRequestMessageBody requestMsgBodyValue, CancellationToken cancellationToken) { // async methods are not supported for actor event interface throw new NotImplementedException(); }
/// <summary> /// Called by the generated proxy class to send the requestMessage to the remote object. /// </summary> /// <param name="interfaceId">Id of the remote interface.</param> /// <param name="methodId">Id of the remote method to be invokved.</param> /// <param name="requestMsgBodyValue">Message body to be sent to remote object.</param> protected void InvokeV2( int interfaceId, int methodId, IServiceRemotingRequestMessageBody requestMsgBodyValue) { this.InvokeImplV2( interfaceId, methodId, requestMsgBodyValue); }
IOutgoingMessageBody IServiceRemotingRequestMessageBodySerializer.Serialize(IServiceRemotingRequestMessageBody serviceRemotingRequestMessageBody) { var writeStream = new MemoryStream(); Serializer.Serialize(writeStream, serviceRemotingRequestMessageBody); var segment = new ArraySegment <byte>(writeStream.ToArray()); var segments = new List <ArraySegment <byte> > { segment }; return(new OutgoingMessageBody(segments)); }
public void RaiseEvent(int eventInterfaceId, int methodId, IServiceRemotingRequestMessageBody eventMsgBody) { var headers = new ActorRemotingMessageHeaders { ActorId = new ActorId(this.id), InterfaceId = eventInterfaceId, MethodId = methodId }; this.callbackV2.SendOneWay( new ServiceRemotingRequestMessage(headers, eventMsgBody)); }
public IOutgoingMessageBody Serialize(IServiceRemotingRequestMessageBody serviceRemotingRequestMessageBody) { if (serviceRemotingRequestMessageBody == null) { return(null); } string json = serviceRemotingRequestMessageBody.ToString(); byte[] bytes = Encoding.UTF8.GetBytes(json); ArraySegment <byte> segment = new ArraySegment <byte>(bytes); return(new OutgoingMessageBody(new[] { segment })); }
public IOutgoingMessageBody Serialize(IServiceRemotingRequestMessageBody serviceRemotingRequestMessageBody) { if (serviceRemotingRequestMessageBody == null) { return(null); } var bytes = serviceRemotingRequestMessageBody .Serialize(); var segment = new ArraySegment <byte>(bytes); return(new OutgoingMessageBody(new [] { segment })); }
private async Task <IServiceRemotingResponseMessageBody> HandleRequestResponseAsync( IServiceRemotingRequestMessageHeader remotingRequestMessageHeader, IServiceRemotingRequestMessageBody requestMessageBody, CancellationToken cancellationToken) { IServiceRemotingResponseMessage retval = await this.OnDispatch(remotingRequestMessageHeader, requestMessageBody, cancellationToken); if (retval != null) { return(retval.GetBody()); } return(null); }
private Task <IServiceRemotingResponseMessageBody> OnDispatch( IActorRemotingMessageHeaders actorMessageHeaders, IServiceRemotingRequestMessageBody requestBody, CancellationToken cancellationToken) { return(this.actorService.ActorManager .InvokeAsync( actorMessageHeaders.ActorId, actorMessageHeaders.InterfaceId, actorMessageHeaders.MethodId, actorMessageHeaders.CallContext, requestBody, this.GetRemotingMessageBodyFactory(), cancellationToken)); }
/// <summary> /// Called by the generated proxy class to send the request to the remote object and get the response back. /// </summary> /// <param name="interfaceId">Id of the remote interface.</param> /// <param name="methodId">Id of the remote method to be invokved.</param> /// <param name="requestMsgBodyValue">Request body.</param> /// <param name="cancellationToken">Cancellation token</param> /// <returns>A task that represents the asynchronous operation async call to remote object.</returns> protected async Task <IServiceRemotingResponseMessageBody> InvokeAsyncV2( int interfaceId, int methodId, IServiceRemotingRequestMessageBody requestMsgBodyValue, CancellationToken cancellationToken) { var responseMsg = await this.InvokeAsyncImplV2( interfaceId, methodId, requestMsgBodyValue, cancellationToken); return(responseMsg != null?responseMsg.GetBody() : null); }
////Why we pass IServiceRemotingMessageBodyFactory to this function instead of /// setting at class level?. Since we cache MethodDispatcher for each interface , /// we can't set IServiceRemotingMessageBodyFactory at class level . /// These can be cases where multiple IServiceRemotingMessageBodyFactory implmenetation /// but single dispatcher class . /// <summary> ///This method is used to dispatch request to the specified methodId of the /// interface implemented by the remoted object. /// </summary> /// <param name="objectImplementation"></param> /// <param name="methodId"></param> /// <param name="requestBody"></param> /// <param name="remotingMessageBodyFactory"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public Task <IServiceRemotingResponseMessageBody> DispatchAsync(object objectImplementation, int methodId, IServiceRemotingRequestMessageBody requestBody, IServiceRemotingMessageBodyFactory remotingMessageBodyFactory, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var dispatchTask = this.OnDispatchAsync( methodId, objectImplementation, requestBody, remotingMessageBodyFactory, cancellationToken); return(dispatchTask); }
/// <summary> /// Dispatches the messages received from the client to the actor service methods or the actor methods. /// This can be be used by user as an independent dispatcher like short-circuiting. /// </summary> /// <param name="requestBody"></param> /// <param name="cancellationToken"></param> /// <param name="actorDispatchHeaders"></param> /// <returns></returns> public Task <IServiceRemotingResponseMessageBody> HandleRequestResponseAsync( ActorRemotingDispatchHeaders actorDispatchHeaders, IServiceRemotingRequestMessageBody requestBody, CancellationToken cancellationToken) { //For Actor Service Requests if (!string.IsNullOrEmpty(actorDispatchHeaders.ServiceInterfaceName)) { return(base.HandleRequestResponseAsync(actorDispatchHeaders, requestBody, cancellationToken)); } var header = this.CreateActorHeader(actorDispatchHeaders); return(this.HandleActorMethodDispatchAsync(header, requestBody, cancellationToken)); }
public OutgoingMessageBody Serialize(IServiceRemotingRequestMessageBody serviceRemotingRequestMessageBody) { if (serviceRemotingRequestMessageBody == null) { return(null); } var json = serviceRemotingRequestMessageBody.ToString(); var bytes = Encoding.UTF8.GetBytes(json); var segment = new ArraySegment <byte>(bytes); var segments = new List <ArraySegment <byte> > { segment }; return(new OutgoingMessageBody(segments)); }
internal override Task <IServiceRemotingResponseMessage> InvokeAsyncImplV2( int interfaceId, int methodId, IServiceRemotingRequestMessageBody requestMsgBodyValue, CancellationToken cancellationToken) { var headers = new ServiceRemotingRequestMessageHeader() { InterfaceId = interfaceId, MethodId = methodId }; return(this.partitionClientV2.InvokeAsync( new ServiceRemotingRequestMessage(headers, requestMsgBodyValue), cancellationToken)); }
private Task <IServiceRemotingResponseMessageBody> ActorMethodDispatch( Remoting.V2.Builder.ActorMethodDispatcherBase methodDispatcher, ActorBase actor, int interfaceId, int methodId, IServiceRemotingRequestMessageBody requestBody, IServiceRemotingMessageBodyFactory remotingMessageBodyFactory, CancellationToken innerCancellationToken) { var actorInterfaceMethodKey = DiagnosticsEventManager.GetInterfaceMethodKey((uint)interfaceId, (uint)methodId); this.DiagnosticsEventManager.ActorMethodStart(actorInterfaceMethodKey, actor, RemotingListener.V2Listener); Task <IServiceRemotingResponseMessageBody> dispatchTask; try { dispatchTask = methodDispatcher.DispatchAsync(actor, methodId, requestBody, remotingMessageBodyFactory, innerCancellationToken); } catch (Exception e) { this.DiagnosticsEventManager.ActorMethodFinish(actorInterfaceMethodKey, actor, e, RemotingListener.V2Listener); throw; } return(dispatchTask.ContinueWith( t => { IServiceRemotingResponseMessageBody responseMsgBody = null; try { responseMsgBody = t.GetAwaiter().GetResult(); } catch (Exception e) { this.DiagnosticsEventManager.ActorMethodFinish(actorInterfaceMethodKey, actor, e, RemotingListener.V2Listener); throw; } this.DiagnosticsEventManager.ActorMethodFinish(actorInterfaceMethodKey, actor, null, RemotingListener.V2Listener); return responseMsgBody; }, TaskContinuationOptions.ExecuteSynchronously)); }
internal override Task <IServiceRemotingResponseMessage> InvokeAsyncImplV2( int interfaceId, int methodId, IServiceRemotingRequestMessageBody requestMsgBodyValue, CancellationToken cancellationToken) { var headers = new ActorRemotingMessageHeaders { ActorId = this.servicePartitionClientV2.ActorId, InterfaceId = interfaceId, MethodId = methodId, CallContext = Helper.GetCallContext() }; return(this.servicePartitionClientV2.InvokeAsync(new ServiceRemotingRequestMessage(headers, requestMsgBodyValue), cancellationToken)); }
public OutgoingMessageBody Serialize(IServiceRemotingRequestMessageBody serviceRemotingRequestMessageBody) { if (serviceRemotingRequestMessageBody == null) { return(null); } using (var stream = new Messaging.SegmentedPoolMemoryStream(this.bufferPoolManager)) { using (var writer = XmlDictionaryWriter.CreateBinaryWriter(stream)) { this.serializer.WriteObject(writer, serviceRemotingRequestMessageBody); writer.Flush(); return(new OutgoingMessageBody(stream.GetBuffers())); } } }
public IOutgoingMessageBody Serialize(IServiceRemotingRequestMessageBody serviceRemotingRequestMessageBody) { if (serviceRemotingRequestMessageBody == null) { return(null); } using (var writeStream = new MemoryStream()) using (var jsonWriter = new JsonTextWriter(new StreamWriter(writeStream))) { _serializer.Serialize(jsonWriter, serviceRemotingRequestMessageBody); jsonWriter.Flush(); var bytes = writeStream.ToArray(); var segment = new ArraySegment <byte>(bytes); var segments = new List <ArraySegment <byte> > { segment }; return(new OutgoingMessageBody(segments)); } }
private async Task <IServiceRemotingResponseMessageBody> HandleActorMethodDispatchAsync( IActorRemotingMessageHeaders actorMessageHeaders, IServiceRemotingRequestMessageBody msgBody, CancellationToken cancellationToken) { var startTime = DateTime.UtcNow; IServiceRemotingResponseMessageBody retVal; this.actorService.ActorManager.DiagnosticsEventManager.ActorRequestProcessingStart(); try { retVal = await this.OnDispatch(actorMessageHeaders, msgBody, cancellationToken); } finally { this.actorService.ActorManager.DiagnosticsEventManager.ActorRequestProcessingFinish(startTime); } return(retVal); }
private async Task <IServiceRemotingResponseMessage> HandleSubscriptionRequestsAsync( IServiceRemotingRequestContext requestContext, IServiceRemotingRequestMessageHeader messageHeaders, IServiceRemotingRequestMessageBody requestMsgBody) { var actorHeaders = (IActorRemotingMessageHeaders)messageHeaders; if (actorHeaders.MethodId == Runtime.ActorEventSubscription.SubscribeMethodId) { var castedRequestMsgBody = (EventSubscriptionRequestBody)requestMsgBody.GetParameter(0, "Value", typeof(EventSubscriptionRequestBody)); await this.actorService.ActorManager .SubscribeAsync( actorHeaders.ActorId, castedRequestMsgBody.eventInterfaceId, new ActorEventSubscriberProxy( castedRequestMsgBody.subscriptionId, requestContext.GetCallBackClient())); return(null); } if (messageHeaders.MethodId == Runtime.ActorEventSubscription.UnSubscribeMethodId) { var castedRequestMsgBody = (Actors.Remoting.EventSubscriptionRequestBody)requestMsgBody.GetParameter(0, "Value", typeof(Actors.Remoting.EventSubscriptionRequestBody)); await this.actorService.ActorManager .UnsubscribeAsync( actorHeaders.ActorId, castedRequestMsgBody.eventInterfaceId, castedRequestMsgBody.subscriptionId); return(null); } throw new MissingMethodException(string.Format(CultureInfo.CurrentCulture, SR.ErrorInvalidMethodId, messageHeaders.MethodId)); }
public OutgoingMessageBody Serialize(IServiceRemotingRequestMessageBody serviceRemotingRequestMessageBody) { var parameters = new object[_parameterCount]; for (var i = 0; i < _parameterCount; i++) { parameters[i] = serviceRemotingRequestMessageBody.GetParameter(i, "", typeof(void)); } var constructed = _payloadType.GetConstructors()[1].Invoke(parameters); using (var stream = _createSegmentedPoolMemoryStream(_bufferPoolManager)) { var outputStream = new OutputStream(stream); var writer = new FastBinaryWriter <OutputStream>(outputStream); _serializer.Serialize(constructed, writer); outputStream.Flush(); var buffers = _getBuffers(stream); return(new OutgoingMessageBody(buffers)); } }
public OutgoingMessageBody Serialize(IServiceRemotingRequestMessageBody serviceRemotingRequestMessageBody) { if (serviceRemotingRequestMessageBody == null) { return(null); } using (var stream = new MemoryStream()) { using (var writer = XmlDictionaryWriter.CreateBinaryWriter(stream)) { serializer.WriteObject(writer, serviceRemotingRequestMessageBody); writer.Flush(); var bytes = stream.ToArray(); var segments = new List <ArraySegment <byte> >(); segments.Add(new ArraySegment <byte>(bytes)); return(new OutgoingMessageBody(segments)); } } }
private void SendToSubscribers(int eventInterfaceId, int eventMethodId, IServiceRemotingRequestMessageBody messageBody) { IList <Guid> subscribersToRemove = null; foreach (var subscriber in this.subscriberProxiesV2) { try { SendTo(subscriber.Value, eventInterfaceId, eventMethodId, messageBody); } catch (Exception e) { ActorTrace.Source.WriteWarning( "ActorEventProxy.SendToSubscribers", "Error while Sending Message To Subscribers : {0}", e); if (subscribersToRemove == null) { subscribersToRemove = new List <Guid> { subscriber.Key }; } else { subscribersToRemove.Add(subscriber.Key); } } } if (subscribersToRemove != null) { foreach (var subscriberKey in subscribersToRemove) { IActorEventSubscriberProxy eventProxy; this.subscriberProxiesV2.TryRemove(subscriberKey, out eventProxy); } } }