Exemplo n.º 1
0
        /// <summary>
        /// Deserialize <see cref="IZooKeeperRequest"/>
        /// </summary>
        /// <param name="xid">the callid</param>
        /// <param name="type">type of the call</param>
        /// <param name="sessionState">The PerSession State</param>
        /// <param name="ringMasterRequest">The ring master request.</param>
        /// <exception cref="System.ArgumentException">unknown type  + type</exception>
        /// <returns>The Zookeeper Request</returns>
        private IZooKeeperRequest DeserializeZooKeeperRequest(int xid, ZooKeeperRequestType type, ZkprPerSessionState sessionState, out IRingMasterRequest ringMasterRequest)
        {
            ringMasterRequest = null;
            switch (type)
            {
            case ZooKeeperRequestType.Notification:     // "0" for Createing a session
                ringMasterRequest = null;
                return(this.DeserializeNotification(xid));

            case ZooKeeperRequestType.CreateSession:
                ZkprProtocolMessages.CreateSession cs = this.DeserializeCreateSession();
                ringMasterRequest            = new RequestInit((ulong)cs.SessionId, cs.IsNullPassword ? string.Empty : cs.Password);
                sessionState.ConnectRecieved = true;
                return(cs);

            case ZooKeeperRequestType.Exists:
                ZkprProtocolMessages.Exists ex = this.DeserializeExists(xid);
                ringMasterRequest = new RequestExists(ex.Path, ex.Watch == false ? null : new Watcher((ulong)xid, WatcherKind.OneUse));
                return(ex);

            case ZooKeeperRequestType.GetChildren:
                ZkprProtocolMessages.GetChildren gc = this.DeserializeGetChildren(xid);
                ringMasterRequest = new RequestGetChildren(gc.Path, gc.Watch == false ? null : new Watcher((ulong)xid, WatcherKind.OneUse), null);
                return(gc);

            case ZooKeeperRequestType.GetChildren2:
                ZkprProtocolMessages.GetChildren2 gc2 = this.DeserializeGetChildren2(xid);
                ringMasterRequest = new RequestGetChildren(gc2.Path, gc2.Watch == false ? null : new Watcher((ulong)xid, WatcherKind.OneUse), null);
                return(gc2);

            case ZooKeeperRequestType.GetData:
                ZkprProtocolMessages.GetData gd = this.DeserializeGetData(xid);
                ringMasterRequest = new RequestGetData(gd.Path, RequestGetData.GetDataOptions.None, gd.Watch == false ? null : new Watcher((ulong)xid, WatcherKind.OneUse));
                return(gd);

            case ZooKeeperRequestType.Create:
                ZkprProtocolMessages.Create cr   = this.DeserializeCreate(xid);
                IReadOnlyList <Acl>         acls = this.TranslateZkprAclListToRMAclList(cr.Acls);
                CreateMode cm = this.TranslateZkprCreatFlagsToRmCreateMode(cr.Flags);
                ringMasterRequest = new RequestCreate(cr.Path, cr.Data, acls, cm);
                return(cr);

            case ZooKeeperRequestType.Create2:
                ZkprProtocolMessages.Create2 cr2   = this.DeserializeCreate2(xid);
                IReadOnlyList <Acl>          acls2 = this.TranslateZkprAclListToRMAclList(cr2.Acls);
                CreateMode cm2 = this.TranslateZkprCreatFlagsToRmCreateMode(cr2.Flags);
                ringMasterRequest = new RequestCreate(cr2.Path, cr2.Data, acls2, cm2);
                return(cr2);

            case ZooKeeperRequestType.SetData:
                ZkprProtocolMessages.SetData sd = this.DeserializeSetData(xid);
                ringMasterRequest = new RequestSetData(sd.Path, sd.Data, sd.Version);
                return(sd);

            case ZooKeeperRequestType.Delete:
                ZkprProtocolMessages.Delete dl = this.DeserializeDelete(xid);
                ringMasterRequest = new RequestDelete(dl.Path, dl.Version, false);
                return(dl);

            case ZooKeeperRequestType.Ping:
                ringMasterRequest = null;
                return(this.DeserializePing(xid));

            case ZooKeeperRequestType.CloseSession:
                ringMasterRequest            = null;
                sessionState.ConnectRecieved = false;     // Renegotiate the CreateSession
                return(this.DeserializeCloseSession(xid));

            case ZooKeeperRequestType.GetACL:
                ZkprProtocolMessages.GetACL ga = this.DeserializeGetACL(xid);
                ringMasterRequest = new RequestGetAcl(ga.Path, null);
                return(ga);

            case ZooKeeperRequestType.SetACL:
                ZkprProtocolMessages.SetACL sa      = this.DeserializeSetACL(xid);
                IReadOnlyList <Acl>         sa_acls = this.TranslateZkprAclListToRMAclList(sa.Acls);
                ringMasterRequest = new RequestSetAcl(sa.Path, sa_acls, sa.Version);
                return(sa);

            case ZooKeeperRequestType.Multi:
                ZkprProtocolMessages.Multi mu    = this.DeserializeMulti(xid);
                IReadOnlyList <Op>         rmOps = this.TranslateZkprOpsListToRmOpsList(mu.Ops);
                ringMasterRequest = new RequestMulti(rmOps, false);
                return(mu);

            case ZooKeeperRequestType.Auth:
                ZkprProtocolMessages.Auth au = this.DeserializeAuth(xid);
                ringMasterRequest = new RequestSetAuth(au.RmAuthId);
                return(au);

            case ZooKeeperRequestType.Check:
            case ZooKeeperRequestType.Sync:
            case ZooKeeperRequestType.Reconfig:
            case ZooKeeperRequestType.SetWatches:
            case ZooKeeperRequestType.RemoveWatches:
            case ZooKeeperRequestType.CreateContainer:
            case ZooKeeperRequestType.DeleteContainer:
            case ZooKeeperRequestType.Sasl:
            case ZooKeeperRequestType.Error:
            default:
                break;
            }

            return(null);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Serialize <see cref="RequestGetAcl"/>.
 /// </summary>
 /// <param name="request">Request to serialize</param>
 private void SerializeRequestGetAcl(RequestGetAcl request)
 {
     this.SerializeStat(request.Stat);
 }