All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.twitter.server.handler.AbortHandler.scala Maven / Gradle / Ivy

The newest version!
package com.twitter.server.handler

import com.twitter.finagle.Service
import com.twitter.finagle.http.{Request, Response}
import com.twitter.server.util.HttpUtils.newOk
import com.twitter.util.Future
import java.util.logging.Logger

class AbortHandler extends Service[Request, Response] {
  private[this] val log = Logger.getLogger(getClass.getName)

  private[this] def background(f: => Unit): Unit = {
    (new Thread("lifecycle") {
      override def run() {
        Thread.sleep(10)
        f
      }
    }).start()
  }

  def apply(req: Request): Future[Response] = {
    log.info(s"[${req.uri}] from ${req.remoteAddress.getHostAddress} aborting")
    background { Runtime.getRuntime.halt(0) }
    newOk("aborting\n")
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy