Example #1
0
 public WatcherImpl(ByteSequence key, WatchOption watchOption, WatchImpl owner)
 {
     this.key         = key;
     this.watchOption = watchOption;
     this.revision    = watchOption.getRevision();
     this.owner       = owner;
 }
Example #2
0
        public IWatcher Watch(ByteSequence key, WatchOption watchOption)
        {
            if (IsClosed())
            {
                throw new ClosedWatchClientException();
            }
            WatcherImpl watcher = new WatcherImpl(key, watchOption, this);

            // this.pendingWatchers.Enqueue(watcher);

            Etcdserverpb.WatchRequest       request       = new Etcdserverpb.WatchRequest();
            Etcdserverpb.WatchCreateRequest createRequest = new Etcdserverpb.WatchCreateRequest();
            createRequest.Key            = key.GetByteString();
            createRequest.PrevKv         = watchOption.isPrevKV();
            createRequest.ProgressNotify = watchOption.isProgressNotify();
            createRequest.RangeEnd       = watchOption.getEndKey().GetByteString();
            createRequest.StartRevision  = watchOption.getRevision();
            request.CreateRequest        = createRequest;
            Grpc.Core.CallOptions callOptions = new Grpc.Core.CallOptions();
            watchClient.Watch(callOptions);
            // watchClient.Watch()
            // watchClient.Watch()

            //  if (this.pendingWatchers.Count == 1) {
            // head of the queue send watchCreate request.
            //  WatchRequest request = this.toWatchCreateRequest(watcher);
            // this.getGrpcWatchStreamObserver().onNext(request);
            // }

            return(watcher);
        }
Example #3
0
        public GetResponse Get(ByteSequence key, GetOption option)
        {
            Etcdserverpb.RangeRequest request = new Etcdserverpb.RangeRequest();
            request.Key          = key.GetByteString();
            request.KeysOnly     = option.IsCountOnly();
            request.Limit        = option.GetLimit();
            request.Revision     = option.GetRevision();
            request.KeysOnly     = option.IsKeysOnly();
            request.Serializable = option.isSerializable();
            request.SortOrder    = OptionsUtil.ToRangeRequestSortOrder(option.GetSortOrder());
            request.SortTarget   = OptionsUtil.ToRangeRequestSortTarget(option.GetSortField());
            if (option.GetEndKey() != null)
            {
                request.RangeEnd = option.GetEndKey().GetByteString();
            }
            var         rsp      = kVClient.Range(request);
            GetResponse response = new GetResponse(rsp);

            return(response);
            //return Util.ToCompletableFutureWithRetry(
            //    stub.Range(request),
            //     new FunctionResponse<Etcdserverpb.RangeRequest, GetResponse>(),
            //    Util.IsRetriable
            //);
        }
Example #4
0
        public void Put(string key, string value)
        {
            ByteSequence bkey   = ByteSequence.From(key, Encoding.UTF8);
            ByteSequence bvalue = ByteSequence.From(value, Encoding.UTF8);

            client.GetKVClient().Put(bkey, bvalue);
        }
Example #5
0
            /**
             * Enables 'Get' requests to obtain all the keys with matching prefix.
             *
             * <p>You should pass the key that is passed into
             * {@link KV#get(ByteSequence) KV.get} method
             * into this method as the given key.
             *
             * @param prefix the common prefix of all the keys that you want to get
             * @return builder
             */
            public Builder withPrefix(ByteSequence prefix)
            {
                ByteSequence prefixEnd = OptionsUtil.PrefixEndOf(prefix);

                this.withRange(prefixEnd);
                return(this);
            }
Example #6
0
        private static Permission ToPermission(Authpb.Permission perm)
        {
            ByteSequence key      = ByteSequence.from(perm.Key);
            ByteSequence rangeEnd = ByteSequence.from(perm.RangeEnd);

            Permission.Type type;
            switch (perm.PermType)
            {
            case Authpb.Permission.Types.Type.Read:
                type = Permission.Type.READ;
                break;

            case Authpb.Permission.Types.Type.Write:
                type = Permission.Type.WRITE;
                break;

            case Authpb.Permission.Types.Type.Readwrite:
                type = Permission.Type.READWRITE;
                break;

            default:
                type = Permission.Type.UNRECOGNIZED;
                break;
            }

            return(new Permission(type, key, rangeEnd));
        }
Example #7
0
 public WatcherImpl(ByteSequence key, WatchOption watchOption, WatchImpl owner)
 {
     this.key         = key;
     this.watchOption = watchOption;
     this.revision    = watchOption.Revision;
     this.owner       = owner;
     this.watchClient = owner.watchClient;
 }
