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

Scala Akka类代码示例

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

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



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

示例1: ExecutionContexts

//设置package包名称以及导入依赖的类
package context
import play.api.libs.concurrent.Akka
import play.api.Play.current



object ExecutionContexts {
  // 0-500 msecs
  implicit val genericOps = Akka.system.dispatchers.lookup("contexts.generic-ops")
  // 0-500 msecs
  implicit val criticalOps = Akka.system.dispatchers.lookup("contexts.critical-ops")

  // 1000 msecs-1 min
  implicit val slowIoOps = Akka.system.dispatchers.lookup("contexts.slow-io-ops")
  // More than 1 min
  implicit val slowCpuOps = Akka.system.dispatchers.lookup("contexts.slow-cpu-ops")
} 
开发者ID:emrekarakis,项目名称:TwitterProject,代码行数:18,代码来源:ExecutionContexts.scala


示例2: sendEmailAsync

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

import javax.inject.Inject

import play.api.Play.current
import play.api.libs.concurrent.Akka
import play.api.libs.concurrent.Execution.Implicits._
import play.api.libs.mailer._

import scala.language.postfixOps
import scala.concurrent.duration._

trait MailService {
  def sendEmailAsync(recipients: String*)(subject: String, bodyHtml: String, bodyText: String = ""): Unit
  def sendEmail(recipients: String*)(subject: String, bodyHtml: String, bodyText: String = ""): Unit
}

class MailServiceImpl @Inject() (mailerClient: MailerClient) extends MailService {

  def from: String = current.configuration.getString("play.mailer.from").getOrElse("UNKNOWN")

  def sendEmailAsync(recipients: String*)(subject: String, bodyHtml: String, bodyText: String = ""): Unit = {
    Akka.system.scheduler.scheduleOnce(100 milliseconds) {
      sendEmail(recipients: _*)(subject, bodyHtml, bodyText)
    }
  }
  def sendEmail(recipients: String*)(subject: String, bodyHtml: String, bodyText: String = ""): Unit = {
    mailerClient.send(Email(
      subject,
      from,
      recipients,

      // sends text, HTML or both...
      Some(bodyText),
      Some(bodyHtml)
    ))
  }
} 
开发者ID:pawank,项目名称:play-silhouette-mongodb-multi-project-sbt,代码行数:39,代码来源:MailService.scala


示例3: Global

//设置package包名称以及导入依赖的类
import play.api._
import models._
import akka.actor._
import play.api.libs.iteratee._
import play.api.libs.concurrent.Akka
import play.api.Play.current

object Global extends GlobalSettings {
  override def onStart(app: Application) {
    class Listener extends Actor {
      var out: Option[Concurrent.Channel[String]] = None
      def receive = {
        case Start(out)       => this.out = Some(out)
        case UserRegistration => this.out.map(_.push("user"))
        case NewMessage       => this.out.map(_.push("message"))
      }
    }
    val listener = Akka.system.actorOf(Props[Listener], "listener")
  }
} 
开发者ID:clrvynt,项目名称:sse,代码行数:21,代码来源:Global.scala


示例4: Application

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

import play.api._
import play.api.mvc._
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import play.api.libs.concurrent.Akka
import play.api.Play.current
import models._

import play.api.libs.EventSource
import play.api.libs.iteratee._

class Application extends Controller {

  val (out, channel) = Concurrent.broadcast[String]
  val listener = Akka.system.actorSelection("akka://application/user/listener")
  listener ! Start(channel)

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

  def index = Action {
    Ok(views.html.index("Your new application is ready."))
  }
  def createNewUser = Action.async {
    listener ! UserRegistration
    Future.successful(Ok(""))
  }

  def sendMessage = Action.async {
    listener ! NewMessage
    Future.successful(Ok(""))
  }
  def stream = Action { implicit req =>
        Ok.feed(out &> EventSource()).as("text/event-stream")
  }
}

object Application extends Application 
开发者ID:clrvynt,项目名称:sse,代码行数:42,代码来源:Application.scala


示例5: ChatController

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

import play.api.libs.json._
import play.api.mvc.WebSocket.FrameFormatter
import play.api.mvc._
import play.api.Play.current
import play.api.libs.concurrent.Akka
import akka.actor._
import java.util.Date
import java.text.SimpleDateFormat

object ChatController extends Controller {
  // ?????????????????????????
  case class ChatMessage(name: String, message: String, date: Option[String])

