private[this] def checkParrotServer()

in src/main/scala/com/twitter/iago/util/ParrotCluster.scala [302:335]


  private[this] def checkParrotServer(address: InetSocketAddress, timeout: Duration): Unit = {
    val futurePool = FuturePool.interruptibleUnboundedPool
    val timer = DefaultTimer.twitter

    def isConnectable(address: InetSocketAddress): Boolean = {
      val socket = new Socket()
      try {
        socket.connect(address, 1000)
        true
      } catch { case e: IOException =>
        log.info("Parrot server at %s is not available yet: %s", address, e.getMessage)
        false
      } finally {
        socket.close()
      }
    }

    def checkConnectivity(address: InetSocketAddress): Future[Unit] = {
      futurePool(isConnectable(address))
        .delayed(Duration(1000, TimeUnit.MILLISECONDS))(timer).flatMap {
        case true => Future.Unit
        case _ => checkConnectivity(address)
      }
    }

    Await.result(
      checkConnectivity(address)
        .raiseWithin(
          timer,
          timeout,
          new RuntimeException(s"Timeout waiting for parrot server at $address")
        )
    )
  }