Esempio n. 1
0
        private void SendSynchronously(IRingMasterBackendRequest req)
        {
            Stopwatch sw = Stopwatch.StartNew();

            try
            {
                this.backend.ProcessMessage(
                    req,
                    this.session,
                    (r, e) =>
                {
                    RequestResponse resp = r;
                    req.NotifyComplete(resp.ResultCode, resp.Content, resp.Stat, resp.ResponsePath);
                    this.OnComplete(req, resp.ResultCode, sw.ElapsedMilliseconds);
                    sw.Stop();
                });
            }
            catch (TimeoutException)
            {
                this.OnComplete(req, (int)RingMasterException.Code.Operationtimeout, sw.ElapsedMilliseconds);
                sw.Stop();
            }
            catch (Exception)
            {
                this.OnComplete(req, (int)RingMasterException.Code.Systemerror, sw.ElapsedMilliseconds);
                sw.Stop();
            }
        }
Esempio n. 2
0
        /// <inheritdoc />
        public override void Send(IRingMasterBackendRequest req)
        {
            if (req == null)
            {
                throw new ArgumentNullException("req");
            }

            if (this.client == null)
            {
                SecureTransport transport = null;
                try
                {
                    var endpoints = SecureTransport.ParseConnectionString(this.ConnectString);
                    transport            = new SecureTransport(this.transportConfiguration);
                    this.client          = new RingMasterClient(this.protocol, transport);
                    this.secureTransport = transport;

                    // The lifetime of transport is now owned by RingMasterClient
                    transport = null;

                    this.secureTransport.StartClient(endpoints);
                }
                finally
                {
                    transport?.Dispose();
                }
            }

            this.client.Request(req.WrappedRequest).ContinueWith(responseTask =>
            {
                try
                {
                    RequestResponse response = responseTask.Result;
                    req.NotifyComplete(response.ResultCode, response.Content, response.Stat, response.ResponsePath);
                }
                catch (System.Exception)
                {
                    req.NotifyComplete((int)RingMasterException.Code.Systemerror, null, null, null);
                }
            });
        }
Esempio n. 3
0
            public override void Send(IRingMasterBackendRequest req)
            {
                if (req == null)
                {
                    return;
                }

                List <Action> actions = new List <Action>();

                RequestResponse resp;

                if (req.RequestType == RingMasterRequestType.Multi && ((Backend.RequestMulti)req).ScheduledName != null)
                {
                    string scheduledName = ((Backend.RequestMulti)req).ScheduledName;
                    ((Backend.RequestMulti)req).ScheduledName = null;

                    Requests.RequestCreate crReq = new Requests.RequestCreate("/$metadata/scheduler/commands/" + scheduledName, ScheduledCommand.GetBytes(req, this.marshaller), null, CreateMode.Persistent);
                    RequestResponse        aux   = this.ProcessT(crReq, actions);

                    this.ev.PushEvent(this.ToString(crReq));

                    resp = new RequestResponse()
                    {
                        CallId  = 0,
                        Content = new List <OpResult>()
                        {
                            OpResult.GetOpResult(RingMasterRequestType.Create, aux)
                        }.AsReadOnly(),
                        ResponsePath = string.Empty,
                        Stat         = null,
                        ResultCode   = aux.ResultCode
                    };
                }
                else
                {
                    resp = this.Process(req.WrappedRequest, actions);
                    this.ev.PushEvent(this.ToString(req.WrappedRequest));
                }

                foreach (Action action in actions)
                {
                    action();
                }

                ThreadPool.QueueUserWorkItem(_ =>
                {
                    req.NotifyComplete(resp.ResultCode, resp.Content, resp.Stat, resp.ResponsePath);
                });
            }