Example #8
0
        public static ByteArray ReceiveTeam(byte position, string identity, ByteSequence team)
        {
            ByteArray byteArray = new ByteArray();

            byteArray.WriteInt(-1287328945);
            byteArray.WriteByte(position);
            byteArray.WriteUTF(identity);
            team.WriteToByteArray(byteArray);
            return(byteArray);
        }
Example #9
0
        private static bool OnReceiveTeam(ByteArray byteArray, IPokemonBattleClientService clientService)
        {
            byte         position = byteArray.ReadByte();
            string       identity = byteArray.ReadUTF();
            ByteSequence team     = new ByteSequence();

            team.ReadFromByteArray(byteArray);
            clientService.OnReceiveTeam(position, identity, team);
            return(true);
        }
        private static bool OnReceiveTeam(int sessionID, ByteArray byteArray, IPokemonBattleServerService serverService)
        {
            byte         position = byteArray.ReadByte();
            string       identity = byteArray.ReadUTF();
            ByteSequence team     = new ByteSequence();

            team.ReadFromByteArray(byteArray);
            serverService.OnReceiveTeam(sessionID, position, identity, team);
            return(true);
        }
Example #11
0
        public string Get(string key)
        {
            ByteSequence    bkey      = ByteSequence.From(key, Encoding.UTF8);
            List <KeyValue> keyValues = client.GetKVClient().Get(bkey).GetKvs();

            if (keyValues.Count > 0)
            {
                return(keyValues[0].GetValue().ToString());
            }
            return(null);
        }
        /**
         * get token from etcd with name and password.
         *
         * @param channel channel to etcd
         * @param username auth name
         * @param password auth password
         * @return authResp
         */
        private static AuthenticateResponse Authenticate(Channel channel, ByteSequence username, ByteSequence password)
        {
            AuthenticateRequest requet = new AuthenticateRequest();

            requet.Name     = username.ToString();
            requet.Password = password.ToString();
            Auth.AuthClient      authClient = new Auth.AuthClient(channel);
            var                  rsp        = authClient.Authenticate(requet);
            AuthenticateResponse response   = new AuthenticateResponse(rsp);

            return(response);
        }
Example #13
0
        public AuthUserGetResponse UserGet(ByteSequence user)
        {
            Etcdserverpb.AuthUserGetRequest userGetRequest = new Etcdserverpb.AuthUserGetRequest();
            userGetRequest.Name = user.ToString();
            var rsp = authClient.UserGet(userGetRequest);
            AuthUserGetResponse response = new AuthUserGetResponse(rsp);

            return(response);
            //return Util.ToCompletableFuture(
            //    this.stub.userGet(userGetRequest),
            //    new FunctionResponse<Etcdserverpb.AuthUserGetRequest, AuthUserGetResponse>());
        }
Example #14
0
        public AuthRoleDeleteResponse RoleDelete(ByteSequence role)
        {
            Etcdserverpb.AuthRoleDeleteRequest roleDeleteRequest = new Etcdserverpb.AuthRoleDeleteRequest();
            roleDeleteRequest.Role = role.ToString();
            var rsp = authClient.RoleDelete(roleDeleteRequest);
            AuthRoleDeleteResponse response = new AuthRoleDeleteResponse(rsp);

            return(response);
            //  return Util.ToCompletableFuture(
            //   this.stub.roleDelete(roleDeleteRequest),
            //   new FunctionResponse<Etcdserverpb.AuthRoleDeleteRequest, AuthRoleDeleteResponse>());
        }
Example #15
0
        public AuthUserAddResponse UserAdd(ByteSequence user, ByteSequence password)
        {
            Etcdserverpb.AuthUserAddRequest addRequest = new Etcdserverpb.AuthUserAddRequest();
            addRequest.Name     = user.ToString();
            addRequest.Password = password.ToString();
            var rsp = authClient.UserAdd(addRequest);
            AuthUserAddResponse response = new AuthUserAddResponse(rsp);

            return(response);
            //return Util.ToCompletableFuture(
            //    this.stub.userAdd(addRequest),
            //   new FunctionResponse<Etcdserverpb.AuthUserAddRequest, AuthUserAddResponse>());
        }
Example #16
0
 private GetOption(ByteSequence endKey, long limit, long revision,
                   SortOrder sortOrder, SortTarget sortTarget, bool serializable, bool keysOnly,
                   bool countOnly)
 {
     this.endKey       = endKey;
     this.limit        = limit;
     this.revision     = revision;
     this.sortOrder    = sortOrder;
     this.sortTarget   = sortTarget;
     this.serializable = serializable;
     this.keysOnly     = keysOnly;
     this.countOnly    = countOnly;
 }
