• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala StdIn类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中scala.io.StdIn的典型用法代码示例。如果您正苦于以下问题:Scala StdIn类的具体用法?Scala StdIn怎么用?Scala StdIn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了StdIn类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: Demo1

//设置package包名称以及导入依赖的类
package lew.bing.akka.http

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model._
import akka.http.scaladsl.server.{Directive, RequestContext, Route, RouteResult}
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.Flow

import scala.io.StdIn


object Demo1 {

  def main(args: Array[String]): Unit = {
    implicit val system = ActorSystem("my-http")
    implicit val materializer = ActorMaterializer()
    // needed for the future flatMap/onComplete in the end
    implicit val executionContext = system.dispatcher



    val route:Route =
      path("hello"){
        get {
          complete(HttpEntity(ContentTypes.`text/html(UTF-8)`,"<h1>Say hello to akka-http</h1>"))
        }
      }
    val map = Flow[RequestContext].map(route)
    //???????????
    val bindingFuture = Http().bindAndHandle(route,"localhost",9898)
    println(s"Server online at http://localhost:9898/\nPress RETURN to stop...")
    StdIn.readLine() // let it run until user presses return
    bindingFuture
      .flatMap(_.unbind()) // trigger unbinding from the port
      .onComplete(_ => system.terminate()) // and shutdown when done
  }

} 
开发者ID:liuguobing634,项目名称:akka,代码行数:41,代码来源:Demo1.scala


示例2: Main

//设置package包名称以及导入依赖的类
package game_of_life

import game_of_life.controller.GameController
import game_of_life.model.Game
import game_of_life.model.Game.SetupPredicate

import scala.io.StdIn
import scala.reflect.runtime.currentMirror
import scala.tools.reflect.ToolBox

object Main extends App {

  val controller = new GameController(
    Game(rows = args(0).toInt, columns = args(1).toInt) {
      args drop 2 match {
        case Array() => Game.randomInit
        case Array(word) if word equalsIgnoreCase "blinkers" => (row, column) => row % 4 == 1 && column % 4 < 3
        case array => eval[SetupPredicate]("($r: Int, $c: Int) => { " + (array mkString " ") + " }: Boolean")
      }
    }
  )()

  do {
    controller toggle ()
  } while ((StdIn readLine ()) != null)
  controller stop ()

  private def eval[A](string: String): A = {
    val tb = currentMirror mkToolBox ()
    val tree = tb parse string
    (tb eval tree).asInstanceOf[A]
  }
} 
开发者ID:christian-schlichtherle,项目名称:akka-game-of-life,代码行数:34,代码来源:Main.scala


示例3: CodebaseAnalyzerAkkaApp

//设置package包名称以及导入依赖的类
package tutor

import akka.actor.{ActorRef, ActorSystem}
import tutor.CodebaseAnalyzeAggregatorActor.AnalyzeDirectory

import scala.io.StdIn

object CodebaseAnalyzerAkkaApp extends App {

  val system = ActorSystem("CodebaseAnalyzer")
  val codebaseAnalyzerControllerActor: ActorRef = system.actorOf(CodebaseAnalyzerControllerActor.props())

  var shouldContinue = true
  try {
    while (shouldContinue) {
      println("please input source file folder or :q to quit")
      val input = StdIn.readLine()
      if (input == ":q") {
        shouldContinue = false
      } else {
        codebaseAnalyzerControllerActor ! AnalyzeDirectory(input)
      }
    }
  } finally {
    println("good bye!")
    system.terminate()
  }
} 
开发者ID:notyy,项目名称:CodeAnalyzerTutorial,代码行数:29,代码来源:CodebaseAnalyzerAkkaApp.scala


示例4: Boot

//设置package包名称以及导入依赖的类
package com.saleass.app.web

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model._
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer
import scala.io.StdIn

object Boot extends App {
  implicit val system = ActorSystem("saleass")
  implicit val mat = ActorMaterializer()
  implicit val ec = system.dispatcher