  // ChatMessage?JSON????????????????
  implicit val chatMessageFormat = Json.format[ChatMessage]
  implicit val chatMessageFormatter = FrameFormatter.jsonFrame[ChatMessage]

  // ?????????
  def chat = Action {
    implicit request =>
      Ok(views.html.chat())
  }

  // ??????WebSocket????????
  def socket = WebSocket.acceptWithActor[ChatMessage, ChatMessage] {
    request => out =>
      Akka.system.eventStream.subscribe(out, classOf[ChatMessage])
      Props(new WebSocketActor())
  }

  // ????????????Actor
  class WebSocketActor() extends Actor{
    def receive = {
      case msg: ChatMessage => {
        val date = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date())
        Akka.system.eventStream.publish(msg.copy(date = Some(date)))
      }
    }
  }
} 
开发者ID:tail12,项目名称:scala-chat-sample,代码行数:43,代码来源:ChatController.scala


示例6: ExecutionContexts

//设置package包名称以及导入依赖的类
package context
import play.api.libs.concurrent.Akka
import play.api.Play.current


object ExecutionContexts {
  // 0-500 msecs
  implicit val genericOps = Akka.system.dispatchers.lookup("contexts.generic-ops")
  // 0-500 msecs
  implicit val criticalOps = Akka.system.dispatchers.lookup("contexts.critical-ops")

  // 1000 msecs-1 min
  implicit val slowIoOps = Akka.system.dispatchers.lookup("contexts.slow-io-ops")
  // More than 1 min
  implicit val slowCpuOps = Akka.system.dispatchers.lookup("contexts.slow-cpu-ops")
} 
开发者ID:emrekarakis,项目名称:AmazonProject,代码行数:17,代码来源:ExecutionContexts.scala


示例7: sendEmail

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

import play.api.libs.concurrent.Akka
import play.api.Play.current
import play.api.mvc.RequestHeader
import play.api.i18n.Lang
import play.twirl.api.{ Txt, Html }
import com.typesafe.plugin._
import scala.concurrent.duration._
import play.api.libs.concurrent.Execution.Implicits._
import akka.actor._
import com.mohiva.play.silhouette.api._


  def sendEmail(subject: String, recipient: String, body: (Option[Txt], Option[Html])) = {

    play.Logger.debug(s"[securesocial] sending email to $recipient")
    play.Logger.debug(s"[securesocial] mail = [$body]")
    
    Akka.system.scheduler.scheduleOnce(1 seconds) {
      val mail = use[MailerPlugin].email
      mail.setSubject(subject)
      mail.setRecipient(recipient)
      mail.setFrom(fromAddress)
      // the mailer plugin handles null / empty string gracefully
      mail.send(body._1.map(_.body).getOrElse(""), body._2.map(_.body).getOrElse(""))
    }
  }

} 
开发者ID:Flibberty-GEA,项目名称:silhouette-rest-seed,代码行数:31,代码来源:MailService.scala


示例8: sendEmailAsync

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

import javax.inject.Inject

import akka.actor.{ActorSystem, Props}
import com.google.inject.ImplementedBy
import play.api.Configuration
import play.api.Play.current
import play.api.libs.concurrent.Akka
import play.api.libs.concurrent.Execution.Implicits._
import play.api.libs.mailer._

import scala.language.postfixOps
import scala.concurrent.duration._

@ImplementedBy(classOf[MailServiceImpl])
trait MailService {
  def sendEmailAsync(recipients: String*)(subject: String, bodyHtml: String, bodyText: String): Unit
  def sendEmail(recipients: String*)(subject: String, bodyHtml: String, bodyText: String): Unit
}

class MailServiceImpl @Inject() (mailerClient: MailerClient, val conf: Configuration) extends MailService with ConfigSupport {

	lazy val from = confRequiredString("play.mailer.from")

  def sendEmailAsync(recipients: String*)(subject: String, bodyHtml: String, bodyText: String) = {
    Akka.system.scheduler.scheduleOnce(100 milliseconds) {
      sendEmail(recipients: _*)(subject, bodyHtml, bodyText)
    }
  }
  def sendEmail(recipients: String*)(subject: String, bodyHtml: String, bodyText: String) =
    mailerClient.send(Email(subject, from, recipients, Some(bodyText), Some(bodyHtml)))
} 
开发者ID:benetis,项目名称:olive,代码行数:34,代码来源:MailService.scala