Example #17
0
        public AuthUserRevokeRoleResponse UserRevokeRole(ByteSequence user, ByteSequence role)
        {
            Etcdserverpb.AuthUserRevokeRoleRequest userRevokeRoleRequest = new Etcdserverpb.AuthUserRevokeRoleRequest();
            userRevokeRoleRequest.Name = user.ToString();
            userRevokeRoleRequest.Role = role.ToString();
            var rsp = authClient.UserRevokeRole(userRevokeRoleRequest);
            AuthUserRevokeRoleResponse response = new AuthUserRevokeRoleResponse(rsp);

            return(response);
            //return Util.ToCompletableFuture(
            //authClient.UserRevokeRole(userRevokeRoleRequest),
            //new FunctionResponse<Etcdserverpb.AuthUserRevokeRoleResponse, AuthUserRevokeRoleResponse>());
        }
Example #18
0
        public UnlockResponse UnLock(ByteSequence lockKey)
        {
            V3Lockpb.UnlockRequest request = new V3Lockpb.UnlockRequest();
            request.Key = lockKey.GetByteString();
            var            rsp      = lockClient.Unlock(request);
            UnlockResponse response = new UnlockResponse(rsp);

            return(response);
            //return Util.ToCompletableFutureWithRetry(
            //       stub.Unlock(request),
            //       new FunctionResponse<V3Lockpb.UnlockRequest, UnlockResponse>(),
            //       Util.IsRetriable
            //);
        }
Example #19
0
 private WatchOption(ByteSequence endKey,
                     long revision,
                     bool prevKV,
                     bool progressNotify,
                     bool noPut,
                     bool noDelete)
 {
     this.endKey         = endKey;
     this.revision       = revision;
     this.prevKV         = prevKV;
     this.progressNotify = progressNotify;
     this.noPut          = noPut;
     this.noDelete       = noDelete;
 }
Example #20
0
        public DeleteResponse Delete(ByteSequence key, DeleteOption option)
        {
            Etcdserverpb.DeleteRangeRequest request = new Etcdserverpb.DeleteRangeRequest();
            request.Key      = key.GetByteString();
            request.PrevKv   = option.IsPrevKV;
            request.RangeEnd = option.EndKey.GetByteString();
            var            rsp      = kVClient.DeleteRange(request);
            DeleteResponse response = new DeleteResponse(rsp);

            return(response);
            //return Util.ToCompletableFutureWithRetry(
            //    stub.DeleteRange(request),
            //   new FunctionResponse<Etcdserverpb.DeleteRangeRequest, DeleteResponse>()
            //);
        }
Example #21
0
        public AuthRoleRevokePermissionResponse RoleRevokePermission(ByteSequence role,
                                                                     ByteSequence key, ByteSequence rangeEnd)
        {
            Etcdserverpb.AuthRoleRevokePermissionRequest roleRevokePermissionRequest = new Etcdserverpb.AuthRoleRevokePermissionRequest();
            roleRevokePermissionRequest.Role     = role.ToString();
            roleRevokePermissionRequest.Key      = role.ToString();
            roleRevokePermissionRequest.RangeEnd = rangeEnd.ToString();
            var rsp = authClient.RoleRevokePermission(roleRevokePermissionRequest);
            AuthRoleRevokePermissionResponse response = new AuthRoleRevokePermissionResponse(rsp);

            return(response);
            //  return Util.ToCompletableFuture(
            //        this.stub.roleRevokePermission(roleRevokePermissionRequest),
            //     new FunctionResponse<Etcdserverpb.AuthRoleRevokePermissionRequest, AuthRoleRevokePermissionResponse>());
        }
Example #22
0
        public IWatcher Watch(ByteSequence key, WatchOption watchOption)
        {
            if (closed)
            {
                throw new ClosedWatchClientException();
            }
            WatcherImpl watcher = null;

            lock (this)
            {
                watcher = new WatcherImpl(key, watchOption, this);
                watcher.Resume();
                pendingWatchers.Enqueue(watcher);
            }
            return(watcher);
        }
Example #23
0
        /**
         * Gets the range end of the given prefix.
         *
         * <p>The range end is the key plus one (e.g., "aa"+1 == "ab", "a\xff"+1 == "b").
         *
         * @param prefix the given prefix
         * @return the range end of the given prefix
         */
        public static ByteSequence PrefixEndOf(ByteSequence prefix)
        {
            byte[] endKey = (byte[])prefix.GetBytes().Clone();
            for (int i = endKey.Length - 1; i >= 0; i--)
            {
                if (endKey[i] < 0xff)
                {
                    endKey[i] = (byte)(endKey[i] + 1);
                    byte[] dest = new byte[endKey.Length - i - 1];
                    Array.Copy(endKey, i + 1, dest, 0, dest.Length);
                    return(ByteSequence.From(dest));
                }
            }

            return(ByteSequence.From(NO_PREFIX_END));
        }