  val route = path("hello") {
    get {
      complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, "<h1>Damn you av!"))
    }
  }

  val httpBindFuture = Http().bindAndHandle(route, "localhost", 8080)
  StdIn.readLine()
  httpBindFuture.flatMap(_.unbind()).onComplete(_ => system.terminate())
} 
开发者ID:arinal,项目名称:saleass,代码行数:25,代码来源:Boot.scala


示例5: WebServer

//设置package包名称以及导入依赖的类
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model._
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer
import scala.io.StdIn

object WebServer {
  def main(args: Array[String]) {

    implicit val system = ActorSystem("my-system")
    implicit val materializer = ActorMaterializer()
    implicit val executionContext = system.dispatcher

    val route =
      path("hello") {
        get {
          complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, "<h1>Say hello to akka-http</h1>"))
        }
      }

    val bindingFuture = Http().bindAndHandle(route, "0.0.0.0", 8080)

    println(s"Server online at http://localhost:8080/\nPress RETURN to stop...")
    StdIn.readLine() // let it run until user presses return
    bindingFuture
      .flatMap(_.unbind()) // trigger unbinding from the port
      .onComplete(_ => system.terminate()) // and shutdown when done
  }
} 
开发者ID:artyomboyko,项目名称:death-star-design,代码行数:31,代码来源:WebServer.scala


示例6: AService

//设置package包名称以及导入依赖的类
package service.a.app

import scala.concurrent.ExecutionContext
import scala.io.StdIn

import akka.http.scaladsl.Http
import akka.http.scaladsl.marshallers.xml.ScalaXmlSupport.defaultNodeSeqMarshaller
import akka.http.scaladsl.marshalling.ToResponseMarshallable.apply
import akka.http.scaladsl.server.Directive.addByNameNullaryApply
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.RouteResult.route2HandlerFlow
import akka.stream.ActorMaterializer
import service.a.core.ACoreBooted


object AService extends App with ACoreBooted with AConfig {
  
  protected implicit val executor: ExecutionContext = system.dispatcher
  protected implicit val materializer: ActorMaterializer = ActorMaterializer()

  val route = 
    path("hello") {
      get {
        complete {
          <h1>Say hello to akka-http</h1>
        }
      }
    } ~
    path("dude") {
      get {
        complete {
          <h1>Say hello to dude</h1>
        }
      }
    }
  
  val bindingFuture = Http().bindAndHandle(route, "localhost", port.toInt)
  
  println(s"Server online at http://localhost:11011/\nPress RETURN to stop...")
  StdIn.readLine()
  bindingFuture
    .flatMap(_.unbind())
    .onComplete { _ => system.terminate() }

} 
开发者ID:kevinkl,项目名称:scalakka,代码行数:46,代码来源:AService.scala


示例7: InterpreterMain

//设置package包名称以及导入依赖的类
package qq

import monix.eval.Task
import monix.execution.CancelableFuture
import monix.execution.Scheduler.Implicits.global
import qq.util.Interpreter

import scala.concurrent.Await
import scala.concurrent.duration._
import scala.io.StdIn

object InterpreterMain extends App {

  def runInterpreter(interpreter: Interpreter): Task[Unit] = Task.defer {
    println("Entered interpreter " + interpreter.name)
    interpreter.resume(StdIn.readLine()).fold(
      Task.defer {
        val () = println("what?")
        runInterpreter(interpreter)
      }) {
      _.fold(
        _ => Task.eval(println("Bye!")),
        _.flatMap { case (output, nextInterpreter) =>
          val () = println(output)
          runInterpreter(nextInterpreter)
        }
      )
    }
  }

  val interpreterFinished: CancelableFuture[Unit] = runInterpreter(Interpreter.mainMenu).runAsync
  val () = Await.result(interpreterFinished, Duration.Inf)

} 
开发者ID:edmundnoble,项目名称:slate,代码行数:35,代码来源:InterpreterMain.scala


示例8: OrderApp

//设置package包名称以及导入依赖的类
package com.github.simonthecat.eventdrivenorders.orderservice

import org.apache.kafka.clients.consumer.KafkaConsumer
import org.apache.kafka.clients.producer.KafkaProducer

import scala.io.StdIn


object OrderApp extends App {

