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

Scala Iteratee类代码示例

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

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



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

示例1: ProxyResponse

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

import java.util.concurrent.TimeUnit

import play.api.http.HeaderNames
import play.api.libs.iteratee.Iteratee
import play.api.mvc.{Result, Results}

import scala.concurrent.Await
import scala.concurrent.duration.Duration

object ProxyResponse {

  def apply(result: Result): ProxyResponse = {

    val body = new String(contentAsBytes(result))
    val httpMessage = HttpMessage(result.header.headers.mapValues(_.split(",").toList), Some( body))
    new ProxyResponse(result.header.status, httpMessage)
  }

  private def contentAsBytes(result: Result): Array[Byte] = {
    val eBytes = result.header.headers.get(HeaderNames.TRANSFER_ENCODING) match {
      case Some("chunked") => result.body &> Results.dechunk
      case _ => result.body
    }
      Await.result(eBytes |>>> Iteratee.consume[Array[Byte]](), Duration(1, TimeUnit.SECONDS))
  }
}

case class ProxyResponse(status: Int = 200, httpMessage: HttpMessage = HttpMessage(Map.empty, None)) {

  def simpleHeaderMap: Map[String, String] = {
    httpMessage.headers.map {
      case (k, v) => (k, v.mkString(","))
    }
  }
} 
开发者ID:innoq,项目名称:docster,代码行数:38,代码来源:ProxyResponse.scala


示例2: IterateeSpec

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

import play.api.libs.iteratee.Iteratee

import anorm._

import acolyte.jdbc.AcolyteDSL.withQueryResult
import acolyte.jdbc.RowLists.stringList
import acolyte.jdbc.Implicits._

object IterateeSpec extends org.specs2.mutable.Specification {
  "Play Iteratee" title

  "Iteratees" should {
    "broadcast the streaming result" in (
      withQueryResult(stringList :+ "A" :+ "B" :+ "C")) { implicit con =>
        Iteratees.from(SQL"SELECT * FROM Test", SqlParser.scalar[String]).
          run(Iteratee.getChunks[String]) must beEqualTo(List("A", "B", "C")).
          await(1000)
      }
  }
} 
开发者ID:Wwarrior1,项目名称:ScalaProject_Hello,代码行数:23,代码来源:IterateeSpec.scala


示例3: MyWebSocket

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

import de.htwg.se.setGame.controller.{NewGame, StartGame, UpdateGame}
import play.api.Logger
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.libs.iteratee.{Concurrent, Iteratee}
import play.api.mvc.WebSocket
import scala.swing.Reactor


class MyWebSocket(private val manager: GameManager) extends Reactor {
  def get: WebSocket = WebSocket.using[String] { request =>
    val session = new SessionHandler(request.session)
    val controller = manager.get(session.getSessionId)
    val in = Iteratee.foreach[String](_ => {}).map { _ =>
      Logger.debug(MyWebSocket.Disconnect.format(session.getSessionId))
    }
    val (out, channel) = Concurrent.broadcast[String]
    Logger.debug(MyWebSocket.Connected.format(session.getSessionId))
    listenTo(controller.getController)

    reactions += {
      case e: NewGame =>
        Logger.debug(MyWebSocket.EventNewGame.format(session.getSessionId))
        channel.push(e.getClass.getName)
      case e: StartGame =>
        Logger.debug(MyWebSocket.EventStartGame.format(session.getSessionId))
        channel.push(e.getClass.getName)
      case e: UpdateGame =>
        Logger.debug(MyWebSocket.EventUpdateGame.format(session.getSessionId))
        channel.push(e.getClass.getName)
    }

    (in, out)
  }
}

object MyWebSocket {
  val Disconnect = "%s - disconnect from websocket"
  val Connected = "%s - connected to websocket"
  val EventNewGame = "%s - websocket received 'NewGame' event"
  val EventStartGame = "%s - websocket received 'StartGame' event"
  val EventUpdateGame = "%s - websocket received 'UpdateGame' event"
} 
开发者ID:phaldan,项目名称:htwg-set-game-scala-wui,代码行数:45,代码来源:MyWebSocket.scala


