public WatcherImpl(ByteSequence key, WatchOption watchOption, WatchImpl owner) { this.key = key; this.watchOption = watchOption; this.revision = watchOption.getRevision(); this.owner = owner; }
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); }
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 //); }
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); }
/** * 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); }
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)); }
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; }
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); }
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); }
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); }
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>()); }
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>()); }
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>()); }
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; }
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>()); }
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 //); }
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; }
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>() //); }
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>()); }
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); }
/** * 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)); }
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 //); }
/** * 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); }
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 //); }
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>()); }
public DeleteResponse Delete(ByteSequence key) { return(this.Delete(key, DeleteOption.DEFAULT)); }
/** * 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); }
public GetResponse Get(ByteSequence key) { return(this.Get(key, GetOption.DEFAULT)); }