  val confirmationService = new ConfirmationService(
    confirmationConsumer = new KafkaConsumer[String, String](kafka.storeConfirmationConsumer),
    confirmationTopic = "order.confirmation",
    replyProducer = new KafkaProducer[String, String](kafka.producerCfg),
    replyTopic = "api.reply"
  )

  val orderService = new OrderProcessingService(
    new KafkaConsumer[String, String](kafka.orderConsumerCfg),
    "order.order",
    new KafkaProducer[String, String](kafka.producerCfg),
    "store.update"
  )

  confirmationService.start()
  orderService.start()

  StdIn.readLine()
  confirmationService.stop()
  orderService.stop()
} 
开发者ID:simonko91,项目名称:event-driven-orders,代码行数:32,代码来源:OrderApp.scala


示例9: Launcher

//设置package包名称以及导入依赖的类
package org.codeape.sc.backend

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer

import scala.io.StdIn

object Launcher {

  def main(args: Array[String]): Unit = {
    implicit val system = ActorSystem("my-system")
    implicit val materializer = ActorMaterializer()
    // needed for the future flatMap/onComplete in the end
    implicit val executionContext = system.dispatcher

    val route =
      path("") {
        getFromFile("backend/target/UdashStatic/WebContent/index.html")
      } ~
      pathPrefix("scripts"){
        getFromDirectory("backend/target/UdashStatic/WebContent/scripts")
      } ~
      pathPrefix("assets"){
        getFromDirectory("backend/target/UdashStatic/WebContent/assets")
      }
    val bindingFuture = Http().bindAndHandle(route, "localhost", 8080)

    println(s"Server online at http://localhost:8080/\nPress RETURN to stop...")
    StdIn.readLine() // let it run until user presses return
    bindingFuture
      .flatMap(_.unbind()) // trigger unbinding from the port
      .onComplete(_ => system.terminate()) // and shutdown when done

  }
} 
开发者ID:codeape,项目名称:StampClock,代码行数:38,代码来源:Launcher.scala


示例10: Main

//设置package包名称以及导入依赖的类
package com.bau5.sitetracker.server

import akka.actor.PoisonPill
import akka.util.Timeout
import com.bau5.sitetracker.common.BaseProvider
import com.bau5.sitetracker.common.Events.{Message, MessageAll, SaveRequest}

import scala.concurrent.duration._
import scala.io.StdIn


object Main extends BaseProvider("ServerSystem", "") {
  override implicit val timeout: Timeout = Timeout(5 seconds)

  val messageAll = "message-all (.+)".r

  def main(args: Array[String]) {
    val serverActor = newActor[ServerActor]("server")
    serverActor ! LoadSavedData

    while (true) StdIn.readLine("> ") match {
      case "save" =>
        serverActor ! SaveRequest
      case "quit" =>
        serverActor ! SaveRequest
        serverActor ! PoisonPill
        sys.exit(0)
      case messageAll(msg) =>
        serverActor ! MessageAll(Message(msg))
      case _ =>
        println("Unrecognized input.")
    }
  }
} 
开发者ID:rickbau5,项目名称:SiteTracker,代码行数:35,代码来源:Main.scala


示例11: WebServer

//设置package包名称以及导入依赖的类
package dummy_authenticator.server

import akka.actor.ActorSystem
import akka.http.scaladsl._
import akka.stream.ActorMaterializer
import dummy_authenticator.config.Configuration
import dummy_authenticator.rest.Routes

import scala.concurrent.ExecutionContextExecutor
import scala.io.StdIn

object WebServer extends Routes {
  val config: Configuration                 = Configuration.get
  implicit val system                       = ActorSystem(config.app.name)
  implicit val materializer                 = ActorMaterializer()
  implicit val ec: ExecutionContextExecutor = system.dispatcher

  def main(args: Array[String]) {
    val interface = config.server.interface
    val port      = config.server.dummy_port

    // The Magic Words
    val bindingFuture = Http().bindAndHandle(routes, interface, port)

    // Console "Controls"
    println(s"dummy_authenticator online at http://$interface:$port/\nPress RETURN to stop...")
    StdIn.readLine() // let it run until user presses return

    // Closing Shop
    bindingFuture
      .flatMap(_.unbind()) // trigger unbinding from the port
      .onComplete(_ => system.terminate()) // and shutdown when done
  }
} 
开发者ID:DalenWBrauner,项目名称:Alkes-Prototype,代码行数:35,代码来源:WebServer.scala