示例9: ServiceLocatorModule

//设置package包名称以及导入依赖的类
package com.lightbend.lagom.dns

import com.lightbend.lagom.javadsl.api.ServiceLocator
import play.api.{ Configuration, Environment, Mode }
import play.api.inject.{ Binding, Module }
import javax.inject.Singleton

import play.api.libs.concurrent.Akka
import com.lightbend.dns.locator.{ ServiceLocator => ServiceLocatorService }


class ServiceLocatorModule extends Module {

  override def bindings(environment: Environment, configuration: Configuration): Seq[Binding[_]] =
    if (environment.mode == Mode.Prod)
      Seq(
        bind[ServiceLocator].to[DnsServiceLocator].in[Singleton],
        Akka.bindingOf[ServiceLocatorService]("ServiceLocatorService")
      )
    else
      Seq.empty
} 
开发者ID:typesafehub,项目名称:service-locator-dns,代码行数:23,代码来源:ServiceLocatorModule.scala


示例10: Worker

//设置package包名称以及导入依赖的类
import play.api._
import play.api.libs.concurrent.Akka
import play.api.mvc._

import play.api.Logger
import scala.concurrent.Future

import akka.actor._

import scala.concurrent.duration._
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.Play.current

object Worker extends GlobalSettings {


  override def onStart(app: Application): Unit = {
    val testActor = Akka.system.actorOf(MyActor.props)
    Akka.system.scheduler.schedule(0 seconds, 5 seconds, testActor, "tick")
  }
}

object  MyActor{
  def props = Props[MyActor]
}
class MyActor extends Actor{
  import MyActor._
  override def receive: Receive = {
    case "tick" => println("execute!")
    case _ => println("ups?")
  }
} 
开发者ID:ammoniak,项目名称:dfseccheck,代码行数:33,代码来源:Worker.scala


示例11: EmailUtil

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

import akka.actor.Props
import akka.routing.RoundRobinPool
import org.apache.commons.mail.{DefaultAuthenticator, Email}
import play.api.Play
import play.api.libs.concurrent.Akka
import play.api.Play.current


package object support {
  object EmailUtil {
    val smtpHost = Play.application.configuration.getString("smtp.host").getOrElse("mail.m8chat.com")
    val smtpPort = Play.application.configuration.getInt("smtp.port").getOrElse(587)
    val smtpUser = Play.application.configuration.getString("smtp.user").getOrElse("[email protected]")
    val smtpPassword = Play.application.configuration.getString("smtp.password").getOrElse("64PscSUvTHRV8wB3")
    val smtpStartTls = Play.application.configuration.getBoolean("smtp.startTls").getOrElse(true)
    val smtpDebug = Play.application.configuration.getBoolean("smtp.debug").getOrElse(false)

    val noReplySender = "[email protected]"

    def send(mail: Email) = {
      mail.setHostName(EmailUtil.smtpHost)
      mail.setSmtpPort(EmailUtil.smtpPort)
      mail.setAuthenticator(new DefaultAuthenticator(EmailUtil.smtpUser, EmailUtil.smtpPassword))
      mail.setSSLCheckServerIdentity(false)
      mail.setStartTLSRequired(EmailUtil.smtpStartTls)
      mail.setDebug(EmailUtil.smtpDebug)
      mail.send()
    }
  }

  val ContactUsEmailRouter = Akka.system.actorOf(RoundRobinPool(3).props(Props[ContactUsEmailSender]), "support.ContactUsEmailRouter")
  val AdminEmailSender = Akka.system.actorOf(Props[AdminEmailSender], "support.AdminEmailSender")
} 
开发者ID:pro-zw,项目名称:m8chat,代码行数:36,代码来源:package.scala


示例12: MazeGlobal

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

import actors.MazeActor
import akka.actor.Props
import play.api.libs.concurrent.Akka
import play.api.{Application, GlobalSettings, Logger}
import play.api.Play.current


object MazeGlobal extends GlobalSettings {

  lazy val actor = Akka.system.actorOf(Props[MazeActor], "MazeActor")

  override def onStart(app: Application): Unit = {
    super.onStart(app)
    Logger.info("App started")
  }

  override def onStop(app: Application): Unit = {
    super.onStop(app)
    Logger.info("App Stopped")
    Akka.system.shutdown()
  }

} 
开发者ID:pamu,项目名称:zippr-challenge,代码行数:26,代码来源:MazeGlobal.scala


