<commit_before>package mot.impl

import mot.util.Util.FunctionToRunnable
import mot.protocol.Frame
import mot.protocol.ResponseFrame
import java.util.concurrent.ConcurrentHashMap
import mot.protocol.RequestFrame
import java.net.Socket
import java.util.concurrent.TimeUnit
import scala.collection.JavaConversions._
import java.util.concurrent.atomic.AtomicLong
import mot.protocol.HelloFrame
import java.net.InetSocketAddress
import mot.util.UnaryPromise
import mot.protocol.MessageFrame
import mot.Message
import mot.MessageTooLargeException
import mot.protocol.FlowControlFrame
import mot.dump.TcpEvent
import mot.dump.Direction
import mot.dump.Operation
import mot.util.Util.RichAtomicLong

final class ClientConnection(val connector: ClientConnector, socketImpl: Socket)
  extends AbstractConnection(connector.client, socketImpl) {

  val readerThread = new Thread(readerLoop _, s"mot(${connector.client.name})-reader-for-${connector.target}")

  val helloPromise = new UnaryPromise[ServerHello]

  val remoteHelloLatch = helloPromise.latch

  def remoteNameOption = helloPromise.value.map(_.name)
  def remoteMaxLength = helloPromise.value.map(_.maxLength)

  def isClosed() = socket.isClosed()

  def startAndBlockWriting(): Unit = {
    party.context.dumper.dump(TcpEvent(this, Direction.Outgoing, Operation.Creation))
    readerThread.start()
    writerLoop()
    // TODO: join reader?
  }
<commit_msg>Add join<commit_after>package mot.impl

import mot.util.Util.FunctionToRunnable
import mot.protocol.Frame
import mot.protocol.ResponseFrame
import java.util.concurrent.ConcurrentHashMap
import mot.protocol.RequestFrame
import java.net.Socket
import java.util.concurrent.TimeUnit
import scala.collection.JavaConversions._
import java.util.concurrent.atomic.AtomicLong
import mot.protocol.HelloFrame
import java.net.InetSocketAddress
import mot.util.UnaryPromise
import mot.protocol.MessageFrame
import mot.Message
import mot.MessageTooLargeException
import mot.protocol.FlowControlFrame
import mot.dump.TcpEvent
import mot.dump.Direction
import mot.dump.Operation
import mot.util.Util.RichAtomicLong

final class ClientConnection(val connector: ClientConnector, socketImpl: Socket)
  extends AbstractConnection(connector.client, socketImpl) {

  val readerThread = new Thread(readerLoop _, s"mot(${connector.client.name})-reader-for-${connector.target}")

  val helloPromise = new UnaryPromise[ServerHello]

  val remoteHelloLatch = helloPromise.latch

  def remoteNameOption = helloPromise.value.map(_.name)
  def remoteMaxLength = helloPromise.value.map(_.maxLength)

  def isClosed() = socket.isClosed()

  def startAndBlockWriting(): Unit = {
    party.context.dumper.dump(TcpEvent(this, Direction.Outgoing, Operation.Creation))
    readerThread.start()
    writerLoop() // block for the duration of the connection
    readerThread.join() // the writer signals the reader to finish, so this should not take much time
  }

{'fraction_non_alphanumeric': 0.08864643709512444, 'fraction_numerical': 0.0, 'mean_word_length': 5.683371298405467, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4731616', 'n_tokens_mistral': 843, 'n_tokens_neox': 818, 'n_words': 188}