<commit_before>package com.ldaniels528.trifecta.support.zookeeper

import org.apache.curator.RetryPolicy
import org.apache.curator.framework.{CuratorFramework, CuratorFrameworkFactory}
import org.apache.curator.retry.ExponentialBackoffRetry
import org.apache.zookeeper.CreateMode
import org.apache.zookeeper.CreateMode._

import scala.collection.JavaConversions._

/**
 * ZooKeeper Proxy (Apache Curator client)
 * @author <NAME> <<EMAIL>>
 */
case class ZkProxyCurator(connectionString: String) extends ZKProxy {
  var mode: CreateMode = PERSISTENT
  var encoding: String = "UTF-8"
  var retryPolicy: RetryPolicy = new ExponentialBackoffRetry(1000, 3)
  var client: CuratorFramework = _

  // create the connection
  connect()

  override def close(): Unit = client.close()

  override def connect(): Unit = {
    client = CuratorFrameworkFactory.newClient(connectionString, retryPolicy)
    client.start()
  }

  override def create(tupleSeq: (String, Array[Byte])*): Iterable[String] = {
    tupleSeq.map { case (path, bytes) =>
      client.create().creatingParentsIfNeeded().forPath(path, bytes)
    }
  }

  override def create(path: String, bytes: Array[Byte]): String = {
    client.create().creatingParentsIfNeeded().forPath(path, bytes)
  }

  override def createDirectory(path: String): String = {
    client.create().creatingParentsIfNeeded().forPath(path)
  }

  override def delete(path: String): Boolean = {
    client.delete().forPath(path)
    exists(path)
  }

  override def deleteRecursive(path: String): Boolean = {
    client.delete().deletingChildrenIfNeeded().forPath(path)
    exists(path)
  }

  override def exists(path: String): Boolean = {
    Option(client.checkExists().forPath(path)) exists (_.getCtime > 0)
  }

  override def ensurePath(path: String): List[String] = {
    List(client.create().creatingParentsIfNeeded().forPath(path)) // TODO
  }

  override def ensureParents(path: String): List[String] = {
    List(client.create().creatingParentsIfNeeded().forPath(path)) // TODO<commit_msg>fixed issue with exists function<commit_after>package com.ldaniels528.trifecta.support.zookeeper

import org.apache.curator.RetryPolicy
import org.apache.curator.framework.{CuratorFramework, CuratorFrameworkFactory}
import org.apache.curator.retry.ExponentialBackoffRetry
import org.apache.zookeeper.CreateMode
import org.apache.zookeeper.CreateMode._

import scala.collection.JavaConversions._

/**
 * ZooKeeper Proxy (Apache Curator client)
 * @author <NAME> <<EMAIL>>
 */
case class ZkProxyCurator(connectionString: String) extends ZKProxy {
  var mode: CreateMode = PERSISTENT
  var encoding: String = "UTF-8"
  var retryPolicy: RetryPolicy = new ExponentialBackoffRetry(1000, 3)
  var client: CuratorFramework = _

  // create the connection
  connect()

  override def close(): Unit = client.close()

  override def connect(): Unit = {
    client = CuratorFrameworkFactory.newClient(connectionString, retryPolicy)
    client.start()
  }

  override def create(tupleSeq: (String, Array[Byte])*): Iterable[String] = {
    tupleSeq.map { case (path, bytes) =>
      client.create().creatingParentsIfNeeded().forPath(path, bytes)
    }
  }

  override def create(path: String, bytes: Array[Byte]): String = {
    client.create().creatingParentsIfNeeded().forPath(path, bytes)
  }

  override def createDirectory(path: String): String = {
    client.create().creatingParentsIfNeeded().forPath(path)
  }

  override def delete(path: String): Boolean = {
    client.delete().forPath(path)
    exists(path)
  }

  override def deleteRecursive(path: String): Boolean = {
    client.delete().deletingChildrenIfNeeded().forPath(path)
    exists(path)
  }

  override def exists(path: String): Boolean = {
    Option(client.checkExists().forPath(path)).isDefined
  }

  override def ensurePath(path: String): List[String] = {
    List(client.create().creatingParentsIfNeeded().forPath(path)) // TODO
  }

  override def ensureParents(path: String): List[String] = {
    List(client.create().creatingParentsIfNeeded().forPath(path)) // TODO
{'fraction_non_alphanumeric': 0.12484609702043832, 'fraction_numerical': 0.004678650578675204, 'mean_word_length': 4.713080168776371, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7153633', 'n_tokens_mistral': 1277, 'n_tokens_neox': 1244, 'n_words': 254}