public static void createPathIfNotExists ( final CuratorFramework client , final String basePath , final byte [ ] initData ) { Preconditions . checkNotNull ( client , "client" ) ; Preconditions . checkNotNull ( basePath , "basePath" ) ; Preconditions . checkNotNull ( initData , "initData" ) ; try { if ( client . checkExists ( ) . forPath ( basePath ) == null ) { client . create ( ) . creatingParentsIfNeeded ( ) . forPath ( basePath , initData ) ; } } catch ( KeeperException . NodeExistsException e ) { log . debug ( "Path exists {}, ignoring exception" , basePath ) ; } catch ( Exception e ) { throw new RuntimeException ( "Exception while creating znode: " + basePath , e ) ; } }
Creates the znode if is doesn t already exist in zookeeper .