示例13: AppModule

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

import java.time.{Clock, ZoneId}

import akka.actor.{Actor, ActorRef, Props}
import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier
import com.google.api.client.http.javanet.NetHttpTransport
import com.google.api.client.json.jackson2.JacksonFactory
import com.google.api.client.util.store.AbstractDataStoreFactory
import com.google.inject.AbstractModule
import com.google.inject.name.Names
import com.google.inject.util.Providers
import controllers.AppController
import play.api.libs.concurrent.{Akka, AkkaGuiceSupport}
import services._
import services.support.SystemClock

import scala.reflect.ClassTag

class AppModule extends AbstractModule {
  def configure = {
    bind(classOf[AppController]).asEagerSingleton // in prod mode all dependencies of AppController get built at startup time
    bind(classOf[AbstractDataStoreFactory]).to(classOf[RepositoryDataStoreFactory])
    bind(classOf[GoogleIdTokenVerifier]).toInstance(new GoogleIdTokenVerifier.Builder(new NetHttpTransport, new JacksonFactory).build)
    bind(classOf[Clock]).toInstance(new SystemClock(ZoneId.systemDefault()))
  }
}

class AkkaModule extends AbstractModule with AkkaGuiceSupport {
  def configure = {
    bindActorNoEager[SuperSupervisorActor](SuperSupervisorActor.actorName)
    bindActorFactory[UserSupervisorActor, UserSupervisorActor.Factory]
  }

  private def bindActorNoEager[T <: Actor : ClassTag](name: String, props: Props => Props = identity): Unit = {
    binder.bind(classOf[ActorRef])
      .annotatedWith(Names.named(name))
      .toProvider(Providers.guicify(Akka.providerOf[T](name, props)))
  }
} 
开发者ID:phdezann,项目名称:connectus,代码行数:41,代码来源:Module.scala


示例14: TFLInsertPolyLineDefinition

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

import akka.actor.{Actor, ActorRef, Props}
import com.mongodb.casbah.commons.MongoDBObject
import database.{POLYLINE_INDEX_DOCUMENT, POLYLINE_INDEX_COLLECTION, DatabaseCollections, DatabaseInsert}
import com.mongodb.casbah.Imports._
import play.api.Logger
import play.api.libs.concurrent.Akka
import play.api.Play.current


object TFLInsertPolyLineDefinition extends DatabaseInsert{

  override protected val collection: DatabaseCollections = POLYLINE_INDEX_COLLECTION
  override val supervisor: ActorRef = Akka.system.actorOf(Props[TFLInsertPolyLineDefinitionSupervisor], "TFLUpdatePolyLineSupervisor")
}

class TFLInsertPolyLineDefinitionSupervisor extends Actor {
  val dbTransactionActor: ActorRef = context.actorOf(Props[TFLInsertPolyLineDefinition], name = "TFLUpdatePolyLineActor")

  override def receive: Actor.Receive = {
    case doc1: POLYLINE_INDEX_DOCUMENT => dbTransactionActor ! doc1
  }
}

class TFLInsertPolyLineDefinition extends Actor {

  val collection = POLYLINE_INDEX_COLLECTION

  override def receive: Receive = {
    case doc1: POLYLINE_INDEX_DOCUMENT => insertToDB(doc1)
    case _ =>
      Logger.error("TFL PolyLine Definition Actor received unknown message")
      throw new IllegalStateException("TFL PolyLine Definition Actor received unknown message")
  }


  private def insertToDB(doc: POLYLINE_INDEX_DOCUMENT) = {
    TFLInsertPolyLineDefinition.numberDBTransactionsRequested += 1

    val query = MongoDBObject(
      collection.FROM_STOP_CODE -> doc.fromStopCode,
      collection.TO_STOP_CODE -> doc.toStopCode)

    val update = $set(collection.POLYLINE -> doc.polyLine)

      TFLInsertPolyLineDefinition.dBCollection.update(query, update, upsert = true)
     TFLInsertPolyLineDefinition.numberDBTransactionsExecuted += 1
  }
} 
开发者ID:chrischivers,项目名称:London-Bus-Tracker-Play-Framework,代码行数:51,代码来源:TFLInsertPolyLineDefinition.scala


示例15: BMotticus

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

import com.typesafe.scalalogging.StrictLogging
import play.api.libs.concurrent.{Akka, Execution}
import play.api.Application
import modules._
import play.api.libs.ws._
import javax.inject.{Inject,Singleton}