Example #24
0
        public LockResponse Lock(ByteSequence name, long leaseId)
        {
            V3Lockpb.LockRequest request = new V3Lockpb.LockRequest();
            request.Name  = name.GetByteString();
            request.Lease = leaseId;
            var          rsp      = lockClient.Lock(request);
            LockResponse response = new LockResponse(rsp);

            return(response);
            //   return Util.ToCompletableFutureWithRetry(
            //    stub.Lock(request),
            //    new FunctionResponse<V3Lockpb.LockRequest, LockResponse>(),
            //    Util.IsRetriable

            //);
        }
Example #25
0
 /**
  * Keys is the list of keys attached to this lease.
  */
 public List <ByteSequence> getKeys()
 {
     lock (lock_obj)
     {
         if (keys == null)
         {
             var kkeys = GetResponse().Keys;
             List <ByteSequence> list = new List <ByteSequence>(kkeys.Count);
             foreach (var k in kkeys)
             {
                 list.Add(ByteSequence.From(k));
             }
             keys = list;
         }
     }
     return(keys);
 }
Example #26
0
        public PutResponse Put(ByteSequence key, ByteSequence value,
                               PutOption option)
        {
            Etcdserverpb.PutRequest request = new Etcdserverpb.PutRequest();
            request.Key    = key.GetByteString();
            request.Value  = value.GetByteString();
            request.Lease  = option.LeaseId;
            request.PrevKv = option.PrevKV;
            var         rsp      = kVClient.Put(request);
            PutResponse response = new PutResponse(rsp);

            return(response);
            //return Util.ToCompletableFutureWithRetry(
            //     stub.Put(request),
            //     new FunctionResponse<Etcdserverpb.PutRequest, PutResponse>(),
            //     Util.IsRetriable
            //);
        }
Example #27
0
        public AuthRoleGrantPermissionResponse RoleGrantPermission(ByteSequence role,
                                                                   ByteSequence key, ByteSequence rangeEnd, auth.Permission.Type permType)
        {
            Authpb.Permission.Types.Type type;
            switch (permType)
            {
            case Permission.Type.WRITE:
                type = Authpb.Permission.Types.Type.Write;
                break;

            case Permission.Type.READWRITE:
                type = Authpb.Permission.Types.Type.Readwrite;
                break;

            case Permission.Type.READ:
                type = Authpb.Permission.Types.Type.Read;
                break;

            default:
                type = Authpb.Permission.Types.Type.Readwrite;
                break;
            }
            Authpb.Permission perm = new Authpb.Permission();
            perm.Key      = key.GetByteString();
            perm.RangeEnd = rangeEnd.GetByteString();
            perm.PermType = type;
            Etcdserverpb.AuthRoleGrantPermissionRequest roleGrantPermissionRequest = new Etcdserverpb.AuthRoleGrantPermissionRequest();
            roleGrantPermissionRequest.Name = role.ToString();
            roleGrantPermissionRequest.Perm = perm;
            var rsp = authClient.RoleGrantPermission(roleGrantPermissionRequest);
            AuthRoleGrantPermissionResponse response = new AuthRoleGrantPermissionResponse(rsp);

            return(response);
            // return Util.ToCompletableFuture(
            // this.stub.roleGrantPermission(roleGrantPermissionRequest),
            //  new FunctionResponse<Etcdserverpb.AuthRoleGrantPermissionRequest, AuthRoleGrantPermissionResponse>());
        }
Example #28
0
 public DeleteResponse Delete(ByteSequence key)
 {
     return(this.Delete(key, DeleteOption.DEFAULT));
 }
Example #29
0
 /**
  * Set the end key of the get request. If it is set, the get request will return the keys from
  * <i>key</i> to <i>endKey</i> (exclusive).
  *
  * <p>If end key is '\0', the range is all keys >= key.
  *
  * <p>If the end key is one bit larger than the given key, then it gets all keys with the prefix
  * (the given key).
  *
  * <p>If both key and end key are '\0', it returns all keys.
  *
  * @param endKey end key
  * @return builder
  */
 public Builder withRange(ByteSequence endKey)
 {
     this.endKey = endKey;
     return(this);
 }
Example #30
0
 public GetResponse Get(ByteSequence key)
 {
     return(this.Get(key, GetOption.DEFAULT));
 }