Akka Documentation Release 1.1.3
Total Page:16
File Type:pdf, Size:1020Kb
Akka Documentation Release 1.1.3 Scalable Solutions AB June 29, 2011 CONTENTS 1 Introduction 1 1.1 What is Akka?............................................1 1.2 Why Akka?..............................................2 1.3 Getting Started............................................3 1.4 Getting Started Tutorial (Scala): First Chapter...........................6 1.5 Getting Started Tutorial (Scala with Eclipse): First Chapter.................... 17 1.6 Getting Started Tutorial (Java): First Chapter............................ 31 1.7 Use-case and Deployment Scenarios................................. 44 1.8 Examples of use-cases for Akka................................... 45 2 General 47 2.1 Akka and the Java Memory Model.................................. 47 2.2 Configuration............................................. 48 2.3 Event Handler............................................ 52 2.4 SLF4J................................................. 53 3 Common utilities 54 3.1 Scheduler............................................... 54 3.2 Duration............................................... 54 4 Scala API 56 4.1 Actors (Scala)............................................ 56 4.2 Typed Actors (Scala)......................................... 65 4.3 ActorRegistry (Scala)........................................ 69 4.4 Futures (Scala)............................................ 70 4.5 Dataflow Concurrency (Scala).................................... 75 4.6 Agents (Scala)............................................ 79 4.7 Software Transactional Memory (Scala)............................... 82 4.8 Transactors (Scala).......................................... 91 4.9 Remote Actors (Scala)........................................ 95 4.10 Serialization (Scala)......................................... 107 4.11 Fault Tolerance Through Supervisor Hierarchies (Scala)...................... 121 4.12 Dispatchers (Scala).......................................... 129 4.13 Routing (Scala)............................................ 133 4.14 FSM................................................. 138 4.15 HTTP................................................. 145 4.16 HTTP Security............................................ 154 4.17 Testing Actor Systems........................................ 158 4.18 Tutorial: write a scalable, fault-tolerant, network chat server and client (Scala).......... 165 5 Java API 178 5.1 Actors (Java)............................................. 178 5.2 Typed Actors (Java)......................................... 185 5.3 ActorRegistry (Java)......................................... 189 i 5.4 Futures (Java)............................................. 190 5.5 Dataflow Concurrency (Java).................................... 195 5.6 Software Transactional Memory (Java)............................... 198 5.7 Transactors (Java).......................................... 207 5.8 Remote Actors (Java)........................................ 212 5.9 Serialization (Java).......................................... 222 5.10 Fault Tolerance Through Supervisor Hierarchies (Java)....................... 225 5.11 Dispatchers (Java).......................................... 233 5.12 Routing (Java)............................................ 238 5.13 Guice Integration........................................... 239 6 Information for Developers 241 6.1 Building Akka............................................ 241 6.2 Developer Guidelines........................................ 243 6.3 Documentation Guidelines...................................... 244 6.4 Team................................................. 246 7 Project Information 247 7.1 Migration Guides........................................... 247 7.2 Release Notes............................................ 252 7.3 Scaladoc API............................................. 266 7.4 Documentation for Other Versions.................................. 267 7.5 Issue Tracking............................................ 267 7.6 Licenses............................................... 268 7.7 Sponsors............................................... 271 7.8 Support................................................ 271 7.9 Mailing List............................................. 271 7.10 Downloads.............................................. 271 7.11 Source Code............................................. 272 7.12 Maven Repository.......................................... 272 8 Additional Information 273 8.1 Add-on Modules........................................... 273 8.2 Articles & Presentations....................................... 273 8.3 Benchmarks............................................. 275 8.4 Here is a list of recipies for all things Akka............................. 276 8.5 External Sample Projects....................................... 276 8.6 Projects using the removed Akka Persistence modules....................... 280 8.7 Companies and Open Source projects using Akka.......................... 280 8.8 Third-party Integrations....................................... 284 8.9 Other Language Bindings...................................... 285 8.10 Feature Stability Matrix....................................... 285 9 Links 286 Python Module Index 287 Index 288 ii CHAPTER ONE INTRODUCTION 1.1 What is Akka? Simpler Scalability, Fault-Tolerance, Concurrency & Remoting through Actors We believe that writing correct concurrent, fault-tolerant and scalable applications is too hard. Most of the time it’s because we are using the wrong tools and the wrong level of abstraction. Akka is here to change that. Using the Actor Model together with Software Transactional Memory we raise the abstraction level and provide a better plat- form to build correct concurrent and scalable applications. For fault-tolerance we adopt the Let it crash/Embrace failure model which have been used with great success in the telecom industry to build applications that self-heals, systems that never stop. Actors also provides the abstraction for transparent distribution and the basis for truly scalable and fault-tolerant applications. Akka is Open Source and available under the Apache 2 License. Download from http://akka.io/downloads/ 1.1.1 Akka implements a unique hybrid • Actors (Java), which gives you: – Simple and high-level abstractions for concurrency and parallelism. – Asynchronous, non-blocking and highly performant event-driven programming model. – Very lightweight event-driven processes (create ~6.5 million actors on 4GB RAM). • Fault Tolerance Through Supervisor Hierarchies (Java) through supervisor hierarchies with “let-it-crash” semantics. Excellent for writing highly fault-tolerant systems that never stop, systems that self-heal. • Software Transactional Memory (Java) (STM). (Distributed transactions coming soon). • Transactors (Java): combine actors and STM into transactional actors. Allows you to compose atomic message flows with automatic retry and rollback. • Remote Actors (Java): highly performant distributed actors with remote supervision and error management. • Java API and Scala API 1.1.2 Akka can be used in two different ways • As a library: used by a web app, to be put into ‘WEB-INF/lib’ or as a regular JAR on your classpath. • As a microkernel: stand-alone kernel, embedding a servlet container and all the other modules. See the Use-case and Deployment Scenarios for details. 1 Akka Documentation, Release 1.1.3 1.2 Why Akka? 1.2.1 What features can the Akka platform offer, over the competition? Akka is an unified runtime and programming model for: • Scale up (Concurrency) • Scale out (Remoting) • Fault tolerance One thing to learn and admin, with high cohesion and coherent semantics. Akka is a very scalable piece of software, not only in the performance sense, but in the size of applications it is useful for. The core of Akka, akka-actor, is very small and easily dropped into an existing project where you need asynchronicity and lockless concurrency without hassle. You can choose to include only the parts of akka you need in your application and then there’s the whole package, the Akka Microkernel, which is a standalone container to deploy your Akka application in. With CPUs growing more and more cores every cycle, Akka is the alternative that provides outstanding performance even if you’re only running it on one machine. Akka also supplies a wide array of concurrency-paradigms, allowing for users to choose the right tool for the job. The integration possibilities for Akka Actors are immense through the Apache Camel integration. We provide Software Transactional Memory concurrency control through the excellent Multiverse project, and have integrated that with Actors, creating Transactors for coordinated concurrent transactions. We have Agents and Dataflow concurrency as well. 1.2.2 What’s a good use-case for Akka? (Web, Cloud, Application) Services - Actors lets you manage service failures (Supervisors), load management (back-off strategies, timeouts and processing-isolation), both horizontal and vertical scalability (add more cores and/or add more machines). Think payment processing, invoicing, order matching, datacrunching, messaging. Really any highly transactional systems like banking, betting, games. Here’s what some of the Akka users have to say about how they are using Akka: http://stackoverflow.com/questions/4493001/good-use-case-for-akka 1.2.3 Cloudy Akka And that’s all in the ApacheV2-licensed open source project. On top of that we have a commercial product called Cloudy Akka which provides the following