示例12: WebServer

//设置package包名称以及导入依赖的类
package co.horn.alkes.server

import akka.actor.ActorSystem
import akka.http.scaladsl._
import akka.stream.ActorMaterializer
import co.horn.alkes.auth._
import co.horn.alkes.config.Configuration
import co.horn.alkes.dao.DataHandler
import co.horn.alkes.dao.implementations.riak.RiakDataHandler
import co.horn.alkes.log.Logger
import co.horn.alkes.rest.Routes

import scala.concurrent.ExecutionContextExecutor
import scala.io.StdIn

object WebServer extends Routes {
  implicit val system                       = ActorSystem("alkes")
  implicit val materializer                 = ActorMaterializer()
  implicit val ec: ExecutionContextExecutor = system.dispatcher
  val config: Configuration                 = Configuration.get
  val dao: DataHandler                      = new RiakDataHandler(config)
  val auth: Authority                       = new WasatAuthority(config)
  val log: Logger                           = config.log.server

  def main(args: Array[String]) {
    val interface = config.server.interface
    val port      = config.server.port

    // The Magic Words
    val bindingFuture = Http().bindAndHandle(routes, interface, port)

    // Console "Controls"
    println(s"alkes online at http://$interface:$port/\nPress RETURN to stop...")
    StdIn.readLine() // let it run until user presses return

    // Closing Shop
    bindingFuture
      .flatMap(_.unbind()) // trigger unbinding from the port
      .onComplete(_ => system.terminate()) // and shutdown when done
  }
} 
开发者ID:DalenWBrauner,项目名称:Alkes-Prototype,代码行数:42,代码来源:WebServer.scala


示例13: webServer

//设置package包名称以及导入依赖的类
package akka_in_action.http

import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.http.scaladsl.Http
import akka.http.scaladsl.model._
import akka.http.scaladsl.server.Directives._
import scala.io.StdIn

object webServer extends App {
  implicit val system = ActorSystem("my-system")
  implicit val materializer = ActorMaterializer()
  implicit val executionContext = system.dispatcher

  val route =
    path("hello") {
      get {
        complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, "<h1>Hello, holy crapper.</h2>"))
      }
    }

  val host = "127.0.0.1"
  val port = 8080
  val bindingFuture = Http().bindAndHandle(route, host, port)

  println(s"Server onlien at http://${host}:${port}/\nPress RETURN to stop...")
  StdIn.readLine
  bindingFuture
    .flatMap(_.unbind)
    .onComplete(_ => system.terminate)
} 
开发者ID:rockdragon,项目名称:fourthgala,代码行数:32,代码来源:webServer.scala


示例14: InventoryApplication

//设置package包名称以及导入依赖的类
package com.tuplejump.inventory.cli

import scala.io.StdIn
import org.jboss.aesh.console._
import org.jboss.aesh.console.settings.SettingsBuilder
import com.tuplejump.inventory.client.Client

object InventoryApplication {

  def main(args: Array[String]) {
    print("Enter number of POS terminals: ")
    val num = StdIn.readInt()
    val cli = new Client(num)
    cli.start()
    val builder: SettingsBuilder = new SettingsBuilder().ansi(true)
    builder.logging(true).logfile(System.getProperty("user.dir") +
      System.getProperty("file.separator") + "akka.log")
    builder.persistHistory(true)
    builder.parseOperators(false)
    val console: Console = new Console(builder.create)
    val consoleCallback: ConsoleCallback = new ConsoleCallBack(console, cli)
    console.setConsoleCallback(consoleCallback)
    val prompt: Prompt = new Prompt("Enter command>")
    console.start()
    console.setPrompt(prompt)
  }
} 
开发者ID:shrutig,项目名称:inventory,代码行数:28,代码来源:InventoryApplication.scala


示例15: JavaFXExamples

//设置package包名称以及导入依赖的类
package com.outr.nextui.examples.desktop