class BMotticus  @Inject() (implicit val app: Application) extends BMPlugin with Context with StrictLogging{
  
  lazy val config = app.configuration

  implicit def ctx: modules.Context = this
  
  implicit def actorSystem = Akka.system
  
  lazy val oAuthConfigs = new OAuthConfiguration(config.getObject("google.client_id.json.web").get)
  
  lazy val usersM = new modules.UsersModule(ctx)
  lazy val accountsM = new modules.AccountsModule(ctx)
  lazy val storeM = new modules.StoreModule(ctx)
  lazy val userM = new modules.UserModule(ctx)
  lazy val googleAuth = new modules.GoogleOAuthClient(
    WS.client(app),
    oAuthConfigs,
    config.getString("google.api_key").get  
  )
  
  println(config.getObject("google.client_id.json"))
  
  override def onStart() = {
    logger.info("BMotticus application started using " + Thread.currentThread.getName)
    super.onStart()
  }
  
  override def onStop () = {
    logger.info("Application Shutting down")
    super.onStop()
  }
  
}

import play.api.Play.current

trait BMotticusContext {
  def bm: plugins.BMotticus = current.plugin[BMotticus].getOrElse(throw new RuntimeException("Plugin Failed to load"))
}

object BMotticusContext extends BMotticusContext 
开发者ID:brandonmott,项目名称:Play24-Scala-Modules,代码行数:51,代码来源:BMotticus.scala


示例16: sendEmailAsync

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

import javax.inject.Inject
import com.google.inject.ImplementedBy
import play.api.Play.current
import play.api.libs.concurrent.Akka
import play.api.libs.concurrent.Execution.Implicits._
import play.api.libs.mailer._
import play.api.Configuration
import scala.concurrent.duration._

@ImplementedBy(classOf[MailServiceImpl])
trait MailService {
  def sendEmailAsync(recipients: String*)(subject: String, bodyHtml: String, bodyText: String): Unit
  def sendEmail(recipients: String*)(subject: String, bodyHtml: String, bodyText: String): Unit
}

class MailServiceImpl @Inject() (mailerClient: MailerClient, val conf: Configuration) extends MailService with ConfigSupport {

	lazy val from = confRequiredString("play.mailer.from")

  def sendEmailAsync(recipients: String*)(subject: String, bodyHtml: String, bodyText: String) = {
    Akka.system.scheduler.scheduleOnce(100 milliseconds) {
      sendEmail(recipients: _*)(subject, bodyHtml, bodyText)
    }
  }
  def sendEmail(recipients: String*)(subject: String, bodyHtml: String, bodyText: String) =
    mailerClient.send(Email(subject, from, recipients, Some(bodyText), Some(bodyHtml)))
} 
开发者ID:BriacPi,项目名称:Khala,代码行数:30,代码来源:MailService.scala


示例17: ZipkinTraceService

//设置package包名称以及导入依赖的类
package jp.co.bizreach.trace.play23

import brave.Tracing
import brave.sampler.Sampler
import jp.co.bizreach.trace._
import play.api.{Play, Configuration}
import play.api.libs.concurrent.Akka
import zipkin.reporter.AsyncReporter
import zipkin.reporter.okhttp3.OkHttpSender

import scala.concurrent.ExecutionContext


object ZipkinTraceService extends ZipkinTraceServiceLike {
  import play.api.Play.current
  val conf: Configuration = Play.configuration

  implicit val executionContext: ExecutionContext = Akka.system.dispatchers.lookup(ZipkinTraceConfig.AkkaName)

  val tracing = Tracing.newBuilder()
    .localServiceName(conf.getString(ZipkinTraceConfig.ServiceName) getOrElse "unknown")
    .reporter(AsyncReporter
      .builder(OkHttpSender.create(
        (conf.getString(ZipkinTraceConfig.ZipkinBaseUrl) getOrElse "http://localhost:9411") + "/api/v1/spans"
      ))
      .build()
    )
    .sampler(conf.getString(ZipkinTraceConfig.ZipkinSampleRate)
      .map(s => Sampler.create(s.toFloat)) getOrElse Sampler.ALWAYS_SAMPLE
    )
    .build()

} 
开发者ID:bizreach,项目名称:play-zipkin-tracing,代码行数:34,代码来源:ZipkinTraceService.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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