logo资料库

Building applications with Scala 无水印pdf.pdf

第1页 / 共434页
第2页 / 共434页
第3页 / 共434页
第4页 / 共434页
第5页 / 共434页
第6页 / 共434页
第7页 / 共434页
第8页 / 共434页
资料共434页,剩余部分请下载后查看
Cover
Table of Contents
Copyright
About the Author
Preface
1. Introduction to FP, Reactive, and Scala
Functional programming
Principles of functional programming
Immutability
Disciplined state
Pure functions and no side effects
First-class functions and higher-order functions
Type systems
Referential transparency
Installing Java 8 and Scala 2.11
Read Eval Print and Loop - REPL
Scala Hello World using the REPL
Scala REPL Hello World program
Scala object-oriented HelloWorld program
Scala HelloWorld App in the Scala REPL
Java HelloWorld application
Scala language - the basics
Scala variables - var and val
Scala REPL var usage
Scala val usage at the Scala REPL
Creating immutable variables
Scala variable type in the Scala REPL
Scala variables with explicit typing at the Scala REPL
Scala conditional and loops statements
If statements in Scala REPL
If statements in return statements in Scala REPL
Basic for loop in Scala REPL
For with List in Scala REPL
For with if statements for filtering - Scala REPL
Java code for filtering even numbers
For comprehensions
For comprehension in Scala REPL
Java code for performing filtering with collections
Scala collections
Creating, removing, and getting an item from a mutable list in Scala REPL
Scala tuples
Scala immutable Map in Scala REPL
Scala mutable Maps at Scala REPL
Monads
Scala Map function in Scala REPL
Option Monad in Scala
A list of all methods using the Scala REPL
Scala class, traits, and OO programming
A simple Scala class in Scala REPL
Scala plain old Java object in Scala REPL
Person class in Java
Traits and inheritance
Scala inheritance code in Scala REPL
Scala traits sample code in Scala REPL
Scala traits using variable mixing technique at Scala REPL
Scala type alias sample in Scala REPL
Case classes
Scala case classes feature in Scala REPL
Pattern Matcher
Simple Pattern Matcher in Scala
Advanced pattern matcher in Scala REPL
Advanced complex pattern matcher in Scala REPL
Partial functions
Simple Partial function in Scala REPL
Scala PartialFunction without OO using case statements in Scala REPL
PartialFunction composition in Scala REPL
Package objects
package.scala
MainApp.scala
Functions
Partial application
Partial function in Scala REPL
Curried functions
Curried functions - Scala REPL
Curried transformation in Scala REPL
Operator overloading
Scala operator overloading in Scala REPL
Implicits
Scala Implicits in SCALA REPL
Implicit Parameter at Scala REPL
Futures
Simple Future code in Scala REPL
A complete Future sample at Scala REPL
Reactive Programing and RxScala
Simple Observables Scala with RxScala
Simple Observables Scala with RxScala - Execution in the console
Complex Scala with RxScala Observables
Summary
2. Creating Your App Architecture and Bootstrapping with SBT
Introducing SBT
Installing SBT on Ubuntu Linux
Getting started with SBT
Adding dependencies
Generating Eclipse project files from SBT
Application distribution
Hello world SBT / Scala App
Bootstrapping our Play framework app with Activator
Activator shell
Activator - compiling, testing, and running
Summary
3. Developing the UI with Play Framework
Getting started
Creating our models
Creating routes
Creating our controllers
Working with services
Configuring the Guice module
Working with views(UI)
Summary
4. Developing Reactive Backing Services
Getting started with reactive programming
IPriceService - Scala trait
PriceService - RxScala PriceService implementation
Guice Injection - Module.scala
NGServiceEndpoint
Play framework and high CPU usage
RndDoubleGeneratorController
IRndService.scala - Scala trait
RndService.scala - RndService implementation
Module.scala - Guice Injections
main.scala.html
product_details.scala.html
Summary
5. Testing Your Application
Unit testing principles
Making code testable
Isolation and self-contained tests
Effective naming
Levels of testing
Testing with Junit
Behavior-Driven Development - BDD
MyFirstPlaySpec.scala - First BDD with ScalaTest and the Play framework
Testing with Play framework support
ProductService.scala - FIX the code issue
ImageServiceTestSpec.scala - ImageService Test
ReviewServiceTestSpec.scala - ReviewService test
Testing routes
RoutesTestingSpec.scala - Play framework route testing
Controller testing
RndDoubleGeneratorControllerTestSpec.scala - RndDoubleGeneratorController tests
IntegrationSpec.scala
ProductControllerTestSpec.scala
product_index.scala.html
ImageControllerTestSpec.scala
image_index.scala.html
ReviewControllerTestSpec.scala
review_index.scala.html
ApplicationSpec.scala
NGServiceImplTestSpec.scala
NGServiceEndpointControllerTest.scala
Summary
6. Persistence with Slick
Introducing the Slick framework
MySQL setup
Configuring Slick in our Play framework app
Configure the database connection
FPM Mapping
ProductDao
ReviewDAO
ImageDao
Slick evolutions
Refactoring services
Refactoring controllers
Configuring DAO packages in Guice
Refactoring tests
Generic mocks
Service tests
Controller tests
Running the application
Summary
7. Creating Reports
Introducing JasperReports
JasperReports workflow
Jasper sessions
Installing Jaspersoft Studio 6
Configuring MySQL Data Adapter in Jaspersoft Studio
Creating a product report
Creating a review report
Creating an image report
Integrating JasperReports with Play framework
build.sbt
Generic report builder
Adding the report to the product controller
Adding the report to the review controller
Adding the report to the image controller
Routes - adding new report routes
New centralized reports UI
Adding the report button for each view
Summary
8. Developing a Chat with Akka
Adding the new UI introduction to Akka
Introduction to the Actor model
What is an Actor?
Message exchange and mailboxes
Coding actors with Akka
Actor routing
Persistence
Creating our chat application
The chat protocol
The chat controller
Implementing the chat controller
Configuring the routes
Working on the UI
Adding Akka tests
Scala test for Akka Actor
Chat room Actor test
Chat Bot Admin Actor test
Summary
9. Design Your REST API
Introduction to REST
REST API design
HTTP verbs design
Uniform API
Response with HTTP status codes
REST API patterns
API versioning
Some anti-patterns to be avoided
Creating our API with REST and JSON
RestApiContoller
REST API Front Controller implementation
JSON mapping
Configuring new routes
Testing the API using the browser
Creating a Scala client
Configuring plugins.sbt
Configuring build.sbt
Scala client code
Creating our REST client proxies
Creating ScalaTest tests for the proxies
Adding back pressure
The leaky bucket algorithm
Scala leaky bucket implementation
Testing back pressure
Adding Swagger support
Swagger UI
Build and install Swagger Standalone
Summary
10. Scaling up
Standalone deploy
Reports folder
Changing report builder
Defining the secret
Running the standalone deploy
Architecture principles
Service orientation (SOA/microservices)
Performance
Scalability/Resiliency
Scalability principles
Vertical and horizontal scaling (up and out)
Caching
Load balancer
Throttling
Database cluster
Cloud computing/containers
Auto Scaling
A note about automation
Don't forget about telemetry
Reactive Drivers and discoverability
Mid-Tier load balancer, timeouts, Back pressure, and caching
Scaling up microservices with an Akka cluster
Scaling up the infrastructure with Docker and AWS cloud
Summary
Building Applications with Scala
Table of Contents Building Applications with Scala Credits About the Author Acknowledgments About the Reviewer www.PacktPub.com Why subscribe? Preface What this book covers What you need for this book Who this book is for Conventions Reader feedback Customer support Downloading the example code Downloading the color images of this book Errata Piracy Questions 1. Introduction to FP, Reactive, and Scala Functional programming Principles of functional programming Immutability Disciplined state Pure functions and no side effects First-class functions and higher-order functions Type systems Referential transparency Installing Java 8 and Scala 2.11 Read Eval Print and Loop - REPL Scala Hello World using the REPL Scala REPL Hello World program Scala object-oriented HelloWorld program Scala HelloWorld App in the Scala REPL Java HelloWorld application Scala language - the basics Scala variables - var and val Scala REPL var usage Scala val usage at the Scala REPL Creating immutable variables Scala variable type in the Scala REPL
Scala variables with explicit typing at the Scala REPL Scala conditional and loops statements If statements in Scala REPL If statements in return statements in Scala REPL Basic for loop in Scala REPL For with List in Scala REPL For with if statements for filtering - Scala REPL Java code for filtering even numbers For comprehensions For comprehension in Scala REPL Java code for performing filtering with collections Scala collections Creating, removing, and getting an item from a mutable list in Scala REPL Scala tuples Scala immutable Map in Scala REPL Scala mutable Maps at Scala REPL Monads Scala Map function in Scala REPL Option Monad in Scala A list of all methods using the Scala REPL Scala class, traits, and OO programming A simple Scala class in Scala REPL Scala plain old Java object in Scala REPL Person class in Java Traits and inheritance Scala inheritance code in Scala REPL Scala traits sample code in Scala REPL Scala traits using variable mixing technique at Scala REPL Scala type alias sample in Scala REPL Case classes Pattern Matcher Scala case classes feature in Scala REPL Simple Pattern Matcher in Scala Advanced pattern matcher in Scala REPL Advanced complex pattern matcher in Scala REPL Partial functions Simple Partial function in Scala REPL Scala PartialFunction without OO using case statements in Scala REPL PartialFunction composition in Scala REPL Package objects package.scala MainApp.scala Functions Partial application
Partial function in Scala REPL Curried functions Curried functions - Scala REPL Curried transformation in Scala REPL Operator overloading Scala operator overloading in Scala REPL Implicits Futures Scala Implicits in SCALA REPL Implicit Parameter at Scala REPL Simple Future code in Scala REPL A complete Future sample at Scala REPL Reactive Programing and RxScala Simple Observables Scala with RxScala Simple Observables Scala with RxScala - Execution in the console Complex Scala with RxScala Observables Summary 2. Creating Your App Architecture and Bootstrapping with SBT Introducing SBT Installing SBT on Ubuntu Linux Getting started with SBT Adding dependencies Generating Eclipse project files from SBT Application distribution Hello world SBT / Scala App Bootstrapping our Play framework app with Activator Activator shell Activator - compiling, testing, and running Summary 3. Developing the UI with Play Framework Getting started Creating our models Creating routes Creating our controllers Working with services Configuring the Guice module Working with views(UI) Summary 4. Developing Reactive Backing Services Getting started with reactive programming IPriceService - Scala trait PriceService - RxScala PriceService implementation Guice Injection - Module.scala NGServiceEndpoint
Play framework and high CPU usage RndDoubleGeneratorController IRndService.scala - Scala trait RndService.scala - RndService implementation Module.scala - Guice Injections main.scala.html product_details.scala.html Summary 5. Testing Your Application Unit testing principles Making code testable Isolation and self-contained tests Effective naming Levels of testing Summary 6. Persistence with Slick Introducing the Slick framework MySQL setup Configuring Slick in our Play framework app Configure the database connection FPM Mapping ProductDao ReviewDAO Testing with Junit Behavior-Driven Development - BDD MyFirstPlaySpec.scala - First BDD with ScalaTest and the Play framework Testing with Play framework support ProductService.scala - FIX the code issue ImageServiceTestSpec.scala - ImageService Test ReviewServiceTestSpec.scala - ReviewService test Testing routes Controller testing RoutesTestingSpec.scala - Play framework route testing RndDoubleGeneratorControllerTestSpec.scala - RndDoubleGeneratorController tests IntegrationSpec.scala ProductControllerTestSpec.scala product_index.scala.html ImageControllerTestSpec.scala image_index.scala.html ReviewControllerTestSpec.scala review_index.scala.html ApplicationSpec.scala NGServiceImplTestSpec.scala NGServiceEndpointControllerTest.scala
ImageDao Slick evolutions Refactoring services Refactoring controllers Configuring DAO packages in Guice Refactoring tests Generic mocks Service tests Controller tests Running the application Summary 7. Creating Reports Introducing JasperReports JasperReports workflow Jasper sessions Installing Jaspersoft Studio 6 Configuring MySQL Data Adapter in Jaspersoft Studio Creating a product report Creating a review report Creating an image report Integrating JasperReports with Play framework build.sbt Generic report builder Adding the report to the product controller Adding the report to the review controller Adding the report to the image controller Routes - adding new report routes New centralized reports UI Adding the report button for each view Summary 8. Developing a Chat with Akka Adding the new UI introduction to Akka Introduction to the Actor model What is an Actor? Message exchange and mailboxes Coding actors with Akka Actor routing Persistence Creating our chat application The chat protocol The chat controller Implementing the chat controller Configuring the routes Working on the UI
Adding Akka tests Scala test for Akka Actor Chat room Actor test Chat Bot Admin Actor test Summary 9. Design Your REST API Introduction to REST REST API design HTTP verbs design Uniform API Response with HTTP status codes REST API patterns API versioning Some anti-patterns to be avoided Creating our API with REST and JSON RestApiContoller REST API Front Controller implementation JSON mapping Configuring new routes Testing the API using the browser Creating a Scala client Configuring plugins.sbt Configuring build.sbt Scala client code Creating our REST client proxies Creating ScalaTest tests for the proxies Adding back pressure The leaky bucket algorithm Scala leaky bucket implementation Testing back pressure Adding Swagger support Swagger UI Build and install Swagger Standalone Summary 10. Scaling up Standalone deploy Reports folder Changing report builder Defining the secret Running the standalone deploy Architecture principles Service orientation (SOA/microservices) Performance Scalability/Resiliency
分享到:
收藏