import java.util.prefs.Preferences

import com.outr.nextui.desktop.JavaFX
import com.outr.nextui.examples.Examples._

import scala.io.StdIn

object JavaFXExamples {
  def main(args: Array[String]): Unit = {
    val keyName = "nextui.javafx.examples.lastRun"
    val preferences = Preferences.userRoot()
    val previousName = preferences.get(keyName, examples.head.name)
    val previous = examples.find(_.name == previousName).map(examples.indexOf).getOrElse(0) + 1

    println("Choose an example to run:")
    examples.zipWithIndex.foreach {
      case (example, index) => println(s"\t${index + 1}.) ${example.name}")
    }
    println(s"Example number 1 - ${examples.size} [$previous]: ")
    val i = try {
      StdIn.readInt()
    } catch {
      case t: Throwable => previous
    }
    val ui = examples(i - 1)
    preferences.put(keyName, ui.name)
    println(s"Starting ${ui.name}...")
    JavaFX(ui)
  }
} 
开发者ID:outr,项目名称:nextui,代码行数:33,代码来源:JavaFXExamples.scala


示例16: Game

//设置package包名称以及导入依赖的类
import scala.io.StdIn

object Game {
  def displayGame(subject: String, words: Map[String, Int], found: Array[String]) = {
    // Use ANSI escape codes:
    // print("\033[H\033[2J");
    // * 'H' means move to top of the screen
    // * '2J' means "clear entire screen"
    print("\033[H\033[2J")
    println("=====================================")
    println("================ 94% ================")
    println("=====================================")
    println
    println("Subject: " + subject)
    for (wordAndPercentage: (String, Int) <- words) {
      val word = wordAndPercentage._1
      val percentage = wordAndPercentage._2
      val display =
        if (found.contains(word)) "[" + word + " " + percentage + "%]"
        else "[ " + percentage + "% ]"
      println(display)
    }
  }

  def main(args: Array[String]): Unit = {
    val words = Map(
      "Mercedes" -> 30,
      "BMW" -> 30,
      "Renault" -> 20,
      "Citroen" -> 20
    )

    var found = Array.empty[String]

    while (found.size != words.size) {
      displayGame("Car brands", words, found)
      println("Suggest a word: ")
      val suggestedWord = StdIn.readLine()

      found =
        if (words.contains(suggestedWord)) found :+ suggestedWord
        else found
    }

    println
    println("You win!")
  }
} 
开发者ID:joan38,项目名称:Learn-Programming-Scala,代码行数:49,代码来源:Game.scala


示例17: ServerListener

//设置package包名称以及导入依赖的类
package scalapi.server

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer
import org.reflections.Reflections
import scala.collection.JavaConverters._
import scala.io.StdIn


object ServerListener {
  implicit val system = ActorSystem("scalapi-actors")
  implicit val materializer = ActorMaterializer()
  implicit val ec = system.dispatcher

  val route =
    path("hello") {
      get {
        complete {
          "Hello"
        }
      }
    }

  def endpoints: List[Class[_ <: Endpoint]] = {
    val refl = new Reflections()
    refl.getSubTypesOf(classOf[Endpoint]).asScala.toList
  }

  def main(args: Array[String]){

    val port = args match {
      case Array(x, _*) => x.toInt
      case _ => 8080
    }

    val bindingFuture = Http().bindAndHandle(route, "localhost", port)

    println(s"Server online at port $port, press RETURN to stop")
    StdIn.readLine()
    bindingFuture
      .flatMap(_.unbind())
      .onComplete(_ => system.terminate())
  }
} 
开发者ID:Lapanti,项目名称:ScalAPI,代码行数:47,代码来源:ServerListener.scala


示例18: Boot

//设置package包名称以及导入依赖的类
package com.zhranklin.homepage

import java.io.InputStream
import java.security.{KeyStore, SecureRandom}
import javax.net.ssl._

import akka.http.scaladsl._
import akka.util.Timeout
import com.typesafe.config.ConfigFactory

import scala.concurrent.duration._
import scala.io.{Source, StdIn}

object Boot extends App with MyRouteService {

