当前位置: 首页>>代码示例>>Scala>>正文


Scala ActorFlow类代码示例

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


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

示例1: MyApplicationController

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

import play.api.mvc._
import my.samples.core.AppBindings
import play.api.libs.json.JsValue
import play.api.libs.streams.ActorFlow
import play.api.mvc.WebSocket.MessageFlowTransformer

final class MyApplicationController(bindings: AppBindings) extends Controller {

  implicit val messageFlowTransformer =
    MessageFlowTransformer.jsonMessageFlowTransformer[JsValue, JsValue]

  implicit val actorSystem = bindings.actorSystem
  implicit val materializer = bindings.materializer

  def home = Action { implicit request =>
    Ok("The API is ready")
  }

  def observable = WebSocket.accept[JsValue, JsValue] { request =>
    ActorFlow.actorRef(out => MyWebSocketActor.props(bindings.globalChannel.publishChannel, out))
  }

  def connectableObservable = WebSocket.accept[JsValue, JsValue] { request =>
    ActorFlow.actorRef(out => MyWebSocketActor.props(bindings.globalChannel.publishChannel, out))
  }
} 
开发者ID:joesan,项目名称:monix-samples,代码行数:29,代码来源:MyApplicationController.scala

示例2: WebSocketController

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

import javax.inject._

import akka.actor.{ActorSystem, _}
import akka.stream.Materializer
import play.api.libs.json._
import play.api.libs.streams.ActorFlow
import play.api.mvc._
import models._
import play.api.cache.{Cache, CacheApi}



@Singleton
class WebSocketController @Inject()(implicit system: ActorSystem, materializer: Materializer, cache: CacheApi) {

  object MyWebSocketActor {
    def props(out: ActorRef) = Props(new MyWebSocketActor(out))
  }

  class MyWebSocketActor(out: ActorRef) extends Actor {
    override def preStart() {
      println("open")
      println(self.path.parent.toSerializationFormat)
      val x = system.actorSelection(self.path.parent.toSerializationFormat)
      x ! "Message12"
    }

    override def postStop() {
      println("close")
    }

    override def receive = {
      case request: JsValue =>
        val response = handleMessage(request)
        out ! response
    }

    def handleMessage(event: Event): JsValue = {
      event match {
        case event: EventA => {
          val actorId = self.path.parent.toSerializationFormat
          cache.set("actor-id_" + event.data, actorId)
          Json.toJson(event)
        }
        case event: EventB => Json.toJson(event)
      }
    }
  }

  def socket = WebSocket.accept[JsValue, JsValue] { request =>
    ActorFlow.actorRef(out => MyWebSocketActor.props(out))

  }

} 
开发者ID:koduki,项目名称:example-palyframework,代码行数:58,代码来源:WebSocketController.scala

示例3: DashboardController

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

import javax.inject.{Inject, Singleton}

import akka.actor.ActorSystem
import akka.stream.Materializer
import org.apache.spark.streaming.Seconds
import play.api.Configuration
import play.api.inject.ApplicationLifecycle
import play.api.libs.streams.ActorFlow
import play.api.mvc._
import services.{SparkService, StreamActor}

@Singleton()
class DashboardController @Inject() ()(implicit system: ActorSystem, materializer: Materializer, configuration : Configuration, lifecycle: ApplicationLifecycle) extends Controller {

  val sparkService = SparkService.getInstance(configuration, lifecycle)

  def index = Action {
    Ok(views.html.index())
  }

  def stream = WebSocket.accept[String, String] { request =>
    val filters = Seq("Euro")
    val tweets = sparkService.getTwitterStream(filters)
    val stream = tweets
      //      .map { tweet =>
      //        tweet.getText
      //      }
      //      .flatMap { text => text.split("\\s") }
      //      .filter(_.startsWith("#"))
      .map { tweet =>
      Option(tweet.getPlace).map(_.getCountry)
    }
      .filter(_.isDefined)
      .map(_.get)
      .map { element => (element, 1)}
      .reduceByKeyAndWindow(_ + _, Seconds(60))
      .transform( count => count.sortBy(_._2, false))

    ActorFlow.actorRef(out => StreamActor.props(out, stream))
  }

} 
开发者ID:OpenCompare,项目名称:live-pcm,代码行数:45,代码来源:DashboardController.scala

