Akka Java Documentation Release 2.2.5

Total Page:16

File Type:pdf, Size:1020Kb

Akka Java Documentation Release 2.2.5 Akka Java Documentation Release 2.2.5 Typesafe Inc February 19, 2015 CONTENTS 1 Introduction 1 1.1 What is Akka?............................................1 1.2 Why Akka?..............................................3 1.3 Getting Started............................................3 1.4 The Obligatory Hello World.....................................7 1.5 Use-case and Deployment Scenarios.................................8 1.6 Examples of use-cases for Akka...................................9 2 General 10 2.1 Terminology, Concepts........................................ 10 2.2 Actor Systems............................................ 12 2.3 What is an Actor?.......................................... 14 2.4 Supervision and Monitoring..................................... 16 2.5 Actor References, Paths and Addresses............................... 19 2.6 Location Transparency........................................ 25 2.7 Akka and the Java Memory Model.................................. 26 2.8 Message Delivery Guarantees.................................... 28 2.9 Configuration............................................. 33 3 Actors 65 3.1 Actors................................................ 65 3.2 Typed Actors............................................. 84 3.3 Fault Tolerance............................................ 88 3.4 Dispatchers.............................................. 103 3.5 Mailboxes.............................................. 106 3.6 Routing................................................ 111 3.7 Building Finite State Machine Actors................................ 126 3.8 Testing Actor Systems........................................ 129 4 Futures and Agents 143 4.1 Futures................................................ 143 4.2 Software Transactional Memory................................... 151 4.3 Agents................................................ 152 4.4 Transactors.............................................. 154 5 Networking 158 5.1 Cluster Specification......................................... 158 5.2 Cluster Usage............................................. 166 5.3 Remoting............................................... 193 5.4 Serialization............................................. 213 5.5 I/O.................................................. 219 5.6 Encoding and decoding binary data................................. 221 5.7 Using TCP.............................................. 229 5.8 Using UDP.............................................. 242 5.9 ZeroMQ............................................... 245 i 5.10 Camel................................................. 250 6 Utilities 268 6.1 Event Bus............................................... 268 6.2 Logging................................................ 271 6.3 Scheduler............................................... 276 6.4 Duration............................................... 279 6.5 Circuit Breaker............................................ 280 6.6 Akka Extensions........................................... 283 6.7 Durable Mailboxes.......................................... 286 6.8 Microkernel............................................. 289 7 HowTo: Common Patterns 293 7.1 Scheduling Periodic Messages.................................... 293 7.2 Single-Use Actor Trees with High-Level Error Reporting...................... 294 7.3 Template Pattern........................................... 297 8 Experimental Modules 298 8.1 Multi Node Testing.......................................... 298 8.2 External Contributions........................................ 303 9 Information for Akka Developers 323 9.1 Building Akka............................................ 323 9.2 Multi JVM Testing.......................................... 325 9.3 I/O Layer Design........................................... 329 9.4 Developer Guidelines........................................ 330 9.5 Documentation Guidelines...................................... 332 9.6 Team................................................. 334 10 Project Information 335 10.1 Migration Guides........................................... 335 10.2 Issue Tracking............................................ 341 10.3 Licenses............................................... 342 10.4 Sponsors............................................... 342 10.5 Project................................................ 342 11 Additional Information 345 11.1 Books................................................. 345 11.2 Here is a list of recipes for all things Akka............................. 345 11.3 Other Language Bindings...................................... 345 11.4 Akka in OSGi............................................ 345 11.5 Incomplete List of HTTP Frameworks................................ 346 ii CHAPTER ONE INTRODUCTION 1.1 What is Akka? Scalable real-time transaction processing 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 we raise the abstraction level and provide a better platform to build correct, concurrent, and scalable applications. For fault-tolerance we adopt the “Let it crash” model which the telecom industry has used with great success to build applications that self-heal and systems that never stop. Actors also provide 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://typesafe.com/stack/downloads/akka/ Please note that all code samples compile, so if you want direct access to the sources, have a look over at the Akka Docs Project. 1.1.1 Akka implements a unique hybrid Actors Actors give 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 (approximately 2.7 million actors per GB RAM). See Actors (Scala) and Untyped Actors (Java) Fault Tolerance • Supervisor hierarchies with “let-it-crash” semantics. • Supervisor hierarchies can span over multiple JVMs to provide truly fault-tolerant systems. • Excellent for writing highly fault-tolerant systems that self-heal and never stop. See Fault Tolerance (Scala) and Fault Tolerance (Java) Location Transparency Everything in Akka is designed to work in a distributed environment: all interactions of actors use pure message passing and everything is asynchronous. For an overview of the remoting see Location Transparency 1 Akka Java Documentation, Release 2.2.5 Transactors Transactors combine actors and Software Transactional Memory (STM) into transactional actors. It allows you to compose atomic message flows with automatic retry and rollback. See Transactors (Scala) and Transactors (Java) 1.1.2 Scala and Java APIs Akka has both a scala-api and a Java Documentation. 1.1.3 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 to drop your application into. See the Use-case and Deployment Scenarios for details. 1.1.4 What happened to Cloudy Akka? The commercial offering was earlier referred to as Cloudy Akka. This offering consisted of two things: • Cluster support for Akka • Monitoring & Management (formerly called Atmos) Cloudy Akka has been discontinued and the Cluster support is now being moved into the Open Source version of Akka (the upcoming Akka 2.1), while Monitoring & Management (Atmos) has been re-branded as the Typesafe Console, which is now part of the commercial subscription for the Typesafe Stack (see below for details). 1.1.5 Typesafe Stack Akka is now also part of the Typesafe Stack. The Typesafe Stack is a modern software platform that makes it easy for developers to build scalable software applications. It combines the Scala programming language, Akka, the Play! web framework and robust developer tools in a simple package that integrates seamlessly with existing Java infrastructure. The Typesafe Stack is all fully open source. 1.1.6 Typesafe Console On top of the Typesafe Stack we also have a commercial product called Typesafe Console which provides the following features: 1. Slick Web UI with real-time view into the system 2. Management through Dashboard, JMX and REST 3. Dapper-style tracing of messages across components and remote nodes 4. Real-time statistics 5. Very low overhead monitoring agents (should always be on in production) 6. Consolidation of statistics and logging information to a single node 7. Storage of statistics data for later processing 8. Provisioning and rolling upgrades Read more here. 1.1. What is Akka? 2 Akka Java Documentation, Release 2.2.5 1.2 Why Akka? 1.2.1 What features can the Akka platform offer, over the competition? Akka provides scalable real-time transaction processing. 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 context of performance but also 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
Recommended publications
  • Up up and Out: Scaling Software with Akka
    UP UP AND OUT: SCALING SOFTWARE WITH AKKA Jonas Bonér CTO Typesafe @jboner Scaling software with Jonas Bonér CTO Typesafe @jboner ScalingScaling softwaresoftware with with ScalingScaling softwaresoftware with with Akka (Áhkká) The name comes from the goddess in the Sami (native swedes) mythology that represented all the wisdom and beauty in the world. It is also the name of a beautiful mountain in Laponia in the north part of Sweden ScalingScaling softwaresoftware with with Manage System Overload Scale UP & Scale OUT How can we achieve this? How can we achieve this? Let’s use Actors How can we achieve this? What is an Actor? What is an Actor? What is an Actor? • Akka's unit of code organization is called an Actor What is an Actor? • Akka's unit of code organization is called an Actor • Like Java EE servlets and session beans, Actors is a model for organizing your code that keeps many “policy decisions” separate from the business logic What is an Actor? • Akka's unit of code organization is called an Actor • Like Java EE servlets and session beans, Actors is a model for organizing your code that keeps many “policy decisions” separate from the business logic • Actors may be new to many in the Java community, but they are a tried-and-true concept (Hewitt 1973) used for many years in telecom systems with 9 nines uptime Program at a Higher Level Program at a Higher Level Program at a Higher Level • Never think in terms of shared state, state visibility, threads, locks, concurrent collections, thread notifications etc.
    [Show full text]
  • A Software Framework for the Actor Model Focusing on the Optimization of Message Passing
    AICT 2018 : The Fourteenth Advanced International Conference on Telecommunications Actor4j: A Software Framework for the Actor Model Focusing on the Optimization of Message Passing David Alessandro Bauer, Juho Mäkiö Department of Informatics and Electronics University of Applied Sciences Emden/Leer Emden, Germany Email: [email protected], [email protected] Abstract—Common actor implementations often use also the Scale Cube by Abbott [6], which describes the three standardized thread pools without special optimization for the dimensions of scalability. message passing. For that, a high-performance solution was To ensure high parallelization, its one benefit to use worked out. The actor-oriented software framework Akka uses multi-core systems. The computer world of the last few internally a ForkJoinPool that is intended for a MapReduce years has been characterized by a change ("The Free Lunch approach. However, the MapReduce approach is not relevant for message passing, as it may lead to significant performance Is Over" [7]) from constantly increasing computing power losses. One solution is to develop a thread pool that focuses on to multi-core systems due to technical limitations. In the message passing. In the implementation of the Actor4j particular, technical progress always lags behind practical framework, the message queue of the actors is placed in requirements (Wirth's law [8]). Up to now, Moore's law was threads to enable an efficient message exchange. The actors are “that the number of transistors available to semiconductor operated directly from this queue (injecting the message), manufacturers would double approximately every 18 to 24 without further ado.
    [Show full text]
  • Reactive Programming with Scala, Lagom, Spark, Akka and Play
    Issue October 2016 | presented by www.jaxenter.com #53 The digital magazine for enterprise developers Reactive Programming with Scala, Lagom, Spark, Akka and Play Interview with Scala creator Martin Odersky The state of Scala The Lagom Framework Lagom gives the developer a clear path DevOpsCon 2016: Our mission statement This is how we interpret modern DevOps ©istockphoto.com/moorsky Editorial Reactive programming is gaining momentum “We believe that a coherent approach to systems architec- If the definition “stream of events” does not satisfy your ture is needed, and we believe that all necessary aspects are thirst for knowledge, get ready to find out what reactive pro- already recognized individually: we want systems that are Re- gramming means to our experts in Scala, Lagom, Spark, Akka sponsive, Resilient, Elastic and Message Driven. We call these and Play. Plus, we talked to Scala creator Martin Odersky Reactive Systems.” – The Reactive Manifesto about the impending Scala 2.12, the current state of this pro- Why should anyone adopt reactive programming? Because gramming language and the technical innovations that await it allows you to make code more concise and focus on im- us. portant aspects such as the interdependence of events which Thirsty for more? Open the magazine and see what we have describe the business logic. Reactive programming means dif- prepared for you. ferent things to different people and we are not trying to rein- vent the wheel or define this concept. Instead we are allowing Gabriela Motroc, Editor our authors to prove how Scala, Lagom, Spark, Akka and Play co-exist and work together to create a reactive universe.
    [Show full text]
  • Lightweight Affinity and Object Capabilities in Scala
    http://www.diva-portal.org Postprint This is the accepted version of a paper presented at ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA). Citation for the original published paper: Haller, P., Loiko, A. (2016) LaCasa: Lightweight Affinity and Object Capabilities in Scala. In: Proceedings of the 2016 ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and Applications (pp. 272-291). Association for Computing Machinery (ACM) https://doi.org/10.1145/3022671.2984042 N.B. When citing this work, cite the original published paper. © Author | ACM 2016. This is the author's version of the work. It is posted here for your personal use. Not for redistribution. The definitive Version of Record was published in Proceedings of the 2016 ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and Applications, http://dx.doi.org/10.1145/3022671.2984042. Permanent link to this version: http://urn.kb.se/resolve?urn=urn:nbn:se:kth:diva-197902 LACASA: Lightweight Affinity and Object Capabilities in Scala Philipp Haller Alex Loiko KTH Royal Institute of Technology, Sweden Google, Sweden ∗ [email protected] [email protected] Abstract difficulty of reasoning about program behavior and software Aliasing is a known source of challenges in the context of architecture [3], and it can introduce data races in concur- imperative object-oriented languages, which have led to im- rent programs. These observations have informed the devel- portant advances in type systems for aliasing control. How- opment of a number of type disciplines aimed at providing ever, their large-scale adoption has turned out to be a surpris- static aliasing properties, such as linear types [33, 51, 64], ingly difficult challenge.
    [Show full text]
  • Comparing Languages for Engineering Server Software: Erlang, Go, and Scala with Akka
    Comparing Languages for Engineering Server Software: Erlang, Go, and Scala with Akka Ivan Valkov, Natalia Chechina, and Phil Trinder School of Computing Science, University of Glasgow G12 8RZ, United Kingdom [email protected], {Natalia.Chechina, Phil.Trinder}@glasgow.ac.uk Abstract functional or object-oriented, with high-level coordination models, Servers are a key element of current IT infrastructures, and must e.g. actors as in Erlang [2] or a process algebra as in Go [6]. Indeed, often deal with large numbers of concurrent requests. The program- the success of some server-based companies is even attributed to ming language used to construct the server has an important role their use of specific languages. As examples WhatsApp’s success in engineering efficient server software, and must support massive is attributed to their use of Erlang [27]; the video streaming leader concurrency on multicore machines with low communication and Twitch uses Go to serve millions of users a day [13]. Research synchronisation overheads. contributions of this paper include the following: This paper investigates 12 highly concurrent programming lan- • A survey of programming language characteristics relevant for guages suitable for engineering servers, and analyses three repre- servers (Section 2.1). sentative languages in detail: Erlang, Go, and Scala with Akka. • The design and implementation of three benchmarks to analyse We have designed three server benchmarks that analyse key per- the multicore server capabilities of Erlang, Go, and Scala with formance characteristics of the languages. The benchmark results Akka (Section 3). suggest that where minimising message latency is crucial, Go and Erlang are best; that Scala with Akka is capable of supporting the • An evaluation of Erlang, Go, and Scala with Akka for key largest number of dormant processes; that for servers that frequently server capabilities, i.e.
    [Show full text]
  • Parsing with First-Class Derivatives
    Parsing with First-Class Derivatives Jonathan Immanuel Brachthauser¨ Tillmann Rendel Klaus Ostermann rtifact A Comple * t * te n * A * te is W E s A e n C l l L o D C S University of Tubingen,¨ Germany o * * c P u e m s E u O e e n v R t e O o d t a y * s E a * fbrachthaeuser, rendel, [email protected] l u d a e t Abstract often reducing the modularity of their parser because these ad- Brzozowski derivatives, well known in the context of reg- hoc additions are cross-cutting with respect to the otherwise ular expressions, have recently been rediscovered to give a context-free syntactic structure of the language. simplified explanation to parsers of context-free languages. Parser combinators [10, 10, 15, 21, 22] are a parsing We add derivatives as a novel first-class feature to a standard approach that is well-suited for such ad-hoc additions. With parser combinator language. First-class derivatives enable an parser combinators, a parser is described as a first-class inversion of the control flow, allowing to implement modular entity in some host language, and parsers for smaller subsets parsers for languages that previously required separate pre- of a language are combined into parsers of larger subsets processing steps or cross-cutting modifications of the parsers. using built-in or user-defined combinators such as sequence, We show that our framework offers new opportunities for alternative, or iteration. The fact that parsers are first-class reuse and supports a modular definition of interesting use entities at runtime allows an elegant way of structuring cases of layout-sensitive parsing.
    [Show full text]
  • Warp: a Haskell Web Server
    The Functional Web Warp: A Haskell Web Server Michael Snoyman • Suite Solutions oughly two years ago, I began work on about this runtime is its lightweight threads. As the Yesod Web framework. I originally a result of this feature, Warp simply spawns a R intended FastCGI for my deployment strat- new thread for each incoming connection, bliss- egy, but I also created a simple HTTP server for fully unaware of the gymnastics the runtime is local testing, creatively named SimpleServer. performing under the surface. Because Yesod targets the Web Application Part of this abstraction involves converting Interface (WAI), a standard interface between synchronous Haskell I/O calls into asynchro- Haskell Web servers and Web applications, it nous system calls. Once again, Warp reaps the was easy to switch back ends for testing and benefits by calling simple functions like recv production. and send, while GHC does the hard work. It didn’t take long before I started getting Up through GHC 6.12, this runtime sys- feature requests for SimpleServer: slowly but tem was based on the select system call. This surely, features such as chunked transfer encod- worked well enough for many tasks but didn’t ing and sendfile-based file serving made their scale for Web servers. One big feature of the way in. The tipping point was when Matt Brown GHC 7 release was a new event manager, written of Soft Mechanics made some minor tweaks by Google’s Johan Tibell and Serpentine’s Bryan to SimpleServer and found that it was already O’Sullivan. This new runtime uses different sys- the fastest Web server in Haskell (see Figure 1).
    [Show full text]
  • Interleaving Data and Effects"
    Archived version from NCDOCKS Institutional Repository http://libres.uncg.edu/ir/asu/ Interleaving data and effects By: Robert Atkey and Patricia Johann Abstract: The study of programming with and reasoning about inductive datatypes such as lists and trees has benefited from the simple categorical principle of initial algebras. In initial algebra semantics, each inductive datatype is represented by an initial f-algebra for an appropriate functor f. The initial algebra principle then supports the straightforward derivation of definitional principles and proof principles for these datatypes. This technique has been expanded to a whole methodology of structured functional programming, often called origami programming.In this article we show how to extend initial algebra semantics from pure inductive datatypes to inductive datatypes interleaved with computational effects. Inductive datatypes interleaved with effects arise naturally in many computational settings. For example, incrementally reading characters from a file generates a list of characters interleaved with input/output actions, and lazily constructed infinite values can be represented by pure data interleaved with the possibility of non-terminating computation. Straightforward application of initial algebra techniques to effectful datatypes leads either to unsound conclusions if we ignore the possibility of effects, or to unnecessarily complicated reasoning because the pure and effectful concerns must be considered simultaneously. We show how pure and effectful concerns can be separated using the abstraction of initial f-and-m-algebras, where the functor f describes the pure part of a datatype and the monad m describes the interleaved effects. Because initial f-and-m-algebras are the analogue for the effectful setting of initial f- algebras, they support the extension of the standard definitional and proof principles to the effectful setting.
    [Show full text]
  • On the Duality of Streams How Can Linear Types Help to Solve the Lazy IO Problem?
    Draft: do not distribute On the Duality of Streams How Can Linear Types Help to Solve the Lazy IO Problem? Jean-Philippe Bernardy Josef Svenningsson Chalmers University of Technology and University of Gothenburg bernardy,josefs at chalmers.se Abstract sired behavior does not always happen. Indeed, a necessary con- We present a novel stream-programming library for Haskell. As dition is that the production pattern of f matches the consumption other coroutine-based stream libraries, our library allows syn- pattern of g; otherwise buffering occurs. In practice, this means that chronous execution, which implies that effects are run in lockstep a seemingly innocuous change in either of the function definitions and no buffering occurs. may drastically change the memory behavior of the composition, A novelty of our implementation is that it allows to locally in- without warning. If one cares about memory behavior, this means troduce buffering or re-scheduling of effects. The buffering require- that the compositionality principle touted by Hughes breaks down. ments (or re-scheduling opportunities) are indicated by the type- Second, lazy evaluation does not extend nicely to effectful pro- system. cessing. That is, if (say) an input list is produced by reading a file lazily, one is exposed to losing referential transparency (as ? has Our library is based on a number of design principles, adapted 1 from the theory of Girard’s Linear Logic. These principles are shown). For example, one may rightfully expect that both follow- applicable to the design of any Haskell structure where resource ing programs have the same behavior: management (memory, IO, ...) is critical.
    [Show full text]
  • A Companion Booklet to "Functional Programming in Scala"
    A companion booklet to ”Functional Programming in Scala” Chapter notes, errata, hints, and answers to exercises Rúnar Óli Bjarnason This book is for sale at http://leanpub.com/fpinscalacompanion This version was published on 2015-03-05 This is a Leanpub book. Leanpub empowers authors and publishers with the Lean Publishing process. Lean Publishing is the act of publishing an in-progress ebook using lightweight tools and many iterations to get reader feedback, pivot until you have the right book and build traction once you do. ©2015 Manning Publications Co., Rúnar Óli Bjarnason, and other contributors Contents About this booklet ......................................... 2 Why make this? ......................................... 2 License .............................................. 2 Errata ................................................ 3 Chapter notes ........................................... 6 Getting answers to your questions ............................... 6 Notes on chapter 1: What is functional programming? .................... 6 Notes on chapter 2: Getting started ............................... 7 Notes on chapter 3: Functional data structures ........................ 9 Notes on chapter 4: Handling errors without exceptions ................... 12 Notes on chapter 5: Strictness and laziness .......................... 14 Notes on chapter 6: Purely functional state .......................... 16 Notes on chapter 7: Purely functional parallelism ....................... 20 Notes on chapter 8: Property-based testing .........................
    [Show full text]
  • Akka Java Documentation Release 2.2.4
    Akka Java Documentation Release 2.2.4 Typesafe Inc March 04, 2014 CONTENTS 1 Introduction 1 1.1 What is Akka?............................................1 1.2 Why Akka?..............................................3 1.3 Getting Started............................................3 1.4 The Obligatory Hello World.....................................7 1.5 Use-case and Deployment Scenarios.................................8 1.6 Examples of use-cases for Akka...................................9 2 General 10 2.1 Terminology, Concepts........................................ 10 2.2 Actor Systems............................................ 12 2.3 What is an Actor?.......................................... 14 2.4 Supervision and Monitoring..................................... 16 2.5 Actor References, Paths and Addresses............................... 19 2.6 Location Transparency........................................ 25 2.7 Akka and the Java Memory Model.................................. 26 2.8 Message Delivery Guarantees.................................... 28 2.9 Configuration............................................. 33 3 Actors 65 3.1 Actors................................................ 65 3.2 Typed Actors............................................. 84 3.3 Fault Tolerance............................................ 88 3.4 Dispatchers.............................................. 103 3.5 Mailboxes.............................................. 106 3.6 Routing................................................ 111 3.7 Building Finite State Machine
    [Show full text]
  • Operations Hub Open Source Software List
    GE Operations Hub Open Source Software List (for Version 1.7) In accordance with certain software license terms, the General Electric Company (“GE”) makes available the following software package installations. This code is provided to you on an “as is” basis, and GE makes no representations or warranties for the use of this code by you independent of any GE provided software or services. Refer to the licenses and copyright notices files for each package for any specific license terms that apply to each software bundle, associated with this product release. NOTE: These software package versions may change or be removed as needed for updates to this product. Copyright © 2018 General Electric Company. All rights reserved. Page 1 of 67 Software Name & Company Link License Name & Copyright Version Version (by Component) HikariCP https://github.com/brettwooldr Apache 2.0 3.4.2 idge/HikariCP Not found MsSql Jdbc 7.4.1.jre8 Copyright(c) 2019 Microsoft MIT https://www.microsoft.com/ Corporation snakeyaml http://www.snakeyaml.org Copyright (c) 2008, Apache License 2.0 1.2.6 http://www.snakeyaml.org COMMON DEVELOPMENT HK2 Class-Model 2.5.0-b06 https://javaee.github.io/glassfish/ AND DISTRIBUTION LICENSE Copyright (c) 2010-2015 Oracle and/or (CDDL) Version 1.1 its affiliates. All rights reserved. https://code.google.com/archive/p/ Copyright (C) 2003-2013 Virginia Tech. VT Crypt Library 2.1.4 Apache License 2.0 vt-middleware/ All rights reserved. https://code.google.com/archive/p/ Copyright (C) 2003-2013 Virginia Tech. VT Dictionary Libraries 3.0 Apache License 2.0 vt-middleware/ All rights reserved.
    [Show full text]