コード例 #1
0
 /**
  * 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
  *
  * @param zookeeper    the client
  * @param path         path to ensure
  * @param makeLastNode if true, all nodes are created. If false, only the parent nodes are created
  * @param aclProvider  if not null, the ACL provider to use when creating parent nodes
  * @throws InterruptedException                 thread interruption
  * @throws org.apache.zookeeper.KeeperException Zookeeper errors
  */
 public static void mkdirs(ZooKeeper zookeeper,
                           String path,
                           bool makeLastNode,
                           IInternalACLProvider aclProvider)
 {
     mkdirs(zookeeper, path, makeLastNode, aclProvider, false);
 }
コード例 #2
0
        /**
         * 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
         *
         * @param zookeeper    the client
         * @param path         path to ensure
         * @param makeLastNode if true, all nodes are created. If false, only the parent nodes are created
         * @param aclProvider  if not null, the ACL provider to use when creating parent nodes
         * @param asContainers if true, nodes are created as {@link CreateMode#CONTAINER}
         * @throws InterruptedException                 thread interruption
         * @throws org.apache.zookeeper.KeeperException Zookeeper errors
         */
        public static async void mkdirs(ZooKeeper zookeeper,
                                        String path,
                                        bool makeLastNode,
                                        IInternalACLProvider aclProvider,
                                        bool asContainers)
        {
            PathUtils.validatePath(path);

            int pos = 1; // skip first slash, root is guaranteed to exist

            do
            {
                pos = path.IndexOf(PATH_SEPARATOR, pos + 1);

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

                String subPath = path.Substring(0, pos);
                if (await zookeeper.existsAsync(subPath, false) == null)
                {
                    try
                    {
                        IList <ACL> acl = null;
                        if (aclProvider != null)
                        {
                            acl = aclProvider.getAclForPath(subPath);
                            if (acl == null)
                            {
                                acl = aclProvider.getDefaultAcl();
                            }
                        }
                        if (acl == null)
                        {
                            acl = ZooDefs.Ids.OPEN_ACL_UNSAFE;
                        }
                        await zookeeper.createAsync(subPath,
                                                    new byte[0],
                                                    acl.ToList(),
                                                    getCreateMode(asContainers))
                        .ConfigureAwait(false);
                    }
                    catch (KeeperException.NodeExistsException)
                    {
                        // ignore... someone else has created it since we checked
                    }
                }
            }while (pos < path.Length);
        }
コード例 #3
0
ファイル: EnsurePath.cs プロジェクト: Lagrang/CuratorNet
 protected EnsurePath(String path, 
                         AtomicReference<Helper> helper, 
                         bool makeLastNode, 
                         IInternalACLProvider aclProvider)
 {
     this.path = path;
     this.makeLastNode = makeLastNode;
     this.aclProvider = aclProvider;
     this.helper = helper ?? new AtomicReference<Helper>(new InitialHelper(this));
 }
コード例 #4
0
ファイル: EnsurePath.cs プロジェクト: chinaboard/CuratorNet
 protected EnsurePath(String path,
                      AtomicReference <Helper> helper,
                      bool makeLastNode,
                      IInternalACLProvider aclProvider)
 {
     this.path         = path;
     this.makeLastNode = makeLastNode;
     this.aclProvider  = aclProvider;
     this.helper       = helper ?? new AtomicReference <Helper>(new InitialHelper(this));
 }
コード例 #5
0
ファイル: ZKPaths.cs プロジェクト: Lagrang/CuratorNet
    /**
     * 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
     *
     * @param zookeeper    the client
     * @param path         path to ensure
     * @param makeLastNode if true, all nodes are created. If false, only the parent nodes are created
     * @param aclProvider  if not null, the ACL provider to use when creating parent nodes
     * @param asContainers if true, nodes are created as {@link CreateMode#CONTAINER}
     * @throws InterruptedException                 thread interruption
     * @throws org.apache.zookeeper.KeeperException Zookeeper errors
     */
    public static async void mkdirs(ZooKeeper zookeeper, 
                                String path, 
                                bool makeLastNode, 
                                IInternalACLProvider aclProvider, 
                                bool asContainers)
    {
        PathUtils.validatePath(path);

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

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

            String subPath = path.Substring(0, pos);
            if ( await zookeeper.existsAsync(subPath, false) == null )
            {
                try
                {
                    IList<ACL> acl = null;
                    if ( aclProvider != null )
                    {
                        acl = aclProvider.getAclForPath(subPath);
                        if ( acl == null )
                        {
                            acl = aclProvider.getDefaultAcl();
                        }
                    }
                    if ( acl == null )
                    {
                        acl = ZooDefs.Ids.OPEN_ACL_UNSAFE;
                    }
                    await zookeeper.createAsync(subPath,
                                                new byte[0],
                                                acl.ToList(),
                                                getCreateMode(asContainers))
                                    .ConfigureAwait(false);
                }
                catch ( KeeperException.NodeExistsException)
                {
                    // ignore... someone else has created it since we checked
                }
            }

        }
        while ( pos<path.Length );
    }
コード例 #6
0
ファイル: ZKPaths.cs プロジェクト: Lagrang/CuratorNet
 /**
  * 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
  *
  * @param zookeeper    the client
  * @param path         path to ensure
  * @param makeLastNode if true, all nodes are created. If false, only the parent nodes are created
  * @param aclProvider  if not null, the ACL provider to use when creating parent nodes
  * @throws InterruptedException                 thread interruption
  * @throws org.apache.zookeeper.KeeperException Zookeeper errors
  */
 public static void mkdirs(ZooKeeper zookeeper, 
                             String path, 
                             bool makeLastNode, 
                             IInternalACLProvider aclProvider)
     {
         mkdirs(zookeeper, path, makeLastNode, aclProvider, false);
     }
コード例 #7
0
ファイル: EnsurePath.cs プロジェクト: Lagrang/CuratorNet
 /**
  * @param path the full path to ensure
  * @param aclProvider if not null, the ACL provider to use when creating parent nodes
  */
 public EnsurePath(String path, IInternalACLProvider aclProvider)
     : this(path, null, true, aclProvider)
 {
 }
コード例 #8
0
ファイル: EnsurePath.cs プロジェクト: chinaboard/CuratorNet
 /**
  * @param path the full path to ensure
  * @param aclProvider if not null, the ACL provider to use when creating parent nodes
  */
 public EnsurePath(String path, IInternalACLProvider aclProvider)
     : this(path, null, true, aclProvider)
 {
 }