示例4: VoiceController

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

import javax.inject.{Inject, Named, Singleton}

import actors.{FeedbackAggregatorActor, MonkeyActor, UserWebSocketActor}
import akka.actor.{ActorRef, ActorSystem}
import akka.stream.Materializer
import play.api.libs.json.JsValue
import play.api.libs.streams.ActorFlow
import play.api.mvc._

@Singleton
class VoiceController @Inject()(@Named("feedbackActor") feedbackActor: ActorRef)
                               (implicit system: ActorSystem, materializer: Materializer) extends Controller {


  // Render basic page
  def index = Action { implicit request =>
    Ok(views.html.voice.the_voice())
  }

  def openWebSocket = WebSocket.accept[JsValue, JsValue] { request =>
    ActorFlow.actorRef(outActorRef => UserWebSocketActor.props(outActorRef, feedbackActor))
  }
} 
开发者ID:ChrisCooper,项目名称:customer-feedback-screen,代码行数:26,代码来源:VoiceController.scala

示例5: BasicActorCtrl

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



import javax.inject.Inject

import akka.actor.ActorSystem
import akka.stream.Materializer
import com.mohiva.play.silhouette.api.{HandlerResult, Silhouette}
import models.daos.actors.ChatActorFactory
import play.api.Logger
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.libs.concurrent.Execution.Implicits._
import play.api.libs.json.JsValue
import play.api.libs.streams.ActorFlow
import play.api.mvc._
import utils.DefaultEnv

import scala.concurrent.Future

class BasicActorCtrl @Inject()(
    val messagesApi: MessagesApi,
    implicit val mat: Materializer,
    implicit val actorSystem: ActorSystem,
    val chatActorFactory: ChatActorFactory,
    silhouette: Silhouette[DefaultEnv]
) extends Controller with I18nSupport {

  val log = Logger("IDP." + this.getClass.getSimpleName);

  def send(eventName: String, username: String, token: String) = WebSocket.acceptOrResult[JsValue, JsValue] {
    request =>
      {
        //log.debug(s"new query string:  ${request.getQueryString("X-Auth-Token")}")
        val tmpRequest = request.copy(headers = new Headers(Seq("X-Auth-Token" -> token)))
        implicit val req = Request(tmpRequest, AnyContentAsEmpty)
        silhouette.SecuredRequestHandler { securedRequest =>
          Future.successful(HandlerResult(Ok, Some(securedRequest.identity)))
        }.map {
          case HandlerResult(r, Some(user)) => {
            Right(ActorFlow.actorRef(chatActorFactory.props(username, eventName, _)))
          }
          case HandlerResult(r, None) => {
            Left(r)
          }
        }
      }
  }
} 
开发者ID:seyuf,项目名称:play-swagger-silhouette-actors,代码行数:50,代码来源:BasicActorCtrl.scala

示例6: ChatController

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

import javax.inject.Inject

import akka.actor._
import akka.stream._
import akka.stream.scaladsl.{ Flow, Keep }
import domains.chat.ChatMessage
import play.api.libs.json.JsValue
import play.api.libs.streams.ActorFlow
import play.api.mvc.WebSocket
import services.chat.ChatService


class ChatController @Inject()(
    implicit val system: ActorSystem,
    implicit val materializer: Materializer,
    streamChatService: ChatService
) {

  def start(roomId: String) = WebSocket.accept[JsValue, JsValue] { request =>


    val userName = request.queryString("user_name").headOption.getOrElse("anon")

    val userInput: Flow[JsValue, ChatMessage, _] = ActorFlow.actorRef[JsValue, ChatMessage](out => ChatRequestActor.props(out, userName))
    val room = streamChatService.start(roomId, userName)
    val userOutPut: Flow[ChatMessage, JsValue, _] = ActorFlow.actorRef[ChatMessage, JsValue](out => ChatResponseActor.props(out,userName))

    userInput.viaMat(room.bus)(Keep.right).viaMat(userOutPut)(Keep.right)
  }
} 
开发者ID:cm-wada-yusuke,项目名称:chatserver-play-websocket-akka-stream,代码行数:33,代码来源:ChatController.scala

示例7: ClientMessagingController

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

