1 / 20

Three-tier architecture

Three-tier architecture. Presentation. Service Layer. Business Logic. Domain Model. Data source. Concurrency. Often in service layer Keep domain model independent of technology Keep presentation layer simple

more
Télécharger la présentation

Three-tier architecture

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Three-tier architecture Presentation Service Layer Business Logic Domain Model Data source

  2. Concurrency • Often in service layer • Keep domain model independent of technology • Keep presentation layer simple • “On-line” locking is when a business transaction is the same as a database transaction. The DBMS handles these. • Concurrency makes life difficult • “On-line” locking is less difficult

  3. Concurrency problem • Airline reservation system • Tell customer whether there are seats available at a certain price • If customer agrees, reserve a seat. • Stupid problem - give two customer the same seat • Unavoidable problem - inform customer that seat has already been taken

  4. Reserving a seat price = flight.lowestPrice(); … Transaction = session.beginTransaction(); if (flight.lowestPrice() >= price) flight.reserveAt(price); else … transaction.commit();

  5. Facts of concurrency control • Committing a transaction can fail • Failure is normal in concurrent systems • Should test failure case

  6. When you need offline concurrency patterns • When application spans several systems • And don’t want to use a “transaction monitor” • When application closes session but does not discard data

  7. Concurrency Patterns • Optimistic Offline Lock • Use timestamp to abort a process if another process interfered with it • Pessimistic Offline Lock • Use lock to keep other processes from accessing data • Coarse-Grained Lock • Use a single lock for a set of related objects. • Implicit Lock • Allow framework to acquire the locks

  8. Pessimistic Locking • “Real” locking. • Three step process • Lock all data you read and write • Make changes • Unlock data • Can fail because of deadlock • Never fails after work is done • Less concurrent than optimistic locking

  9. Optimistic “locking” • Optimistic concurrency control is not locking • Keep version number (time-stamp) on all data • To commit a transaction, check that all data has the right version number, then update. • Transaction commitment can fail • Works well when chance of two transactions changing the same data is small

  10. Service Layer • Service layer (and domain model) is often developed by more technical programmers. • Applications are usually developed by programmers who do not understand concurrency well • So, make the service layer responsible for concurrency control. • But sometimes concurrency control is hard to separate from presentation.

  11. Course-Grained Locking • Instead of locking each object individually, have a single lock for a set of objects. • Example: When editing an expense report, lock the entire report. • Prevents two people from editing the same report • Very simple

  12. Fowler’s First Law of Distributed Object Design • Don’t distribute your objects • First, distribute presentation layer. Next, distribute data source. As a last resort, distribute domain layer.

  13. Myth of Distribution and Objects • In OOP, objects will “send messages” to each other. • Thus, it is easy to build distributed systems from objects. • Just build a normal OO system • Decide which objects run on which machine • Use proxies to talk to remote objects

  14. Sad Reality • Good OO design is usually not a good distributed design • Fine grained objects cause performance problems • Reliability – operations can fail • Synchronization – more concurrency

  15. What to do? • Divide system into subsystems • Represent each subsystem with a “remote façade” • Ensure that data that is passed to and from a remote façade is a “data transfer object” and not a pointer to a real object

  16. Remote Facade • Fine grained objects are the right answer for complex logic. • Coarse-grained objects are the right answer for distributed systems. • Remote Façade puts a “thin skin” on a group of fine-grained objects to make it be a single large object.

  17. Three-tier architecture Presentation Remote Facade Service Layer Business Logic Domain Model Data source

  18. Data Transfer Object • To avoid multiple calls to a Remote Façade, put all the data needed in one object. • DTO is the collection of data needed by a call. • Think of DTO as “encapsulated XML” • Normally a DTO is bad object design, but it is necessary for distributed systems

  19. Subsystems • Eric Evans says to divide a domain if several groups of people work on it or if group gets too large • Divide domain if parts are on different servers

  20. Subsystem • Divide a system into parts if different groups work on them or they get too large. Put the parts on different servers if necessary. • Each part has a façade. If necessary, make it a remote façade.

More Related