<commit_before>package main

import akka.actor._
import akka.cluster.Cluster
import akka.http.scaladsl.Http
import akka.stream.ActorMaterializer
import com.typesafe.config.ConfigFactory

import scala.collection.immutable
import scala.concurrent.Await
import scala.util.{Failure, Success}

object Application extends App {
  /*
  import scala.collection.JavaConverters._
  val env = System.getenv().asScala
  */

  val SystemName = "docker-cluster"

  val hostPort = Option(System.getenv().get("akka.remote.netty.tcp.port"))
    .fold(throw new Exception("Couldn't find seedHostPort"))(identity)


  val hostName = Option(System.getenv().get("akka.remote.netty.tcp.hostname")).filter(_.length>0)

  val seedHost = Option(System.getenv().get("seed.tcp.hostname")).filter(_.length>0)

  val cfg = ConfigFactory.load()

  /*if (isSeed) {
    ConfigFactory.empty()
      //.withFallback(seeds)
      //.withFallback(ConfigFactory.parseString(s"akka.remote.netty.tcp.bind-port=$port0"))
      //.withFallback(ConfigFactory.parseString(s"akka.remote.netty.tcp.bind-hostname=$external"))
      .withFallback(ConfigFactory.parseString(s"akka.remote.netty.tcp.port=$seedHostPort"))
      //.withFallback(ConfigFactory.parseString(s"akka.remote.netty.tcp.hostname=$hostName0"))
      .withFallback(ConfigFactory.load())
  } else ConfigFactory.load()*/


  implicit val system = ActorSystem(SystemName, cfg)
  implicit val mat = ActorMaterializer()
  implicit val _ = mat.executionContext

  /*val seed = if(hostName.isDefined) Address("akka.tcp", SystemName, hostName.get, hostPort.toInt)
  else Address("akka.tcp", SystemName, seedHost.get, hostPort.toInt)*/

  val cluster = Cluster(system)

  println(s"$hostPort - $hostName - ${seedHost}")

  if(seedHost.isEmpty) {
    val seed = Address("akka.tcp", SystemName, hostName.get, hostPort.toInt)
    println("****Join self seed node: " + seed) //cluster.selfAddress
    cluster.join(seed)
  } else {
    val seed = Address("akka.tcp", SystemName, seedHost.get, hostPort.toInt)
    println("****Join seed node: " + seed)
    cluster.joinSeedNodes(immutable.Seq(seed))
  }


  seedHost.fold(
    Http().bindAndHandle(new HttpRoutes(hostName.get, cluster).route, interface = hostName.get, port = 9000).onComplete {
      case Success(r) =>
        println(s"http server available on ${r.localAddress}")
      case Failure(ex) =>
        println(ex.getMessage)
        System.exit(-1)
    }) { _ => () }

  sys.addShutdownHook {
    system.log.info("ShutdownHook")
    import scala.concurrent.duration._
    Await.ready(system.terminate, 5 seconds)
    cluster.leave(cluster.selfAddress)
  }
}

/**
 * seed-nodes = [
 *  akka.tcp://docker-cluster@seed-node:2551
 *  akka.tcp://docker-cluster@seed-node:2551
 *  akka.tcp://docker-cluster@seed-node:2551
 * ]
 */<commit_msg>a try to change port<commit_after>package main

import akka.actor._
import akka.cluster.Cluster
import akka.http.scaladsl.Http
import akka.stream.ActorMaterializer
import com.typesafe.config.ConfigFactory

import scala.collection.immutable
import scala.concurrent.Await
import scala.util.{Failure, Success}

object Application extends App {
  /*
  import scala.collection.JavaConverters._
  val env = System.getenv().asScala
  */

  val SystemName = "docker-cluster"

  val hostPort = Option(System.getenv().get("akka.remote.netty.tcp.port"))
    .fold(throw new Exception("Couldn't find seedHostPort"))(identity)


  val hostName = Option(System.getenv().get("akka.remote.netty.tcp.hostname")).filter(_.length>0)

  val seedHost = Option(System.getenv().get("seed.tcp.hostname")).filter(_.length>0)

  val cfg = ConfigFactory.load()

  /*if (isSeed) {
    ConfigFactory.empty()
      //.withFallback(seeds)
      //.withFallback(ConfigFactory.parseString(s"akka.remote.netty.tcp.bind-port=$port0"))
      //.withFallback(ConfigFactory.parseString(s"akka.remote.netty.tcp.bind-hostname=$external"))
      .withFallback(ConfigFactory.parseString(s"akka.remote.netty.tcp.port=$seedHostPort"))
      //.withFallback(ConfigFactory.parseString(s"akka.remote.netty.tcp.hostname=$hostName0"))
      .withFallback(ConfigFactory.load())
  } else ConfigFactory.load()*/


  implicit val system = ActorSystem(SystemName, cfg)
  implicit val mat = ActorMaterializer()
  implicit val _ = mat.executionContext

  /*val seed = if(hostName.isDefined) Address("akka.tcp", SystemName, hostName.get, hostPort.toInt)
  else Address("akka.tcp", SystemName, seedHost.get, hostPort.toInt)*/

  val cluster = Cluster(system)

  println(s"$hostPort - $hostName - ${seedHost}")

  if(seedHost.isEmpty) {
    val seed = Address("akka.tcp", SystemName, hostName.get, hostPort.toInt)
    //****Join self seed node: akka.tcp://docker-cluster@seed-node:2551
    println("****Join self seed node: " + seed) //cluster.selfAddress
    cluster.joinSeedNodes(immutable.Seq(seed))
  } else {
    val seed = Address("akka.tcp", SystemName, seedHost.get, hostPort.toInt)
    println("****Join seed node: " + seed)
    cluster.joinSeedNodes(immutable.Seq(seed))
  }


  seedHost.fold(
    Http().bindAndHandle(new HttpRoutes(hostName.get, cluster).route, interface = hostName.get, port = 9000).onComplete {
      case Success(r) =>
        println(s"http server available on ${r.localAddress}")
      case Failure(ex) =>
        println(ex.getMessage)
        System.exit(-1)
    }) { _ => () }

  sys.addShutdownHook {
    system.log.info("ShutdownHook")
    import scala.concurrent.duration._
    Await.ready(system.terminate, 5 seconds)
    cluster.leave(cluster.selfAddress)
  }
}

/**
 * seed-nodes = [
 *  akka.tcp://docker-cluster@seed-node:2551
 *  akka.tcp://docker-cluster@seed-node:2551
 *  akka.tcp://docker-cluster@seed-node:2551
 * ]
 */
{'fraction_non_alphanumeric': 0.1496765168735793, 'fraction_numerical': 0.008393075712537158, 'mean_word_length': 4.053003533568905, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '1535108', 'n_tokens_mistral': 1960, 'n_tokens_neox': 1897, 'n_words': 301}