import access.authentication.PasswordResetCodeSender
import access.registration.AccountActivationCodeSender
import access.{AuthenticatedActionCreator, JWTAlgorithmProvider, JWTPrivateKeyProvider, JWTPublicKeyProvider}
import akka.actor.ActorSystem
import akka.stream.Materializer
import com.eigenroute.id.UUIDProvider
import com.eigenroute.time.TimeProvider
import com.google.inject.Inject
import messaging.MessageTranslator
import play.api.Configuration
import play.api.libs.json.JsValue
import play.api.libs.streams.ActorFlow
import play.api.mvc._

class ClientMessagingController @Inject() (
    override val timeProvider: TimeProvider,
    override val configuration: Configuration,
    override val authenticationAPI: AuthenticationAPI,
    registrationAPI: RegistrationAPI,
    override val jWTAlgorithmProvider: JWTAlgorithmProvider,
    override val jWTPublicKeyProvider: JWTPublicKeyProvider,
    jWTPrivateKeyProvider: JWTPrivateKeyProvider,
    system: ActorSystem,
    materializer: Materializer,
    userChecker: UserChecker,
    userAPI: UserAPI,
    uUIDProvider: UUIDProvider,
    passwordResetCodeSender: PasswordResetCodeSender,
    accountActivationLinkSender:AccountActivationCodeSender)
 extends Controller
 with AuthenticatedActionCreator {

  implicit val mat = materializer
  implicit val actorRefFactory = system

  def connect = {

    WebSocket.accept[JsValue, JsValue] { request =>
      ActorFlow.actorRef(unnamedClient =>
        MessageTranslator.props(
          userChecker,
          userAPI,
          authenticationAPI,
          registrationAPI,
          jWTAlgorithmProvider,
          jWTPublicKeyProvider,
          jWTPrivateKeyProvider,
          configuration,
          timeProvider,
          uUIDProvider,
          unnamedClient,
          passwordResetCodeSender,
          accountActivationLinkSender))
    }
  }

} 
开发者ID:shafiquejamal,项目名称:api-gateway-template,代码行数:60,代码来源:ClientMessagingController.scala

示例8: BidChampController

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

import java.util.UUID
import javax.inject._

import actors.WebSocketActor
import akka.actor.ActorSystem
import akka.stream.Materializer
import play.api.Logger
import play.api.libs.json.JsValue
import play.api.libs.streams.ActorFlow
import play.api.mvc._
import services.{BidChampCore, UserStore}

import scala.concurrent.Future
import scala.util.Try

@Singleton
class BidChampController @Inject()(
  bidChamp: BidChampCore, val userStore: UserStore
)(implicit system: ActorSystem, materializer: Materializer)
    extends Controller with Authorization {

  val logger: Logger = Logger(this.getClass)

  def state = Action { Ok("Cool story bro") }

  def socket = WebSocket.acceptOrResult[JsValue, JsValue] { request =>
    Future.successful {
      val flow = for {
        tokenString <- request.session.get("session-token")
        token <- parseUuid(tokenString)
        userAccount <- userStore.getUserByToken(token)
      } yield ActorFlow.actorRef(out => WebSocketActor.props(userAccount.uuid, out, bidChamp.gameActor))

      flow.toRight(Forbidden)
    }
  }

  def parseUuid(s: String): Option[UUID] = Try(UUID.fromString(s)).toOption
} 
开发者ID:jkpl,项目名称:bidchamp,代码行数:42,代码来源:BidChampController.scala

示例9: SnakeController

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

import java.util.UUID
import javax.inject.Inject

import actors.{SnakeMasterActor, SnakeSocketActor}
import akka.actor.{ActorSystem, Props}
import akka.stream.Materializer
import play.api.libs.streams.ActorFlow
import play.api.mvc.{Controller, WebSocket}
import shared._

class SnakeController @Inject()(
  actorSystem: ActorSystem,
  materializer: Materializer
) extends Controller {

  import models.Formats._

  lazy val master = actorSystem.actorOf(Props(new SnakeMasterActor()))

  def ws() = WebSocket.accept[Direction, WorldState] { rs =>
    val clientId = UUID.randomUUID()
    ActorFlow.actorRef(out => Props(new SnakeSocketActor(out, master, clientId)))(actorSystem, materializer)
  }

} 
开发者ID:lenstr,项目名称:horrible-snake,代码行数:28,代码来源:SnakeController.scala

