private ResponseMessage InternalDispatch(RequestMessage reqMessage)
		{
			ResponseMessage response = null;

			var watch = System.Diagnostics.Stopwatch.StartNew();
			if (Castle.Zmq.LogAdapter.LogEnabled)
			{
//				Castle.Zmq.LogAdapter.LogDebug(
//					"Castle.Facilities.Zmq.Rpc.RemoteRequestListener",
//					"About to dispatch request for " + reqMessage.TargetService + "-" + reqMessage.TargetMethod);
			}

			try
			{
				var result =
					this._dispatcher.Dispatch(reqMessage.TargetService,
						reqMessage.TargetMethod,
						reqMessage.Params, reqMessage.ParamTypes);

				response = Builder.BuildResponse(result);
			}
			catch (TargetInvocationException ex)
			{
				var e = ex.InnerException;
				response = Builder.BuildResponse(e);
			}
			catch (Exception ex)
			{
				response = Builder.BuildResponse(ex);
			}
			finally
			{
				watch.Stop();

				if (Castle.Zmq.LogAdapter.LogEnabled)
				{
//					Castle.Zmq.LogAdapter.LogDebug(
//						"Castle.Facilities.Zmq.Rpc.RemoteRequestListener",
//						"Dispatched request for " + reqMessage.TargetService + "-" + reqMessage.TargetMethod +
//						" took " + watch.ElapsedMilliseconds + "ms (" + watch.Elapsed.TotalSeconds + "s)");
				}
			}
			return response;
		}
		public override byte[] SerializeRequest(RequestMessage requestMessage)
		{
			return Builder.SerializeRequest(requestMessage);
		}
Beispiel #3
0
		public static byte[] SerializeRequest(RequestMessage requestMessage)
		{
			return Serialization.Serialize(requestMessage);
		}
		public object Invoke(string host, string service, string methodName, 
							 object[] parameters, Type[] parametersTypes, Type retType)
		{
			var endpoint = this._endpointRegistry.GetEndpoint(host);

			var serializedArs = this._serializationStrategy.SerializeParameters(parameters, parametersTypes);
			var serializedPInfo = this._serializationStrategy.SerializeParameterTypes(parametersTypes);

			var requestMessage = new RequestMessage(service, methodName, serializedArs, serializedPInfo);

			var request = new RemoteRequest(this._context, endpoint, requestMessage, this._serializationStrategy)
			{
				ReqPoll = this._requestPoll
			};

			var watch = System.Diagnostics.Stopwatch.StartNew();
			if (Castle.Zmq.LogAdapter.LogEnabled)
			{
				Castle.Zmq.LogAdapter.LogDebug(
					"Castle.Facilities.Zmq.Rpc.RemoteRequestService", 
					"About to send request for " + host + "-" + service + "-" + methodName);
			}

			var attempts = 0;
			const int maxAttempts = 3;

			ResponseMessage response = null;

			while (attempts++ < maxAttempts)
			{
//				request.Monitor = attempts > 1;

				response = request.Get();

				watch.Stop();
				if (Castle.Zmq.LogAdapter.LogEnabled)
				{
					Castle.Zmq.LogAdapter.LogDebug(
						"Castle.Facilities.Zmq.Rpc.RemoteRequestService",
						"Reply from " + host + "-" + service + "-" + methodName +
						" took " + watch.ElapsedMilliseconds + "ms (" + watch.Elapsed.TotalSeconds + "s). " +
						"Exception? " + (response.ExceptionInfo != null));
				}

				if (response.ExceptionInfo != null)
				{
					if (response.ExceptionInfo.Typename == RemoteRequest.TimeoutTypename)
					{
						// our side (local) set a exception info just to inform us - the caller - about a timeout. 
						// since that's the case, attempt to try again
						continue;
					}

					// otherwise -- it's some other kind of error, and we should just fail fast
					ThrowWithExceptionInfoData(response);
				}

				// all went fine

				if (retType != typeof(void))
				{
					return _serializationStrategy.DeserializeResponseValue(response, retType);
				}

				return null;
			}

			if (response.ExceptionInfo != null)
			{
				ThrowWithExceptionInfoData(response);
			}

			return null;
		}