コード例 #1
0
      public async Task HandleInvocationRequestAsync(IInboundMessageEvent<RmiRequestDto> e) {
         Trace.Assert(e.Message.ReceiverId == identity.Id);

         if (logger.IsDebugEnabled) {
            logger.Debug($"Received RMI {e.Body.InvocationId.ToString("n").Substring(0, 6)} Request on method {e.Body.MethodName} for service {e.Body.ServiceId.ToString("n").Substring(0, 6)}");
         }

         var request = e.Body;
         object service;
         if (!services.TryGetValue(request.ServiceId, out service)) {
            if (logger.IsDebugEnabled) {
               logger.Debug($"Unable to handle RMI {e.Body.InvocationId.ToString("n").Substring(0, 6)} Request on method {e.Body.MethodName} for service {e.Body.ServiceId.ToString("n").Substring(0, 6)} - service not found.");
            }
            await RespondError(e, new ServiceUnavailableException(request)).ConfigureAwait(false);
            return;
         }
         var typeInfo = service.GetType().GetTypeInfo();
         var method = typeInfo.GetMethod(request.MethodName);
         if (method.IsGenericMethodDefinition) {
            method = method.MakeGenericMethod(request.MethodGenericArguments);
         }
         object result;
         var args = request.MethodArguments;
         try {
            result = await TaskUtilities.UnboxValueIfTaskAsync(method.Invoke(service, args)).ConfigureAwait(false);
         } catch (Exception ex) {
            await RespondError(e, ex).ConfigureAwait(false);
            return;
         }
         var outParameters = method.GetParameters().Where(p => p.IsOut);
         await RespondSuccess(e, outParameters.Select(p => args[p.Position]).ToArray(), result).ConfigureAwait(false);
      }
コード例 #2
0
      public Task HandleInvocationResponse(IInboundMessageEvent<RmiResponseDto> x) {
         Trace.Assert(x.Message.ReceiverId == localIdentity.Id);

         var response = x.Body;
         logger.Info("Handling invocation response for {0}.", response.InvocationId);
         AsyncBox<RmiResponseDto> responseBox;
         if (!responseBoxes.TryRemove(response.InvocationId, out responseBox)) {
            logger.Error("Could not find response box for invocation id {0}.", response.InvocationId);
            throw new InvalidStateException();
         }
         responseBox.SetResult(response);
         return Task.CompletedTask;
      }
コード例 #3
0
 private Task RespondSuccess(IInboundMessageEvent<RmiRequestDto> e, object[] outParameters, object result) {
    if (logger.IsDebugEnabled) {
       logger.Debug($"Successfully handled RMI {e.Body.InvocationId.ToString("n").Substring(0, 6)} Request on method {e.Body.MethodName} for service {e.Body.ServiceId.ToString("n").Substring(0, 6)}. Sending return {result?.ToString() ?? "[null]"}.");
    }
    return messenger.SendReliableAsync(
       new RmiResponseDto {
          InvocationId = e.Body.InvocationId,
          ReturnValue = result,
          Outs = outParameters,
          Exception = null,
       },
       e.Sender.Identity.Id);
 }
コード例 #4
0
 private Task RespondSuccess(IInboundMessageEvent <RmiRequestDto> e, object[] outParameters, object result)
 {
     if (logger.IsDebugEnabled)
     {
         logger.Debug($"Successfully handled RMI {e.Body.InvocationId.ToString("n").Substring(0, 6)} Request on method {e.Body.MethodName} for service {e.Body.ServiceId.ToString("n").Substring(0, 6)}. Sending return {result?.ToString() ?? "[null]"}.");
     }
     return(messenger.SendReliableAsync(
                new RmiResponseDto {
         InvocationId = e.Body.InvocationId,
         ReturnValue = result,
         Outs = outParameters,
         Exception = null,
     },
                e.Sender.Identity.Id));
 }
コード例 #5
0
 private Task RespondError(IInboundMessageEvent <RmiRequestDto> e, Exception ex)
 {
     if (logger.IsDebugEnabled)
     {
         logger.Debug($"Threw when handling RMI {e.Body.InvocationId.ToString("n").Substring(0, 6)} Request on method {e.Body.MethodName} for service {e.Body.ServiceId.ToString("n").Substring(0, 6)}. Error: {ex}.");
     }
     return(messenger.SendReliableAsync(
                new RmiResponseDto {
         InvocationId = e.Body.InvocationId,
         Outs = new object[0],
         ReturnValue = null,
         Exception = RemoteException.Create(ex, e.Body)
     },
                e.Sender.Identity.Id));
 }
コード例 #6
0
        public Task HandleInvocationResponse(IInboundMessageEvent <RmiResponseDto> x)
        {
            Trace.Assert(x.Message.ReceiverId == localIdentity.Id);

            var response = x.Body;

            logger.Info("Handling invocation response for {0}.", response.InvocationId);
            AsyncBox <RmiResponseDto> responseBox;

            if (!responseBoxes.TryRemove(response.InvocationId, out responseBox))
            {
                logger.Error("Could not find response box for invocation id {0}.", response.InvocationId);
                throw new InvalidStateException();
            }
            responseBox.SetResult(response);
            return(Task.CompletedTask);
        }
コード例 #7
0
        public async Task HandleInvocationRequestAsync(IInboundMessageEvent <RmiRequestDto> e)
        {
            Trace.Assert(e.Message.ReceiverId == identity.Id);

            if (logger.IsDebugEnabled)
            {
                logger.Debug($"Received RMI {e.Body.InvocationId.ToString("n").Substring(0, 6)} Request on method {e.Body.MethodName} for service {e.Body.ServiceId.ToString("n").Substring(0, 6)}");
            }

            var    request = e.Body;
            object service;

            if (!services.TryGetValue(request.ServiceId, out service))
            {
                if (logger.IsDebugEnabled)
                {
                    logger.Debug($"Unable to handle RMI {e.Body.InvocationId.ToString("n").Substring(0, 6)} Request on method {e.Body.MethodName} for service {e.Body.ServiceId.ToString("n").Substring(0, 6)} - service not found.");
                }
                await RespondError(e, new ServiceUnavailableException(request)).ConfigureAwait(false);

                return;
            }
            var typeInfo = service.GetType().GetTypeInfo();
            var method   = typeInfo.GetMethod(request.MethodName);

            if (method.IsGenericMethodDefinition)
            {
                method = method.MakeGenericMethod(request.MethodGenericArguments);
            }
            object result;
            var    args = request.MethodArguments;

            try {
                result = await TaskUtilities.UnboxValueIfTaskAsync(method.Invoke(service, args)).ConfigureAwait(false);
            } catch (Exception ex) {
                await RespondError(e, ex).ConfigureAwait(false);

                return;
            }
            var outParameters = method.GetParameters().Where(p => p.IsOut);

            await RespondSuccess(e, outParameters.Select(p => args[p.Position]).ToArray(), result).ConfigureAwait(false);
        }
コード例 #8
0
 private Task RespondError(IInboundMessageEvent<RmiRequestDto> e, Exception ex) {
    if (logger.IsDebugEnabled) {
       logger.Debug($"Threw when handling RMI {e.Body.InvocationId.ToString("n").Substring(0, 6)} Request on method {e.Body.MethodName} for service {e.Body.ServiceId.ToString("n").Substring(0, 6)}. Error: {ex}.");
    }
    return messenger.SendReliableAsync(
       new RmiResponseDto {
          InvocationId = e.Body.InvocationId,
          Outs = new object[0],
          ReturnValue = null,
          Exception = RemoteException.Create(ex, e.Body)
       },
       e.Sender.Identity.Id);
 }