示例10: WebSocketController

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

import javax.inject.Inject

import actors.{MessageActor, RoomActor, RoomClientActor, RoomMasterActor}
import akka.actor.ActorSystem
import akka.stream.Materializer
import json.{IncomingMessage, IncomingRoomMessage, OutgoingMessage, OutgoingRoomMessage}
import play.api.libs.json.Json
import play.api.libs.streams.ActorFlow
import play.api.mvc.WebSocket.MessageFlowTransformer
import play.api.mvc.{Controller, WebSocket}


class WebSocketController @Inject() (implicit system: ActorSystem, materializer: Materializer) extends Controller{
  
  implicit val inMessageFormat = Json.format[IncomingMessage]
  implicit val outMessageFormat = Json.format[OutgoingMessage]
  implicit val inRoomMessageFormat = Json.format[IncomingRoomMessage]
  implicit val outRoomMessageFormat = Json.format[OutgoingRoomMessage]
  
  implicit val messageFlowTransformer = MessageFlowTransformer.jsonMessageFlowTransformer[IncomingMessage, OutgoingMessage]
  implicit val roomFlowTransformer = MessageFlowTransformer.jsonMessageFlowTransformer[IncomingRoomMessage, OutgoingRoomMessage]
  
  def messageWebSocket(userId: String) = WebSocket.accept[IncomingMessage, OutgoingMessage] {
    request => ActorFlow.actorRef(out => MessageActor.props(out, userId))
  }
  
  def roomWebSocket(userId: String) = WebSocket.accept[IncomingRoomMessage, OutgoingRoomMessage] {
    request => ActorFlow.actorRef(out => RoomClientActor.props(out, userId))
  }
  
} 
开发者ID:dazito,项目名称:messengr,代码行数:34,代码来源:WebSocketController.scala

示例11: HomeController

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

import javax.inject._

import akka.actor.ActorSystem
import akka.stream.Materializer
import play.api.libs.json._
import play.api.libs.streams.ActorFlow
import play.api.mvc._
import services.{DestinationsFeedWSConnection, KafkaProducerService}

@Singleton
class HomeController @Inject()(
  implicit system: ActorSystem,
  materializer: Materializer,
  environment: play.api.Environment,
  configuration: play.api.Configuration) extends Controller {
  // TODO: Have this be injected
  private val logQueue = KafkaProducerService()
  lazy val destinationFeedManager = system.actorSelection("akka://application/user/DestinationsFeedManager")

  def index = Action {
    Ok(views.html.index("Your new application is ready."))
  }

  def liveState = WebSocket.accept[JsValue, JsValue] { request =>
    ActorFlow.actorRef(out => DestinationsFeedWSConnection.props(destinationFeedManager, out))
  }

  def cityPage(country: String, city: String) = Action { request =>
    logQueue.publish("requestpathdata", request.path)
    Ok(s"You requested $city in $country")
  }
} 
开发者ID:aerohit,项目名称:TravellingWhere,代码行数:35,代码来源:HomeController.scala

示例12: WebSocketController

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

import javax.inject.Singleton

import actors.{ActorManager, WebSocketActor}
import akka.actor.{ActorSystem, Props}
import akka.stream.Materializer
import com.google.inject.Inject
import play.api.Configuration
import play.api.libs.json.JsValue
import play.api.libs.streams.ActorFlow
import play.api.mvc.{Action, Controller, WebSocket}
import play.modules.reactivemongo.{MongoController, ReactiveMongoApi, ReactiveMongoComponents}

import scala.concurrent.ExecutionContext


@Singleton
class WebSocketController @Inject() (val reactiveMongoApi: ReactiveMongoApi)
                                    (implicit executionContext: ExecutionContext,
                                     configuration: Configuration,
                                     system: ActorSystem,
                                     materializer: Materializer)
  extends Controller with MongoController with ReactiveMongoComponents  {

  lazy final val actorManager = system.actorOf(Props[ActorManager],"actor-manager")

  def socket = WebSocket.accept[JsValue,JsValue] { request =>
    //request.session.get(Id).map { id =>
      ActorFlow.actorRef(out => WebSocketActor.props(actorManager,out,"10"))
    //}.getOrElse(throw new Exception("connection error"))
  }

  def index = Action { implicit request =>
    Ok(views.html.websocket("test"))
  }

} 
开发者ID:tictactoki,项目名称:Immutaskable,代码行数:39,代码来源:WebSocketController.scala

