private def start()

in management/src/main/scala/org/apache/pekko/management/scaladsl/PekkoManagement.scala [149:183]


  private def start(effectiveProviderSettings: ManagementRouteProviderSettings,
      serverBindingPromise: Promise[Http.ServerBinding]): Future[Uri] = {
    val effectiveBindHostname = settings.Http.EffectiveBindHostname
    val effectiveBindPort = settings.Http.EffectiveBindPort

    // TODO instead of binding to hardcoded things here, discovery could also be used for this binding!
    // Basically: "give me the SRV host/port for the port called `pekko-bootstrap`"
    // discovery.lookup("_pekko-bootstrap" + ".effective-name.default").find(myaddress)
    // ----
    // FIXME -- think about the style of how we want to make these available

    log.info("Binding Pekko Management (HTTP) endpoint to: {}:{}", effectiveBindHostname, effectiveBindPort)

    val combinedRoutes = prepareCombinedRoutes(effectiveProviderSettings)

    val baseBuilder = Http()
      .newServerAt(effectiveBindHostname, effectiveBindPort)
      .withSettings(ServerSettings(system).withRemoteAddressHeader(true))

    val securedBuilder = effectiveProviderSettings.httpsConnectionContext match {
      case Some(httpsContext) => baseBuilder.enableHttps(httpsContext)
      case None               => baseBuilder
    }
    val serverFutureBinding = securedBuilder.bind(combinedRoutes)

    serverBindingPromise.completeWith(serverFutureBinding).future.flatMap { binding =>
      val boundPort = binding.localAddress.getPort
      log.info(
        ManagementLogMarker.boundHttp(s"$effectiveBindHostname:$boundPort"),
        "Bound Pekko Management (HTTP) endpoint to: {}:{}",
        effectiveBindHostname,
        boundPort)
      selfUriPromise.success(effectiveProviderSettings.selfBaseUri.withPort(boundPort)).future
    }
  }