Integration of the Framework Akka and Java EE 6

Total Page:16

File Type:pdf, Size:1020Kb

Integration of the Framework Akka and Java EE 6 Masaryk University Faculty of Informatics Integration of the framework Akka and Java EE 6 Bachelors thesis Tibor Bogár Brno, autumn 2013 1 Announcement I annouce, that this bachelor's thesis is my original author's work, which I created autonomosly. Every source, strand and literature, which I used or extracted in my work is properly quoted specifying entire reference on the relevant source. Thesis supervisor: doc. RNDr. Tomáš Pitner, Ph.D. 2 Acknowledgement Foremost, I would like to express my sincere gratitude to my advisor Mgr. Martin Švehla, for his patience, motivation and immense knowledge. His guidance helped me in the time of research and writing this thesis. Besides my advisor, I would like to thank my thesis supervisor doc. RNDr. Tomáš Pitner, Ph.D., for his patience and tolerance. My sincere thanks to Helena Kryštofová and whole Office for Studies for helping me with administration. Last and not least, my mother for supporting me and making it possible to work entirely on thesis. 3 Contents 1. Introduction....................................................................................5 2. Context and Dependency Injection.............................................7 2.1. CDI bean characteristic....................................................................8 2.2. Qualifiers............................................................................................8 2.3. Scope...................................................................................................9 2.4. Injection Points..................................................................................9 2.5. Lose coupling with strong typing..................................................10 2.5.1. Producer methods.......................................................................10 2.5.2. Interceptors..................................................................................11 2.5.3. Decorators....................................................................................11 2.5.4. Events...........................................................................................11 2.5.5. Stereotypes...................................................................................12 3. Akka framework...........................................................................13 3.1. Actor Systems...................................................................................13 3.2. Actor Reference................................................................................14 3.3. State …...............................................................................................14 3.4. Behavior.............................................................................................15 3.5. Mailbox..............................................................................................15 3.6. Children.............................................................................................16 3.7. Supervisor Strategy..........................................................................16 3.8. When an Actor Terminates.............................................................16 3.9. Creating Actors.................................................................................17 3.9.1. Untyped Actor.............................................................................17 3.9.2. Props.............................................................................................17 3.9.3. Typed Actor.................................................................................18 4. Application.....................................................................................19 5. CDI Extension................................................................................21 6. Akka Modul.....…..........................................................................25 7. Examples in Spring and Google Guice......................................27 8. Conclusion......................................................................................29 9. Reference........................................................................................30 4 1. Introduction The goal of this work was to make an extension for Context and Depedency Injection [1] and a modul for framework Akka [2], which allows to use design pattern Dependency Injection in Actors of framework Akka i.e. Automatization of creating Java EE components and sources in Akka Actors and creating Actors into Java EE components using anotations. Context and Dependency Injection (CDI) framework deal with inserting dependencies and context in Java EE 6. Main advantage of this framework is to simplify access to objects and unify used services. Accessing to objects is secured throught design pattern inversion of control sometimes also called depednency injection, where we access to objects not directly through creating instancies with standard constructing methods, but our application server is managing the whole lifecycle of a corectly created class. These objects are called beans. CDI includes built-in support for several different kinds of bean, including Java EE component types as managed beans and EJB session beans. Prior to Java EE 6, there was no clear definition of the term "bean" in the Java EE platform. Java EE 6 finally lays down that common definition in the Managed Beans specification. Managed Beans are defined as container-managed objects with minimal programming restrictions, otherwise known by the acronym POJO (Plain Old Java Object). CDI allows the container to create and destroy instances of your beans and associate them with a designated context, injecting them into other beans, using them in EL expressions, specializing them with qualifier annotations, even adding interceptors and decorators to them. Akka framework uses Actor Model to raise the abstraction level and provide a better platform to build concurrent scalable and fault-tolerant applications. Any system that have the need for high- throughput and low latency can be easily implemented using Akka framework. Thnks to Actor Model developers musnt take care of managing threads and accesing to mutable data objects. Actors are objects which encapsulate state and behavior, they communicate exclusively by exchanging messages. In a sense, actors are the most stringent form of object-oriented programming, but it serves better to view them as persons: while modeling a solution with actors, imagine a group of people and assign sub-tasks to them, arrange 5 their functions into an organizational structure and think about how to deal with a failure and not careing for their emotional state or moral issues. Actors form hierarchies in terms of one actor with a certain function can split up tasks into smaller more managable pieces. Every Actor which splits his task into other actors must supervise these newly created actors. It is called parental supervision. This spliting tasks into smaller and smaller ones helps us to solve complex problems and makeing them easier to work up. There may be milions of actors within one system. The exact order in which messages are processed in large systems is not controllable by the application author, so we let Akka to take care of that. An actor object needs to be shielded from the outside in order to benefit from the actor model. Therefore, actors are represented to the outside using actor references, which are objects that can be passed around freely and without restriction. This split into inner and outer object enables transparency for all the desired operations and making impossible to look inside an actor and see its state from the outside, unless an actor publishes this information itself. Actors communicate with oneanother by exchanging messages. An actor can recieve message from other actors or from outside the actor system and its purpouse is to process these messages. Each actor has exactly one mailbox to which all senders enqueue their messages. Messages in mailboxes are defualtly defined by FIFO queue's algorithm, but they can be also prioritized. Actors always handle the next dequeued message. First of all we had to read and understand the uppermentioned frameworks and learn how to use them. Integrating modules are now used in many important and often used frameworks e.g. Spring and Google Guice. There is often a loss of clarity in writing new applications and therefore every developer wants the process of writing source code to be simple and a lot of things to be delegated and automatized. This simplifing of creating source codes is called convention over configuration. By decreasing the amount of decisions there is often a loss in flexibility. Our integration solution bring us simplicity but it doesnt lose much flexibility, because for example in case of creating new ActorSystem we can still use the old method of instanciating. Work on the implementation consists of two tasks. First of all we had to create a simple application based on assigment of consultant Mr. Mgr. Martin Švehla, on which we can see the function of our CDI extension and Akka module. The first task was to make extension for CDI framework, 6 where we had worked on automatic creating of actor classes, which were being created by the application server. We had to decide how to mark and specify the actor, which we wanted to instanciate by application server. We decide to mark the actors by annotation Named. This was easier as anotating it by annotation Qualifiers. Actors marked by annotation Named must have unique name so as application server could specify
Recommended publications
  • Weld 3.0.2.Final - CDI Reference Implementation
    Weld 3.0.2.Final - CDI Reference Implementation CDI: Contexts and Dependency In- jection for the Java EE platform by Gavin King, Pete Muir, Jozef Hartinger, Martin Kouba, Dan Allen, and David Allen and thanks to Nicola Benaglia, Gladys Guerrero, Eun- Ju Ki,, Terry Chuang, Francesco Milesi, and Sean Wu A note about naming and nomenclature ............................................................................. ix I. Beans ............................................................................................................................ 1 1. Introduction ......................................................................................................... 5 1.1. What is a bean? ......................................................................................... 5 1.2. Getting our feet wet .................................................................................... 5 2. More about beans ................................................................................................ 9 2.1. The anatomy of a bean ............................................................................. 10 2.1.1. Bean types, qualifiers and dependency injection ............................... 10 2.1.2. Scope ............................................................................................ 13 2.1.3. EL name ........................................................................................ 13 2.1.4. Alternatives .................................................................................... 14 2.1.5. Interceptor
    [Show full text]
  • 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
    [Show full text]
  • 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]
  • (Minus Sign) in Class Diagrams, 15 * (Asterisk) As Wildcard, 58 ? (Question
    Index - (minus sign) in class diagrams, 15 AOP module (Spring), 34, 37 * (asterisk) as wildcard, 58 Apache Axis web services framework, 210 ? (question mark) for positional bind Apache Maven, 280–285 variables, 187 Apache Struts framework, 23 + (plus sign) in class diagrams, 15 Apache Tiles framework, 122, 278 Apache Tomcat, 257 ■ A APF (Authentication Processing Filter), AbstractCachingViewResolver class, 60 233–243 AbstractCommandController class, 74–78 application contexts (Spring), 33 AbstractController class, 71–74 Application Controller pattern AbstractEnterpriseBean class, 158, 200 action/command handling, 52–56 AbstractHandlerMapping, 54 action handlers, using, 56–58 AbstractMessageDrivenBean class, 200 for action-view management, 50–52 AbstractProcessingFilter, 234 background, 50–51 AbstractStatelessSessionBean, 158 benefits and concerns, 68 AbstractTemplateViewResolver class, strategies with Spring framework, 52 60–61 view handlers, 59–62, 62–68 AbstractWizardFormController class, 89 application server transactions, 261 access decision manager (Spring application servers, 138 Security), 228 application service implementation class, accessDecisionManager property, 164 246–247 Application Service pattern Acegi Security, 223–224 benefits and concerns, 167 action/command handling (application to concentrate business logic in POJO controller), 52–56 classes, 162–163 action handlers strategies with Spring framework, page controllers and, 51 164–167 sequence, 54 applicationContext-security.xml, 229 using (application controller), 56–58
    [Show full text]
  • Perception and Effects of Implementing Kotlin in Existing Projects
    Bachelor thesis Undergraduate level Perception and effects of implementing Kotlin in existing projects A case study about language adoption Author: Emil Sundin Supervisor: Wei Song Examiner: Azadeh Sarkheyli Discipline: Informatics Course: IK2017 Credit: 15 credits Examination date: 2018-05-25 Dalarna University provides the opportunity for publishing the thesis through DiVA as Open Access. This means that the thesis work will become freely available to read and download through their portal. Dalarna University encourages students as well as researchers to publish their work in the Open Access format. We approve the publishing of this thesis work under the Open Access format: Yes ☒ No ☐ Dalarna University – SE-791 88 Falun – Phone +4623-77 80 00 Abstract The Kotlin programming language has seen an increase of adoption since its launch in 2011. In late 2017 Google announced first-class support for Kotlin on the Android platform which further popularized the language. With this increase in popularity we felt it was interesting to investigate how Kotlin affects the developer experience. We performed a case study to see how Java developers perceive the Kotlin language, and how it meets the requirements of these developers. To gather the developer requirements and their perception of Kotlin we performed two sets of interviews and rewrote parts of their codebase. The first set of interviews identified developer requirements and the second set of interviews showcased the Kotlin language and its potential use in their codebase. The results show that Kotlin can meet most of the developer requirements and that the perception of Kotlin is positive. Kotlin’s ability to be incrementally adopted was a prominent feature which reduced the inherent risks of technology adoption while providing them the ability to further evaluate the language.
    [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]
  • Develop a Simple Web Application with Apache Wicket and Apache
    Develop a simple Web application with Apache Wicket and Apache Geronimo Combine Wicket, Geronimo, and Apache Derby to form an open source Java Web development platform Skill Level: Intermediate Robi Sen ([email protected]) Vice President Department 13 LLC 10 Jul 2007 Apache Wicket is an innovative Java™ Web application framework that was introduced a couple of years ago. It helps simplify Web application development by clearly separating the roles of developers and designers. It lets you remove logical code from the view layer, eliminating the need for JavaServer Pages (JSP), providing a simple plain old Java object (POJO)-centric mode of development, and removing much of the need for XML and other configuration file formats. In this tutorial, learn how to set up your system to develop a simple Web application with Wicket, using Apache Geronimo as your application server and Apache Derby as the embedded database. Section 1. Before you start This tutorial is designed for developers who have found Java frameworks, such as Struts, lacking in needed functionality. If you're interested in developing Web applications in a more object-oriented manner, where the view is clearly separated from logic and there's minimal configuration and mapping, then Wicket is for you! This tutorial walks you through the basics of how Wicket works, while using Apache Geronimo to set up a Java Platform, Enterprise Edition (Java EE) server, Web server, and embedded database in just minutes. Combining Wicket with Geronimo lets you develop data-driven, scalable Web applications using software that's all open source. Develop a simple Web application with Apache Wicket and Apache Geronimo © Copyright IBM Corporation 1994, 2008.
    [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]
  • Towards High-Quality Android Applications Development with Kotlin Bruno Gois Mateus
    Towards high-quality Android applications development with Kotlin Bruno Gois Mateus To cite this version: Bruno Gois Mateus. Towards high-quality Android applications development with Kotlin. Mobile Computing. Université Polytechnique Hauts-de-France, 2021. English. NNT : 2021UPHF0012. tel- 03247062 HAL Id: tel-03247062 https://tel.archives-ouvertes.fr/tel-03247062 Submitted on 2 Jun 2021 HAL is a multi-disciplinary open access L’archive ouverte pluridisciplinaire HAL, est archive for the deposit and dissemination of sci- destinée au dépôt et à la diffusion de documents entific research documents, whether they are pub- scientifiques de niveau recherche, publiés ou non, lished or not. The documents may come from émanant des établissements d’enseignement et de teaching and research institutions in France or recherche français ou étrangers, des laboratoires abroad, or from public or private research centers. publics ou privés. PhD Thesis Université Polytechnique Hauts-de-France and from INSA Hauts-de-France Subject: Computer Science Presented and defended by Bruno GÓIS MATEUS On March 26, 2021, Valenciennes Doctoral School: Sciences Pour l’Ingénieur (ED SPI 072) Research team, Laboratory: Département d’Informatique Laboratory of Industrial and Human Automation control, Mechanical engineering and Computer Science (LAMIH UMR CNRS 8201) Towards high-quality Android applications development with Kotlin JURY Committee President - Káthia MARÇAL DE OLIVEIRA. Professor at Université Polytechnique Hauts-de-France. Reviewers - Guilherme HORTA TRAVASSOS. Professor at Federal University of Rio de Janeiro. - Jacques KLEIN. Professor at University of Luxembourg. Examiner - Dalila TAMZALIT. Associate Professor at Université de Nantes. Supervisor - Christophe KOLSKI. Professor at Université Polytechnique Hauts-de-France. Co-Supervisor - Matias MARTINEZ.
    [Show full text]
  • Esper Reference
    Esper Reference Version 8.3.0 by EsperTech Inc. [http://www.espertech.com] Copyright 2006 - 2019 by EsperTech Inc. Preface ......................................................................................................................... xxvii 1. Getting Started ............................................................................................................ 1 1.1. Introduction to Complex Event Processing ........................................................... 1 1.2. Introduction to the Architecture ............................................................................ 1 1.3. Introduction to EPL ............................................................................................. 2 1.4. Compiler Getting-Started ..................................................................................... 3 1.4.1. Compiler - Step One: Setting up the Compiler Classpath ............................ 3 1.4.2. Compiler - Step Two: Provide Information on Input Events .......................... 3 1.4.3. Compiler - Step Three: Compiling EPL ...................................................... 4 1.5. Runtime Getting-Started ...................................................................................... 5 1.5.1. Runtime - Step One: Setting up the Runtime Classpath .............................. 5 1.5.2. Runtime - Step Two: Obtain Runtime ........................................................ 6 1.5.3. Runtime - Step Three: Deploy EPL Compiled Module and Attach a Callback .........................................................................................................................
    [Show full text]