示例13: Application

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

import akka.actor.ActorSystem
import akka.stream.Materializer
import com.google.inject.Inject
import play.api.mvc._
import shared.SharedMessages
import play.api.libs.streams.ActorFlow
import sparkConn.{SparkCommon, TwitterStreamer}
import sparkStream._

class Application @Inject() (implicit system: ActorSystem,
                             materializer: Materializer) extends Controller {

  def index = Action {
    Ok(views.html.index(SharedMessages.itWorks))
  }

  def sparkSocket = WebSocket.accept[String,String] { request =>
    ActorFlow.actorRef(out => WebSocketActor.props(out))
  }

  def setupLogging() = {
   import org.apache.log4j.{Level,Logger}
    val rootLogger = Logger.getRootLogger
    rootLogger.setLevel(Level.ERROR)
  }

  def fontDir(file: String) = Action.async {
    implicit request => {
      controllers.Assets.at("/../client/src/main/resources/", file, false).apply(request)
    }
  }

  def sparkBookData = Action {
    val sc = SparkCommon.sc
    //System.setProperty("twitter4j.oauth")
    val inputList = sc.parallelize(List(1,2,3,4))
    val text = "Test123" + inputList.collect().foldLeft(" ")((a,b) => a + b)

    val input = sc.textFile("book.txt")
    var words = input.flatMap(line => line.split(' '))
    val lowerCaseWords = words.map(_.toLowerCase())
    val wordCounts = lowerCaseWords.countByValue()

    val sample = wordCounts.take(20)

    for ((word, count) <- sample) {
      println(word + " " + count)
    }

    //val ssc = SparkCommon.ssc

    Ok(text)
  }

} 
开发者ID:gvatn,项目名称:play-scalajs-webgl-spark,代码行数:58,代码来源:Application.scala

示例14: Chat

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

import actors.{Chatroom, User}
import akka.actor.{ActorRef, ActorSystem}
import akka.stream.Materializer
import play.api.libs.json.JsValue
import play.api.libs.streams.ActorFlow
import play.api.mvc.{Action, Controller, WebSocket}


class Chat(implicit actorSystem: ActorSystem, materializer: Materializer)
    extends Controller {

  // long-lived chatroom
  private val chatRoom: ActorRef = actorSystem.actorOf(Chatroom.props)

  def index = Action { implicit req =>
    Ok(views.html.index())
  }

  def chat = WebSocket.accept[JsValue, JsValue] { _ =>
    // instantiate a User actor and pass it the chatroom
    ActorFlow.actorRef(out => User.props(chatRoom, out))
  }

} 
开发者ID:lloydmeta,项目名称:play-chatroom,代码行数:27,代码来源:Chat.scala

示例15: GameController

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

import javax.inject._

import actors.{HostWebSocketActor, ScorekeeperWebSocketActor, SignonWebSocketActor}
import akka.actor.ActorSystem
import akka.stream.Materializer
import play.api.libs.streams.ActorFlow
import play.api.mvc._

class GameController @Inject()(implicit system: ActorSystem,
                               materializer: Materializer,
                               webJarAssets: WebJarAssets)
  extends Controller {


  def signonSocket: WebSocket = WebSocket.accept[String, String] { request =>
    ActorFlow.actorRef(out => SignonWebSocketActor.props(out))
  }

  def hostSocket: WebSocket = WebSocket.accept[String, String] { request =>
    ActorFlow.actorRef(out => HostWebSocketActor.props(out))
  }

  def scorekeeperSocket: WebSocket = WebSocket.accept[String, String] { request =>
    ActorFlow.actorRef(out => ScorekeeperWebSocketActor.props(out))
  }

  def index = Action { request =>
    request.session.get("name").map { name =>
      Ok(views.html.game("Let's play trivia!.", name, webJarAssets))
    }.getOrElse(Redirect(routes.LoginController.loginIntro()))
  }
} 
开发者ID:dhinojosa,项目名称:operation-trivia,代码行数:35,代码来源:GameController.scala


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