示例#1
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);
                });
            }
示例#2
0
            private RequestResponse ProcessT(Requests.RequestCreate req, List <Action> actions)
            {
                string parent = req.Path.Substring(0, req.Path.LastIndexOf('/'));

                if (parent.Length == 0)
                {
                    parent = "/";
                }

                TestNode newNode = new TestNode(req.Path);

                newNode.Data = req.Data;
                TestNode parentNode;

                if (!this.dataByPath.TryGetValue(parent, out parentNode))
                {
                    if (req.CreateMode == CreateMode.PersistentAllowPathCreation || req.CreateMode == CreateMode.PersistentSequentialAllowPathCreation)
                    {
                        parentNode = new TestNode(parent);
                        this.dataByPath[parent] = parentNode;

                        string   pa = parent;
                        TestNode ch = parentNode;

                        while (pa != "/")
                        {
                            string name = pa.Substring(pa.LastIndexOf('/') + 1);

                            pa = pa.Substring(0, pa.LastIndexOf('/'));

                            if (pa.Length == 0)
                            {
                                pa = "/";
                            }

                            if (this.dataByPath.TryGetValue(pa, out ch))
                            {
                                break;
                            }

                            ch = new TestNode(pa);

                            ch.AddChild(name);
                            this.dataByPath[pa] = ch;
                        }
                    }
                    else
                    {
                        return(new RequestResponse()
                        {
                            ResultCode = (int)RingMasterException.Code.Nonode,
                            ResponsePath = req.Path,
                            Content = null,
                            Stat = null,
                        });
                    }
                }

                parentNode.AddChild(req.Path.Substring(req.Path.LastIndexOf('/') + 1));
                this.dataByPath[req.Path] = newNode;

                actions.Add(new Action(() =>
                {
                    this.TriggerWatcher(parent, null, WatchedEvent.WatchedEventType.NodeChildrenChanged);
                }));

                return(new RequestResponse()
                {
                    ResultCode = (int)RingMasterException.Code.Ok,
                    ResponsePath = req.Path,
                    Content = req.Path,
                    Stat = newNode.Stat
                });
            }