Exemplo n.º 1
0
        /// <summary>
        /// Return the stat of the node of the given path. Return null if no such a
        /// node exists.
        ///
        /// If the watch is non-null and the call is successful (no exception is thrown),
        /// a watch will be left on the node with the given path. The watch will be
        /// triggered by a successful operation that creates/delete the node or sets
        /// the data on the node.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="watcher">The watcher.</param>
        /// <returns>the stat of the node of the given path; return null if no such a node exists.</returns>
        public Stat Exists(string path, IWatcher watcher)
        {
            string clientPath = path;

            PathUtils.ValidatePath(clientPath);

            // the watch contains the un-chroot path
            WatchRegistration wcb = null;

            if (watcher != null)
            {
                wcb = new ExistsWatchRegistration(watchManager, watcher, clientPath);
            }

            string        serverPath = PrependChroot(clientPath);
            RequestHeader h          = new RequestHeader();

            h.Type = (int)OpCode.Exists;
            ExistsRequest   request  = new ExistsRequest(serverPath, watcher != null);
            SetDataResponse response = new SetDataResponse();
            ReplyHeader     r        = cnxn.SubmitRequest(h, request, response, wcb);

            if (r.Err != 0)
            {
                if (r.Err == (int)KeeperException.Code.NONODE)
                {
                    return(null);
                }
                throw KeeperException.Create((KeeperException.Code)Enum.ToObject(typeof(KeeperException.Code), r.Err), clientPath);
            }

            return(response.Stat.Czxid == -1 ? null : response.Stat);
        }
Exemplo n.º 2
0
        public async Task testNonExistingOpCode()
        {
            ZooKeeper zk = await createClient();

            const string path = "/m1";

            RequestHeader h = new RequestHeader();

            h.set_Type(888); // This code does not exists
            ExistsRequest request = new ExistsRequest();

            request.setPath(path);
            request.setWatch(false);
            ExistsResponse response = new ExistsResponse();
            ReplyHeader    r        = await zk.cnxn.submitRequest(h, request, response, null);

            Assert.assertEquals(r.getErr(), (int)KeeperException.Code.UNIMPLEMENTED);

            try {
                await zk.existsAsync("/m1", false);

                Assert.fail("The connection should have been closed");
            }
            catch (KeeperException.ConnectionLossException) {
            }
        }
Exemplo n.º 3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 internal static string GetExistsText(ExistsRequest request)
 {
     if (cache.TryGetValue(request, out var commandText) == false)
     {
         var statementBuilder = EnsureStatementBuilder(request.Connection, request.StatementBuilder);
         commandText = statementBuilder.CreateExists(new QueryBuilder(),
                                                     request.Name,
                                                     request.Where,
                                                     request.Hints);
         cache.TryAdd(request, commandText);
     }
     return(commandText);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Checks if username exists
 /// </summary>
 /// <param name="exists"><see cref="ExistsRequest"/></param>
 /// <returns>True if username already exists</returns>
 public bool Exists(ExistsRequest exists)
 {
     using (MySqlConnection connection = WebApiConfig.Connection())
         using (MySqlCommand command = new MySqlCommand($"SELECT * FROM `{exists.TableName}` WHERE {exists.Column} = \"{exists.Value}\"", connection))
         {
             connection.Open();
             using (MySqlDataReader reader = command.ExecuteReader())
             {
                 if (reader.Read())
                 {
                     return(true);
                 }
                 return(false);
             }
         }
 }
Exemplo n.º 5
0
    public override Task <ExistsResponse> Exists(ExistsRequest request, ServerCallContext context)
    {
        if (File.Exists(request.Path))
        {
            return(Task.FromResult(new ExistsResponse {
                Exists = true, Kind = Kind.File
            }));
        }

        if (Directory.Exists(request.Path))
        {
            return(Task.FromResult(new ExistsResponse {
                Exists = true, Kind = Kind.Directory
            }));
        }

        return(Task.FromResult(new ExistsResponse {
            Exists = false
        }));
    }
Exemplo n.º 6
0
        public async Task testNonExistingOpCode()
        {
            DisconnectedWatcher disconnectedWatcher = new DisconnectedWatcher();
            ZooKeeper           zk = await createClient(disconnectedWatcher);

            const string path = "/m1";

            RequestHeader h = new RequestHeader();

            h.set_Type(888); // This code does not exists
            ExistsRequest request = new ExistsRequest();

            request.setPath(path);
            request.setWatch(false);
            ExistsResponse response = new ExistsResponse();

            ReplyHeader r = await zk.cnxn.submitRequest(h, request, response, null);

            Assert.assertEquals(r.getErr(), (int)KeeperException.Code.UNIMPLEMENTED);

            // Sending a nonexisting opcode should cause the server to disconnect
            Assert.assertTrue("failed to disconnect",
                              await disconnectedWatcher.getTask().WithTimeout(5000));
        }
Exemplo n.º 7
0
 public Task <ExistsResult> ExistsAsync(ExistsRequest request) =>
 throw new NotSupportedException();
 /// <inheritdoc cref="IZooKeeperClient.ExistsAsync"/>
 public static ExistsResult Exists(this IZooKeeperClient client, ExistsRequest request) =>
 client.ExistsAsync(request).GetAwaiter().GetResult();
 /// <inheritdoc />
 public Task <ExistsResult> ExistsAsync(ExistsRequest request) =>
 ExecuteOperation(new ExistsOperation(request, watcherWrapper));