示例4: ResponseTimeLogFilter

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

import play.api.libs.iteratee.Iteratee
import play.api.mvc._
import play.api.Logger
import	play.api.libs.concurrent.Execution.Implicits.defaultContext

object ResponseTimeLogFilter extends EssentialFilter {
  override def apply(next: EssentialAction): EssentialAction = new EssentialAction {
    override def apply(v1: RequestHeader): Iteratee[Array[Byte], Result] = {
      val startTime = System.currentTimeMillis()
      next(v1).map { result =>
        val endTime =   System.currentTimeMillis()
        val responseTime = (endTime - startTime) / 1000F
        Logger.info(s"${v1.remoteAddress} - ${v1.method}	${v1.uri}"
          + s" ${result.header.status} ${responseTime}" + " sec")
        result


      }
    }
  }
} 
开发者ID:alkurop,项目名称:play-server-scala,代码行数:24,代码来源:ResponseTimeLogFilter.scala


示例5: AuthKey

//设置package包名称以及导入依赖的类
package jp.t2v.lab.play2.auth

import de.frosner.broccoli.conf
import de.frosner.broccoli.controllers.AuthConfigImpl
import de.frosner.broccoli.models.Anonymous
import de.frosner.broccoli.services.SecurityService
import de.frosner.broccoli.util.Logging
import jp.t2v.lab.play2.stackc.{RequestAttributeKey, RequestWithAttributes, StackableController}
import play.api.libs.iteratee.{Enumerator, Iteratee}

import scala.concurrent.ExecutionContext.Implicits.global
import play.api.mvc._

import scala.concurrent.Future

trait BroccoliWebsocketSecurity extends AsyncAuth with AuthConfigImpl with Logging {

  self: Controller with AuthConfig =>

  val securityService: SecurityService

  private[auth] case object AuthKey extends RequestAttributeKey[User]

  def withSecurity[A](req: RequestHeader)(
      f: (Option[AuthenticityToken], User, RequestHeader) => (Iteratee[A, _], Enumerator[A]))
    : Future[Either[Result, (Iteratee[A, _], Enumerator[A])]] =
    securityService.authMode match {
      case conf.AUTH_MODE_CONF =>
        val maybeToken = extractToken(req)
        val tokenString = maybeToken.getOrElse("<session ID missing>")
        val maybeUser = restoreUser(req, scala.concurrent.ExecutionContext.Implicits.global)
        maybeUser
          .recover {
            case exception =>
              Logger.info(s"Authenticating the following session failed (session probably outdated): $tokenString") // TODO log level
              (None, identity[Result] _) // don't follow IntelliJ's recommendation here!
          }
          .flatMap {
            // TODO do we need the updater here? can we even use cookies or should we authenticate for each new WS connection?
            case (Some(user), updater) =>
              Logger.info(s"Successfully authenticated session $tokenString of $user") // TODO log level
              Future.successful(Right(f(maybeToken, user, req)))
            case (None, _) =>
              Logger.info(s"Websocket to ${req.remoteAddress} not established because of missing authentication") // TODO log level
              authenticationFailed(req).map(result => Left(result))
          }
      case conf.AUTH_MODE_NONE =>
        Future.successful(Right(f(None, Anonymous, req)))
      case other => throw new IllegalStateException(s"Unrecognized auth mode: ${securityService.authMode}")
    }

  implicit def loggedIn(implicit req: RequestWithAttributes[_]): User = securityService.authMode match {
    case conf.AUTH_MODE_CONF => req.get(AuthKey).get
    case conf.AUTH_MODE_NONE => Anonymous.asInstanceOf[User]
    case other               => throw new IllegalStateException(s"Unrecognized auth mode: ${securityService.authMode}")
  }

} 
开发者ID:FRosner,项目名称:cluster-broccoli,代码行数:59,代码来源:BroccoliWebsocketSecurity.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala Scheduler类代码示例发布时间:2022-05-23
下一篇:
Scala Directive0类代码示例发布时间: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