Integrating with Akka
来源:互联网 发布:中国域名注册中心 编辑:程序博客网 时间:2024/05/29 08:30
Integrating with Akka
Akka uses the Actor Model to raise the abstraction level and provide a better platform to build correct concurrent and scalable applications. For fault-tolerance it adopts the ‘Let it crash’ model, which has been used with great success in the telecoms industry to build applications that self-heal - systems that never stop. Actors also provide the abstraction for transparent distribution and the basis for truly scalable and fault-tolerant applications.
The application actor system
Akka can work with several containers called ActorSystems
. An actor system manages the resources it is configured to use in order to run the actors which it contains.
A Play application defines a special actor system to be used by the application. This actor system follows the application life-cycle and restarts automatically when the application restarts.
Note: Nothing prevents you from using another actor system from within a Play application. The provided default is convenient if you only need to start a few actors without bothering to set-up your own actor system.
You can access the default application actor system using the play.api.libs.concurrent.Akka
helper:
val myActor = Akka.system.actorOf(Props[MyActor], name = "myactor")
Configuration
The default actor system configuration is read from the Play application configuration file. For example, to configure the default dispatcher of the application actor system, add these lines to the conf/application.conf
file:
akka.default-dispatcher.fork-join-executor.pool-size-max =64akka.actor.debug.receive = on
Note: You can also configure any other actor system from the same file; just provide a top configuration key.
For Akka logging configuration, see configuring logging.
Scheduling asynchronous tasks
You can schedule sending messages to actors and executing tasks (functions or Runnable
). You will get aCancellable
back that you can call cancel
on to cancel the execution of the scheduled operation.
For example, to send a message to the testActor
every 300 microseconds:
import play.api.libs.concurrent.Execution.Implicits._Akka.system.scheduler.schedule(0.microsecond, 300.microsecond, testActor, "tick")
Note: This example uses implicit conversions defined in
scala.concurrent.duration
to convert numbers toDuration
objects with various time units.
Similarly, to run a block of code one seconds from now:
import play.api.libs.concurrent.Execution.Implicits._Akka.system.scheduler.scheduleOnce(1000.microsecond) { file.delete()}
Next: Internationalization
- Integrating with Akka
- Integrating with Spring
- Integrating Dokuwiki with Mantis
- Integrating JDBC with Hibernate
- Integrating C++ with QML
- Integrating JavaScript lint with vim
- Integrating Apache Spark with PyCharm
- Integrating libtool with your package
- Integrating PrimeNG with Angular CLI
- INTEGRATING SMARTY WITH THE ZEND FRAMEWORK
- Integrating Smarty with the Zend Framework
- Integrating Smarty with the Zend Framework Travello_View_Smarty
- Integrating Smarty with the Zend Framework
- Single SignOn - Integrating Liferay With CAS Server
- Integrating Seam with Maven, Netbeans and GlassFish
- Integrating with Eclipse: The Subclipse Plug-in
- Integrating WorldWind Java with GeoServer WMS
- Integrating AdMob with Cocos2D-iPhone Applications
- eclipse快捷键
- 阿里实习生面试经历
- Spring中的WebUtils类
- 5 Gsps采样率的高速数据采集系统的构成和设计要点
- Think Python: Chapter 11 Dictionaries
- Integrating with Akka
- 最大子列和问题(20)
- 利用keepalived构建高可用MySQL-HA
- Cocos2d-x中__Array容器以及实例介绍
- MFC 视频监控闪屏
- WebService介绍
- 日常-4-22-2015
- android Shape Drawable
- ubuntu好长时间没有无线了,终于下定决心安装无线网卡