  import ActorImplicits._

  implicit val timeout = Timeout(5.seconds)

  val conf = ConfigFactory.load().getConfig("settings.server")
  val host = conf.getString("host")
  val httpBindingFuture = Http().bindAndHandle(myRoute, host, conf.getInt("http_port"))
  val httpsBindingFuture =
    Http().bindAndHandle(myRoute, host, conf.getInt("https_port"), SSLConfig.https)
  println(s"Server online at http://$host:8080/\nPress RETURN to stop...")
  if (System.getProperty("dev") != null) {
    StdIn.readLine() // let it run until user presses return
    Seq(httpBindingFuture, httpsBindingFuture).foreach { _
      .flatMap(_.unbind())
      .onComplete(_ ? system.terminate())
    }
  }
}

object SSLConfig {
  val https: HttpsConnectionContext = {

    val password: Array[Char] = Source.fromInputStream(getClass.getClassLoader.getResourceAsStream("password")).toArray.filter(_ != '\n')

    val ks: KeyStore = KeyStore.getInstance("jks")
    val keystore: InputStream = getClass.getClassLoader.getResourceAsStream("zhranklin.com.jks")

    require(keystore != null, "Keystore required!")
    ks.load(keystore, password)

    val keyManagerFactory: KeyManagerFactory = KeyManagerFactory.getInstance("SunX509")
    keyManagerFactory.init(ks, password)

    val tmf: TrustManagerFactory = TrustManagerFactory.getInstance("SunX509")
    tmf.init(ks)

    val sslContext: SSLContext = SSLContext.getInstance("TLS")
    sslContext.init(keyManagerFactory.getKeyManagers, tmf.getTrustManagers, new SecureRandom)
    ConnectionContext.https(sslContext)
  }

} 
开发者ID:zhranklin,项目名称:Private_Blog,代码行数:58,代码来源:Boot.scala


示例19: Server

//设置package包名称以及导入依赖的类
package org.snowflake.web

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model._
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer

import scala.io.{Source, StdIn}

object Server {
  def main(args: Array[String]) {

    implicit val system = ActorSystem("system")
    implicit val materializer = ActorMaterializer()
    // needed for the future flatMap/onComplete in the end
    implicit val executionContext = system.dispatcher

    val raw = Source.fromInputStream(getClass.getResourceAsStream("/response.json")).mkString

    val route =
      path("api" / "v1" / "test") {
        get {
          complete(HttpEntity(ContentTypes.`application/json`, raw))
        }
      }

    val bindingFuture = Http().bindAndHandle(route, "localhost", 8008)

    println(s"Server online at http://localhost:8008/\nPress RETURN to stop...")
//    StdIn.readLine() // let it run until user presses return
//    bindingFuture
//      .flatMap(_.unbind()) // trigger unbinding from the port
//      .onComplete(_ => system.terminate()) // and shutdown when done
  }
} 
开发者ID:shakhovv,项目名称:snowflake,代码行数:37,代码来源:Server.scala


示例20: WebServer

//设置package包名称以及导入依赖的类
package terriajs.server

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer

import scala.io.StdIn
 
object WebServer {
  def main(args: Array[String]) {
 
    implicit val system = ActorSystem("my-system")
    implicit val materializer = ActorMaterializer()
    // needed for the future flatMap/onComplete in the end
    implicit val executionContext = system.dispatcher

    val route =
      path("ping")(complete("OK")) ~
      pathPrefix("proxy")(new Proxy(system, materializer).route)

    val bindingFuture = Http(system).bindAndHandle(route, "localhost", 8080)
 
    println(s"Server online at http://localhost:8080/\nPress RETURN to stop...")
    StdIn.readLine() // let it run until user presses return
    bindingFuture
      .flatMap(_.unbind()) // trigger unbinding from the port
      .onComplete(_ => system.terminate()) // and shutdown when done
  }
} 
开发者ID:kring,项目名称:terriajs-server-scala,代码行数:31,代码来源:WebServer.scala



注:本文中的scala.io.StdIn类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala ControllerConfig类代码示例发布时间:2022-05-23
下一篇:
Scala ServicesConfig类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap