Exemplo n.º 1
0
        /// <summary>
        ///     Make sure all the nodes in the path are created. NOTE: Unlike File.mkdirs(), Zookeeper doesn't distinguish
        ///     between directories and files. So, every node in the path is created. The data for each node is an empty blob
        /// </summary>
        /// <param name="zookeeper">    the client </param>
        /// <param name="path">         path to ensure </param>
        /// <param name="makeLastNode"> if true, all nodes are created. If false, only the parent nodes are created </param>
        /// <param name="aclProvider">  if not null, the ACL provider to use when creating parent nodes </param>
        /// <param name="asContainers"> if true, nodes are created as <seealso cref="CreateMode#CONTAINER" /> </param>
        /// <exception cref="InterruptedException">                 thread interruption </exception>
        /// <exception cref="org.apache.zookeeper.KeeperException"> Zookeeper errors </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void mkdirs(org.apache.zookeeper.ZooKeeper zookeeper, String path, boolean makeLastNode, InternalACLProvider aclProvider, boolean asContainers) throws InterruptedException, org.apache.zookeeper.KeeperException
        public static async void mkdirs(ZooKeeper zookeeper, string path, bool makeLastNode, InternalACLProvider aclProvider,
            bool asContainers)
        {
            PathUtils.validatePath(path);

            var pos = 1; // skip first slash, root is guaranteed to exist
            do
            {
                pos = path.IndexOf(PATH_SEPARATOR, pos + 1, StringComparison.Ordinal);

                if (pos == -1)
                {
                    if (makeLastNode)
                    {
                        pos = path.Length;
                    }
                    else
                    {
                        break;
                    }
                }

                var subPath = path.Substring(0, pos);
                if ((await zookeeper.existsAsync(subPath, false) )== null)
                {
                    try
                    {
                        List<ACL> acl = null;
                        if (aclProvider != null)
                        {
                            acl = aclProvider.getAclForPath(path);
                            if (acl == null)
                            {
                                acl = aclProvider.getDefaultAcl();
                            }
                        }
                        if (acl == null)
                        {
                            acl = ZooDefs.Ids.OPEN_ACL_UNSAFE;
                        }
                        await zookeeper.createAsync(subPath, new byte[0], acl, getCreateMode(asContainers));
                    }
                    catch (KeeperException.NodeExistsException)
                    {
                        // ignore... someone else has created it since we checked
                    }
                }
            } while (pos < path.Length);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Make sure all the nodes in the path are created. NOTE: Unlike File.mkdirs(), Zookeeper doesn't distinguish
        ///     between directories and files. So, every node in the path is created. The data for each node is an empty blob
        /// </summary>
        /// <param name="zookeeper">    the client </param>
        /// <param name="path">         path to ensure </param>
        /// <param name="makeLastNode"> if true, all nodes are created. If false, only the parent nodes are created </param>
        /// <param name="aclProvider">  if not null, the ACL provider to use when creating parent nodes </param>
        /// <exception cref="InterruptedException">                 thread interruption </exception>
        /// <exception cref="org.apache.zookeeper.KeeperException"> Zookeeper errors </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void mkdirs(org.apache.zookeeper.ZooKeeper zookeeper, String path, boolean makeLastNode, InternalACLProvider aclProvider) throws InterruptedException, org.apache.zookeeper.KeeperException
        public static void mkdirs(ZooKeeper zookeeper, string path, bool makeLastNode, InternalACLProvider aclProvider)
        {
            mkdirs(zookeeper, path, makeLastNode, aclProvider, false);
        }