<commit_before>package com.stratio.bus

import scala.concurrent._
import com.typesafe.config.ConfigFactory
import scala.concurrent.duration._
import java.util.UUID
import com.stratio.bus.utils.JsonUtils

case class Create(
  createTableProducer: KafkaProducer,
  zookeeperConsumer: ZookeeperConsumer) {
  val config = ConfigFactory.load()

  def create(queryString: String) = {
    val zNodeUniqueId = UUID.randomUUID().toString
    createMessageInTheCreationTopic(queryString, zNodeUniqueId)
    waitForTheStreamingResponse(zNodeUniqueId)
  }

  def createMessageInTheCreationTopic(queryString: String, creationUniqueId: String) = {
    val message = JsonUtils.appendElementsToJsonString(queryString, Map("zNodeId" -> creationUniqueId))
    createTableProducer.send(message)
  }
  
  def waitForTheStreamingResponse(zNodeUniqueId: String) = {
    try {
      val createTableTimeOut = config.getString("create.table.ack.timeout.in.seconds").toInt
      val creationFullPath = getCreationZNodeFullPath(zNodeUniqueId, "create")
      Await.result(zookeeperConsumer.readZNode(creationFullPath), createTableTimeOut seconds)
      println("ACK RECEIVED!!!!")
      //TODO define response (json, exceptions....)
    } catch {
      case e: TimeoutException => {<commit_msg>Getting ack response from zookeeper zNode<commit_after>package com.stratio.bus

import scala.concurrent._
import com.typesafe.config.ConfigFactory
import scala.concurrent.duration._
import java.util.UUID
import com.stratio.bus.utils.JsonUtils

case class Create(
  createTableProducer: KafkaProducer,
  zookeeperConsumer: ZookeeperConsumer) {
  val config = ConfigFactory.load()

  def create(queryString: String) = {
    val zNodeUniqueId = UUID.randomUUID().toString
    createMessageInTheCreationTopic(queryString, zNodeUniqueId)
    waitForTheStreamingResponse(zNodeUniqueId)
  }

  def createMessageInTheCreationTopic(queryString: String, creationUniqueId: String) = {
    val message = JsonUtils.appendElementsToJsonString(queryString, Map("zNodeId" -> creationUniqueId))
    createTableProducer.send(message)
  }
  
  def waitForTheStreamingResponse(zNodeUniqueId: String) = {
    try {
      val createTableTimeOut = config.getString("create.table.ack.timeout.in.seconds").toInt
      val creationFullPath = getCreationZNodeFullPath(zNodeUniqueId, "create")
      Await.result(zookeeperConsumer.readZNode(creationFullPath), createTableTimeOut seconds)
      val response = zookeeperConsumer.getZNodeData(creationFullPath)
      println("The response has been: "+response)
      //TODO define response (json, exceptions....)
    } catch {
      case e: TimeoutException => {
{'fraction_non_alphanumeric': 0.09214501510574018, 'fraction_numerical': 0.0, 'mean_word_length': 5.0204545454545455, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1876803', 'n_tokens_mistral': 780, 'n_tokens_neox': 770, 'n_words': 145}