Ejemplo n.º 1
0
        private T CreateInvocationProxy <T>(Guid serviceId, PeerContext peer)
        {
            var remoteServiceInfo = new RemoveServiceInfo {
                Peer        = peer,
                ServiceType = typeof(T),
                ServiceId   = serviceId
            };
            var interceptor = new RemoteServiceProxyInvocationInterceptor(remoteServiceInfo, remoteServiceInvoker);

            return((T)proxyGenerator.CreateInterfaceProxyWithoutTarget(typeof(T), interceptor));
        }
Ejemplo n.º 2
0
        public async Task <RmiResponseDto> Invoke(RemoveServiceInfo serviceInfo, MethodInfo methodInfo, object[] methodArguments)
        {
            var invocationId = Guid.NewGuid();
            var request      = new RmiRequestDto {
                InvocationId           = invocationId,
                MethodArguments        = methodArguments,
                MethodGenericArguments = methodInfo.GetGenericArguments(),
                MethodName             = methodInfo.Name,
                ServiceId = serviceInfo.ServiceId
            };

            if (logger.IsDebugEnabled)
            {
                logger.Debug($"Sending RMI {invocationId.ToString("n").Substring(0, 6)} Request on method {methodInfo.Name} for service {serviceInfo.ServiceType.Name}. Local: {localIdentity.Id.ToString("n").Substring(0, 6)}, Remote: {serviceInfo.Peer.Identity.Id.ToString("n").Substring(0, 6)}");
            }

            if (localIdentity.Id == serviceInfo.Peer.Identity.Id)
            {
                if (logger.IsErrorEnabled)
                {
                    logger.Error($"Swallowing as routed to self - RMI {invocationId.ToString("n").Substring(0, 6)} Request on method {methodInfo.Name} for service {serviceInfo.ServiceType.Name}. Local: {localIdentity.Id.ToString("n").Substring(0, 6)}, Remote: {serviceInfo.Peer.Identity.Id.ToString("n").Substring(0, 6)}");
                }
                throw new ArgumentException("Attempted to perform remote service invocation on self.");
            }

            var responseBox = new AsyncBox <RmiResponseDto>();

            responseBoxes.AddOrThrow(invocationId, responseBox);

            await messenger.SendReliableAsync(request, serviceInfo.Peer.Identity.Id).ConfigureAwait(false);

            if (logger.IsDebugEnabled)
            {
                logger.Debug($"Sent RMI {invocationId.ToString("n").Substring(0, 6)} Request on method {methodInfo.Name} for service {serviceInfo.ServiceType.Name}");
            }

            // response box removed by HandleInvocationResponse - don't cleanup
            var result = await responseBox.GetResultAsync().ConfigureAwait(false);

            if (logger.IsDebugEnabled)
            {
                logger.Debug($"Received RMI {invocationId.ToString("n").Substring(0, 6)} Response on method {methodInfo.Name} for service {serviceInfo.ServiceType.Name}");
            }
            return(result);
        }
      public async Task<RmiResponseDto> Invoke(RemoveServiceInfo serviceInfo, MethodInfo methodInfo, object[] methodArguments) {
         var invocationId = Guid.NewGuid();
         var request = new RmiRequestDto {
            InvocationId = invocationId,
            MethodArguments = methodArguments,
            MethodGenericArguments = methodInfo.GetGenericArguments(),
            MethodName = methodInfo.Name,
            ServiceId = serviceInfo.ServiceId
         };

         if (logger.IsDebugEnabled) {
            logger.Debug($"Sending RMI {invocationId.ToString("n").Substring(0, 6)} Request on method {methodInfo.Name} for service {serviceInfo.ServiceType.Name}. Local: {localIdentity.Id.ToString("n").Substring(0, 6)}, Remote: {serviceInfo.Peer.Identity.Id.ToString("n").Substring(0, 6)}");
         }

         if (localIdentity.Id == serviceInfo.Peer.Identity.Id) {
            if (logger.IsErrorEnabled) {
               logger.Error($"Swallowing as routed to self - RMI {invocationId.ToString("n").Substring(0, 6)} Request on method {methodInfo.Name} for service {serviceInfo.ServiceType.Name}. Local: {localIdentity.Id.ToString("n").Substring(0, 6)}, Remote: {serviceInfo.Peer.Identity.Id.ToString("n").Substring(0, 6)}");
            }
            throw new ArgumentException("Attempted to perform remote service invocation on self.");
         }

         var responseBox = new AsyncBox<RmiResponseDto>();
         responseBoxes.AddOrThrow(invocationId, responseBox);

         await messenger.SendReliableAsync(request, serviceInfo.Peer.Identity.Id).ConfigureAwait(false);

         if (logger.IsDebugEnabled) {
            logger.Debug($"Sent RMI {invocationId.ToString("n").Substring(0, 6)} Request on method {methodInfo.Name} for service {serviceInfo.ServiceType.Name}");
         }

         // response box removed by HandleInvocationResponse - don't cleanup
         var result = await responseBox.GetResultAsync().ConfigureAwait(false);

         if (logger.IsDebugEnabled) {
            logger.Debug($"Received RMI {invocationId.ToString("n").Substring(0, 6)} Response on method {methodInfo.Name} for service {serviceInfo.ServiceType.Name}");
         }
         return result;
      }
Ejemplo n.º 4
0
 public RemoteServiceProxyInvocationInterceptor(RemoveServiceInfo remoteServiceInfo, RemoteServiceInvoker remoteServiceInvoker)
 {
     this.remoteServiceInfo    = remoteServiceInfo;
     this.remoteServiceInvoker = remoteServiceInvoker;
 }
 public RemoteServiceProxyInvocationInterceptor(RemoveServiceInfo remoteServiceInfo, RemoteServiceInvoker remoteServiceInvoker) {
    this.remoteServiceInfo = remoteServiceInfo;
    this.remoteServiceInvoker = remoteServiceInvoker;
 }