예제 #1
0
        public string Invoke(string identifier, UInt32 version, byte[] payload, InvokeCallback cb, int timeoutMs)
        {
            if (isConnecting || !isReady)
            {
                try
                {
                    cb(ErrorCodes.INTERNAL_SERVER_ERROR, null, "ESB client not connected");
                }
                catch (Exception e)
                {
                    log.ErrorFormat("Exception in invoke callback: {0}", e.ToString());
                }
                return string.Empty;
            }

            if (log.IsDebugEnabled) log.DebugFormat("Invoke()");

            string cmdGuid = genGuid();

            var s = new ResponseStruct
            {
                callback = (errCode, data, err) =>
                {
                    try
                    {
                        cb(errCode, data, err);
                    }
                    catch (Exception e)
                    {
                        log.ErrorFormat("Exception in invoke callback: {0}", e.ToString());
                    }
                },
                reqTime = DateTime.Now.AddMilliseconds(timeoutMs)
            };
            var msgReq = new Message
            {
                cmd = Message.Cmd.INVOKE,
                source_operation_guid = cmdGuid,
                identifier = identifier + "/v" + version,
                payload = payload,
                source_component_guid = guid
            };

            //responsesMutex.WaitOne();
            while (!responses.TryAdd(cmdGuid, s))
                Thread.Sleep(1);
            //responsesMutex.ReleaseMutex();
            publisher.Publish(proxyGuid, ref msgReq);
            return cmdGuid;
        }