<commit_before>package spmd

object Spmd {
  def main(args: Array[String]) = {
    // Start listening
    Server
    // Establish client conn
    // API, json?
    // Integrate to console
  }
}

trait Client {
//  def names = names(inet.getHostName)
//  def names(host: HostName)
//  def registerNode(name: Name, port: Int)
}

// PUT /nodes/{node}/{ip}/{port} HTTP/1.1
object Server {
  import java.io._
  import java.net._
  import scala.actors.Actor

  val serverSocket = new ServerSocket(6128)

  while (true) {
    new Handler(serverSocket.accept).start    
  }

  class Handler(clientSocket: Socket) extends Actor {
    def act {
      val out = new PrintWriter(clientSocket.getOutputStream, true)
      val in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream))
      val req = Request.fromRequestLine(in.readLine)
      val res = req match {
        case Request(PUT, "nodes" :: node :: ip :: port :: Nil) => Response(OK, "{ ok }")
        case Request(GET, "nodes" :: node :: ip :: port :: Nil) => Response(OK, "{ ok }") // Remove
        case _ => Response(NotFound, "")
      }
      println(res.toString)
      out.write(res.toString)
      out.flush
      out.close
    }
  }

  case class Response(status: Status, body: String) {
    override def toString = 
      "HTTP/1.0 " + status.code + " " + status.toString + "\r\n" +
      "Content-Type: application/json\r\n" +
      body + "\r\n"
  }

  case class Request(method: Method, url: List[String])
  case object Request {
    def fromRequestLine(s: String) = {
      val elems = s.split(" ")
      (elems(0), elems(1).split("/").filter(!_.isEmpty).toList) match {
        case ("PUT", url) => new Request(PUT, url)
        case ("GET", url) => new Request(GET, url)
        case _ => error("unknown method: " + s)
      }
    }
  }
  
  sealed abstract class Method
  case object PUT extends Method
  case object GET extends Method

  sealed abstract class Status(val code: Int)
  case object OK extends Status(200) {
    override def toString = "OK"
  }
  case object NotFound extends Status(404) {
    override def toString = "Not Found"
  }<commit_msg>http client<commit_after>package spmd

object Spmd {
  def main(args: Array[String]) = {
    Http.Server.start
  }
}

trait Client {
  import scala.actors.remote.Node

//  def names = names(inet.getHostName)
//  def names(host: HostName)
  def registerNode(name: String, node: Node) = {
    val http = new Http.Client("localhost", 6128)
    val req = http.put("/nodes/" + name + "/" + node.address + "/" + node.port, "")
    http.send(req)
  }
{'fraction_non_alphanumeric': 0.13921113689095127, 'fraction_numerical': 0.007733952049497293, 'mean_word_length': 2.7276657060518734, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '902791', 'n_tokens_mistral': 847, 'n_tokens_neox': 828, 'n_words': 225}